Skip to main content

django-slack-utils Build Status Coverage Status

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

It supports verification through HTTP_X_SLACK_SIGNATURE and HTTP_X_SLACK_REQUEST_TIMESTAMP.

Installation

Add the following to your settings.py

INSTALLED_APPS = [
    ...
    'slack_utils',
]

SLACK_SIGNING_SECRET = 'your signing secret from Slack'

Add the following to your urls.py

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

Usage

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

@slack_view
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 slack.py module of your app.

from slack_utils.decorators import slack_command

@slack_command('/test')
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 slack.py of your app or make sure it's loaded once.

from slack_utils.decorators import slack_receiver

@slack_receiver('reaction_added')
def on_reaction_added(event_data, **kwargs):
    # your logic 
 

Signal

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

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

    # your other logic 
 

Release files for django-slack-utils 0.3.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-slack-utils 0.3.1
File Size Uploaded
django-slack-utils-0.3.1.tar.gz 5.2 kB Details

Release files / django-slack-utils-0.3.1.tar.gz

Download URL django-slack-utils-0.3.1.tar.gz
Size 5.2 kB
Tags Source
SHA-256 checksum
How to use checksums
e03b6be896d443f4580210546fa96aeef6becfc9e2cdbe720dbe2ab935c4a0e0
BLAKE2b-256 checksum
How to use checksums
74cf02dd783e9507ca3af6b74ef41ea25b75160c87efb3038d095b195d4e1e75
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.9.2

Release history Release notifications | RSS feed

This release

0.3.1 This release

1 release file

0.3.0

1 release file

0.2.0

1 release file

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page