【问题标题】:How can I get my bot to ignore conversation until it is addressed directly?如何让我的机器人忽略对话,直到直接解决?
【发布时间】:2017-09-29 02:08:22
【问题描述】:

我想将我的机器人添加到 Slack 频道。但我希望它在直接解决之前忽略对话,例如:

me: hi!
me: hi!
me: @bot hi!
bot: why hello there!

在 Microsoft Bot Framework v1 中,有一个选项:“收听所有消息”。我在 v3 中没有看到该选项。有没有一种简单的方法来做到这一点(即不分析每个话语来查看机器人是否被解决)?

我正在使用 node.js botbuilder 3.1。

【问题讨论】:

    标签: node.js botframework slack


    【解决方案1】:

    虽然检查活动文本肯定是一个有效的选项,但我会改用库提供的提及功能(至少在 C# 中)。

    if (activity.GetMentions().Any(x => x.Mentioned.Name == "botName") 
    {
      ...
    }
    

    IMessageActivity 有一个Entities 列表。该列表中可能出现的实体之一是 Mention 实体。

    GetMentions() 方法只是过滤实体列表以检索“提及”类型的实体。

    更新

    刚刚意识到您要求的是 Node.js。如您在Node.js docs 中所见,实体方法仍然有效。你可以使用session.message.entities

    【讨论】:

    • session.message 对象对于与 LUIS 意图匹配的消息似乎不存在。
    【解决方案2】:

    最愚蠢的方法是使用MessageController.cs。您在 Post 方法中做的第一件事是检查 Activity 是否包含“@bot”。

    if (activity.Text.Contains("@bot") {
        //do your normal stuff
    }
    else {
        return Request.CreateResponse(HttpStatusCode.OK); //ignore message
    }
    

    【讨论】:

      【解决方案3】:

      一个快速的解决方案可能如下:

      bot.dialog('/', [
        function(session, params) {
          if(session.message.text.includes('@bot')) {
            // ... start the conversation's flow
          }
        }
      ]);
      

      希望对你有帮助!

      【讨论】:

        【解决方案4】:

        这段代码对我有用:

        if (session.message.address.channelId == "slack") {
          //Channel conversation
          if (session.message.address.conversation.isGroup) {
            if (session.message.text.includes("@botname")) {
              //your code
            }
            session.endDialog();
            //bot not mentioned, hence do nothing
          } else {
            //your bot reply to a DM
          }
        }
        

        【讨论】:

          猜你喜欢
          • 2022-07-21
          • 2020-12-05
          • 1970-01-01
          • 2021-06-13
          • 1970-01-01
          • 2020-01-06
          • 2014-05-18
          • 1970-01-01
          • 2020-12-19
          相关资源
          最近更新 更多