thibaud-dauce/mattermost-php

Mattermost PHP 驱动程序,用于发送传入的 webhooks

1.3.0 2020-11-26 13:26 UTC

This package is auto-updated.

Last update: 2024-09-08 20:34:05 UTC


README

此驱动程序允许您为 传入的 webhooks 发送消息。

安装

使用 composer 安装项目

  composer require thibaud-dauce/mattermost-php

使用/示例

以下是从 tests/test.php 的完整示例

<?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*.')
    ->channel('tests')
    ->username('A Tester')
    ->iconUrl('https://upload.wikimedia.org/wikipedia/fr/f/f6/Phpunit-logo.gif')
    ->attachment(function (Attachment $attachment) {
        $attachment->fallback('This is the fallback test for the attachment.')
            ->success()
            ->pretext('This is optional pretext that shows above the attachment.')
            ->text('This is the text. **Finaly!**')
            ->authorName('Mattermost')
            ->authorIcon('http://www.mattermost.org/wp-content/uploads/2016/04/icon_WS.png')
            ->authorLink('http://www.mattermost.org/')
            ->title('Example attachment', 'http://docs.mattermost.com/developer/message-attachments.html')
            ->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)
            ->imageUrl('http://www.mattermost.org/wp-content/uploads/2016/03/logoHorizontal_WS.png')
            ->action([
                'name' => 'Some button text',
                'integration' => [
                    'url' => 'https://my-post-api.example.org',
                    'context' => [
                        'user_id' => '123',
                        'secret_key' => 'bépo22',
                    ],
                ]
            ]);
    });

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

您可以通过运行 php tests/test.php 来玩转它,在设置好服务器的传入 webhook URL 后。