草庐IT

javascript - Slack Botkit - 如何从 'reaction_added' 事件中获取消息的内容

coder 2024-07-24 原文

我正在使用 botkit 框架在向消息添加 react 时做出响应,但我不确定在触发事件时如何提取消息的内容。以下是我目前拥有的:

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

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

根据Slack API ,我只能得到像 event.item 这样的数据,它有消息的类型、 channel 和 ts。有谁知道如何做到这一点?

最佳答案

想通了。鉴于时间戳和 channel ,我能够在 channel 历史记录中手动搜索消息并提取我需要的数据。

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

关于javascript - Slack Botkit - 如何从 'reaction_added' 事件中获取消息的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36988083/

有关javascript - Slack Botkit - 如何从 'reaction_added' 事件中获取消息的内容的更多相关文章

随机推荐