A simple chat bot for Slack

pip install asyncbot==0.1.1


PyPI Build Status

A chat bot for Slack inspired by llimllib/limbo and will.
A fork from lins05/slackbot.



  1. Installation
  2. Usage
  3. Create custom plugins
  4. Discussion


sudo pip install asyncbot


Generate the slack api token

First you need to get the slack api token for your bot. You have two options:

  1. If you use a bot user integration of slack, you can get the api token on the integration page.
  2. If you use a real slack user, you can generate an api token on slack web api page.

Configure the bot

Make sure you have installed asyncbot and then create a with your own instance of asyncbot. like this:

from import Bot

def main():
    bot = Bot(
        default_reply="Hello World"

if __name__ == "__main__":
Run the bot

Launch the file from your shell. We recommend to daemonize the process.

Default reply

The default reply can be either a string or a function. This will be executed whenever the bot doesn't recognize a pattern.

If you decide to create your own function, you will have to create a Message instance. This way you can access any variable at the client you might be interested on.

def my_func(message):
Configure the docs answer

The Message object, the same one is passed instantiated as an attribute to your custom plugins has an special function message.docs_reply() that will parse all the plugins available and return the __doc__ in each one of them as a message.

Configure the plugins

Add your plugin modules to the instantiation of your bot:

    plugins = [

Now you can talk to your bot in your slack client!

Attachment Support

from import respond_to
import re
import json

@respond_to('github', re.IGNORECASE)
def github():
    attachments = [
        'fallback': 'Fallback text',
        'author_name': 'Author',
        'author_link': '',
        'text': 'Some text',
        'color': '#59afe1'
    message.send_webapi('', json.dumps(attachments))

Create Plugins

A chat bot is meaningless unless you can extend/customize it to fit your own use cases.

To write a new plugin, simplely create a function decorated by or

  • A function decorated with respond_to is called when a message matching the pattern is sent to the bot (direct message or @botname in a channel/group chat)
  • A function decorated with listen_to is called when a message matching the pattern is sent on a channel/group chat (not directly sent to the bot)
from import respond_to
from import listen_to
import re

@respond_to('hi', re.IGNORECASE)
def hi(message):
    message.reply('I can understand hi or HI!')
    # react with thumb up emoji

@respond_to('I love you')
def love(message):
    message.reply('I love you too!')

@listen_to('Can someone help me?')
def help(message):
    # Message is replied to the sender (prefixed with @user)
    message.reply('Yes, I can!')

    # Message is sent on the channel
    # message.send('I can help everybody!')

To extract params from the message, you can use regular expression:

from import respond_to

@respond_to('Give me (.*)')
def giveme(message, something):
    message.reply('Here is {}'.format(something))

If you would like to have a command like 'stats' and 'stats start_date end_date', you can create reg ex like so:

from import respond_to
import re

@respond_to('stat$', re.IGNORECASE)
@respond_to('stat (.*) (.*)', re.IGNORECASE)
def stats(message, start_date=None, end_date=None):

Add the string representing the python module you created:

my_bot = Bot(
    plugins = [