Interactive Slack bot using AWS Serverless
Learn how to build a simple interactive Slack bot using AWS Serverless technologies.
Let us first set up the Serverless Slack Bot in AWS
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
}
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
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”.
Step 3: In the next step, select “Event Subscriptions” and proceed.
Step 4: In “Event Subscriptions”, paste the copied Bot API URL and click verify.
Step 5: Add app_mention and message.im bot user events and save changes.
Step 6: Install the created app to your Slack workspace.
Step 7: Copy the created Bot Token.
Step 8: Scroll down, add chat:write Bot Token Scope under Scopes in OAuth & Permissions page and reinstall the app.
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
}
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).
Congrats! you have completed setting up an Interactive Slack bot using AWS Serverless and it is ready to use.
Thank you so much for reading! Please clap 👏 and share if you found this article useful.