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)
Metadata
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)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| nameko-slack-0.0.3.tar.gz | 7.7 kB | Without provenance | Details for nameko-slack-0.0.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| nameko_slack-0.0.3-py2-none-any.whl | Python 2 | none | any | Details for nameko_slack-0.0.3-py2-none-any.whl |
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 |
Security for nameko-slack 0.0.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.