coffeescript - How do I get a Slack message's id/timestamp from a Hubot script? -
there doesn't seem timestamp
property , id
property undefined
. here 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 # property doesn't exist }) .post() (err, res, body) -> console.log(body) return
the response slack api is:
{"ok":false,"error":"bad_timestamp"}
when log msg.message
looks this:
{ user: { id: 'abc123', name: 'travis', room: 'test-bots', reply_to: 'zyx987' }, text: 'clock', id: undefined, done: false, room: 'test-bots' }
how can timestamp or id message triggered listener?
i heard slack's team , there newer property called rawmessage have access when upgrade newer api. here's steps went through working:
- upgrade nodejs & hubot (this may optional, our versions out of date)
- upgrade slack-adapter , follow instructions connect newer api https://github.com/slackhq/hubot-slack#upgrading-from-earlier-versions-of-hubot
- you should access newer properties scripts.
here's code worked 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 timestamp, uses rawmessage find timestamp: msg.message.id # id no longer undefined } if (querydata.timestamp?) msg.http("https://slack.com/api/reactions.add") .query(querydata) .post() (err, res, body) -> #todo: error handling return
Comments
Post a Comment