Mattermost PHP driver to send incoming webhooks

1.1.1 2018-03-06 14:04 UTC


This driver for Mattermost allows you to send message for incoming webhooks.

This is a full example from tests/test.php:


require __DIR__ . '/../vendor/autoload.php';

use GuzzleHttp\Client;
use ThibaudDauce\Mattermost\Mattermost;
use ThibaudDauce\Mattermost\Message;
use ThibaudDauce\Mattermost\Attachment;

$mattermost = new Mattermost(new Client);

$message = (new Message)
    ->text('This is a *test*.')
    ->username('A Tester')
    ->attachment(function (Attachment $attachment) {
        $attachment->fallback('This is the fallback test for the attachment.')
            ->pretext('This is optional pretext that shows above the attachment.')
            ->text('This is the text. **Finaly!**')
            ->title('Example attachment', '')
            ->field('Long field', 'Testing with a very long piece of text that will take up the whole width of the table. And then some more text to make it extra long.', false)
            ->field('Column one', 'Testing.', true)
            ->field('Column two', 'Testing.', true)
            ->field('Column one again', 'Testing.', true)
                'name' => 'Some button text',
                'url' => '',
                'context' => [
                    'user_id' => '123',
                    'secret_key' => 'bépo22',

$mattermost->send($message, 'https://your_mattermost_webhook_url');

You can play with it by running php tests/test.php after setting your incoming webhook URL for your server.