How can I get my bot to ignore conversation until it is addressed directly?

匿名 (未验证) 提交于 2019-12-03 02:38:01

问题:

I want to add my bot to a Slack channel. But I want it to ignore conversation until it is addressed directly, e.g.:

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

In Microsoft Bot Framework v1, there was an option: "Listen to all messages". I don't see that option in v3. Is there a simple way to do this (i.e. without analyzing every utterance to see whether the bot was addressed)?

I'm using node.js botbuilder 3.1.

回答1:

While checking the activity text is certainly a valid option, I would instead use the Mentions capabilities provided by the library (at least in C#).

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

IMessageActivity has a list of Entities. One of the possible entities coming in that list is the Mention entity.

The GetMentions() method is just a filtering the list of entities to retrieve the ones of type "mention".

Update

Just realized that you were asking for Node.js. The Entities approach is still valid, as you can see in the Node.js docs. You can use session.message.entities.



回答2:

The dumbest way would be to use MessageController.cs. The first thing you do in the Post method there would be to check that the Activity contains "@bot".

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


回答3:

A quick solution could be the following:

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

Hope it helps!



回答4:

This code worked for me:

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


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!