magdv / mattermost
Library to send messages with Mattermost Webhook
0.0.3
2024-07-03 10:05 UTC
Requires
- php: >=8.0
- ext-json: *
- nyholm/psr7: ^1.8
Requires (Dev)
- guzzlehttp/guzzle: ^7.8
- overtrue/phplint: ^2.0
- phpunit/phpunit: ^9.2
- psr/http-client: ^1.0
- roave/security-advisories: dev-master
- squizlabs/php_codesniffer: ^3.5
- vimeo/psalm: ^3.8
This package is auto-updated.
Last update: 2024-12-03 11:05:20 UTC
README
This library will help you send messages to Mattermost by Webhook.
Installation / Usage
Install the latest version via composer:
composer require magdv/mattermost
Here is an example of usage.
use MagDv\Mattermost\Attachment; use MagDv\Mattermost\Message; use MagDv\Mattermost\WebhookClient; use MagDv\Mattermost\WebhookParams; use GuzzleHttp\Client; // Any PSR7 Client $psr7Client = new Client(); $client = new WebhookClient( $psr7Client, 'http://matermost/hooks/2222222222', 'tester' ); $attachment = (new Attachment())->setFallback('This is the fallback test for the attachment.') ->setSuccessColor() ->setPretext('This is optional pretext that shows above the attachment.') ->setText('This is the text. **Finaly!** :let_me_in: '); // you can add array of attachments $message = new Message(); $message->setText('Testing Mattermost client') ->setAttachments([$attachment]) ->setChannel('town-square'); $client->send($message); // or $client->batchSend([$message]);
If you need to send huge text, more than 4000 symbols, you can use
$messages = MessageHelper::createMessagesWithTextAttachments( 'channelName' 'huge text, longer 4000 symbols' ); $client->batchSend(...$messages);
It will create Message[], which you can send. It will break text by pages and qoute it by ``` So you just send it and it will print at chat one after another.