talvbansal / laravel-ms-teams-notification-channel
Laravel 基础 MS Teams 通知通道
资助包维护!
talvbansal
paypal.me/talvbansal
Requires
- php: ^7.2 || ^8.0
- guzzlehttp/guzzle: ^7.0
- illuminate/notifications: ^6.0 || ^7.0 || ^8.0 || ^9.0
- illuminate/support: ^6.0 || ^7.0 || ^8.0 || ^9.0
Requires (Dev)
- ext-json: *
- mockery/mockery: ^1.0
- orchestra/database: ^4.0 || ^5.0 || ^6.0
- orchestra/testbench: ^4.0 || ^5.0 || ^6.0
- phpunit/phpunit: ^8.0 || ^9.0
This package is auto-updated.
Last update: 2024-09-20 13:43:35 UTC
README
此包使您能够通过 Laravel 5.5+ - 8.0 向 MS Teams 发送通知,非常简单。
内容
安装
您可以通过 composer 安装此包。
composer require talvbansal/laravel-ms-teams-notification-channel
设置连接器
请参阅 这篇文章 以设置并将 webhook 连接器添加到您的 MS Team 频道。
然后,配置您的 webhook url
// config/services.php ... 'ms-teams' => [ 'webhook_url' => env('MS_TEAMS_WEBHOOK_URL', 'WEBHOOK URL HERE') ], ...
您可以将其更改为任何您喜欢的,如果您想向多个团队发送通知,可以执行以下操作
// config/services.php ... 'ms-teams' => [ 'developers_webhook_url' => env('MS_TEAMS_DEVELOPERS_WEBHOOK_URL'), 'helpdesk_webhook_url' => env('MS_TEAMS_HELPDESK_WEBHOOK_URL'), ], ...
只要您记得将通知路由到正确的团队。
使用
现在您可以在 Notification 类中的 via() 方法中使用此通道。
通知
use NotificationChannels\MsTeams\MsTeamsChannel; use NotificationChannels\MsTeams\MsTeamsMessage; use Illuminate\Notifications\Notification; class InvoicePaid extends Notification { public function via($notifiable) { return [MsTeamsChannel::class]; } public function toMsTeams($notifiable) { $url = url('/invoice/' . $this->invoice->id); return MsTeamsMessage::create() // Optional recipient user id. ->to(config('services.ms-teams.webhook_url')) // Markdown supported. ->content("Hello there!\nYour invoice has been *PAID*") // (Optional) Inline Buttons ->button('View Invoice', $url) ->button('Download Invoice', $url) // (Optional) Supporting images ->image('https://source.unsplash.com/random/800x800?animals,nature&q='.now()) ->image('https://source.unsplash.com/random/900x600?building,car&q='.now()); } }
路由消息
您可以通过向 to($url) 方法提供收件人的 webhook url 来发送通知,如上例所示,或者在你的 notifiable 模型中添加 routeNotificationForMsTeams() 方法
... /** * Route notifications for the MS Teams channel. * * @return int */ public function routeNotificationForMsTeams() { return config('services.ms-teams.webhook_url'); } ...
可用的消息方法
to($webhookUrl): (string)
收件人的聊天 ID。title(''): (string)
通知标题,不支持 markdown。content(''): (string)
通知消息,支持 markdown。button($text, $url): (string)
添加内联“操作”按钮。您可以添加任意多个。image($url): (string)
从给定的 URL 添加内联图像。您可以添加任意多个。code($code): (string)
在消息中添加代码片段。您可以添加任意多个。type($type): (string)
改变发送卡片的高亮。您可以选择 'info', 'warning', 'error', 'success'。
更多示例和有关此包的信息可以在此处找到 这里。
限制通知
如果您发现您接收到的某个通知太多,您可以使用 此包 来帮助限制在出现问题时一定时间内您接收到的通知数量。
变更日志
有关最近更改的更多信息,请参阅 CHANGELOG。
测试
$ composer test
安全
如果您发现任何安全问题,请通过 :author_email 发送电子邮件,而不是使用问题跟踪器。
贡献
有关详细信息,请参阅 CONTRIBUTING。
鸣谢
许可
MIT 许可证 (MIT)。请参阅 许可文件 以获取更多信息。
有关提交通道建议的说明,请参阅 此存储库。