Skip to main content

Slack event subscriptions for Flask

Project description

Pypi Build Status Codecov Codeclimate

Slack event subscriptions for Flask


Install last stable version from Pypi:

pip install flask-slack-events

Create a Slack bot user

See the Slack’s documentation for further guidance on creating your bot (step 1).

Within the Basic Information about your application, copy the Signing Secret necessary to verify requests from Slack.

Signing Secret

Configure your Application

You should create a SlackManager object within your application:

slack_manager = SlackManager()

Configure your application object updating the SLACK_SIGNING_SECRET key with the value obtained in the previous step 1:

app.config['SLACK_SIGNING_SECRET'] = '<your Signing Secret>'

Once the actual application object has been created, you can configure it for SlackManager object with:


Configure your Slack Bot

Continue with the Slacks’s documentation to setting up the Events API (step 2) and enter the URL to receive the subscriptions joining your host and the relative path /slack/events:

Enable Event

Finally, install your bot to a workspace (step 3).

How it Works

Now in order to subscribe to Slack Events, use the SlackManager.on decorator:

# Reply to only the message events that mention your bot

def reply_to_app_mention(sender, data, **extra):
    event = data['event']

        text=f":robot_face: Hello <@{event['user']}>!")

Context Processors

To inject new variables automatically into the context of a handler, context processors exist in Flask-Slack-Events.

A context processor is a function that returns a dictionary:

def context_processor(data):
    return dict(my_bot_id='UAZ02BCBH')

The injected variables will be sent as an extra argument for each event handler f(sender, data, **extra).

Dispatch Events Asynchronously

Some event handlers can delay the execution of another, to avoid this you can configure the event dispatcher and call handlers asynchronously:

def async_event_dispatcher(sender, data, handlers, **extra):
    for handler in handlers:
        task(handler)(data, **extra)

Subscribe to Signals

The following signals are sended internally by Flask-Slack-Events:


Sent when the request received is unauthorized

Receiver: f(sender, **extra)


Sent when the event has expired according to the value of SLACK_EVENT_EXPIRATION_DELTA and the HTTP header X-Slack-Request-Timestamp received

Receiver: f(sender, **extra)


Sent when the signature included within the HTTP header X-Slack-Signature is invalid

Receiver: f(sender, **extra)


Sent when an event has been received

Receiver: f(sender, data, **extra)

SlackManager Handlers

The following handlers are used internally by Flask-Slack-Events:


Called to handle an unauthorized request

Handler: f()

Default: SlackManager.unauthorized()


Called to handle an expired event

Handler: f()

Default: SlackManager.expired_event()


Called to handle a request with an invalid signature

Handler: f()

Default: SlackManager.invalid_signature()


Called to dispatch the event to all handlers connected with SlackManager.on(event_type) decorator

Handler: f(sender, data, handlers, **extra)

Default: SlackManager.dispatch_event(data)


The following configuration values are used internally by Flask-Slack-Events:


Signing Secret to verify whether requests from Slack are authentic

Default: ''


URL rule that is used to register the Subscription View

Default: /slack/events


Timedelta added to time.time() to set the expiration time of each event If the value is None then the event never expires

Default: timedelta(seconds=60 * 5) (5 minutes)

Marvin the Paranoid Android

Marvin is a Slack Bot layout for Flask to develop Slack Event handlers and deploy on AWS Lambda + API Gateway

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Flask-Slack-Events-0.0.2.tar.gz (7.0 kB view hashes)

Uploaded Source

Built Distribution

Flask_Slack_Events-0.0.2-py2.py3-none-any.whl (7.5 kB view hashes)

Uploaded Python 2 Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page