LoginSignup
5
9

More than 5 years have passed since last update.

slack hubotを使ってみる

Last updated at Posted at 2018-02-24

Macでやります。
version: Sierra 10.12.6

Hubotの準備

このURLでHubotを検索
https://slack.com/apps

Hubotインストール

↓な感じ。
スクリーンショット 2018-02-24 11.55.21.png

↓インストールする
スクリーンショット 2018-02-24 11.59.46.png

↓Botの名前を決める
スクリーンショット 2018-02-24 12.01.41.png

名前を決めたら↓ような画面が出てくる。ここでAPI Tokenを取得できる。
スクリーンショット 2018-02-24 12.03.50.png
好きな画像やアイコンに変えちゃいましょう。

slackのチャンネルにHubotさんを招待

↓slackにて先ほど作成したHubotさんをチャンネルに追加しましょう。
スクリーンショット 2018-02-24 12.08.34.png

きました〜
スクリーンショット 2018-02-24 12.10.36.png

これで準備完了ですね〜

Bot環境準備

このままだと何にもしてくれないので、中身を作ってみます。

環境準備

Node.jsが動く環境とnpmがいるのでバージョンチェック(だいぶ前に入れてました)。
インストール方法はググると出てくるので、その辺を参考に。

$ node -v
v8.9.4
$ npm -v
5.6.0

以下インストール

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

こんな感じのが出てきたらOK

Everything looks all right!
+ coffee-script@1.12.7
+ generator-hubot@0.4.0
+ yo@2.0.1
+ hubot@2.19.0
$ mkdir myhubot
$ cd myhubot/
$ 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 [オーナー名] <メールアドレス>
? Bot name [Bot名]
? Description [Botの説明]
? Bot adapter slack

〜(略)〜

+ hubot-diagnostics@0.0.2
+ hubot-help@0.2.2
+ hubot-pugme@0.1.1
+ hubot@2.19.0
+ hubot-rules@0.1.2
+ hubot-slack@4.4.0
+ hubot-scripts@2.17.2
+ hubot-google-images@0.2.7
+ hubot-heroku-keepalive@1.0.3
+ hubot-maps@0.0.3
+ hubot-google-translate@0.2.1
+ hubot-redis-brain@0.0.4
+ hubot-shipit@0.2.1

なかんじ。

$ bin/hubot 
slackhubot> slackhubot echo "aaa"
slackhubot> "aaa"
$ HUBOT_SLACK_TOKEN=<API Token> ./bin/hubot --adapter slack
npm WARN hubot-help@0.2.2 requires a peer of coffee-script@^1.12.6 but none is installed. You must install peer dependencies yourself.

up to date in 2.316s
warn: SlackDataStore is deprecated and will be removed in the next major version. See project documentation for a migration guide.
warn: SlackDataStore is deprecated and will be removed in the next major version. See project documentation for a migration guide.
[Sat Feb 24 2018 21:35:21 GMT+0900 (JST)] INFO Logged in as <>
[Sat Feb 24 2018 21:35:22 GMT+0900 (JST)] INFO Slack client now connected
[Sat Feb 24 2018 21:35:22 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.
[Sat Feb 24 2018 21:35:22 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)`
[Sat Feb 24 2018 21:35:23 GMT+0900 (JST)] INFO hubot-redis-brain: Using default redis on localhost:6379

これでSlackにHubotさんにメンション付きでpingしてみると反応してくれる

スクリーンショット 2018-02-24 21.37.32.png

一旦これでHubotのセッティングはできた

scriptsディレクトリに実装していくと色々できるみたい

scripts/hello.coffee

module.exports = (robot) ->
  robot.respond /おはよう/i, (msg) ->
    msg.send "Hello World"

これでも一回

$ HUBOT_SLACK_TOKEN=<API Token> ./bin/hubot --adapter slack

を実行して「おはよう」してみる
スクリーンショット 2018-02-24 21.45.21.png

これで一旦使ってみれたので、次回色々HuBotさんにさせてみたいと思います。

5
9
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
5
9