The Magento 2 Slack Notifier module sends logger exceptions automatically to a specified Slack channel. This integration helps you stay updated with critical issues in your Magento store by sending real-time notifications directly to your Slack workspace.
composer require magify/magento2-module-slacknotifier
php bin/magento module:enable Magify_SlackNotifier
php bin/magento setup:upgrade
Stores > Configuration > Advanced > Developer > Slack Notifier
.Configure the following settings:
https://slack.com/api/chat.postMessage
.Once configured, the module will automatically send log exceptions of the specified types to your Slack channel. You can monitor these notifications to quickly respond to issues in your Magento store.
The custom message service allows developers to send any message to a specified Slack channel, with the option to choose between asynchronous or synchronous sending.
If the channel and token are not set in the function parameters, the service will use the values configured in the Magento admin panel.
Here is an example of how to use the custom message service in your Magento 2 module:
Inject the CustomMessage
in your class:
<?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);
}
}
Call the notifyMessage
method with your title, message, channel ID, token and sending type (async/sync).
For support and feature requests, please open an issue on the GitHub repository.
This module is licensed under the MIT License.