Skip to main content

Slack

typeslack

A Slack receiver in Siren tied to a Slack workspace. The implementation uses slack-go library to send notification to a Slack app. This Slack app must be installed in the required workspaces and added to the required channels. Siren helps with the installation flow by automating the exchanging code for access token flow.

Initializing a Slack App

Here is the list of actions one need to take to attach a Slack app to Siren.

  1. Create a Slack app and configure these permissions. Visit this. If you already have an app, make sure permissions mentioned below are there.
    channels:read
    chat:write
    groups:read
    im:read
    team:read
    users:read
    users:read.email
  2. Enable Distribution
  3. Setup a redirection server. You can use localhost as well. This must be a https server. Slack will call this server once we install the app in any workspace.
  4. Install your app to a workspace. Visit Manage Distribution section on the App Dashboard. Click the Add to Slack Button.
  5. This will prompt you to the OAuth Consent screen. Make sure you have selected the correct Slack Workspace by verifying the dropdown in the top-right corner. Click Allow.
  6. Copy the code that you received from Slack redirection URL query params and use this as auth_code inside create receiver payload.

In order to send Slack notifications via Siren API, you need to create its receiver. To add a new slack receiver you need all credentials mentioned in this configuration.

Configurations in API

"configurations": {
"client_id": <string>,
"client_secret": <string>,
"auth_code": <string>
}

Configurations Stored in DB

"configurations": {
"token": <encrypted string>
}

Creating a slack receiver involves exchanging the auth code for a token with slack oAuth server. Siren will need the auth code, client id, client secret and optional label metadata.

Example

$ siren receiver create --file slack_receiver.yaml

On success, this will store the encrypted app token for that particular slack workspace and use it for sending out notifications.

Subscription

Slack has additional SubscriptionConfig where user could routes the notification to a specific channel or individual in a workspace. Here is the subscription config.

"configurations": {
"channel_name": <string>,
"channel_type": <string>
}

The channel_type has two possible enum values channel and user. The default value of this is channel. If channel_type is channel, channel_name should be a slack channel handle in the workspace e.g. #gotocompany-critical. If one wants to send notification to an individual, channel_type needs to be user and channel_name needs to be populated with slack user's e-mail e.g. user1@gotocompany.com.

Message Payload

Contract

Payload format of slack needs to follow slack chat.postMessage API contract.

channel: <string>
text: <string>
username: <string>
icon_emoji: <string>
icon_url: <string>
link_names: <boolean>
attachments:
- <key1>: <any>
<key2>: <any>
- <key3>: <any>
<key4>: <any>
.
.

Default Alert Template

Siren has a slack default notification template used by all alert notifications.