在直接解决之前,如何让我的机器人忽略对话?

时间:2016-09-22 21:52:26

标签: node.js botframework slack

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

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

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

我正在使用node.js botbuilder 3.1。

4 个答案:

答案 0 :(得分:1)

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

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

IMessageActivity有一个Entities列表。进入该列表的可能实体之一是Mention实体。

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

更新

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

enter image description here

答案 1 :(得分:0)

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

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

答案 2 :(得分:0)

快速解决方案如下:

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

希望它有所帮助!

答案 3 :(得分:0)

此代码对我有用:

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
  }
}
相关问题