【问题标题】:slack how to know if bot recently posted松弛如何知道机器人最近是否发布
【发布时间】:2018-12-08 08:02:38
【问题描述】:

我正在使用 botkit,我有一个响应某个单词的机器人。 但我不希望机器人在最近这样做时做出响应。

目前我正在使用channels.history 方法检索 4 条最近的消息然后找到机器人 ID,如果它在那里它不会回复。这不漂亮,我一直在寻找有用的方法来使用,但我找不到任何方法。我只是想知道该机器人是否最近发布并根据它执行操作。

   const targetBotID = 'GKALXJCM6'  
   bot.api.channels.history({
            channel: message.channel,
                latest: message.ts,
                count: 4,
                inclusive: 1,
            },  function(err, response) {
                  if(err) { bot.reply(message, 'Something is wrong with me, check log if there is??'); }

                  if(response){
                      const recentPostFound = response.messages.filter(function (member) {
                                                 return member.user === targetBotID;
                                              });

                      if(recentPostFound){
                        return bot.reply();
                      }
                        return bot.reply(answer) // Answer if no matching id found

                  }
              });

【问题讨论】:

    标签: node.js slack-api botkit


    【解决方案1】:

    我可以看到您的问题的两种解决方案:

    1. 在某种应用程序上下文(例如数据库)中记录您的机器人以前的操作。然后,您可以每次验证您的机器人是否已经回答。

    2. 考虑使用Events API,而不是每次都加载聊天记录。然后,您的机器人会针对频道中的每条新消息获得一个事件请求,您可以确定您的机器人只会响应一次。

    【讨论】:

    • 有人告诉我要使用计时器。我试过了,但似乎不太顺利,所以谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-03-12
    • 1970-01-01
    • 1970-01-01
    • 2016-10-27
    • 2017-03-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多