denis-korolev/mattermost-webhook

Mattermost Webhook发送消息的库

1.0.2 2020-12-04 20:27 UTC

This package is auto-updated.

Last update: 2024-09-19 01:45:51 UTC


README

Test status on master

与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[],您可以将它发送出去。它会将文本分页并使用```引用,所以您只需发送它,它就会在聊天中依次打印。