mwakaambrose/laravel-slack-alert 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

mwakaambrose/laravel-slack-alert

Composer 安装命令:

composer require mwakaambrose/laravel-slack-alert

包简介

Send a message to Slack

README 文档

README

This package can quickly send alerts to Slack. You can use this to notify yourself of any noteworthy events happening in your app.

use MwakaAmbrose\SlackAlert\Facades\SlackAlert;

SlackAlert::string("You have a new subscriber to the {$newsletter->name} newsletter!");

Under the hood, a job is used to communicate with Slack. This prevents your app from failing in case Slack is down.

Installation

You can install the package via composer:

composer require mwakaambrose/laravel-slack-alert

You can set a SLACK_ALERT_WEBHOOK env variable containing a valid Slack webhook URL. You can learn how to get a webhook URL in the Slack API docs.

Alternatively, you can publish the config file with:

php artisan vendor:publish --tag="slack-alert-config"

This is the contents of the published config file:

return [
    /*
     * The webhook URLs that we'll use to send a message to Slack.
     */
    'webhook_urls' => [
        'default' => env('SLACK_ALERT_WEBHOOK'),
    ],
];

Usage

To send a message to Slack, simply call SlackAlert::string() and pass it any message you want.

SlackAlert::string("You have a new subscriber to the {$newsletter->name} newsletter!");

Using multiple webhooks

You can also use an alternative webhook, by specify extra ones in the config file.

// in config/slack-alert.php

'webhook_urls' => [
    'default' => 'https://hooks.slack.com/services/XXXXXX',
    'marketing' => 'https://hooks.slack.com/services/YYYYYY',
],

The webhook to be used can be chosen using the to function.

use MwakaAmbrose\SlackAlert\Facades\SlackAlert;

SlackAlert::to('marketing')->string("You have a new subscriber to the {$newsletter->name} newsletter!");

Using a custom webhooks

The to function also supports custom webhook urls.

use MwakaAmbrose\SlackAlert\Facades\SlackAlert;

SlackAlert::to('https://custom-url.com')->message("You have a new subscriber to the {$newsletter->name} newsletter!");

Formatting

Markdown

You can format your messages with Slack's markup. Learn how in the Slack API docs.

use MwakaAmbrose\SlackAlert\Facades\SlackAlert;

SlackAlert::string("A message *with some bold statements* and _some italicized text_.");

Links are formatted differently in Slack than the classic markdown structure.

SlackAlert::string("<https://theonehq.com|This is a link to our homepage>");

Emoji's

You can use the same emoji codes as in Slack. This means custom emoji's are also supported.

use MwakaAmbrose\SlackAlert\Facades\SlackAlert;

SlackAlert::string(":smile: :custom-code:");

Mentioning

You can use mentions to notify users and groups. Learn how in the Slack API docs.

use MwakaAmbrose\SlackAlert\Facades\SlackAlert;

SlackAlert::string("A message that notifies <@username> and everyone else who is <!here>")

Sending an exception

Yo can send an exception to slack by calling the exception function and passing in any instance of throwable. You will receive the message, file, line number and apps environment on slack.

SlackAlert::to("failed_vsla_wallet")->exception(new \Exception("This is a test exception"));

More advanced

You can pass a callback function the returns an instance of SlackPhp\Blockkit\Surfaces\Message to construct your own robust message blocks in slack. See the packaages home for more information.

SlackAlert::to('failed_vsla_wallet')->send(function(){
    $msg = Message::new();
    // Then you can add blocks using the surface's available methods.
    $msg->text('Don\'t you just love Slack?');
    $msg->divider();
    $msg->newImage()
        ->title('Team Chat')
        ->url('https://imgs.xkcd.com/comics/team_chat.png')
        ->altText('Comic about the stubbornness of some people switching chat clients');

    return $msg;
});

Testing

composer test

Credits

License

The MIT License (MIT). Please see License File for more information.

mwakaambrose/laravel-slack-alert 适用场景与选型建议

mwakaambrose/laravel-slack-alert 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 755 次下载、GitHub Stars 达 0, 最近一次更新时间为 2022 年 08 月 25 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「laravel」 「slack」 「mwaka」 「ambrose」 「laravel-slack-alert」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 mwakaambrose/laravel-slack-alert 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 mwakaambrose/laravel-slack-alert 我们能提供哪些服务?
定制开发 / 二次开发

基于 mwakaambrose/laravel-slack-alert 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 755
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 11
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 42
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-08-25