A neat Slack bot for Pythonistas
Python 3.4+
$pip install -r requirements.txt
If you are using Python 2.x use 0.0.3
Like Django, you can config your bot by editing settings.py
set SLACK_TOKEN
variable in settings.py.
if REDIS_URL
is not setted, all Redis relevant features, like redis_brain, will be disabled.
- install dependencies
- Add your bot for your slack account at Custom Integration Page
- Copy API Token to clipboard.
- Open
settings.py
- Set
SLACK_TOKEN
. You can setREDIS_URL
if it's available. - Run
$python robot.py
. Python 3.5.3+ is required. - Invite your bot to the channel
/invite @YOUR_BOT_NAME
👹 2nd step is important because RTM is working only with legacy bot.
Type command with Command Prefix (default is !
) on the channel where the bot is on.
Honey is going to respond to your command kindly.
YOU: !help
Honey: Hello world!!
We call each function that you plugged-in to the Honey, the app.
Built-in and example apps are in the apps
directory.
Below is basic form of app.
This just says Hello world!!
to the channel when user typed the command, !hi
.
from .decorators import on_command
@on_command(['hi', 'hello', '하이', 'ㅎㅇ'])
def hello_world(robot, channel, user, tokens):
'''
Simple app just says `Hello word!!`
@params {object} robot - Honey bot instance
@params {str} channel - channel name where invoked this app
@params {str} user - user id who invoked this app
@params {list} tokens - user input tokens
@returns {str, str} - channel name, message
'''
return channel, 'Hello world!!'
And Honey supports multiple commands for each function.
The above app can be invoked the command with Command Prefix (default is !
) on the channel.
It would be !hello
, !hi
, !하이
or !ㅎㅇ
Honey automatically split your message into tokens by whitespaces.
Let's assume that you typed !memo remember this
with blow app.
@on_command(['memo'])
def remember(robot, channel, user, tokens):
assert 2 == len(tokens)
assert 'remember' == tokens[0]
assert 'this' == tokens[1]
return channel, tokens[1]
You may want tokens containing whitespaces. In that case, wrap your token with double quote(") like
!memo remember "kill -9 $(ps aux | grep gunicorn | grep -v 'grep' | awk '{print $2 }')"
Honey supports semi-permanent storage using Redis as well as Hubot.
The full usage code is on apps/redis_brain
. If you want to use the feature, just add redis_brain
to APPS
variable at your settings.py
Let's assume that you typed !memo whats this
in your channel with below app.
after that, whenever you type !memo whats
Honey will says this
to the channel.
if you forgot what you memoized, just type !memo
. Honey let you know what she memoized before.
- Add your app and put it into
apps
folder - open
settings.py
and add your app name(likehello_world
) toAPPS
- restart your bot