Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Slack Botkit - How to get a message's content from a 'reaction_added' event

I'm using the botkit framework to respond when a reaction is added to a message but I'm not sure how to extract the message's content when the event is triggered. Below is what I currently have:

controller.on('reaction_added',function(bot, event) {

   if (event.reaction == 'x') {
      // bot reply with the message's text
   }
});

According to the Slack API, I can only get data like event.item which has the type, channel, and ts of the message. Does anyone know how to accomplish this?

like image 308
Brandon Fujii Avatar asked May 02 '16 17:05

Brandon Fujii


1 Answers

Figured it out. Given the timestamp and the channel, I was able to manually search for the message in the channel history and extract the data I needed.

function getTaskID(channel_id, timestamp, callback) {
  slack.api("channels.history", {
      channel: channel_id,
      latest: timestamp,
      count: 1,
      inclusive: 1
    }, function(err, response) {
      // do something with the response
  });
}
like image 137
Brandon Fujii Avatar answered Oct 18 '22 15:10

Brandon Fujii