Prerequisites

For sending notifications through Slack, you’ll need to create a Slack App. This App will basically be responsible for sending notifications to users / channels in their Slack workspace. To create Slack App, you’ll need a Slack account and a Slack workspace where you’ll be configuring the App. You will also need permission to create a Slack app. If you do not have access already, you can create your own free Slack workspace.

  1. Create a Slack Account

  2. Create a Slack Workspace

  3. Create a Slack App

What all is covered here?

In this documentation, we’ll create an app to send direct messages to users or channels in a slack workspace. Here’s an overview of the steps required to integrate and send messages to a slack workspace:

  1. Enable Slack Channel on SuprSend Platform

  2. Create Slack App - You’ll use this app to send direct messages to a user or channel

  3. Building OAuth flow to get the user permission and access token to send them notifications. This information will be stored as user’s slack channel information. Unlike email where if you know user’s email id, you can send email to that user. In case of Slack, your users have to authenticate and allow your app to send them notifications on Slack.

By following the above steps, your Slack integration will be setup. The next steps will be to

  1. Update slack channel information in user or channel profile to send message

  2. Create a Slack template and trigger workflow

This is how you get started:

Enable Slack Channel on SuprSend vendor page

Go to SuprSend dashboard -> Slack Vendor Settings page. Enable Slack channel

Create Slack App

You’ll need to create a Slack app and assign required OAuth Scopes to that App to send notifications via SuprSend. If you have an existing Slack app, you can directly go to OAuth Scopes.

1

Sign in to Slack.

Navigate to Apps page and click on “Create New App” button

2

Select Create an App "From scratch"

3

Give your App a suitable name

Give your App a suitable name and select the workspace you will be using to develop this app. For your test app, you can use something like “SuprSend Test App” for app name

4

Assign OAuth Scopes to App

OAuth is a protocol that lets your app request authorization to private details in a user’s Slack account without getting their password. It’s also the vehicle by which Slack apps are installed on a team. You can authorize your app using one of the below methods:

Update slack channel in user / object profile

The information required in the user profile is dependent on the type of message you are sending.

Order of Precedence

The Slack profile should only contain incoming_webhook->url, or the access_token with one of these keys: channel_id, user_id, or email. If there are multiple keys in user.add_slack() call, the order of precedence is as follows:

incoming_webhook->url > channel_id > user_id > email. For example, if your add_slack argument is as follows:

const distinct_id = "__uniq_user_id__"  // Unique id of user in your application
const user = supr_client.user.get_instance(distinct_id) // Instantiate User profile

user.add_slack(
  {
    "incoming_webhook": {
      "url": "https://hooks.slack.com/services/TXXXXXXXXX/BXXXXXXXX/XXXXXXXXXXXXXXXXXXX"
    },
    "email": "john@abc.com",
    "user_id": "U/WXXXXXXXX",
    "channel_id": "CXXXXXXXX",
    "access_token": "xoxb-xxxxx",
  })

const response = user.save()
response.then((res) => console.log("response", res));

The profile will be saved as {"incoming_webhook": { "url": "https://hooks.slack.com/services/TXXXXXXXXX/BXXXXXXXX/XXXXXXXXXXXXXXXXXXX" } }

Update Slack Template

Refer section to create slack template using JSONNET editor.