weboccult-laravel / slack-notifier
一个用于在Laravel中发送Slack消息的简单包。
1.0.3
2023-10-02 05:43 UTC
Requires
This package is auto-updated.
Last update: 2024-10-01 00:20:43 UTC
README
一个用于在Laravel中发送Slack消息的简单包。
安装
您可以通过Composer安装此包。
composer require weboccult-laravel/slack-notifier
配置
-
您需要在Slack工作空间中创建Slack通知器应用。
-
在您的Slack工作空间中启用“入站Webhooks”。
-
在您的Slack工作空间中生成Bot用户OAuth令牌。
-
在.env文件中设置SLACK_BOT_USER_OAUTH_TOKEN。
-
为频道创建一个入站Webhook。
-
在.env文件中设置这些频道。
-
根据您的需求设置“Bot Token Scopes”。
-
在
config/services.php
中设置认证令牌、频道及其Webhook。例如
'slack' => [ 'notifications' => [ 'bot_user_oauth_token' => env('SLACK_BOT_USER_OAUTH_TOKEN'), 'general' => env('SLACK_GENERAL_WEBHOOK_URL'), 'laravel-slack-demo' => env('SLACK_LARAVEL_SLACK_DEMO_WEBHOOK_URL'), ], ]
示例
-
简单消息
slack_send_message("Hello from *slack-notifier*","channel_name");
-
带标题的消息
slack_send_message_with_heading("Welcome to *slack-notifier*","New message for you :wave:","channel_name");
-
带有字段块的消息
- 无标题
slack_send_message_with_field_block("This is message for you",[ 'System Name' => config('app.name'), 'System URL' => config('app.url'), 'System Description' => 'Slack Notifier System' ],'general');
- 有标题
slack_send_message_with_field_block("This is message for you",[ 'System Name' => config('app.name'), 'System URL' => config('app.url'), 'System Description' => 'Slack Notifier System' ],'general', ":bell: Alert :bell:");