Skip to end of banner
Go to start of banner

Slack Listener Module Use Case

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 9 Next »

In this Article

Use Case: Using Slack Snap Pack To Design an Event Listener for Slack Workspace

In any enterprise ecosystem, receiving notifications is critical to carry out your daily tasks. Emails are no longer the preferred method of receiving notifications, especially when the notifications involve time-critical issues. Managers usually run on a time crunch; to fasten the decision-making process and deliver results, they can configure an Event Listener in their Slack workspace to cut through the clutter and get notified on items that need their immediate attention. This use case demonstrates how we can use the Slack Snap Pack to route events that are important to the manager into a custom channel created for this purpose.

Problem

In a real business case scenario, checking for all messages on the Slack Channel is time-consuming and owing to the the hectic schedule of managers leaves them with little time to go through all the messages posted on Slack. However they cannot miss on important updates that requires their attention. 

Solution

Using Slack integration for your organization allows you to set up notifications to send messages to a Slack private channel or a specific user on Slack. We can efficiently automate the process of listening to Slack events, configuring the events, and receiving alerts on your Slack Channel upon the trigger of events. This Pipeline demonstrates how we can automate the process of receiving alerts on the private channel when these events are triggered.

Parent Pipeline - Slack ListenerChild Pipeline - Process Event

Download the Slack Pipelines. 

Understanding the Slack Pipeline

In this Use Case, we want to configure the following two events and receive alerts when these events occur:

  • Event 1: When a new member joins the SWAT channel.
  • Event 2: When a SWAT ticket is posted in the channel.

This example assumes that you have: 

  • Created an app in your Slack Workspace that listens to the Slack instance.
  • Set the required scopes. In this case we set the Bot and User Token scopes to perform the following actions:
    • Add read channels, read messages, and read users.
    • Add write messages and read channels.

Building this Pipeline involves the following key steps:

  1. Create a Private Channel in Sack.
  2. Subscribe to the Slack events.
    1. Verify URL
  3. Create a Child Pipeline.
  4. Create a Parent Pipeline.

Create a Private Channel in Slack

Create a private channel named Alerts, and add the necessary stakeholders who should be alerted for the given events.

Subscribe to Slack Events

To configure events in Slack:

  1. Navigate to https://api.slack.com/apps - Slack Apps page.
  2. Click Event Subscriptions in the left navigation pane.
  3. Enable the toggle for Enable Events.
  4. Subscribe to the events you want to listen.
    1. Bot events: Whenever a bot performs the operation of adding a user to channel, we want to receive an alert.
    2. User events on behalf of the user: Whenever a user posts a message to public channel, private channel, individual user or multiple users or group of users, we want to receive an alert.
  5. Provide the URL of the triggered task of the Parent Pipeline in the Request URL field.
  6. To provide the Request URL in Slack, you need to configure a Pipeline.
    1. Configure a Mapper Snap as follows for verification.
    2. Create a a triggered task for the Pipeline.
    3. Copy the cloud URL and HTTP Header (token) and paste it in Request URL field in Slack app for verification. The bearer token has to be appended to the URL. 
      After the URL is verified, the Verified text appears next to the URL with a check mark. Once you save the changes, the URL is registered.

      The redirect URL should correspond to the same URL used for event subscription.


Create a Parent Pipeline - Slack Listener

We configure the parent Pipeline to perform following operations:

  1. If the Slack sends a challenge, the Pipeline sends it back.
  2. If the Slack sends event details, the Pipeline processes it as per the requirement.

First, we configure the Mapper Snap with an expression to determine if the object is a challenge or an event.

Expression

$.keys().length == 3 && $.hasPath("token") && $.hasPath("challenge") && $.get("type") == 'url_verification' ? {"challenge":$challenge} : (_X_SLACK_RETRY_NUM > 1 ? {"result":"processed already"} : $)

There are three elements in this expression: Token, Challenge and Type with the value URL verification.

  • If the element is a challenge, the Snap sends the JSON response containing the challenge.
  • If the element is an event, the Snap checks whether it is Retry or not, because most often the Pipeline may take more time to process events. Hence, if the Slack application does not get response in three seconds, the Snap retriggers the Pipeline.
  • If it is a retry, the Snap sends the JSON object without processing it. If it is a not a retry, the Snap sends the event for further processing.


Next, we configure the Router Snap with expressions that evaluate whether the input view contains a challenge or an event and routes the outputs appropriately.

If the input is an event, the Router Snap routes the output to the Pipeline Execute Snap that runs the child Pipeline to process the event in the Process_Event Pipeline.

As the triggered task has one output view, we use the Join Snap to join both the output views of Pipeline Execute and Mapper Snaps using left outer join.

Create a Child Pipeline to Process Events

This sample Pipeline uses JSON Generator to source the input (while reading the event) from the Parent Pipeline.

We configure the child Pipeline to perform the following operations:

  1. Determine the type of event and route the flow appropriately.
      • Event 1: When a new member joins the SWAT channel.
      • Event 2: When a new SWAT ticket is posted in the channel.

        You can configure the Pipeline to process more events based on your need.

  1. Join the output views from output views from the Slack User Operations and Channel Operations Snaps to route the final output to the Parent Pipeline.

To this end, we configure the Router Snap to decide on the type of event, whether it is a new member joining the channel or a message posted in the channel.

If it is a message event, we want to check if the message contains the key word SWAT. Hence, we configure the Filter Snap as follows:

If the message contains SWAT, we intend to send the alert to the channel. To this end, we configure the Slack Send Channel Message Snap with relevant Slack message as follows:

If a member joins a channel, the Snap extracts the information relating to the member and the channel. To this end, we configure the following Snaps:

User Operations Snap
Channel Operations Snap

We configure the Mapper Snap to extract the name of the user and map it to the channel.

Next, we join the inputs from the Slack User Operations and Channel Operations Snaps using the Outer join of Join Snap to create a user alert.

We configure the Slack Send Message Snap to send alerts.

Finally, we configure the Join Snap to get a single output from the two output views.

Downloads

  File Modified
No files shared here yet.

  • No labels