magify / magento2-module-slacknotifier
此 Magento 2 模块自动将每个日志异常发送到指定的 Slack 频道。
1.0.0
2024-07-19 08:33 UTC
Requires
- php: >=7.4
- magento/framework: 103.0.*
- magento/module-customer: 103.0.*
- magento/module-store: 101.1.*
Requires (Dev)
- roave/security-advisories: dev-latest
README
概述
The Magento 2 Slack Notifier 模块自动将日志异常发送到指定的 Slack 频道。此集成可以帮助您通过将实时通知直接发送到您的 Slack 工作空间,保持对您的 Magento 商店中关键问题的更新。
功能
- 将日志异常发送到 Slack 频道
- 可配置日志级别(警报、调试、关键、信息、错误、紧急、通知、警告)
- 同步或异步发送选项
- 自定义消息服务,用于使用异步/同步选项将消息发送到指定的频道(针对开发者)
安装
使用 Composer
- 导航到您的 Magento 2 根目录。
- 使用 Composer 需求模块
composer require magify/magento2-module-slacknotifier
- 启用模块
php bin/magento module:enable Magify_SlackNotifier
- 运行设置升级命令
php bin/magento setup:upgrade
配置
-
在 Magento 管理面板中,导航到
商店 > 配置 > 高级 > 开发者 > Slack Notifier
。 -
配置以下设置
- 激活:启用或禁用 Slack 通知器模块。
- 使用异步发送:选择是否异步或同步发送消息。
- API 超时:设置 API 调用的超时时间(秒)。使用 0 以无限期等待。
- 日志类型:选择要发送到 Slack 的日志类型(例如,警报、调试、关键等)。
- URL:Slack API URL。通常,这将是一个
https://slack.com/api/chat.postMessage
。 - 频道 ID:消息将被发送的 Slack 频道的 ID。
- 令牌:您的 Slack 应用程序令牌。
使用方法
一旦配置,该模块将自动将指定类型的日志异常发送到您的 Slack 频道。您可以监视这些通知,以便快速响应 Magento 商店中的问题。
自定义消息服务
概述
自定义消息服务允许开发人员将任何消息发送到指定的 Slack 频道,并可选择异步或同步发送。
注意
如果函数参数中没有设置频道和令牌,则服务将使用在 Magento 管理面板中配置的值。
使用方法
以下是如何在您的 Magento 2 模块中使用自定义消息服务的示例
-
在您的类中注入
CustomMessage
<?php namespace YourVendorName\SlackNotifier\Controller\Index; use Magento\Framework\App\Action\Action; use Magento\Framework\App\Action\Context; use YourVendorName\SlackNotifier\Model\CustomMessage; class Test extends Action { protected $customMessage; public function __construct(Context $context, CustomMessage $customMessage) { $this->customMessage = $customMessage; parent::__construct($context); } public function execute() { $title= "This is a test title"; $message = "This is a test message"; $async = false; // or true based on your requirement $channel = "your-channel-id"; $token = "your-token"; $this->customMessage->notifyMessage($title, $message, $async, $channel, $token); } }
-
使用您的标题、消息、频道 ID、令牌和发送类型(异步/同步)调用
notifyMessage
方法。
支持
有关支持和功能请求,请在 GitHub 仓库 上打开一个问题。
许可
此模块受 MIT 许可证的许可。