There doesn't seem to be a timestamp
property and the id
property is undefined
. Here is the hubot's plugin script code:
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
The response that I get back from the Slack API is:
{"ok":false,"error":"bad_timestamp"}
When I log msg.message
it looks like this:
{ user:
{ id: 'abc123',
name: 'travis',
room: 'test-bots',
reply_to: 'zyx987' },
text: 'clock',
id: undefined,
done: false,
room: 'test-bots' }
How can I get a timestamp or id for the message that triggered the listener?
I heard back from Slack's team and there is a newer property called rawMessage that you have access to when up upgrade to the newer API. Here's the steps I went through to get it working:
Here's the code that worked for me after upgrading: https://gist.github.com/dieseltravis/253eb1c6fea97f116ab0
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