mnsr/laravel-slack

此软件包使向Slack频道发送通知变得更加容易

v1.0.1 2022-07-17 12:34 UTC

This package is not auto-updated.

Last update: 2024-09-23 05:32:39 UTC


README

创建Slack webhook

Slack API webhook 官方文档

将变量添加到.env文件中

# Add if you have a proxy (Ex. http://192.168.1.1:3128)
PROXY_URL=

# Get from Slack Api
LOG_SLACK_WEBHOOK_URL=https://hooks.slack.com/services/xxx/yyy/zzz

# Your default slack channel
SLACK_DEFAULT_CHANNEL="my_channel"

然后清除配置

php artisan config:cache

直接在代码中使用函数

$msg // required parameter
$title // optional parameter

slack_emergency($msg, $title);
slack_alert($msg, $title);
slack_critical($msg, $title);
slack_error($msg, $title);
slack_warning($msg, $title);
slack_notice($msg, $title);
slack_info($msg, $title);
slack_debug($msg, $title);

示例

try{
    // My Code xx ...
    slack_info('code xx finished successfully ..', 'my lovely title');
    // My Code yyy ...
}catch (Exception $exception){
    slack_error($exception->getMessage());
}