Configure Webhook Reception in Slack

NOTE: This documentation was written based on Slack documentation at the time of release. Check Slack for the most current documentation.

There are four steps to complete this task:

  1. Create a Slack app.

  2. Enable incoming webhooks.

  3. Create an incoming webhook.

  4. Use the incoming webhook URL to post a message.

Create a Slack Application

Go to https://api.slack.com/apps/new.

Enable Incoming Webhooks

  1. Go to the settings page for the Slack app.

  2. Click Incoming Webhooks > Activate Incoming Webhooks. The settings page will refresh to show extra options.

Create an Incoming Webhook

  1. Click Add New Webhook to Workspace.

  2. Select a channel that the app will post to and click Authorize.

NOTE: To add the incoming webhook to a private channel, you must be in that channel.

  1. In app settings, Webhook URLs for Your Workspace section there is a new entry with a webhook URL. For example:

    https://hooks.slack.com/services/T00000000/B00000000/
    XXXXXXXXXXXXXXXXXXXXXXXX

This URL is the new incoming webhooks that is specific to a single user and a single channel. Use this URL to create a webhook in SysTrack.

Test the Incoming Webhook

  1. Create an HTTP POST request. For example:

    POST https://hooks.slack.com/services/T00000000/
    B00000000/XXXXXXXXXXXXXXXXXXXXXXXX
    Content-type: application/json
    {
    "text": "Hello, world."
    }                    

NOTE: The URL from the previous section and this URL should be the same.

  1. To verify: go to the channel where you installed the app and you will see the "Hello, World" message that has been posted.

Webhook Body Template for Slack

Copy and paste this content into the Body section of the Add New Recipient dialog box. Edit as needed.

TIP: For Slack, you need the URL you generated, it must use the POST method, and it needs a body like the one shown below.

{
    "blocks": [
        {
            "type": "rich_text",
            "elements": [
                {
                    "type": "rich_text_quote",
                    "elements": [
                        {
                            "type": "text",
                            "text": "@{notificationName}",
                            "style": {
                            "bold": true
                            }
                        }
                    ]
                }
            ]
        },
        {
            "type": "context",
            "elements": [
                {
                    "type": "mrkdwn",
                    "text": "*Activated* @{activationTime}"
                }
            ]
        },
        {
            "type": "rich_text",
            "elements": [
                {
                    "type": "rich_text_section",
                    "elements": [
                        {
                            "type": "text",
                            "text": "Sensor(s): ",
                            "style": {
                            "bold": true
                            }
                        },
                        {
                            "type": "text",
                            "text": "@{sensorNamesUnquoted}"
                        }
                    ]
                },    
                {
                    "type": "rich_text_section",
                    "elements": [
                        {
                            "type": "text",
                            "text": "Group: ",
                            "style": {
                                "bold": true
                            }
                        },
                        {
                            "type": "text",
                            "text": "@{groupName}"
                        }
                    ]
                },
                {
                    "type": "rich_text_section",
                    "elements": [
                        {
                            "type": "text",
                            "text": "Activation: ",
                            "style": {
                                "bold": true
                        }
                    },    
                    {
                        "type": "text",
                        "text": "@{activationThresholdText}"
                    }
                ]
            }
        ]
    },
    {
        "type": "context",
        "elements": [
            {
                "type": "plain_text",
                "text": "@{notificationDescription}"
            }
        ]
    },    
    {
        "type": "section",
        "text": {
            "type": "mrkdwn",
            "text": "@{notificationActivationDetailsURL}|Learn More in SysTrack>"
        }
    }
]
}