by slackapi

Slack Events API adapter for Python (Flask required)

261 Stars 95 Forks Last release: 3 months ago (v2.2.1) MIT License 89 Commits 8 Releases

Available items

No Items, yet!

The developer of this repository has not created any items for sale yet. Need a bug fixed? Help with integration? A different license? Create a request here:

Slack Events API adapter for Python

.. image:: :target: .. image:: :target: .. image:: :target:

The Slack Events Adapter is a Python-based solution to receive and parse events from Slack’s Events API. This library uses an event emitter framework to allow you to easily process Slack events by simply attaching functions to event listeners.

This adapter enhances and simplifies Slack's Events API by incorporating useful best practices, patterns, and opportunities to abstract out common tasks.

πŸ’‘ We wrote a

blog post which explains how
_ the Events API can help you, why we built these tools, and how you can use them to build production-ready Slack apps.

.. _blog post which explains how:

πŸ€– Installation

.. code:: shell

pip install slackeventsapi

πŸ€– App Setup

Before you can use the

Events API
_ you must
create a Slack App
, and turn on
Event Subscriptions

πŸ’‘ When you add the Request URL to your app's Event Subscription settings, Slack will send a request containing a

code to verify that your server is alive. This package handles that URL Verification event for you, so all you need to do is start the example app, start ngrok and configure your URL accordingly.

βœ… Once you have your

Request URL
verified, your app is ready to start receiving Team Events.

πŸ”‘ Your server will begin receiving Events from Slack's Events API as soon as a user has authorized your app.

πŸ€– Development workflow:

(1) Create a Slack app on (2) Add a

bot user
for your app (3) Start the example app on your Request URL endpoint (4) Start ngrok and copy the HTTPS URL (5) Add your Request URL and subscribe your app to events (6) Go to your ngrok URL (e.g. and auth your app

πŸŽ‰ Once your app has been authorized, you will begin receiving Slack Events

⚠️  Ngrok is a great tool for developing Slack apps, but we don't recommend using ngrok
for production apps.

πŸ€– Usage

⚠️ Keep your app's credentials safe!

  • For development, keep them in virtualenv variables.

  • For production, use a secure data store.

  • Never post your app's credentials to github.

.. code:: python


Create a Slack Event Adapter for receiving actions via the Events API

Using the built-in Flask server:

.. code:: python

from slackeventsapi import SlackEventAdapter

slackeventsadapter = SlackEventAdapter(SLACKSIGNINGSECRET, endpoint="/slack/events")

# Create an event listener for "reactionadded" events and print the emoji name @slackeventsadapter.on("reactionadded") def reactionadded(eventdata): emoji = event_data["event"]["reaction"] print(emoji)

# Start the server on port 3000 slackeventsadapter.start(port=3000)

Using your existing Flask instance:

.. code:: python

from flask import Flask from slackeventsapi import SlackEventAdapter

# This

represents your existing Flask app app = Flask(name)

# An example of one of your Flask app's routes @app.route("/") def hello(): return "Hello there!"

# Bind the Events API route to your existing Flask app by passing the server # instance as the last param, or with

. slackeventsadapter = SlackEventAdapter(SLACKSIGNINGSECRET, "/slack/events", app)

# Create an event listener for "reactionadded" events and print the emoji name @slackeventsadapter.on("reactionadded") def reactionadded(eventdata): emoji = event_data["event"]["reaction"] print(emoji)

# Start the server on port 3000 if name == "main":

For a comprehensive list of available Slack

and more information on
, see

πŸ€– Example event listeners

_ for usage examples. This example also utilizes the SlackClient Web API client.

.. /example/

πŸ€” Support

Need help? Join

Slack Community
_ and talk to us in

You can also

create an Issue
_ right here on GitHub.

.. _Events API: .. _create a Slack App: .. _Event Subscriptions: .. _Slack Community: .. _#slack-api: .. _create an Issue:

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.