http://qiita.com/attakei/items/29b3f0086296345216df の続き
今回はSlackを監視して動くErrbotの初期構築をしてみます。
準備するもの
- Slackチーム
- ↑のチーム内で用意したbotユーザーとトークン
- 前回の記事で用意したErrbotの稼働環境
config.pyをSlack用に編集する
config.py
# L47付近
# チャットのバックエンドを指定。今回はここにSlackを指定する
BACKEND = 'Slack' # defaults to XMPP
# L135付近
BOT_IDENTITY = {
# XMPP部分はコメントアウト
# XMPP (Jabber) mode
# 'username': 'err@localhost', # The JID of the user you have created for the bot
# 'password': 'changeme', # The corresponding password for this user
# L152付近
# Slackの使用にはトークンが必要なので、コメントアウトされているトークンを指定する
# Slack mode (comment the others above if using this mode)
'token': 'xoxb-your-slack-token',
# L179付近
# このErrbotの管理権限をもつアカウントのリスト。@から始めるやつ
BOT_ADMINS = ()
# L185付近
# このErrbotが参加しているルームやチャンネル。今回は一人で会話するので空タプル
CHATROOM_PRESENCE = ()
起動してみる
ターミナルで
$ errbot
12:34:47 INFO errbot.err Config check passed...
12:34:47 INFO errbot.err Selected backend 'Slack'.
(略)
12:34:48 INFO errbot.main Found Backend plugin: 'Slack'
12:34:48 INFO errbot.backends.slack Verifying authentication token
12:34:50 INFO requests.packages.urllib3 Starting new HTTPS connection (1): slack.com
12:34:52 INFO errbot.backends.slack Connecting to Slack real-time-messaging API
12:34:52 INFO requests.packages.urllib3 Starting new HTTPS connection (1): slack.com
12:34:56 INFO errbot.backends.slack Connected
(略)
12:34:57 INFO errbot.errBot
12:34:57 INFO errbot.errBot Notifying connection to all the plugins...
12:34:57 INFO errbot.plugins.ChatRoom Callback_connect
12:34:57 INFO errbot.errBot Plugin activation done.
12:34:58 INFO requests.packages.urllib3 Starting new HTTPS connection (1): slack.com
slackのメッセージングAPIに接続してくれます。
会話してみる
ターミナル側
13:05:04 INFO errbot.plugins.ACLS Matching ACL {} against username @attakei for command Help:help
13:05:04 INFO errbot.plugins.ACLS Check if help is admin only command.
13:05:04 INFO errbot.errBot Processing command 'help' with parameters '' from @attakei
ログを見ると、「誰から」「どんな命令が」を出力してくれています。
後は、herokuなりどこかにおけば、chatbotの出来上がり