Organising notifications to Slack business chat

Most ETL processes are set up to run automatically, without direct human involvement. An analyst creates a script, which is then executed by the server on a set schedule or in response to a specific trigger. However, there is often a need to check the script execution results for errors and provide business users with a brief text report.

To automate such checks and minimize manual intervention when everything goes as planned, a notification mechanism has been developed. In this demo, we will show how you can set up notifications in your Slack business chat.

Note: The demo example has a limitation in demonstrating all capabilities when running on the demo stand (Launch Demo). We recommend installing the example locally.

Launch demo

Download example

Algorithm description

1. Data import and problem statement

Data Import

First, let's enter the Import data supernode and load a Megaladata File with the following fields:

Name Description
String type order_id order identifier
String type meal_id product identifier
String type company_id company identifier
String type participants customers
Integer type meal_price meal cost
String type type_of_meal meal type
Date/time type date order date

In this demo example, our goal is to configure a weekly report based on the input data of a restaurant. We want to send text notifications with the report results to Slack.

2. Data transformation

Customer count

At this step, we need to determine the number of clients ordering a meal. Field Participants contains a list of customers. Using Calculator, we find out how many clients participated in each order. To do this, we count ' characters in each line and divide the result by 2:

RegExMatchCount("'", participants) / 2 — the RegExMatchCount function counts the occurrences of specified characters in a string.

After calculation, we get the field Count participant that contains the number of clients.

Counting other metrics

The Grouping by type node calculates the total amount for each type of the orders (breakfast, lunch, or dinner).

  • Group - type_of_meal
  • Parameters - meal_price (Sum)

The Count participant node is another grouping node, which calculates the total number of clients.

  • Parameters - count_participant (Sum)

Node Average bill calculates the average order value.

  • Parameters - meal_price (Avg)
Combining parameters in a single table

The Column Union component is used to combine all the calculated indicators. The node settings remain as default.

3. Sending notifications

Configuring Slack

Create a new application in Slack

  • Go to Slack API and log in to your account.
  • Click on the "Create New App" button
  • Enter the name of the app and select the Slack workspace in which it will be used
  • Click on the "Create App" button

Configure Incoming Webhooks

  • Go to the "Incoming Webhooks" section in the application control panel
  • Activate the "Activate Incoming Webhooks" option by switching the slider
  • Click "Add New Webhook to Workspace"
  • Select the channel to which the notifications will be sent or the user to receive the notifications, and click "Authorize"
  • Copy the URL webhook that will be used to send messages to Slack
Request message

According to the Slack chatbot documentation, the request will be sent in JSON format.

{"text": "Hello, World!"}.

The Prepare msg node is where we write the request text in the text field:

Concat("Report generated. ", type_of_meal, " - ", meal_price_sum, ". ", Data("type_of_meal",1), " - ", Data("meal_price_sum",1), " . ", Data("type_of_meal",2), " - ", Data("meal_price_sum",2), " . Participants per week - ", count_part, ". ", "Average bill - ", Int(meal_price_avg), ".")

Result: Report generated. Breakfast - 1669719. Lunch - 1675184 . Dinner - 1706702 . Clients per week - 20831. Average bill - 403.

For the body field, JSON format is generated:

Concat("{", chr(34), "text" , chr(34), ":",chr(34), Text, chr(34), "}"); function chr(34) returns a quotation mark.

REST request

On the Connections page, we configure a connection to send the request. The configuration is as follows:

  • Service URL: https://hooks.slack.com/services/token; the token value is contained in the Slack app settings
  • Method: POST

We employ a REST Service component which can be found on the Connections tab.

The REST request node receives the request body through the table port and the connection data through a special Connection port. Then, it sends a POST request and returns a response. The node settings are:

  • Message body field: body
  • The rest of the settings are default

If the request is successfully sent, the server response displays Ok.

What a notification looks like in Slack:

Result
Picture 1. Result

Download and open the file in Megaladata. If necessary, you can install the free Megaladata Community Edition.

Download Demo Example

results matching ""

    No results matching ""