thibaud-dauce / laravel-notifications-mattermost
通过 Mattermost 发送 Laravel 通知
1.6.0
2024-04-30 10:45 UTC
Requires
- php: >=5.6.4
- illuminate/notifications: ^5.3|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0
- thibaud-dauce/mattermost-php: ^1.0
README
安装
composer require thibaud-dauce/laravel-notifications-mattermost
在 Mattermost 中创建你的 webhook URL
遵循官方文档 https://docs.mattermost.com/developer/webhooks-incoming.html。
用法
<?php namespace App\Notifications; use Illuminate\Bus\Queueable; use Illuminate\Notifications\Notification; use ThibaudDauce\Mattermost\MattermostChannel; use ThibaudDauce\Mattermost\Message as MattermostMessage; class TicketWasOpenedByCustomer extends Notification { use Queueable; /** * Get the notification's delivery channels. * * @param mixed $notifiable * @return array */ public function via($notifiable) { return [MattermostChannel::class]; } /** * Get the Mattermost representation of the notification. * * @param mixed $notifiable * @return \ThibaudDauce\Mattermost\Message */ public function toMattermost($notifiable) { return (new MattermostMessage) ->username('Helpdesk') ->iconUrl(url('/images/logo_only.png')) ->text("A new ticket has been opened.") ->attachment(function ($attachment) { $attachment->authorName($notifiable->name) ->title("[Ticket #1] Title of the ticket", '/tickets/1') ->text("Message of **the ticket**"); // Markdown supported. }); } }
有关 Message
和 Attachment
的所有可能性,请参阅 https://github.com/ThibaudDauce/mattermost-php。
消息路由
… /** * Route notifications for the Mattermost channel. * * @return int */ public function routeNotificationForMattermost() { return $this->mattermost_webhook_url; } …