- 追加された行はこの色です。
- 削除された行はこの色です。
#author("2019-05-10T07:58:31+00:00","","")
#topicpath
----
#contents
** Slackと連係 [#e9e0defd]
Slack側であらかじめHubotを追加しておきます。具体的には https://[team名].slack.com/apps からHubotを検索して追加。このときに、API Tokenが付与されるのでそれをメモっときます。
Hubot側は、Yeomanで作成したテンプレを起動する際に、環境変数を定義しておけばOK。
$ yo hubot
... ウィザードにしたがって adapterを slackを選択
$ export HUBOT_SLACK_TOKEN=xoxb-xxxxxxxxxx ←Slackの画面から取得
$ export HUBOT_SLACK_TOKEN=xoxb-xxxxxxxxxx ←上記のSlackの画面でメモった値
$ bin/hubot --adapter slack
これでOKです。問い合わせてみるとこんな感じ。
** HTTPでPOSTする [#b6782685]
#ref(01.png)
** httpモジュールでPOSTする [#b6782685]
robot.respond /hoge/i, (res) ->
url = "https://script.google.com/xxxx"
res.http(url)
.query(param1: "value1")
.post() (error, response, body) ->
res.send body
https://github.com/technoweenie/node-scoped-http-client これが使われているっぽい。
** requestモジュールでPOSTする [#kc405f4f]
request = require 'request'
url = "https://script.google.com/xxxx"
options =
url: url
method: "POST"
timeout: 2000
followAllRedirects: true
form:{"param1": "value1"}
request options, (error, response, body) ->
console.log response.statusCode
console.log response.headers.location
res.send body
** GitHubソースをDockerで動かすコードサンプル [#w9ee83cf]
# cat Dockerfile
FROM node
MAINTAINER masatomix
RUN npm install -g yo generator-hubot
RUN npm list -g yo generator-hubot
RUN useradd bot
RUN mkdir /home/bot && chown bot:bot /home/bot
USER bot
WORKDIR /home/bot
RUN git clone https://github.com/masatomix/family-stock-bot.git
RUN cd family-stock-bot && npm install
WORKDIR /home/bot/family-stock-bot
CMD ["bin/hubot", "--adapter", "slack"]
これで上記のGitHubに上がってるnodejs向けコードをDocker 内で起動できるイメージを作成できます。コマンドはこちら。
# docker build -t family-hubot .
作ったイメージを動かすコマンドはこちら
# docker run -it -v /etc/localtime:/etc/localtime:ro
-e "HUBOT_SLACK_TOKEN=xoxb-xxxxx"
-e NODE_CONFIG='{ "bot": { "gas_url": "https://script.google.com/macros/s/" } }' family-hubot
↑ 環境変数っぽいのはサンプル。ちゃんと入れないとこのコード動きません
なかのプログラムが使用したい環境変数は -e で渡せます。なかのプログラムをそのまま起動させっぱにしときたいときは、 Ctrl + p + q で終了させずに抜けます。
**キャッシュを使わないでビルド [#cd868ccc]
# docker build --no-cache -t family-hubot .
----
この記事は
#vote(おもしろかった[1],そうでもない[0])
#comment
#topicpath
SIZE(10){現在のアクセス:&counter;}