Open ginbear opened 7 years ago
https://signup.heroku.com/?c=70130000001x9jFAAQ よりアカウントを作る。 お約束のメール認証からこちらの画面へ
https://ginbear.slack.com/admin/settings#gateways
より、Enable XMPP gateway
する
slack 左上のメニューから、 Manage team members
から bot 用アカウントを用意する
https://github.com/r7kamura/ruboty-template
の READ ME 通りに進めていく (アカウント作成や XMPP Gateway 設定も書いてある)
Your team owner need to enable XMPP Gateway. It's recommended to create a new slack account for your ruboty.
Deploy to heroku をクリック
* SLACK_PASSWORD
は、MENU > Account & Profile > Gatewarys の先に情報がある
初回のせいかクレカ登録を行う (登録したタイミングで Create が失敗したけど、もう一度 Deploy したら成功した)
動かないので見直したら、SLACK_USERNAME がおかしかった
2017-08-14T14:15:05.512009+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path="/" host=okome-slackbot.herokuapp.com request_id=291519e5-778c-4817-b224-76ac42d981ca fwd="27.114.36.192" dyno= connect= service= status=503 bytes= protocol=https
2017-08-14T14:15:06.164290+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path="/favicon.ico" host=okome-slackbot.herokuapp.com request_id=cea697f4-b2e5-4cdd-a665-2ec608769bba fwd="27.114.36.192" dyno= connect= service= status=503 bytes= protocol=https
Settings > Config Variables から値が変更できた
そのあと dashboard から再起動方法がわからず、heroku CLI を使って見ることにした
$ brew install heroku
$ heroku login
Enter your Heroku credentials:
Email: <Email を入力>
Password: **************
Logged in as xxx
https://github.com/ginbear/ruboty-template を fork してくる see https://devcenter.heroku.com/articles/git
$ ruboty-template ⭠master$ git commit --allow-empty -am 'reboot'
[master ed0f2bd] reboot
$ ruboty-template ⭠master$ heroku git:remote -a okome-slackbot
set git remote heroku to https://git.heroku.com/okome-slackbot.git
$ ruboty-template ⭠master$ git push heroku master
Counting objects: 24, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (17/17), done.
Writing objects: 100% (24/24), 118.65 KiB | 0 bytes/s, done.
Total 24 (delta 4), reused 23 (delta 4)
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Ruby app detected
remote: -----> Compiling Ruby
remote: -----> Using Ruby version: ruby-2.3.4
remote: -----> Installing dependencies using bundler 1.15.2
remote: Running: bundle install --without development:test --path vendor/bundle --binstubs vendor/bundle/bin -j4 --deployment
remote: Using rake 11.3.0
remote: Using concurrent-ruby 1.0.2
remote: Using i18n 0.7.0
remote: Using minitest 5.9.1
remote: Using thread_safe 0.3.5
remote: Using bundler 1.15.2
remote: Using dotenv 2.1.1
remote: Using mem 0.1.5
remote: Using slop 4.4.1
remote: Using tzinfo 1.2.2
remote: Using activesupport 5.0.0.1
remote: Using ruboty 1.2.4
remote: Using xrc 0.1.8
remote: Using ruboty-slack 0.1.12
remote: Bundle complete! 2 Gemfile dependencies, 14 gems now installed.
remote: Gems in the groups development and test were not installed.
remote: Bundled gems are installed into ./vendor/bundle.
remote: Bundle completed (0.27s)
remote: Cleaning up the bundler cache.
remote: -----> Detecting rake tasks
remote:
remote: ###### WARNING:
remote: You have not declared a Ruby version in your Gemfile.
remote: To set your Ruby version add this line to your Gemfile:
remote: ruby '2.3.4'
remote: # See https://devcenter.heroku.com/articles/ruby-versions for more information.
remote:
remote: -----> Discovering process types
remote: Procfile declares types -> bot
remote: Default types for buildpack -> console, rake
remote:
remote: -----> Compressing...
remote: Done: 18.2M
remote: -----> Launching...
remote: Released v8
remote: https://okome-slackbot.herokuapp.com/ deployed to Heroku
remote:
remote: Verifying deploy... done.
To https://git.heroku.com/okome-slackbot.git
* [new branch] master -> master
うーむ。heroku の LOG には
2017-08-14T15:05:48.000000+00:00 app[api]: Build started by user r.shimizu47@gmail.com
2017-08-14T15:05:57.688031+00:00 app[api]: Deploy ed0f2bde by user r.shimizu47@gmail.com
2017-08-14T15:05:57.688031+00:00 app[api]: Release v8 created by user r.shimizu47@gmail.com
2017-08-14T15:05:48.000000+00:00 app[api]: Build succeeded
と出たけど、動かず。
謎が解けた。README に書いてあった。
Because Heroku doesn't create dyno by default, you need to add 1 dyno from dashboard.
bot のボタンをずらすと有効になった。このボタンどっちにあるとどうなっているのかよくわからない...
$ ruboty-template ⭠master$ heroku ps
Free dyno hours quota remaining this month: 1000h 0m (100%)
For more information on dyno sleeping and how to upgrade, see:
https://devcenter.heroku.com/articles/dyno-sleeping
=== bot (Free): bundle exec ruboty (1)
bot.1: up 2017/08/15 00:11:53 +0900 (~ 43s ago)
料金体系、Free だと 1日 6h 強制 Sleep だと思った行けど、今調べるとまた新しい料金体系になっていた。 http://qiita.com/tomomichi/items/7904dfcdabb7acc8a286
:tada:
https://github.com/r7kamura/ruboty-google_image
これ
この辺りも併せて参考にした
http://shirakiya.hatenablog.com/entry/2015/12/07/012906
clone 先の ruboty-template の Gemfile に
gem "ruboty-google_image"
を追加. あとは GOOGLE_CSE_KEY, GOOGLE_CSE_ID を設定
:tada:
ruboty を動作... なるほど、REDIS がいるのか
$ ruboty-template ⭠master$ be ruboty
E, [2017-08-15T12:39:46.258569 #19251] ERROR -- : Error: REDIS_SAVE_INTERVAL - Interval sec to push data to Redis (default: 5)
REDIS_URL - Redis URL (e.g. redis://foo:bar@example.com:6379/)
REDISTOGO_URL - Another Redis URL (At least one Redis URL is required)
REDIS_NAMESPACE - Redis name space (default: ruboty)
シュッと install
👺 ruboty-template ⭠master$ brew install redis
Updating Homebrew...
起動
$ redis-server /usr/local/etc/redis.conf
20937:C 15 Aug 12:49:35.062 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
20937:C 15 Aug 12:49:35.062 # Redis version=4.0.1, bits=64, commit=00000000, modified=0, pid=20937, just started
20937:C 15 Aug 12:49:35.062 # Configuration loaded
20937:M 15 Aug 12:49:35.063 * Increased maximum number of open files to 10032 (it was originally set to 4864).
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 4.0.1 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 20937
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
20937:M 15 Aug 12:49:35.064 # Server initialized
20937:M 15 Aug 12:49:35.064 * Ready to accept connections
URL を環境変数に set して動作確認
👺 ruboty-template ⭠master$ export REDIS_URL=redis://127.0.0.1:6379
👺 +ruboty-template ⭠master$ bi
Warning: the running version of Bundler (1.13.1) is older than the version that created the lockfile (1.13.6). We suggest you upgrade to the latest version of Bundler by running `gem install bundler`.
Resolving dependencies...
Using rake 11.3.0
Using concurrent-ruby 1.0.2
Using i18n 0.7.0
Using minitest 5.9.1
Using thread_safe 0.3.5
Using bundler 1.13.1
Using dotenv 2.1.1
Using multipart-post 2.0.0
Using mem 0.1.5
Using redis 3.3.3
Using slop 4.4.1
Using tzinfo 1.2.2
Using faraday 0.12.2
Using redis-namespace 1.5.3
Using activesupport 5.0.0.1
Using faraday_middleware 0.12.2
Using chrono 0.3.0
Using ruboty 1.2.4
Using ruboty-cron 1.1.0
Using ruboty-echo 0.1.0
Using ruboty-google_image 0.1.0
Using ruboty-redis 0.0.6
Bundle complete! 5 Gemfile dependencies, 22 gems now installed.
Bundled gems are installed into ./vendor/bundler.
$ +ruboty-template ⭠master$ be ruboty
Type `exit` or `quit` to end the session.
> @ruboty list jobs
Job not found
> @ruboty add job "* * * * *" @ruboty ping
Job 1202 created
> pong
pong
おお、無事動いた。 ってことは heroku 環境 or slack の何かなんだろうなぁ
https://github.com/r7kamura/ruboty-talk
DOCOMO_API_KEY を以下から取得した
https://dev.smt.docomo.ne.jp/?p=mypage.index
申請ベースだったので時間かかると思ったけど 5 分後ぐらいには使えるようになっていた。 特にハマることなく利用できた。
$ ruboty-template ⭠master$ heroku run "ruby -v"
Running ruby -v on ⬢ okome-slackbot... up, run.2905 (Free)
ruby 2.3.4p301 (2017-03-30 revision 58214) [x86_64-linux]
ruby のバージョンを 2.2.2. に落として見た -> だめ
REDISTOGO_URL
の変数に接続できる情報があるので、local mac から redis-cli を利用して直接 redis に接続して見た
$ ruboty-template ⭠master$ redis-cli -a xxx -h hostname -p nnn/
hostname:nnn> keys *
1) "ruboty:brain"
hostname:nnn> type ruboty:brain
string
hostname:nnn> get ruboty:brain
"\x04\b{\aI\"\tcron\x06:\x06ET{\x00I\"\nalias\x06;\x00T{\x06I\"\x06p\x06;\x00TI\"\tping\x06;\x00T"
hostname:nnn> monitor
OK
1502803450.269677 [0 10.143.40.150:48198] "set" "ruboty:brain" "\x04\b{\aI\"\tcron\x06:\x06ET{\x00I\"\nalias\x06;\x00T{\x06I\"\x06p\x06;\x00TI\"\tping\x06;\x00T"
ふーむ。やはり redis には登録されてないことがわかった
iPhone の slack アプリからだと正常反応することがわかった
ブラウザや Mac の Slack アプリだとだめ... こんなことあるんや...
list や delete もできた
通知もできた。Mac のアプリでできないのはどうしたものかなぁ
自分も同じようなハマり方をして、以下の記事をみて解決しました。
何らかのコードを書く人はいますぐ「スマート引用符」の機能をoffにしよう - Qiita : https://qiita.com/kwappa/items/36a42166b7abae50c8f5
ご参考まで。
なるほど!そいうことだったんですね! 共有ありがとうございます!
目的
Tasks
参考
http://kentana20.hatenablog.com/entry/2014/11/02/180812