- 追加された行はこの色です。
- 削除された行はこの色です。
#topicpath
----
***コンテンツ一覧 [#ed86a7ca]
#ls2
#contents
**Hubotとは [#i0eb1aea]
[[HUBOT>https://hubot.github.com/]]をつかってみました。HubotとはGithub社謹製のbot開発・実行フレームワークです。
簡単にいうとSlackなどのチャットツール上で稼働するボットを作成することができます。
**やってみる [#r10656f2]
Hubotは通常は [[Heroku>https://www.heroku.com/]] にいれるのが定番ぽいのですが、今回は nodejs が 稼働するDockerコンテナ上に入れてみようと思います。じぶんがDocker絶賛勉強中なので。
なので以下、Dockerが動く環境がある前提で進めます。
# docker pull node
# cat Dockerfile
FROM node
MAINTAINER masatomix
RUN npm install -g yo generator-hubot
RUN useradd bot
RUN mkdir /home/bot && chown bot:bot /home/bot
USER bot
WORKDIR /home/bot
Hubotは Yeomanを使ってテンプレからソースを作りますので、それらをインストールしておきます。このDockerfile を使って新しいimageをつくります。
# docker build -t hubot-sample .
docker build -t hubot-sample .
Sending build context to Docker daemon 2.048 kB
Step 1 : FROM node
---> 47522eb1edb5
Step 2 : MAINTAINER masatomix
---> Using cache
---> a1914d9d0328
Step 3 : RUN npm install -g yo generator-hubot
---> Using cache
---> a47cfa033eb7
Step 4 : RUN useradd bot
---> Running in cd8beb5b849b
---> be2fc2c58d90
Removing intermediate container cd8beb5b849b
Step 5 : RUN mkdir /home/bot && chown bot:bot /home/bot
---> Running in d2c532d64b0b
---> 9421a92d23e7
Removing intermediate container d2c532d64b0b
Step 6 : USER bot
---> Running in 5eb063a6afd7
---> 119c2de9066b
Removing intermediate container 5eb063a6afd7
Step 7 : WORKDIR /home/bot
---> Running in 282c1d3afce7
---> 5f173b929721
Removing intermediate container 282c1d3afce7
Successfully built 5f173b929721
#
# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hubot-sample latest 5f173b929721 37 seconds ago 724.3 MB
imageができたので、そこから新しいコンテナを起動します
# docker run -it hubot-sample /bin/bash
bot@8d0968b2a418:~$ node --version
v7.7.3
bot@8d0968b2a418:~$
nodejsがインストールされた環境が起動しました。
ではさっそく Yeomanでソース生成です。Yeomanにはいろいろきかれますが、まあ適当に。
$ mkdir hubot-sample && cd $_
$ yo hubot
? ==========================================================================
We're constantly looking for ways to make yo better!
May we anonymously report usage statistics to improve the tool over time?
More info: https://github.com/yeoman/insight & http://yeoman.io
========================================================================== Yes
_____________________________
/ \
//\ | Extracting input for |
////\ _____ | self-replication process |
//////\ /_____\ \ /
======= |[^_/\_]| /----------------------------
| | _|___@@__|__
+===+/ /// \_\
| |_\ /// HUBOT/\\
|___/\// / \\
\ / +---+
\____/ | |
| //| +===+
\// |xx|
? Owner Masatomix <masatomix@example.com> ←Owner
? Bot name Hubot ← Hubotの名前
? Description A simple helpful robot for your Company
? Bot adapter campfire
create bin/hubot
create bin/hubot.cmd
create Procfile
create README.md
create external-scripts.json
create hubot-scripts.json
create .gitignore
create package.json
create scripts/example.coffee
create .editorconfig
_____________________________
_____ / \
\ \ | Self-replication process |
| | _____ | complete... |
|__\\| /_____\ \ Good luck with that. /
|//+ |[^_/\_]| /----------------------------
| | _|___@@__|__
+===+/ /// \_\
| |_\ /// HUBOT/\\
|___/\// / \\
\ / +---+
\____/ | |
| //| +===+
\// |xx|
... 以下略
npm info ok
起動します
$ ./bin/hubot
... 略
npm info ok
[Mon Mar 20 2017 05:49:38 GMT+0000 (UTC)] INFO hubot-redis-brain: Using default redis on localhost:6379
Hubot>
起動しました。
** ヘルプを表示 [#t108047e]
コマンドが分からないのでとりあえずヘルプ。
Hubot> hubot help
Hubot> Shell: Hubot adapter - Reply with the adapter
Hubot animate me <query> - The same thing as `image me`, except adds a few parameters to try to return an animated GIF instead.
Hubot echo <text> - Reply back with <text>
Hubot help - Displays all of the help commands that Hubot knows about.
Hubot help <query> - Displays all help commands that match <query>.
Hubot image me <query> - The Original. Queries Google Images for <query> and returns a random top result.
Hubot map me <query> - Returns a map view of the area returned by `query`.
Hubot mustache me <url|query> - Adds a mustache to the specified URL or query result.
Hubot ping - Reply with pong
Hubot pug bomb N - get N pugs
Hubot pug me - Receive a pug
Hubot the rules - Make sure hubot still knows the rules.
Hubot time - Reply with current time
Hubot translate me <phrase> - Searches for a translation for the <phrase> and then prints that bad boy out.
Hubot translate me from <source> into <target> <phrase> - Translates <phrase> from <source> into <target>. Both <source> and <target> are optional
ship it - Display a motivation squirrel
Hubot>
というわけで話しかけてみましょう。
Hubot> hubot echo Hello World
Hubot> Hello World
Hubot> hubot ping
Hubot> PONG
Hubot> hubot pug me
Hubot> http://28.media.tumblr.com/tumblr_ls9fa8S9lE1qfbmwho1_500.jpg
Hubot>
パグのリンクはきれてるみたいですが、いろいろ答えてくれるボットができました。
ソースはテンプレのままですが、そこをいじる事でいろんな事をしてくれるボットが作れそうですね。
**関連リンク [#r234c9db]
-[[GitHub社謹製! bot開発・実行フレームワーク「Hubot」:連載|gihyo.jp … 技術評論社>http://gihyo.jp/dev/serial/01/hubot]] 情報は古いが、、。
-[[hubotスクリプトの書き方とサンプル集 | mitc>http://blog.fumiz.me/2012/08/05/hubot-irc-bot-script/]]
-[[CentOS 7.2 で Hubot を Docker で動かしてみた - Qiita>http://qiita.com/miyamiya/items/91d1bac25764a24e820e]]
-[[dockerでhubotが動作する環境を作る - Qiita>http://qiita.com/tubone/items/11a7ceb3e7013139abab]]
-[[dockerでhubot + slack - Qiita>http://qiita.com/nabe/items/3eb9c386eef7c3fb7750]]
-[[こんな僕でも30分でSlackのbotを作れた。 - アラタナエンジニアブログ>http://lab.aratana.jp/entry/2014/12/04/185053]]
-[[CentOS 7 で Hubot on Docker をやってみたメモ 愛しく切ない1bed>http://1bed.saloon.jp/?p=1961]]
----
この記事は
#vote(おもしろかった,そうでもない)
#comment
#topicpath
SIZE(10){現在のアクセス:&counter;}