Before you can run your app you need to put your bot token into the environment.
Note: This is the same token you copied at the end of Step 1.
- Add this token to your environment variables:
$ export SLACK_BOT_TOKEN='xoxb-XXXXXXXXXXXX-xxxxxxxxxxxx-XXXXXXXXXXXXXXXXXXXXXXXX'
- Navigate to your app's Basic Information page from the left sidebar and scroll down to App Credentials and copy the value for Signing Secret:
$ export SLACK_SIGNING_SECRET='xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
- 🏁Run your app
$ python3 app.py
When running locally, you'll likely need to tunnel requests from a public URL to your machine. We recommend ngrok to set up a tunnel. Once you've started ngrok, you'll have a URL that you can set in the Event Subscriptions portion of the Slack app configuration. Append the URL from ngrok with /slack/events. For example, https://abcdef.ngrok.io/slack/events.
In the previous section, we set up handlers for a couple of events, but we need to set up our app to listen to those events. Click on Event Subscriptions on the left hand sidebar of your app.
-
Enter your public URL (for example, in the last step, ours was https://abcdef.ngrok.io/slack/events) and, if your server is running, the domain should be verified.
-
Next, subscribe to the events we used in the previous step:
message.channels
,team_join
,pin_added
, andreaction_added
.
When you click the green Save Changes button, you'll need to reinstall your app.
To demo the app, simply invite your bot to a public channel and send a message that says "start". And then, the app will post a new message in the same channel. You can interact with the message by adding a reaction to it and adding the message to the pinned items. If the app is properly configured, you will see the modifications of the message accordingly.
Previous section: 03 - Responding to Slack events.
Back to the Table of contents.