Slack app example for using the AwsLambdaReceiver of Bolt for JavaScript
This is an example app that updates the Getting Started ⚡️ Bolt for JavaScript app to use the AwsLambdaReceiver and be deployed to AWS Lambda using the Serverless Framework. You can learn how to build this example app by following our 📚 Deploying to AWS Lambda guide.
Before you begin, you may want to follow our Getting Started guide to learn how to build your first Slack app using the Bolt for JavaScript framework.
Follow Amazon's guides to install the AWS CLI v2 for macOS, Windows, or Linux and create a new IAM User.
When you have the AWS CLI and user credentials, then configure your local machine with the command:
aws configureYou can install the app's local development dependencies with the following command:
npm installYou may also want to install ngrok to start a local tunnel for local development.
Ensure you can correctly run the serverless command from your terminal. You may have to reference it from the ./node_modules/.bin/serverless location within the project. If that still doesn't work, refer to the Serverless Getting Started documentation on how to install the Serverless framework.
- Go to https://api.slack.com/apps
- Select Create New App
- Name your app, don't worry you can change it later!
- Select OAuth & Permissions
- Scroll down to Bot Token Scopes
- Add the following bot scopes:
- Add the scope
app_mentions:read - Add the scope
channels:history - Add the scope
chat:write - Add the scope
groups:history - Add the scope
im:history - Add the scope
mpim:history
- Add the scope
- Select Install App to Workspace at the top of the page
export SLACK_SIGNING_SECRET=<your-signing-secret> # Slack app settings > "Basic Information"
export SLACK_BOT_TOKEN=<your-xoxb-bot-token> # Slack app settings > "OAuth & Permissions"Run the following the command to deploy to AWS Lambda:
serverless deploy
# ...
# endpoints:
# POST - https://d5c0t1xad4.execute-api.us-east-1.amazonaws.com/dev/slack/eventsPlease note the endpoint https://{your-domain}.amazonaws.com/dev/slack/events because we'll use it in the next section.
Now that your Slack app is deployed, you can register your AWS Lambda endpoint with the Slack API:
- Go to https://api.slack.com/apps
- Select your app
- Select Event Subscriptions
- Enable Events
- Set the Request URL to
https://{your-domain}.amazonaws.com/dev/slack/events - Scroll down to Subscribe to Bot Events
- Add the following bot events:
app_mentionmessage.channelsmessage.groupsmessage.immessage.mpim
- Select Save Changes
You can test your app by opening a Slack workspace and saying "hello" (lower-case):
💬 hello
🤖 Hey there @Jane!
Remember, your app must be in the channel or DM where you say hello.
Open a terminal session to listen for incoming requests:
npm run serverlessOpen another terminal session to proxy Slack API requests locally:
ngrok http 3000Update your Slack app settings to use your ngrok address:
- Interactivity & Shortcuts
- Set the Request URL to
https://my-unique-name.ngrok.io/slack/events
- Set the Request URL to
- Event Subscriptions
- Set the Request URL to
https://my-unique-name.ngrok.io/slack/events
- Set the Request URL to
Follow the steps to test your app.