denis-korolev / mattermost-webhook
Mattermost Webhook发送消息的库
1.0.2
2020-12-04 20:27 UTC
Requires
- php: ^7.4
- ext-json: ^7.4
- guzzlehttp/guzzle: ^7.2
- nyholm/psr7: ^1.3
- psr/http-client: ^1.0
- webmozart/assert: ^1.6
Requires (Dev)
- overtrue/phplint: ^2.0
- phpunit/phpunit: ^9.2
- roave/security-advisories: dev-master
- squizlabs/php_codesniffer: ^3.5
- vimeo/psalm: ^3.8
This package is auto-updated.
Last update: 2024-09-19 01:45:51 UTC
README
与Matermost webhook协同工作的客户端
此库将帮助您通过Webhook向Mattermost发送消息。
安装/使用
通过composer安装最新版本
composer require denis-korolev/mattermost-webhook
以下是一个使用示例。
use App\Mattermost\Attachment; use App\Mattermost\Message; use App\Mattermost\WebhookClient; use App\Mattermost\WebhookParams; use GuzzleHttp\Client; // Any PSR7 Client $psr7Client = new Client(); $webhookParams = new WebhookParams('http://matermost/hooks/2222222222', 'town-square', 'tester'); $client = new WebhookClient($psr7Client, $webhookParams); $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('Testing Mattermost client', '', [$attachment]); $client->send($message); // or $client->batchSend([$message]);
如果您需要发送大量文本,超过4000个字符,您可以使用
$messages = MessageHelper::createMessagesWithTextAttachments('huge text, longer 4000 symbols'); $client->batchSend(...$messages);
它将创建Message[],您可以将它发送出去。它会将文本分页并使用```引用,所以您只需发送它,它就会在聊天中依次打印。