Skip to content

Latest commit

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..

README.rst

Example Slack events API bot

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.

馃 Setup and running the app

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/

https://cloud.githubusercontent.com/assets/32463/20549718/afdd98d0-b0e3-11e6-8d83-8ad7053deb80.png

Add a bot user for your app

https://cloud.githubusercontent.com/assets/32463/20371297/9044e2a0-ac18-11e6-8f25-3ffbd8a3bf58.png

馃 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

https://cloud.githubusercontent.com/assets/32463/20366593/b40d14a4-ac00-11e6-8413-b473c16ef997.png

https://cloud.githubusercontent.com/assets/32463/20549612/e7ee2ed4-b0e2-11e6-8b9c-01ed08057c7c.png

馃 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

https://cloud.githubusercontent.com/assets/32463/20445302/61ddfc54-ad89-11e6-8523-245a60c875b0.png

馃 Add your OAuth URL

Add your OAuth redirect URL (your ngrok URL + /auth/slack/callback)

https://cloud.githubusercontent.com/assets/32463/20543629/63e41a26-b0bb-11e6-8eee-90c6f4f1dbb1.png

馃 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.

https://cloud.githubusercontent.com/assets/32463/20575277/789c0c5a-b16d-11e6-86fd-e30c3a0d2e61.gif

馃帀 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 馃憢

https://cloud.githubusercontent.com/assets/32463/23047918/964defec-f467-11e6-87c3-9c7da11fc810.gif

馃 Support

Need help? Join Bot Developer Hangout and talk to us in #slack-api.

You can also create an Issue right here on GitHub.