Skip to content
 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Deploying to AWS Lambda ⚡️ Bolt for JavaScript

Slack app example for using the AwsLambdaReceiver of Bolt for JavaScript

Overview

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.

Getting started

1. Set up AWS credentials

Install and configure AWS CLI

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 configure

2. Set up local project

You can install the app's local development dependencies with the following command:

npm install

You 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.

3. Create a Slack app

Create an app on api.slack.com

  1. Go to https://api.slack.com/apps
  2. Select Create New App
    • Name your app, don't worry you can change it later!
  3. Select OAuth & Permissions
    1. Scroll down to Bot Token Scopes
    2. Add the following bot scopes:
      1. Add the scope app_mentions:read
      2. Add the scope channels:history
      3. Add the scope chat:write
      4. Add the scope groups:history
      5. Add the scope im:history
      6. Add the scope mpim:history
    3. Select Install App to Workspace at the top of the page

Export environment variables

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"

4. Deploy to AWS Lambda

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/events

Please note the endpoint https://{your-domain}.amazonaws.com/dev/slack/events because we'll use it in the next section.

5. Update Slack app settings

Now that your Slack app is deployed, you can register your AWS Lambda endpoint with the Slack API:

  1. Go to https://api.slack.com/apps
  2. Select your app
  3. Select Event Subscriptions
    1. Enable Events
    2. Set the Request URL to https://{your-domain}.amazonaws.com/dev/slack/events
    3. Scroll down to Subscribe to Bot Events
    4. Add the following bot events:
      • app_mention
      • message.channels
      • message.groups
      • message.im
      • message.mpim
    5. Select Save Changes

6. Test your Slack app

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.

7. Develop on local machine

Open a terminal session to listen for incoming requests:

npm run serverless

Open another terminal session to proxy Slack API requests locally:

ngrok http 3000

Update your Slack app settings to use your ngrok address:

  1. Interactivity & Shortcuts
    1. Set the Request URL to https://my-unique-name.ngrok.io/slack/events
  2. Event Subscriptions
    1. Set the Request URL to https://my-unique-name.ngrok.io/slack/events

Follow the steps to test your app.

About

Getting Started Slack app using ⚡️ Bolt for JavaScript

Resources

Contributing

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages