LoginSignup
20

More than 5 years have passed since last update.

herokuでhubot立ててみたらカンタンだった

Last updated at Posted at 2016-02-13

heroku-hubot-slackの組み合わせでやってみました。

まずはローカルでhubotを動かしてみる (Windows)

あらかじめnode.jsをインストールしておきます。では、hubotをインストール。

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

yeomanジェネレータでhubotを作ります。

mkdir [your-bot-dir]
cd [your-bot-dir]
yo hubot

では試しに起動してみましょう。

bin\hubot
@[your-bot-name] ping
PONG

slackの設定

Slackから

Browse Apps > Hubot > Configurations on [your-team] > Edit configuration

を開き、API TOKENを取得します。

herokuの準備 (Windows)

herokuのアカウントを作っておきます。heroku toolbeltをインストールし、ローカル環境のコマンドラインで設定します。

add-onを使うので、無料でも事前にクレジットカードの設定をお忘れなく。

heroku login
heroku create [your-bot-name]
heroku addons:create redistogo:nano
heroku config:set HUBOT_SLACK_TOKEN=[your-slack-token] --app [your-bot-name]
heroku config:set HUBOT_SLACK_TEAM=[your-slack-team] --app [your-bot-name]
heroku config:set HUBOT_SLACK_BOTNAME=[your-bot-name] --app [your-bot-name]
heroku config:set HUBOT_URL=https://[your-bot-name].herokuapp.com/ --app [your-bot-name]
heroku config:add TZ=Asia/Tokyo

herokuへデプロイ

heroku-gitを使います。heroku Webサイト上で設定しておきます。gitへpushすると、デプロイが開始されます。

heroku git:remote -a [your-app-name]
git init
git add -all
git commit -m "first commit"
git push heroku master

定期的に起こす

herokuは30分アクセスがないとスリープに入ってしまうので、これを防ぐためにhubot-heroku-keepaliveを使います。yo hubotで同時にインストールされているので、設定だけ行います。

heroku config:set HUBOT_HEROKU_KEEPALIVE_URL=[your-app-url]
heroku config:add HUBOT_HEROKU_WAKEUP_TIME=9:00 -a [your-app-name]
heroku config:add HUBOT_HEROKU_SLEEP_TIME=01:00 -a [your-app-name]

heroku free dynoでは強制的に6時間のスリープに入ってしまいます。そこで、既定の時間になったら再開するよう、add-onとしてHeroku Schedulerを使います。

heroku addons:create scheduler:standard -a [your-app-name
heroku addons:open scheduler

Heroku Schedulerの設定はWeb画面で行います。時間はUTCなので、9時間マイナスしてください。

curl ${HUBOT_HEROKU_KEEPALIVE_URL}heroku/keepalive

HerokuScheduler.png

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
20