Skip to main content

Slackbot with a celery queue for long running tasks

Project description

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.


pip install slackbot-queue


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

# 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

# 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:

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,

Project details

Download files

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

Source Distribution

slackbot-queue-0.3.7.tar.gz (8.2 kB view hashes)

Uploaded source

Built Distribution

slackbot_queue-0.3.7-py3-none-any.whl (9.8 kB view hashes)

Uploaded py3

Supported by

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