似乎没有timestamp
属性,id
属性为undefined
。这是hubot的插件脚本代码:
module.exports = (robot) ->
robot.hear /\bclocks?\b/i, (msg) ->
msg.http("https://slack.com/api/reactions.add")
.query({
token: process.env.SLACK_API_TOKEN
name: "bomb"
timestamp: msg.message.timestamp # This property doesn't exist
})
.post() (err, res, body) ->
console.log(body)
return
我从Slack API返回的响应是:
{"ok":false,"error":"bad_timestamp"}
当我记录msg.message
时,它看起来像这样:
{ user:
{ id: 'abc123',
name: 'travis',
room: 'test-bots',
reply_to: 'zyx987' },
text: 'clock',
id: undefined,
done: false,
room: 'test-bots' }
如何获取触发侦听器的消息的时间戳或ID?
答案 0 :(得分:0)
我从Slack的团队那里听说过,有一个名为rawMessage的新属性,当你升级到新的API时,你可以访问它。以下是我为实现目标而采取的步骤:
以下是升级后对我有用的代码: this one
module.exports = (robot) ->
robot.hear /\bclocks?\b/i, (msg) ->
queryData = {
token: process.env.HUBOT_SLACK_TOKEN
name: "bomb"
channel: msg.message.rawMessage.channel # required with timestamp, uses rawMessage to find this
timestamp: msg.message.id # this id is no longer undefined
}
if (queryData.timestamp?)
msg.http("https://slack.com/api/reactions.add")
.query(queryData)
.post() (err, res, body) ->
#TODO: error handling
return