nycu-csit / laravel-mattermost
Mattermost Notification Channel for Laravel
dev-main
2025-09-28 15:19 UTC
Requires
- laravel/framework: ^10.0|^11.0|^12.0
Requires (Dev)
- laravel/pint: ^1.25
- orchestra/testbench: ^8.0|^9.0|^10.0
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^12.3
This package is auto-updated.
Last update: 2025-10-05 15:59:10 UTC
README
This package provides the custom Mattermost Notification Channel for Laravel 10+ applications.
Installation
Add following lines to your composer.json
:
"repositories": [ { "type": "vcs", "url": "https://github.com/nycu-csit/laravel-mattermost" } ], "require": { "nycu-csit/laravel-mattermost": "^0.1.0" }
Usage
-
Add Mattermost config in the
services.php
// services.php 'mattermost' => [ 'webhook_url' => env('MATTERMOST_WEBHOOK_URL'), ],
-
Use
MattermostChannel
invia
method, and definetoMattermost
method which should return an instance ofMattermostMessage
. You can return falsy value from that method to not send the message to Mattermost.<?php 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'); } }
Testing
./vendor/bin/phpunit