testmonitor / teams-client
The TestMonitor Teams Client.
Installs: 1 831
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 2
Open Issues: 1
Requires
- php: ^8.1
- sebbmeyer/php-microsoft-teams-connector: ^0.2.2
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.0
- mockery/mockery: ^1.4
- phpunit/phpunit: ^10.0
- scrutinizer/ocular: ^1.9
- squizlabs/php_codesniffer: ^3.7
README
This package provides a very basic, convenient, and unified wrapper for sending messages to Microsoft Teams using an incoming webhook.
It's mostly a based on Sebastian Bretschneider's PHP Microsoft Teams Connector, but uses Guzzle instead of the PHP CURL extension. This package exposes the excellent Card objects from PHP Microsoft Teams Connector to build all kinds of messages using a fluent PHP syntax.
Table of Contents
Installation
To install the client you need to require the package using composer:
$ composer require testmonitor/teams-client
Use composer's autoload:
require __DIR__.'/../vendor/autoload.php';
You're all set up now!
Usage
Before you can post messages, you need to set up an incoming webhook in Teams:
- Launch the Microsoft Teams application.
- Select the Teams tab.
- Select a team.
- Right-click on the channel you want the messages to be delivered and select Connectors.
- Select the "Incoming Webhook" connector and click Add.
- Provide your webhook with a name and optionally, a logo.
- Click Create and your webhook URL will be provided.
Use the webhook URL to create a new client instance:
$teams = new \TestMonitor\Teams\Client('https://webhook.url/');
Examples
Post a simple message to Teams:
$card = new \TestMonitor\Teams\Resources\SimpleCard([ 'title' => 'Some title', 'text' => 'Hello World!', ]); $teams->postMessage($card);
The built-in connector package allows way more comprehensive messages. Here's another example:
$user = (object) ['name' => 'John Doe']; $card = new \TestMonitor\Teams\Resources\CustomCard('New Issue', "{$user->name} created a new issue"); $card->setColor('7FB11B') ->addFacts('Issue **I365**', [ 'Status' => '**Open**', 'Priority' => '**High**', 'Resolution' => '**Unresolved**', ]) ->addAction('Open in TestMonitor', 'https://www.testmonitor.com/'); $teams->postMessage($card);
For more information on composing these messages, head over to PHP Microsoft Teams Connector for more examples or refer to Microsoft's Build cards and task modules documentation.
Tests
The package contains integration tests. You can run them using PHPUnit.
$ vendor/bin/phpunit
Changelog
Refer to CHANGELOG for more information.
Contributing
Refer to CONTRIBUTING for contributing details.
Credits
- Thijs Kok - Lead developer - ThijsKok
- Stephan Grootveld - Developer - Stefanius
- Frank Keulen - Developer - FrankIsGek
- Muriel Nooder - Developer - ThaNoodle
License
The MIT License (MIT). Refer to the License for more information.