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)

Download files

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

Source Distribution

nameko-slack-0.0.3.tar.gz (7.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nameko_slack-0.0.3-py2-none-any.whl (5.9 kB view details)

Uploaded Python 2

File details

Details for the file nameko-slack-0.0.3.tar.gz.

File metadata

  • Download URL: nameko-slack-0.0.3.tar.gz
  • Upload date:
  • Size: 7.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for nameko-slack-0.0.3.tar.gz
Algorithm Hash digest
SHA256 7dc748e9b3983a98eb2d9b9af6cd5a284d603d7991809c7c8c7544ccce8e12fc
MD5 3dc40aeaf4d379f8601c295e238ae48c
BLAKE2b-256 fe8a737b30d0a8bcad8cff60fad3459db22ba1d68ef93d94f83e7ddc96bfc5df

See more details on using hashes here.

File details

Details for the file nameko_slack-0.0.3-py2-none-any.whl.

File metadata

File hashes

Hashes for nameko_slack-0.0.3-py2-none-any.whl
Algorithm Hash digest
SHA256 de3e38320bb4e966a41ca996f353847b86692ee9d271175c15251b9b53060e3c
MD5 76a39dfd3b8a13d2a8e9ae41b5bf23f9
BLAKE2b-256 d3434404a3403a3b8fe757941518d91309dbe28ca9b402ad876a1536f6f392b6

See more details on using hashes here.

Release history Release notifications | RSS feed

0.0.6

2 files

0.0.5

2 files

0.0.4

2 files

This release

0.0.3 This release

2 files

0.0.2

2 files

0.0.1

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page