PHP code example of magdv / mattermost

1. Go to this page and download the library: Download magdv/mattermost library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

magdv / mattermost example snippets


        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]);
 
    $messages = MessageHelper::createMessagesWithTextAttachments(
    'channelName'
    'huge text, longer 4000 symbols'
    );
    $client->batchSend(...$messages);