Interactive Slack bot using AWS Serverless

Aswin Kumar Rajendran
3 min readJun 26, 2020

Learn how to build a simple interactive Slack bot using AWS Serverless technologies.

Let us first set up the Serverless Slack Bot in AWS

Serverless Slack Bot

Below Github repository contains the code for a simple serverless slack bot configured using serverless framework.

Github URL: https://github.com/aswinkumar4018/serverless-slack-bot

Prerequisite:
1. CLI access to an AWS Account.
2. IAM user or role access to create and execute API Gateway & Lambda.

Step 1: Clone the serverless-slack-bot Github repository.

Step 2: Install the Serverless CLI globally. https://www.serverless.com/framework/docs/getting-started/

Step 3: Configure your AWS CLI credentials in ~/.aws/credentials.

Step 4: Create a file named config.dev.json in the cloned project directory.
(Note: we will replace the sample bot token with an actual bot token later)

// config.dev.json{
"CREATOR_EMAIL": "example@abc.com", // your email
"BOT_TOKEN": "<Sample_Bot_Token>" // sample bot token
}
config.dev.json

Step 5: Go to the cloned project directory and deploy the serverless slack bot app using the sls deploy command.

// In project directory: serverless-slack-bot/sls deploy
sls deploy

Step 6: Copy the Bot API URL (you will need it while configuring Slack app).

Now let’s set up the Slack App

Step 1: Go to https://api.slack.com/ and login to your slack workspace.

Step 2: Go to “Your Apps” and create a new app “Serverless Slack Bot”.

Create a new Slack app

Step 3: In the next step, select “Event Subscriptions” and proceed.

Select Event Subscriptions

Step 4: In “Event Subscriptions”, paste the copied Bot API URL and click verify.

Verify your Bot API URL

Step 5: Add app_mention and message.im bot user events and save changes.

Add app_mention and message.im bot user events

Step 6: Install the created app to your Slack workspace.

Install the Slack app

Step 7: Copy the created Bot Token.

Copy the Bot Token

Step 8: Scroll down, add chat:write Bot Token Scope under Scopes in OAuth & Permissions page and reinstall the app.

Add chat:write Bot Token Scope

Step 9: Go to the project directory and replace Sample Bot Token in the config.dev.json created before.

// config.dev.json{
"CREATOR_EMAIL": "example@abc.com", // your email
"BOT_TOKEN": "<Bot_Token>" // paste your bot token
}
config.dev.json

Step 10: Now deploy the serverless slack bot app again using the sls deploy command.

// In project directory: serverless-slack-bot/sls deploy

Step 11: After deployment, enable your bot to be always online (optional).

Enable your bot to be Online

Congrats! you have completed setting up an Interactive Slack bot using AWS Serverless and it is ready to use.

Serverless Slack Bot in Action

Thank you so much for reading! Please clap 👏 and share if you found this article useful.

Learn something new every day — Cheers!

--

--

Aswin Kumar Rajendran

Technical Architect — AWS, GCP Certified Solutions Architect working at Presidio with love & experience in building cloud-native applications.