Skip to main content
Python Software Foundation 20th Year Anniversary Fundraiser  Donate today!

Power a Slack bot with Django Channels v2

Project description


Power a Slack bot with Django Channels v2


pip install slack-channeler


slack-channeler relies on the channel layer. First, ensure it's setup. channels-redis is recommended.


    'default': {
        'BACKEND': 'channels_redis.core.RedisChannelLayer',
        'CONFIG': {
            "hosts": [('localhost', 6379)],

Create a consumer to handle Slack events


from channels.consumer import AsyncConsumer, get_handler_name

class SlackConsumer(AsyncConsumer):
    async def dispatch(self, message):
        handler = getattr(self, get_handler_name(message), None)
        if handler:
            await handler(**message['data'])

    async def slack_message(self, channel, text, **kwargs):
        # Simply echo back message
        await self.channel_layer.send('slack', {
            'type': 'message',
            'channel': channel,
            'text': text,

Route Slack events to the consumer


from channels.routing import ProtocolTypeRouter, ChannelNameRouter

from .consumers import SlackConsumer

application = ProtocolTypeRouter({
    'channel': ChannelNameRouter({
        'slack': SlackConsumer,

Start a Channels worker to handle Slack events from the channel layer

python runworker slack

Lastly, run slack-channeler

SLACK_CHANNELER_TOKEN=xoxb-12345678900-098765432100-DeadBeefFeed90iIJjYsf3ay slack_channeler

Building package

Currently, poetry does not support dynamic generation of version files, nor custom hooks to do so. To keep pyproject.toml the source of authority for version numbers, a custom script is used to dynamically generate

To build slack-channeler, run python This has the same semantics as poetry build.

Project details

Download files

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

Files for slack-channeler, version 0.0.1.dev0
Filename, size File type Python version Upload date Hashes
Filename, size slack_channeler-0.0.1.dev0-py3-none-any.whl (5.6 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size slack-channeler-0.0.1.dev0.tar.gz (4.8 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page