LoginSignup
7
6

More than 5 years have passed since last update.

CentOS7.3 環境(Vagrant)に Mattermost いれたので Hubot連携してみる その3

Last updated at Posted at 2017-08-02

hubotって

GitHub社が開発したチャット(bot)です。開発・実行フレームワークには、CoffeeScript を使用しているので簡単に機能を追加することができるというのが目玉ですね。使用用途としては、Slackに組み込んで DevOps 楽~に~なんていうのが流行ってる(結構前からだけどね)という代物です。
Node.js で動くので導入するにもかなり敷居が低いっていうのが人気があるっぽい。

GitHub社謹製! bot開発・実行フレームワーク「Hubot」
【Slack】15分で作る猫ボット (Hubot + 人工知能ボットAPI)

hubot連携

terukizm さんの Hubot連携 記事がとても分かり易いのでそちらの記事に沿って進めました。ただ Mattermost のバージョンが若干古いのでそこらへんを最新化してみる。あと vagrant版hubot-mattermost-vagrant がありますがまず1つずつ手で実行し動作を確認していくという意味でわざわざコマンドを叩いてますw。

vagrant で環境を作成

こんな感じで作成します。ip固定でw

・Hubot側 ※Hubotの受け口ポートは、18080 とします。

config.vm.define :cent73hubot do |cent73hubot|
  cent73hubot.vm.box = "bento/centos-7.3"
  cent73hubot.vm.network :private_network, ip: "192.168.11.226"
  cent73hubot.vm.provider "virtualbox" do |v|
    v.customize ["modifyvm", :id, "--memory", 512]
  end
end

・Mattermost側 ※ホスト側にportforward してます

config.vm.define :cent73Mattermost do |cent73Mattermost|
  cent73Mattermost.vm.box = "bento/centos-7.3"
  cent73Mattermost.vm.network :private_network, ip: "192.168.11.224"
  cent73Mattermost.vm.provider "virtualbox" do |v|
    v.customize ["modifyvm", :id, "--memory", 512]
  end
  config.vm.network :forwarded_port, host: 19191,  guest: 80
end

Hubotのインストール

これこれ、この画像がみたいのですよw。

                     _____________________________  
 _____              /                             \ 
 \    \             |   Self-replication process   |
 |    |    _____    |          complete...         |
 |__\\|   /_____\   \     Good luck with that.    / 
   |//+  |[^_/\_]|   /----------------------------  
  |   | _|___@@__|__                                
  +===+/  ///     \_\                               
   | |_\ /// HUBOT/\\                             
   |___/\//      /  \\                            
         \      /   +---+                            
          \____/    |   |                            
           | //|    +===+                            
            \//      |xx|                            

Node.js , nvm をインストール

CentOS7 で node.js をインストールする手順。windowsとかは若干違うかもしれないからそこらへんは、google先生に聞いて欲しい。

$ sudo yum install epel-release
$ sudo yum install nodejs npm

開発に必要なパッケージ

$ sudo npm install -g jsfmt
$ sudo npm install -g sails
$ sudo npm install -g node-dev
$ sudo npm install -g pm2
$ sudo npm install -g forever
$ sudo npm install -g yo generator-hubot

Hubotの初期設定

下記コマンドを実行して初期設定を行う。

$ mkdir matter-bot && cd matter-bot
$ yo hubot --adapter mattermost --owner=user@example.com --name=matter-bot --description=sample

とりあえずこれで終わり。

Mattermost の設定

統合機能で「内向きのウェブフック, 外向きのウェブフック」を設定する。
① Outgoint WebHooks から ⇒ Hubotで処理 ⇒ Incoming WebHooks
② Hubotで処理 ⇒ Incoming WebHooks
※漢字だったり英字だったり混じってるけど言ってる意味は同じw

image.png

Outgoing WebHooks の設定

とりあえずチャネル「Town Square」に対して内向きのウェブフックを設定する。
MATTERMOST_INCOME_URL の環境変数となります。

image.png

192.168.1.128:19191 となっているのは、ホスト側IPに portforward し ホスト側のネットワーク構成でvagrantを使用できるようにするためにしているだけなので、適宜ここらへん修正するべし。

Incoming WebHooks の設定

「matter-bot」のトリガーワードによりHubotが起動するように設定する。
MATTERMOST_TOKEN の環境変数となります。

image.png

Hubotを起動する前の環境設定

その前に環境設定をする。

~/.bash_profile
export PORT=18080
export MATTERMOST_ENDPOINT=/hubot/incoming
export MATTERMOST_TOKEN=jxh3dhx8yfn17ygo4pjrgqgrxy
export MATTERMOST_INCOME_URL=http://192.168.11.224/hooks/bg54t5czcpyzuxjt9ssaozw9we
export MATTERMOST_HUBOT_USERNAME=matter-bot

Hubotのサンプルスクリプトを設定

terukizm/hubot-mattermost-vagrant さんの sample.coffee をコピーする。

$ cd ~/matter-bot/scripts/
$ wget https://github.com/terukizm/hubot-mattermost-vagrant/blob/master/hubot/scripts/sample.coffee

Hubotを起動する

とりあえず起動してみる。

[vagrant@localhost matter-bot]$ bin/hubot -a mattermost
npm WARN hubot-help@0.2.2 requires a peer of coffee-script@^1.12.6 but none was installed.
[Wed Aug 02 2017 14:37:02 GMT+0900 (JST)] WARNING Loading scripts from hubot-scripts.json is deprecated and will be removed in 3.0 (https://github.com/github/hubot-scripts/issues/1113) in favor of packages for each script.

Your hubot-scripts.json is empty, so you just need to remove it.
[Wed Aug 02 2017 14:37:02 GMT+0900 (JST)] ERROR hubot-heroku-keepalive included, but missing HUBOT_HEROKU_KEEPALIVE_URL. `heroku config:set HUBOT_HEROKU_KEEPALIVE_URL=$(heroku apps:info -s | grep web.url | cut -d= -f2)`
[Wed Aug 02 2017 14:37:02 GMT+0900 (JST)] INFO hubot-redis-brain: Using default redis on localhost:6379

試してみる

image.png

へー。PONG! と PONG が・・・、何故表示されるのかは不明だけど、まあ概ねok

参考にさせて頂いたサイト様

今回特にお世話になりました!!

SlackクローンのMattermostを使ってみる - 外部連携編 -(WebHooks、Hubot)

うんうん

hubotのインストール手順
GitとCIとかチャットとかをオンプレで運用する話

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