Skip to main content

A Django app for handling Slack webhooks

Project description

django-slack-utils Build Status Coverage Status

Django-slack-utils is helper application to handle Slack requests.



Add the following to your


SLACK_SIGNING_SECRET = 'your signing secret from Slack'

Add the following to your

    from django.conf.urls import include
    from django.urls import path
    urlpatterns = [
        path('slack/', include('slack_utils.urls')),


View decorator

The @slack_view decorator adds CSRF exempt and verification to your function-based django view.

from slack_utils.decorators import slack_view
from django.http import HttpResponse

def sample_view(request, *args, **kwargs):
    # your logic
    return HttpResponse("Hello!")

Class-based view

The SlackView base class adds CSRF exempt and verification to your class-based django view.

from slack_utils.views import SlackView
from django.http import HttpResponse

class SampleView(SlackView):
    def post(self, request, *args, **kwargs):
        # your logic
        return HttpResponse("Hello!")

Slash commands

To handle Slack slash commands, point the command URL to /slack/commands/.

Now just add a handler function to module of your app.

from slack_utils.decorators import slack_command

def test_command(text, **kwargs):
    # your logic
    return "Hello!"     # or {'text': "hello!"}

**kwargswould get the rest of the data from Slack request

Events API

Point Slack events API to the /slack/events/.

Subscription can be done in two ways:

Receiver decorator

Put them into of your app or make sure it's loaded once.

from slack_utils.decorators import slack_receiver

def on_reaction_added(event_data, **kwargs):
    # your logic 


from slack_utils.signals import event_received
from django.dispatch import receiver

def on_event_received(sender, event_type, event_data, **kwargs):
    if event_type == 'reaction_added':
        # your logic 

    # your other logic 

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

django-slack-utils-0.3.1.tar.gz (5.2 kB view hashes)

Uploaded source

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