Skip to content

Latest commit

 

History

History
 
 

3_ChatBot

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 

Module 3: Create a Slack app

You will create an application in Slack and make it work with your Serverless Application on AWS. Amazon API Gateway is a managed API service that you will use to subscribe to events from Slack. AWS Secrets Manager is a service to securely store secrets. The app will use two secrets from Slack: 1) the signing secret that enables the app to verify authenticity of events received from Slack and 2) the Bot Token that enables the app to post messages to Slack.

Implementation Instructions

❗ Ensure you've completed the Code Management before beginning this module.

Each of the following sections provides an implementation overview and detailed, step-by-step instructions. The overview should provide enough context for you to complete the implementation if you're already familiar with the AWS Management Console or you want to explore the services yourself without following a walkthrough.

1. Create your Slack application

Create a Slack application and set up the necessary permissions and bot user. Copy the signing secret to AWS Secrets Manager. Install the app to your workspace and copy the bot token to AWS Secrets Manager. Copy the API Gateway endpoint from Lambda and use it to subscribe to Slack events - once you paste it, it should be automatically verified. Choose the events you want to subscribe to and re-install the Slack app to your Slack workspace.

✅ Step-by-step directions

  1. Go to api.slack.com and log in if asked to.

  2. Choose Your apps in the top right corner.

  3. Choose Create New App.

  4. Give your app a name and choose the development workspace that will own the app. Choose Create App.

    Create app modal

  5. In the Basic Information screen, choose Permissions.

  6. Scroll down to Scopes

    1. Select Add an OAuth Scope
    2. Choose the chat:write:bot scope
    3. Choose the bot scope

    Scopes

  7. In the left menu, choose Bot Users and choose Add a Bot User in the screen that opens.

  8. Give your bot a Display name, a Default username, and choose Always Show My Bot as Online. Choose Add Bot User.

  9. In the left menu, choose Basic Information and scroll to the App Credential section.

  10. In the Singing Secret textbox, choose Show and copy the secret value.

    Signing secret image

  11. Go to the AWS Secrets Manager console.

  12. Find the secret named as APP_NAME-Secret and choose it.

    Secrets manager

  13. Scroll down to the Secret value section and choose Retrieve secret value.

  14. Choose Edit.

  15. Paste the Signing secret you copied in Slack to the textbox next to Signing_Secret key. Don't save it yet and keep the tab open.

    Edit secret

  16. Go back to the Slack app configuration page.

  17. In the left menu, choose Install App and choose Install App to Workspace.

  18. Choose Allow in the following screen.

    OAuth

  19. Copy the Bot User OAuth Access Token.

    Bot access token

  20. Go back to the AWS Secrets Manager console and find your secret again.

  21. Paste the token you just copied to the textbox next to Bot_Token key. Choose Save.

  22. Go back to the Lambda applications console and find the application you created in module 1.

  23. Scroll down until you see the API Endpoint section and copy the Endpoint URL.

    API GW Endpoint

  24. Go back to the Slack app configuration page.

  25. In the left menu, choose Event Subscriptions and turn Enable Events on.

  26. Paste the API Gateway endpoint you copied in the Lambda console to the Request URL textbox and add "/slackevents" to the end of it and press Tab. You should see a Verified label.

    Endpoint verified

  27. In Subscribe to Bot Events section, choose Add Bot User Event and select app_mention and message.im.

    Bot events

  28. Choose Save Changes.

  29. A warning message will appear at the top, requesting the app to be re-installed. Choose reinstall your app.

    Reinstall app

  30. Choose Allow in the app installation screen that opens.


2. Test!

  1. Go to the Slack app and find the bot user you've just added. Send it a message. The bot should echo the message back.

    Test IM

  2. Add the bot to a channel and send it an @-message. The bot should respond.

    Test Channel

⭐ Recap

🔧 You just created a Slack app to connect to your AWS account. From here you can now add business logic and easily build more sophisticated bots.

Next

✅ Proceed to the next module, AWS Notifications, wherein you'll configure AWS to send events to your Slack bot.