ohffs/laravel-msteams-alerts
向 MS Teams 发送消息
1.2.1
2023-04-05 13:13 UTC
Requires
- php: ^8.0
- illuminate/contracts: ^8.73|^9.0|^10.0
- spatie/laravel-package-tools: ^1.9.2
Requires (Dev)
- nunomaduro/collision: ^5.10|^6.0
- nunomaduro/larastan: ^1.0|2.0
- orchestra/testbench: ^6.22
- pestphp/pest: ^1.21
- pestphp/pest-plugin-laravel: ^1.1
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
- phpunit/phpunit: ^9.5
- spatie/laravel-ray: ^1.26
README
此包可以快速将警报发送到 Microsoft Teams。您可以使用此功能通知自己在 Laravel 应用中发生的任何重要事件。这是 Spatie 的 laravel-slack-alerts 的分支,因此所有感谢都归功于他们所做的主要工作。我基本上只是将 'Slack' 改为 'MSTeams'。
use Ohffs\MSTeamsAlerts\Facades\MSTeamsAlert; MSTeamsAlert::message("You have a new subscriber to the {$newsletter->name} newsletter!");
在底层,使用一个任务与 MS Teams 进行通信。这可以防止在 Teams 不可用时您的应用程序失败。
想要发送警报到 Discord 或 Slack 代替?请查看 laravel-discord-alerts 和 laravel-slack-alerts。
安装
您可以通过 composer 安装此包
composer require ohffs/laravel-msteams-alerts
您可以为包含有效的 Teams webhook URL 的 MSTEAMS_ALERT_WEBHOOK
环境变量设置值。您可以在 Teams 文档中了解如何获取 webhook URL (请参阅 Teams 文档)。
或者,您可以使用以下命令发布配置文件
php artisan vendor:publish --tag="msteams-alerts-config"
这是已发布配置文件的内容
return [ /* * The webhook URLs that we'll use to send a message to Teams. */ 'webhook_urls' => [ 'default' => env('MSTEAMS_ALERT_WEBHOOK'), ], /* * This job will send the message to Teams. You can extend this * job to set timeouts, retries, etc... */ 'job' => Ohffs\MSTeamsAlerts\Jobs\SendToMSTeamsChannelJob::class, ];
用法
要向 Teams 发送消息,只需调用 MSTeamsAlert::message()
并传递您希望的消息。
MSTeamsAlert::message("You have a new subscriber to the {$newsletter->name} newsletter!");
使用多个 webhook
您还可以在配置文件中指定额外的 webhook,以使用备用 webhook。
// in config/msteams-alerts.php 'webhook_urls' => [ 'default' => 'https://hooks.office.com/services/XXXXXX', 'marketing' => 'https://hooks.office.com/services/YYYYYY', ],
可以使用 to
函数选择要使用的 webhook。
use Ohffs\MSTeamsAlerts\Facades\MSTeamsAlert; MSTeamsAlert::to('marketing')->message("You have a new subscriber to the {$newsletter->name} newsletter!");
使用自定义 webhook
to
函数还支持自定义 webhook URL。
use Ohffs\MSTeamsAlerts\Facades\MSTeamsAlert; MSTeamsAlert::to('https://custom-url.com')->message("You have a new subscriber to the {$newsletter->name} newsletter!");
测试
composer test
更新日志
请参阅 更新日志 了解最近更改的详细信息。
贡献
请参阅 贡献指南 了解详细信息。
安全漏洞
请参阅 我们的安全策略 了解如何报告安全漏洞。
致谢
许可协议
MIT 许可协议(MIT)。请参阅 许可文件 了解更多信息。