Skip to main content
https://travis-ci.org/iky/nameko-slack.svg?branch=master

Slack Extensions for Nameko

Nameko extension for interaction with Slack APIs. Uses Slack Developer Kit for Python.

Real Time Messaging Client

The RTM extension is a Websocket client for Slack’s Real Time Messaging API that allows you to receive events from Slack in real time. The rtm module contains two Nameko entrypoints for handling such events - handle_event and handle_message.

Usage

Provide Slack bot API token in your Nameko service config file:

# config.yml

SLACK:
    TOKEN: "xoxb-abc-1232"

Or using environment variable within your config:

# config.yml

SLACK:
    TOKEN: ${SLACK_BOT_TOKEN}

Define your service with an entrypoint which will listen for and fire on any event coming from Slack:

# service.py

from nameko_slack import rtm

class Service:

    name = 'some-service'

    @rtm.handle_event
    def on_any_event(self, event):
        print(event)

Finally, run the service:

$ SLACK_BOT_TOKEN=xoxb-abc-1232 nameko run --config ./config.yaml service
starting services: some-service
{'type': 'hello'}
{'type': 'presence_change', 'user': 'ABCDE1234', 'presence': 'active'}
{'type': 'user_typing', 'user': 'ABCDE1234', 'channel': 'ABCDE1234'}
{'type': 'message', 'text': 'spam', 'channel': 'ABCDE1234', 'user': 'ABC...
{'type': 'presence_change', 'user': 'ABCDE1234', 'presence': 'active'}
...

More Examples

Listen for events of a particular type:

from nameko_slack import rtm

class Service:

    name = 'some-service'

    @rtm.handle_event('presence_change')
    def on_presence_change(self, event):
        pass

Listen for any message type event:

from nameko_slack import rtm

class Service:

    name = 'some-service'

    @rtm.handle_message
    def on_any_message(self, event, message):
        pass

Use regular expressions to fire on matching messages only:

from nameko_slack import rtm

class Service:

    name = 'some-service'

    @rtm.handle_message('^spam')
    def on_message_starting_with(self, event, message):
        pass

Parse message and pass matching groups as positional or named arguments to the entrypoint:

from nameko_slack import rtm

class Service:

    name = 'some-service'

    @rtm.handle_message('^spam (\w*)')
    def on_spam(self, event, message, egg):
        pass

    @rtm.handle_message('^egg (?P<ham>\w+)')
    def on_egg(self, event, message, ham=None):
        pass

Respond back to the channel by returning a string in the message handling entrypoint:

from nameko_slack import rtm

class Service:

    name = 'some-service'

    @rtm.handle_message
    def sure(self, event, message):
        return 'sure, {}'.format(message)

Release files for nameko-slack 0.0.3

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

Source distribution (sdist)

Source distribution for nameko-slack 0.0.3
File Size Uploaded
nameko-slack-0.0.3.tar.gz 7.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for nameko-slack 0.0.3
File Interpreter ABI Platform
nameko_slack-0.0.3-py2-none-any.whl Python 2 none any Details

Total release size: 13.6 kB

Release files / nameko-slack-0.0.3.tar.gz

Download URL nameko-slack-0.0.3.tar.gz
Size 7.7 kB
Tags Source
SHA-256 checksum
How to use checksums
7dc748e9b3983a98eb2d9b9af6cd5a284d603d7991809c7c8c7544ccce8e12fc
BLAKE2b-256 checksum
How to use checksums
fe8a737b30d0a8bcad8cff60fad3459db22ba1d68ef93d94f83e7ddc96bfc5df
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / nameko_slack-0.0.3-py2-none-any.whl

Download URL nameko_slack-0.0.3-py2-none-any.whl
Size 5.9 kB
Tags Python 2
SHA-256 checksum
How to use checksums
de3e38320bb4e966a41ca996f353847b86692ee9d271175c15251b9b53060e3c
BLAKE2b-256 checksum
How to use checksums
d3434404a3403a3b8fe757941518d91309dbe28ca9b402ad876a1536f6f392b6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

This release

0.0.3 This release

2 release files

0.0.2

2 release files

0.0.1

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