Skip to main content

Slackbot Queue

Slackbot with a celery queue for long running tasks

This can be run even without a celery queue as long as you do not try and add things to the worker. Just run the listener and all the features (besides having a worker queue) will still work.

Install

pip install slackbot-queue

Usage

The example folder has a lot more to show and is ready to run

from slackbot_queue import slack_controller, queue

from example import Example  # Import the example command class

# Set up the celery configs
queue.conf.task_default_queue = 'custom_slackbot'
queue.conf.broker_url = 'amqp://guest:guest@localhost:5672//'

# The token could also be set by the env variable SLACK_BOT_TOKEN
slack_controller.setup(slack_bot_token='xxxxxxxx')

# Set up the command by passing in the slack_controller to it
ex = Example(slack_controller)

# Set up the example command to only work in the `general` channel or as a direct message
slack_controller.add_commands({'__direct_message__': [ex],
                               '__all__': [],
                               'general': [ex],
                               })

# Either start the listener
slack_controller.start_listener()

# Or the worker:
# The argv list is celery arguments used to start the worker
slack_controller.start_worker(argv=['celery', 'worker', '--concurrency', '1', '-l', 'info'])

A full example can be found in the example dir.

Slacks api docs: https://api.slack.com/methods

If the command function returns None, that means that the bot will continue to check the rest of the commands.
But if the command does return something, no other commands will be checked. Meaning that if there are 2 commands that are looking for the same message regex, the command listed first in the channel list will be the only one triggered.

If you want multiple commands to get triggered by the same message, you can have them return None, but sill post to slack inside you function by doing self.slack.slack_client.api_call(**message_data).
message_data is the same as you would normally return but with the added keys (which are normally added when the data gets returned):

'method': 'chat.postMessage',  # or any other method slack supports
'channel': full_event['channel']['id'],
'as_user': True,

Metadata

Release files for slackbot-queue 0.3.7

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

Source distribution (sdist)

Source distribution for slackbot-queue 0.3.7
File Size Uploaded
slackbot-queue-0.3.7.tar.gz 8.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for slackbot-queue 0.3.7
File Interpreter ABI Platform
slackbot_queue-0.3.7-py3-none-any.whl Python 3 none any Details

Total release size: 18.0 kB

Release files / slackbot-queue-0.3.7.tar.gz

Download URL slackbot-queue-0.3.7.tar.gz
Size 8.2 kB
Tags Source
SHA-256 checksum
How to use checksums
38efaa1a6fa63f89173b68503b605bd51e7c98a2fe0cb764a9dc435e855fce18
BLAKE2b-256 checksum
How to use checksums
83267230a949b68e5197df3fa04ff522036125ec184e5a70ca235ed8234dc991
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.6.13

Release files / slackbot_queue-0.3.7-py3-none-any.whl

Download URL slackbot_queue-0.3.7-py3-none-any.whl
Size 9.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
dc6e722769d8ee6dd955fe2ecda846dbc7278106156422a02c581423944d6218
BLAKE2b-256 checksum
How to use checksums
2142706e66998f61c7ffbd88e043f163125857134481c220b95365c640e2f43b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.6.13

Release history Release notifications | RSS feed

This release

0.3.7 This release

2 release files

0.3.6

2 release files

0.3.5

2 release files

0.3.4

1 release file

0.3.3

1 release file

0.3.2

1 release file

0.3.1

1 release file

0.3.0

1 release file

0.2.0

1 release file

0.1.5

1 release file

0.1.4

1 release file

0.1.3

1 release file

0.1.2

1 release file

0.1.1

1 release file

0.1.0

1 release file

0.0.2

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