Skip to main content Skip to complementary content

How to build a Slack chat bot

This page describes a simple method of creating a Slack chatbot that can automatically respond to messages.

Create a new automation to listen to Slack messages

Create a new automation and save it.

We will add some temporary blocks to facilitate the verification process by Slack (more info below).

So for now, add an Inputs block with input type Data and below add an Output block that outputs the challenge received.

Setup for the automation.

an automation consisting of a Start block, an Inputs block, and an Output block.

Use following path in the Output block: { $.inputs.challenge }

Setting the path in the Output block.

The above automation, with the Output block selected. The data to output is set to the above code, and the display mode is set to Use only this output.

This means we are echoing the challenge that we receive from Slack, and that's what Slack expects as part of its verification process.

Make sure to set the Display Mode of the Output block under Settings to "use only this output (overwrite previous outputs)".

Finally, copy the incoming webhook URL of this automation. You will need it below to add it in Slack. You can find it by clicking on the Start block in your automation and changing the run mode to Triggered. Make sure to copy the full GET URL.

Create an app in your Slack account

Next, visit this page to create an app in your Slack account: Slack apps

Once your app is created, go to Features > event subscriptions.

Paste the webhook URL from your new automation in the field Request URL.

Slack will now verify this URL. This means it will do a call to the automation with a challenge in the payload. The automation will echo the challenge code that Slack sends, and the verification should be fine:

Slack verifying a URL.

The Event Subscriptions tab of the Slack API. A URL is pasted into the Request URL field.

Finally, click on Add workspace event and add the event message.channels.

Extend the automation to listen to Slack messages

Next, go back into your automation inQlik Application Automation for OEM, and delete the Outputs block. Instead add some blocks that process the incoming payload from Slack. Slack will call your automation each time a new message is posted on Slack.

The History of the Inputs block will show you the incoming payload from Slack for each new message posted. Example:

type: event_callback
event
    ts: 1536673789.000100
    text: *A message was received in random from xxxx* test
    type: message
    bot_id: BBM7JLV4N
    channel: CB8QRV868
    subtype: bot_message
    event_ts: 1536673789.000100
    username:Qlik Application Automation for OEM
    channel_type: channel
token: ZKiVqNgNnei9RYW36McLr0p
team_id: TB8FD9R6V
event_id: EvCR119L4C
api_app_id: ACQCFLJQ0
event_time: 1536673789
authed_users 1 item
    UB92LTE6P

In this payload, you can retrieve the message that was posted, the person who posted the message, and the channel it was posted in.

Add some business logic in your automation and use the block Slack Send message to post a reply in Slack:

Returning a message in Slack.

an automation consisting of a Start block, an Inputs block, and a Condition block leading to a Send Message block.

Did this page help you?

If you find any issues with this page or its content – a typo, a missing step, or a technical error – let us know how we can improve!