こういうの。
esa
っていうカスタム絵文字を追加して、↓みたいなHubot scriptを書いた。
# Description:
# 特定のリアクションがついたメッセージをesaに投稿する
#
# Notes:
# Slackだと流れていってしまう作業メモなどをesaに書きとめておく
# 環境変数にesaのアクセストークン,チーム名,投稿カテゴリを設定しておく
# `heroku config:set ESA_ACCESS_TOKEN=xxx`
# `heroku config:set ESA_TEAM_NAME=yyy`
# `heroku config:set ESA_BOT_CATEGORY=zzz`
#
decode = require 'decode-html'
handleReaction = (res) ->
message = res.message
item = message.item
reaction = message.reaction
reaction_type = message.type
return unless reaction_type is 'added'
if reaction is 'esa'
res.robot.adapter.client.web.channels.history item.channel, {oldest: item.ts.split('.')[0], count: 1}, (err, data) ->
if err
res.send "Failed to post :( #{err}"
else
if data.messages.length > 0
text = decode data.messages[0].text
data = JSON.stringify {
post: {
name: text.split(/\n/)[0],
body_md: text,
category: process.env.ESA_BOT_CATEGORY,
user: 'esa_bot',
message: 'Add post from slack',
}
}
res.robot.http("https://api.esa.io/v1/teams/#{process.env.ESA_TEAM_NAME}/posts")
.header('Content-Type', 'application/json')
.header('Authorization', "Bearer #{process.env.ESA_ACCESS_TOKEN}")
.post(data) (err, r, body) ->
if err
res.send "Failed to post :( #{err}"
else
res.send "Post to #{(JSON.parse body).url}"
module.exports = (robot) ->
robot.react handleReaction