LoginSignup
1
1

More than 5 years have passed since last update.

idobataにhubotを設置してみる

Last updated at Posted at 2015-05-24

スクリーンショット 2015-05-25 22.42.16.png

資料

http://gihyo.jp/dev/serial/01/hubot
https://hubot.github.com/docs/
https://github.com/idobata/hubot-idobata

やってみた感想

今更だけど、idobataにhubotを置いてみるのを試してみた。
ボットの情報の入出力先をアダプターで気軽に選べたり、
スクリプトを置くのがすごくカンタンで、ちょっとかわいい。

環境

  • Mac OS X
  • ndenv
    • node v0.10

インストール/構築

$ npm install -g yo generator-hubot
$ mkdir cat-hubot
$ ndenv rehash
$ cd cat-hubot/
$ yo hubot

古い手順でやったら…

generatorを使えって。

$  hubot --create cat-hubot
'hubot --create' is deprecated. Use the yeoman generator instead:
    npm install -g yo generator-hubot
    mkdir -p cat-hubot
    yo hubot

とりあえず起動

0.12だったので起動しなかった。

$ bin/hubot
ndenv: version `v0.10' is not installed

0.10をインストール。

$ ndenv install v0.10
$ ndenv local v0.10

起動した。

$ bin/hubot 
cat-hubot> [Sat May 23 2015 19:02:14 GMT+0900 (JST)] ERROR hubot-heroku-alive included, but missing HUBOT_HEROKU_KEEPALIVE_URL. `heroku config:set HUBOT_HEROKU_KEEPALIVE_URL=$(heroku apps:info -s  | grep web_url | cut -d= -f2)`
[Sat May 23 2015 19:02:14 GMT+0900 (JST)] INFO Using default redis on localhost:6379

cat-hubot> 

git/githubで管理する

$ git init
$ git add .
$ git commit -m "first commit"
$ git remote add origin git@github.com:ken1flan/cat-hubot.git
$ git push -u origin master

スクリプトを追加してみる

Helloと聞いたら、にゃーと答える、スクリプト。

scripts/cat.coffee
module.exports = (robot) ->
  robot.hear /hello/i, (res) ->
    res.send "にゃー"
cat-hubot> Hello
にゃー
cat-hubot> 

cat-hubot Helloと話しかけたら、にゃーと答える、スクリプト。

scripts/cat.coffee
module.exports = (robot) ->
  robot.respond /hello/i, (res) ->
    res.send "にゃー"
cat-hubot> Hello
cat-hubot> cat-hubot, Hello
にゃー

idobataとつなげる

アダプターの追加

$ npm install hubot-idobata --save
$ npm install

idobataでボットアカウントを設定

Room Settingsにボットを作る設定があるので、そこで作って、トークンをメモっておく。

起動時に使用するアダプターにidobataを設定。

web: bin/hubot -a idobata
git commit -a -m "change Procfile idobata"

Herokuに置く

herokuにアプリを作って設定。

$ heroku create
$ heroku config:set HUBOT_IDOBATA_API_TOKEN=<トークン>
$ heroku config:set HUBOT_NAME=<ボットの名前>
$ git push heroku master

Googleのスクリプトで生存確認する

作ったボットが寝子なので、Google Apps Scriptで作った猫じゃらしでちょいちょい興味を引くようにする。

function check_server(url)
{
  var response = new Array;
  var start = new Date;
  try{
    var res = UrlFetchApp.fetch(url);
    response['code'] = res.getResponseCode();
  } catch(e){
    response['code'] = 999;
  }
  var end = new Date;
  response['time'] = end - start;
  return response;
}

function keepAwakeCat() {
  url = 'http://(hubotのURL)'
  var response = check_server(url);  
}
1
1
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
1
1