A chat bot for Slack inspired by old pluggable bots like llimllib/limbo, will and slackbot.
- Based on slack slack-bolt
- Simple plugins mechanism
- Messages can be handled concurrently
- bot can work in asyncio and/or in queue system (pubsub/sqs/rabbitmq)
pip install TODO
TODO:
First you need to get the slack api token for your bot. You have two options:
- If you use a bot user integration of slack, you can get the api token on the integration page.
- If you use a real slack user, you can generate an api token on slack web api page.
First create a local_settings.py
and a run.py
in your own instance of slackbot.
Then you need to configure the API_TOKEN
in a python module slackbot_settings.py
, which must be located in a python import path. This will be automatically imported by the bot.
slackbot_settings.py:
API_TOKEN = "<your-api-token>"
Alternatively, you can use the environment variable SLACKBOT_API_TOKEN
.
from seedeebot.bot import Bot
def main():
bot = Bot()
bot.run()
if __name__ == "__main__":
main()
Add a DEFAULT_REPLY to slackbot_settings.py
:
DEFAULT_REPLY = "Sorry but I didn't understand you"
The message
attribute passed to your custom plugins has an special function message.docs_reply()
that will parse all the plugins available and return the Docs in each of them.
Set ERRORS_TO
in slackbot_settings.py
to the desired recipient. It can be any channel, private channel, or user. Note that the bot must already be in the channel. If a user is specified, ensure that they have sent at least one DM to the bot first.
ERRORS_TO = 'some_channel'
# or...
ERRORS_TO = 'username'
Add your plugin modules to a PLUGINS
list in slackbot_settings.py
:
PLUGINS = [
'seedeebot.plugins',
'mybot.plugins',
]
Now you can talk to your bot in your slack client!
A chat bot is meaningless unless you can extend/customize it to fit your own use cases.
To write a new plugin, simply create a function decorated by slackbot.bot.respond_to
or slackbot.bot.listen_to
:
#TODO: write docs how to create the plugin
@default_reply
def my_default_handler(message):
message.reply('...')
Here is another variant of the decorator:
@default_reply(r'hello.*)')
def my_default_handler(message):
message.reply('...')
The above default handler would only handle the messages which must (1) match the specified pattern and (2) can't be handled by any other registered handler.