4
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をローカルで動かすメモ

Last updated at Posted at 2016-04-13

「Python製のチャットボットないかなー」と探してた際に見つけたので、しばらく使ってみる。

マニュアル斜め読み

ドキュメントから雑に確認した際の、自分の理解集

  • Slack, Hipchat などの、いくつかのチャットサービス用のバックエンド機構が最初から同梱されている(hubotのアダプターに相当するもの)
  • 話しかけてきた相手が管理者かどうかを判定して動くことが可能っぽい?
  • プラグイン(ボットの振る舞い)を検証するためのローカル動作モードがある模様
  • 「n分間隔で喋る」ような仕組みはあるっぽい
    • ただし、cronみたいな毎日n時に喋るはまだ見つけられてない

インストール

想定環境

  • pyenv利用して構築

インストールまで

インストールしてみる
$ pyenv virtualenv 3.5.1 errbot
$ pyenv shell errbot
$ pip install errbot slackclient
$ mkdir mybot
$ cd mybot
$ python -c "import errbot;import os;import shutil;shutil.copyfile(os.path.dirname(errbot.__file__) + os.path.sep + 'config-template.py', 'config.py')"

設定を追加

「とりあえず動作確認」のために修正した方がいいところ

config.py
# L66
# データ保存用フォルダ。相対パスの方が挙動確認が楽
BOT_DATA_DIR = './data'
# L85
# カスタムプラグインを置く場所。デフォルトはNoneで使わないが、どうせ作るなら、相対パスで
BOT_EXTRA_PLUGIN_DIR = './plugins'

実行してみる

とりあえず、テキストでバックエンドで起動させてみる
$ vi config.py
$ errbot -T
22:30:14 INFO     errbot.err                Config check passed...
22:30:14 INFO     errbot.err                Selected backend 'Text'.
(中略)
22:30:15 INFO     errbot.errBot
22:30:15 INFO     errbot.errBot             Notifying connection to all the plugins...
22:30:15 INFO     errbot.plugins.ChatRoom   Callback_connect
22:30:15 INFO     errbot.errBot             Plugin activation done.

>>>

ざっくり、挙動解説

デフォルトでは、!を先頭に持つテキストをbotへの命令として認識します
試しに、ヘルプを呼び出してみるとこうなります。

errbot
>>> !help

╌╌[MD  ]╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌
### All commands

╌╌[HTML]╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌
<h3>All commands</h3>

╌╌[TEXT]╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌
All commands

╌╌[IM  ]╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌
_All commands_

╌╌[ANSI]╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌
All commands

╌╌[BORDERLESS]╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌
All commands

>>>

出力量がとてつもなく多いので省略しましたが、Markdown,HTML,プレーンテキストなど様々な種類のフォーマットでレスポンスを返してくれます。
例えばSlackを反応するように起動させると、HTML形式になるように返してくれます。

ちょこちょこいじって遊んでいる最中なので、ちょこちょこ投稿したいと思います。

4
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
4
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?