Skip to content
Slack Events API adapter as a Django app
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


Slack Events API adapter as a Django app

django-slack-events-api is a minimal Django app for making your Slack bot.

It includes a Django porting of the official Slack Events API adapter: python-slack-events-api. The original adapter is based on the Flask framework; so here's a modular Django app version instead ;-)

This is intended to be minimal (devoid of extra model, template, and module-dependency stuff) focusing only on Slack Events handling. However, all the features and examples useful for Slack bot creation (such as utilizing the python-slackclient) found in the original Flask version are retained and functional. After working through the demo section, you'll find it easy to integrate this app into your Django projects as well.

Bonus: Additionally, django-slack-events-api supports three kinds of Slack client library integration:

Credits: Sections marked by 🤖 are a derived work of python-slack-events-api/example/README.rst.



  • Python 2.7
  • Django 1.11.x

Install the app and its dependencies:

$ git clone
$ cd django-slack-events-api
$ pipenv install
$ pipenv shell

Demo: creating a minimal Django project for a Slack bot

In this section, we present a quick demo on how to get a working Django-based Slack bot on your local computer. We create a new Django app from scratch and embed the django-slack app in it. After configurations, we start the Django local server on port 3000. ngrok is used to make sure that the local bot instance is properly communicating with the Slack server on the Internet.

(1) A new django project with a django slack app embedded

$ django-admin startproject bot  # create a new django project called "bot"
$ cp -r slack bot/               # copy (embed) the bare django-slack app under the bot project
$ cd bot                         # move into the root of the bot project

Now the current directory structure should look as follows:

$ find .
.                               # Root of the new "bot" project
./bot/               # to be modified
./bot/                   # to be modified
./slack                         # a copy of django-slack app

(2) Modify bot/ to add the slack app and tokens.

For obtaining the SLACK_VERIFICATION_TOKEN and SLACK_BOT_TOKEN tokens, see Appendix: Setup your bot in Slack.

    'slack',                            # <-- add this

SLACK_VERIFICATION_TOKEN = "xxxxxxxxXxxXxxXxXXXxxXxxx"  # <-- add this
SLACK_BOT_TOKEN = "xxxXXxxXXxXXxXXXXxxxX.xXxxxXxxxx"    # <-- add this

(3) Modify bot/ to configure the endpoint.

from django.conf.urls import url, include  # <-- add this
from django.contrib import admin
from slack import urls as slack_urls  # <-- add this

urlpatterns = [
    url(r'^slack/', include(slack_urls, namespace="slack")),  # <-- add this

(4) [Optional] Modify slack/ to customize the endpoint (default is /slack/events)

(5) [Optional] Select the underlying bot client library

In slack/, uncomment the adapter corresponding to the client library of your choice. (Unmodified, is used by default.)

# uncomment for the slackclient API client (
from .adapter_slackclient import slack_events_adapter, SLACK_VERIFICATION_TOKEN
# uncomment for the slacker API client (
# from .adapter_slacker import slack_events_adapter, SLACK_VERIFICATION_TOKEN
# uncomment for a urllib2-based client implemented in
# This should work with Google App Engine.
# from .adapter_urllib2 import slack_events_adapter, SLACK_VERIFICATION_TOKEN

Depending on your choice of the client library, start hacking your bot's logic by editing one of

(6) 🤖 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.

If you don't have ngrok, download it here.

Here's a rudimentary diagream of how ngrok allows Slack to connect to your server

💡 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

Forwarding -> localhost:9292
Forwarding -> localhost:9292

(7) 🤖 Run the app

You'll need to have your server and ngrok running to complete your app's Event Subscription setup

$ python runserver

🎉 Once your app has been installed and subscribed to Bot Events, you will begin receiving event data from Slack

(8) Interact with your bot

Invite your bot to a public channel (e.g. # general), then say hi and your bot will respond.

Here are Django console logs showing the interaction with the Slack server.

Case: local server + ngrok:

Case: Google App Engine:

Appendix: Setup your bot in Slack

🤖 Create a Slack app

Create a Slack app on

🤖 Add a bot user to your app

🤖 Install your app on your team

Visit your app's Install App page and click Install App to Team.

Authorize your app

🤖 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

Once you've authorized your app, you'll be presented with your app's tokens.

Copy your app's Bot User OAuth Access Token, then add the token in bot/

SLACK_BOT_TOKEN = "xxxXXxxXXxXXxXXXXxxxX.xXxxxXxxxx"

Next, go back to your app's Basic Information page

Copy your app's Verification Token, then add the token in bot/

You can’t perform that action at this time.