This example app shows how easy it is to implement the Slack Events API Adapter to receive Slack Events, extend it to handle the OAuth flow and respond to messages using Slack's Web API via python-slackclient.
Set up your Python environment:
See virtualenv docs for more info.
virtualenv -p /your/path/to/python2 env source env/bin/activate
Install the app's dependencies:
pip install -r requirements.txt
馃 Create a Slack app
Create a Slack app on https://api.slack.com/apps/
Add a bot user for your app
馃 Run the app:
You'll need to have your server and ngrok running to complete your app's Event Subscription setup
python example.py
馃 Start ngrok
In order for Slack to contact your local server, you'll need to run a tunnel. We recommend ngrok or localtunnel. We're going to use ngrok for this example.
馃挕 Slack requires event requests be delivered over SSL, so you'll want to use the HTTPS URL provided by ngrok.
Run ngrok and copy the HTTPS URL
ngrok http 3000
ngrok by @inconshreveable (Ctrl+C to quit) Session status online Version 2.1.18 Region United States (us) Web Interface http://127.0.0.1:4040 Forwarding http://h7465j.ngrok.io -> localhost:9292 Forwarding https://h7465j.ngrok.io -> localhost:9292
馃 Subscribe your app to events
Add your Request URL (your ngrok URL + /slack/events) and subscribe your app to message.channels under bot events. Save and toggle Enable Events to on
馃 Save your app's credentials
Go to your app's Basic Information page and save your app's Client ID, Client Secret and Verification Token to environmental variables
馃 Add your OAuth URL
Add your OAuth redirect URL (your ngrok URL + /auth/slack/callback)
馃 Assign your app's credentials to environment variables:
export SLACK_CLIENT_ID=xxxxxxxxxxx.xxxxxxxxxxxxx export SLACK_CLIENT_SECRET=XxxxXxxXXXxxXxxXX export SLACK_VERIFICATION_TOKEN=xxxxxxxxXxxXxxXxXXXxxXxxx
馃 Restart your app to load it's credentials
python example.py
馃 Auth your app
Go to your ngrok URL (e.g. https://myapp12.ngrok.com/) and auth your app.
馃帀 Once your app has been authorized, you will begin receiving Slack events
馃憢 Interact with your bot:
Invite your bot to a public channel, then say hi and your bot will respond
hi @bot 馃憢
Need help? Join Bot Developer Hangout and talk to us in #slack-api.
You can also create an Issue right here on GitHub.







