DEV Community

Cover image for Magento 2 Slack Notifier Module
Hamza Hannad
Hamza Hannad

Posted on

4

Magento 2 Slack Notifier Module

Overview
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.

Features

  • Sends logger exceptions to a Slack channel
  • Configurable log levels (Alert, Debug, Critical, Info, Error, Emergency, Notice, Warning)
  • Option to use synchronous or asynchronous sending
  • Custom message service to send messages to specified channels with async/sync options (for developers)

Installation

Using Composer
Navigate to your Magento 2 root directory.

Require the module using Composer:
composer require magify/magento2-module-slacknotifier

Enable the module:
php bin/magento module:enable Magify_SlackNotifier

Run the setup upgrade command:
php bin/magento setup:upgrade

Configuration

In the Magento admin panel, navigate to Stores > Configuration > Advanced > Developer > Slack Notifier.

Configure the following settings:

  • Activate: Enable or disable the Slack notifier module.
  • Use Async Send: Select whether to send messages asynchronously or synchronously.
  • API Timeout: Set the timeout duration in seconds for API calls. Use 0 for an indefinite wait.
  • Logger Type: Select the log types to send to Slack (e.g., Alert, Debug, Critical, etc.).
  • URL: The Slack API URL. Typically, this will be https://slack.com/api/chat.postMessage.
  • Channel ID: The ID of the Slack channel where messages will be sent.
  • Token: Your Slack app token.

Usage
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.

Custom Message Service

Overview
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.

Note
If the channel and token are not set in the function parameters, the service will use the values configured in the Magento admin panel.

Usage
Here is an example of how to use the custom message service in your Magento 2 module:

1 - 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);
    }
}
Enter fullscreen mode Exit fullscreen mode

2 - Call the notifyMessage method with your title, message, channel ID, token and sending type (async/sync).

Support
For support and feature requests, please open an issue on the GitHub repository.

Image of AssemblyAI tool

Challenge Submission: SpeechCraft - AI-Powered Speech Analysis for Better Communication

SpeechCraft is an advanced real-time speech analytics platform that transforms spoken words into actionable insights. Using cutting-edge AI technology from AssemblyAI, it provides instant transcription while analyzing multiple dimensions of speech performance.

Read full post

Top comments (1)

Collapse
 
viraxpress profile image
ViraXpress

Hi @hamza_hannad this is Insightful! We have developed a new theme/frontend for Magento. Kindly have a look at it!
viraxpress.com

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay