3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ErrbotでSlackのチャットボットにする

Posted at

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に接続してくれます。

会話してみる

I4RM7l5QoK.gif

ターミナル側
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の出来上がり

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?