LoginSignup
2
2

More than 5 years have passed since last update.

Hubot をインストールし HipChat と連携を行う

Posted at

前書き

記事探せば豊富に見つかりますし超今更感が否めませんが、備忘録として残しておきます。

nodebrew

hokaccha/nodebrew: Node.js version manager

インストール

Node.js をバージョン管理したいため nodebrew を使います。

$ curl -L git.io/nodebrew | perl - setup

or

$ wget git.io/nodebrew
$ perl nodebrew setup

PATH を追加

echo 'export PATH=$HOME/.nodebrew/current/bin:$PATH' >> ~/.bashrc

~/.bashrc を再読み込み

$ source ~/.bashrc

確認

$ nodebrew help

Node.js

インストールできるバージョンを確認

$ nodebrew ls-remote

インストール

$ nodebrew install-binary v5.7.1

バージョンを選択

$ nodebrew use v5.7.1
use v5.7.1

確認

インストールしたバージョンをすべて表示します。
current が選択したバージョンとなります。

$ nodebrew ls
v5.7.1

current: v5.7.1

Hubot

github/hubot: A customizable life embetterment robot.

インストール

Hubot 2.9.x は Yeoman ジェネレーターでインストールするようになっています。

$ npm install -g coffee-script yo generator-hubot

インスタンスを生成

$ mkdir myhubot
$ cd myhubot
$ yo hubot
                     _____________________________  
                    /                             \ 
   //\              |      Extracting input for    |
  ////\    _____    |   self-replication process   |
 //////\  /_____\   \                             / 
 ======= |[^_/\_]|   /----------------------------  
  |   | _|___@@__|__                                
  +===+/  ///     \_\                               
   | |_\ /// HUBOT/\\                             
   |___/\//      /  \\                            
         \      /   +---+                            
          \____/    |   |                            
           | //|    +===+                            
            \//      |xx|                            

? Owner kotarella1110@gmail.com
? Bot name myhubot
? Description A simple helpful robot for your Company
? Bot adapter (campfire) hipchatgot back false
? Bot adapter hipchat
   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|                            

起動

$ cd ~/myhubot
$ bin/hubot
myhubot> [Thu Mar 03 2016 08:16:24 GMT+0000 (UTC)] 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)`
[Thu Mar 03 2016 08:16:24 GMT+0000 (UTC)] INFO hubot-redis-brain: Using default redis on localhost:6379
[Thu Mar 03 2016 08:16:24 GMT+0000 (UTC)] INFO hubot-redis-brain: Data for hubot brain retrieved from Redis

ERROR hubot-heroku-alive included, but missing HUBOT_HEROKU_KEEPALIVE_URL. というエラーが発生したため、下記のように修正します。

external-scripts.json を修正

~/myhubot/external-scripts.json
  [
    "hubot-diagnostics",
    "hubot-help",
-   "hubot-heroku-keepalive",
    "hubot-google-images",
    "hubot-google-translate",
    "hubot-pugme",
    "hubot-maps",
    "hubot-redis-brain",
    "hubot-rules",
    "hubot-shipit"
  ]

再度起動し確認

$ cd ~/myhubot
$ bin/hubot
myhubot> [Thu Mar 03 2016 08:24:56 GMT+0000 (UTC)] INFO hubot-redis-brain: Using default redis on localhost:6379
[Thu Mar 03 2016 08:24:56 GMT+0000 (UTC)] INFO hubot-redis-brain: Data for hubot brain retrieved from Redis

myhubot> myhubot ping
myhubot> PONG

HipChat

hipchat/hubot-hipchat: HipChat adapter for GitHub's Hubot

HipChat Adapter をインストール

HipChat本体はAdapterというものを通してHubotとやりとりを行います。

$ cd ~/myhubot
$ npm install hubot-hipchat --save
~/myhubot/bin/hubot
  #!/bin/sh

  set -e

  npm install
  export PATH="node_modules/.bin:node_modules/hubot/node_modules/.bin:$PATH"
+ 
+ export HUBOT_HIPCHAT_JID="XXXXXX_XXXXXX@chat.hipchat.com"
+ export HUBOT_HIPCHAT_PASSWORD="XXXXXX"
+ export HUBOT_HIPCHAT_ROOMS="XXXXXX_hubot@conf.hipchat.com"
+ export HUBOT_LOG_LEVEL="debug"

  exec node_modules/.bin/hubot --name "myhubot" "$@"

起動

$ bin/hubot -a hipchat

確認

HipChat で Hubot とやりとり

forever

forever をインストールして Hubot をデーモン化します。

foreverjs/forever: A simple CLI tool for ensuring that a given script runs continuously (i.e. forever)

インストール

$ npm install forever -g

bin/hubot の編集

bin/hubot
  #!/bin/sh

  set -e

  npm install
  export PATH="node_modules/.bin:node_modules/hubot/node_modules/.bin:$PATH"

  export HUBOT_HIPCHAT_JID="XXXXXX_XXXXXX@chat.hipchat.com"
  export HUBOT_HIPCHAT_PASSWORD="XXXXXX"
  export HUBOT_HIPCHAT_ROOMS="XXXXXX_hubot@conf.hipchat.com"
  export HUBOT_LOG_LEVEL="debug"

- exec node_modules/.bin/hubot --name "myhubot" "$@"
+ forever start -c coffee node_modules/.bin/hubot -a hipchat

起動

$ bin/hubot
warn:    --minUptime not set. Defaulting to: 1000ms
warn:    --spinSleepTime not set. Your script will exit if it does not stay up for at least 1000ms
info:    Forever processing file: node_modules/.bin/hubot

確認

$ forever list
info:    Forever processes running
data:        uid  command script                             forever pid  id logfile                         uptime
data:    [0] 2sAI coffee  node_modules/.bin/hubot -a hipchat 2137    2142    /home/vagrant/.forever/2sAI.log 0:0:0:19.806

参考文献

2
2
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
2
2