guywarner / laravel-google-chat-alerts
向GoogleChat发送消息
Requires
- php: ^8.0
- illuminate/contracts: ^8.73|^9.0|^10.0|^11.0
- spatie/laravel-package-tools: ^1.9.2
Requires (Dev)
- nunomaduro/collision: ^5.10|^6.0
- orchestra/testbench: ^6.22|^7.0|^8.0
- 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
This package is auto-updated.
Last update: 2024-09-25 18:51:39 UTC
README
此包可以快速将警报发送到Google Chat。您可以使用它来通知自己应用中发生的任何值得注意的事件。
是Spatie的Laravel Slack Alerts的硬分支Laravel Slack Alerts by Spatie
use GuyWarner\GoogleChatAlerts\Facades\GoogleChatAlert; GoogleChatAlert::message("You have a new subscriber to the {$newsletter->name} newsletter!");
在内部,使用作业与Google Chat进行通信。这可以防止您的应用在Google Chat宕机时失败。
想发送到Slack的警报?请查看laravel-slack-alerts。
想发送到GoogleChat的警报?请查看laravel-discord-alerts。
安装
您可以通过composer安装此包
composer require guywarner/laravel-google-chat-alerts
您可以为包含有效Google Chat webhook URL的GOOGLE_CHAT_ALERT_WEBHOOK
环境变量设置。您可以在[Google Chat API文档](https://api.Google Chat.com/messaging/webhooks)中了解如何获取webhook URL。
或者,您可以使用以下命令发布配置文件
php artisan vendor:publish --tag="google-chat-alerts-config"
这是已发布的配置文件的内容
return [ /* * The webhook URLs that we'll use to send a message to Google Chat. */ 'webhook_urls' => [ 'default' => env('GOOGLE_CHAT_ALERT_WEBHOOK'), ], /* * This job will send the message to Google Chat. You can extend this * job to set timeouts, retries, etc... */ 'job' => GuyWarner\GoogleChatAlerts\Jobs\SendToGoogleChatChannelJob::class, ];
用法
要向Google Chat发送消息,只需调用GoogleChatAlert::message()
并传递任何您想要的消息。
GoogleChatAlert::message("You have a new subscriber to the {$newsletter->name} newsletter!");
使用多个webhook
您还可以在配置文件中指定额外的webhook来使用备用webhook。
// in config/google-chat-alerts.php 'webhook_urls' => [ 'default' => 'https://chat.googleapis.com/v1/spaces/XXXX', 'sales' => 'https://chat.googleapis.com/v1/spaces/YYYYYY', ],
可以使用to
函数选择要使用的webhook。
use GuyWarner\GoogleChatAlerts\Facades\GoogleChatAlert; GoogleChatAlert::to('sales')->message("You have a new subscriber to the {$newsletter->name} newsletter!");
格式化
Markdown
您可以使用标记来格式化消息。有关如何在[Google Chat API文档](Google Chat API文档)中使用格式化文本的更多信息。
use GuyWarner\GoogleChatAlerts\Facades\GoogleChatAlert; GoogleChatAlert::message("A message *with some bold statements* and _some italicized text_.");
提及所有用户的消息
您可以使用与Google Chat相同的emoji代码。这意味着也支持自定义emoji。
use GuyWarner\GoogleChatAlerts\Facades\GoogleChatAlert; GoogleChatAlert::message("New support ticket. <users/all>");
测试
composer test
更新日志
请参阅CHANGELOG以获取有关最近更改的更多信息。
贡献
请参阅CONTRIBUTING以获取详细信息。
安全漏洞
请通过warnerdata@gmail.com或通过Twitter私信@DigiGuyDev进行报告。
鸣谢
许可
MIT许可证(MIT)。有关更多信息,请参阅许可证文件。