Skip to content

Instantly share code, notes, and snippets.

@ginpei
Created December 16, 2016 13:44
Show Gist options
  • Save ginpei/bb3d0c56d6ba0761b54f93f40383f37f to your computer and use it in GitHub Desktop.
Save ginpei/bb3d0c56d6ba0761b54f93f40383f37f to your computer and use it in GitHub Desktop.

Hubotのインストールと最初のbot生成

$ mkdir my-hubot
$ cd my-hubot
$ yo hubot
  • 色々聞かれる
  • 基本的には初期値のままenter
  • bot nameは適当にかぶらないように
  • adaptorを slack
$ git init
$ git add .
$ git commit -m init

動かしてみる

scripts/example.coffee を開いて、 module.exports = (robot) -> 以降の行をコメント解除

$ bin/hubot
  • 起動する
  • WARNINGが出るけど気にしなくて大丈夫(気になるならちゃんと読んで)
  • badger@my-hubot open the first doors 等を入力、botの反応を楽しむ。
  • 一通り楽しんだら control + C で停止。
  • 先ほどの scripts/example.coffee を元に戻す。(コメントアウトし直す。)

自分だけのコマンドを作る

  • scripts/hello.coffee を新規作成
  • scripts/example.coffee を参考に、以下の内容で保存
module.exports = (robot) ->

  robot.hear /sushi/i, (res) ->
    res.send 'やったね☆'

  robot.respond /おはよう/i, (res) ->
    res.reply 'おはよ☆'
  • インデントが意味を持つので注意
$ bin/hubot
  • sushi@my-hubot おはよう 等を入力、botの反応を楽しむ。
  • git add .
  • git commit -m "my first bot"

GitHubで公開する

  • https://github.com/
  • 新規リポジトリ作成
  • git remote add origin git@nantoka-kantoka とか何とか
  • git push -u origin master
  • ウェブページを開いて確認

Herokuで動かす

  • https://www.heroku.com/
  • 右上?のNew→Create new app
  • Deploy → Deployment method = GitHub
  • Deploy → Manual deploy → Deploy Branch
    • 現状でデプロイ実行
  • Deploy → Automatic deploys → Enable
    • 今後はGitHubにpushしたら自動的にデプロイされる
  • Settingであれこれする(後で)

SlackとHerokuのhubotを連携

  • 要管理者権限
  • チーム名クリックのメニュー → Apps & Configulations
    • → "hubot" で検索して "Add Configulation"
    • → Integration Settings → API Tokenの内容をコピー
  • → HerokuのSetting → Config Variables → Reveal Config Vars
    • HUBOT_SLACK_TOKEN を、Herokuからコピーしてきたトークンの値で作成
    • HUBOT_HEROKU_KEEPALIVE_URL を、右上 "Open app" のリンク先URLで作成

Slackへhubotを招待する

  • hubotインストールした時点でメンバーに追加されてる
  • 会話したいチャンネルへ追加
  • お楽しみください
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment