PHP code example of nycu-csit / laravel-mattermost

1. Go to this page and download the library: Download nycu-csit/laravel-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/ */

    

nycu-csit / laravel-mattermost example snippets


    // services.php
    'mattermost' => [
        'webhook_url' => env('MATTERMOST_WEBHOOK_URL'),
    ],
    

    

    namespace App\Notifications;

    use NycuCsit\LaravelMattermost\MattermostChannel;
    use NycuCsit\LaravelMattermost\MattermostMessage;
    use Illuminate\Bus\Queueable;
    use Illuminate\Notifications\Notification;

    class NotifyMeetingStartEnd extends Notification
    {
        use Queueable;

        public function __construct(private Meeting $meeting)
        {
        }
        /**
        * Get the notification channels.
        */
        public function via(object $notifiable)
        {
            return [MattermostChannel::class];
        }

        /**
        * Get the payload of the mattermost webhook.
        * See on the [official website](https://developers.mattermost.com/integrate/webhooks/incoming/#parameters).
        * 
        * Notification can exit early without actually sending to Mattermost
        * channel by returning from falsy value.
        */
        public function toMattermost(object $notifiable)
        {
            // exit early
            if ($this->meeting->started) {
                return null;
            }
            // https://developers.mattermost.com/integrate/webhooks/incoming/#parameters
            return (new MattermostMessage)
                ->text('...')
                ->channel('town-square');
        }
    }