Brandon Fujii
Brandon Fujii

Reputation: 179

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?

Upvotes: 7

Views: 1832

Answers (1)

Brandon Fujii
Brandon Fujii

Reputation: 179

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
  });
}

Upvotes: 7

Related Questions