To listen for events happening in a Slack workspace (like when a message is posted or when a reaction is posted to a message) you’ll use the Events API to subscribe to event types. Your app behaves similarly to people on your team - it can post messages, add emoji reactions, and listen and respond to events. Your app should let you know that it’s up and running.
Save your app.py file then on the command line run the following: python3 app.py
Your tokens are enough to create your first Bolt app. If _name_ = "_main_" : SocketModeHandler ( app, os. get ( "SLACK_BOT_TOKEN" )) # Start your app Import os from slack_bolt import App from slack_mode import SocketModeHandler # Initializes your app with your bot token and socket mode handlerĪpp = App ( token = os. If you don’t already have a project, let’s create a new one.
This is where you’ll write the code that handles the logic for your app. With the initial configuration handled, it’s time to set up a new Bolt project. Your app uses tokens to post and retrieve information from Slack workspaces. ? Treat your tokens like passwords and keep them safe. Navigate to Socket Mode on the left side menu and toggle to enable. Add the connections:write scope to this token and save the generated xapp token, we’ll use both these tokens in just a moment. Then head over to Basic Information and scroll down under the App Token section and click Generate Token and Scopes to generate an app-level token. Once you authorize the installation, you’ll land on the OAuth & Permissions page and see a Bot User OAuth Access Token. You’ll be led through Slack’s OAuth UI, where you should allow your app to be installed to your development workspace.
Scroll up to the top of the OAuth & Permissions page and click Install App to Workspace. This grants your app the permission to post messages in channels it’s a member of. Click Add an OAuth Scope.įor now, we’ll just add one scope: chat:write. Navigate to the OAuth & Permissions on the left sidebar and scroll down to the Bot Token Scopes section. We’re going to use bot and app-level tokens for this guide.