简体   繁体   English

如何在Chatbot中实现“后退”对话

[英]How to implement “Back” conversation in Chatbot

I wish to implement following scenario conversation in MS botframework 我希望在MS botframework中实现以下场景对话

Bot: =>  what can do for you?            => User
Bot: <=  I want to rent a house         <= User
Bot: =>  Which city?                    => User
Bot: <=                 London          <= User
Bot: =>  How many bedrooms              => User
Bot: <=  Ops, I want a home in New York <= User  #User wish to change the topic here..

In MS botframework, how can I use Waterfall dialog to implement above story? 在MS botframework中,如何使用Waterfall对话框实现上述故事? any advice? 任何建议?

I don't think it is possible to implement it with waterfall approach with reasonable efforts. 我认为不可能通过合理的努力用瀑布式方法来实现它。 In simple case you can try to analyze the response, in your case it is a number of bedrooms, and if it is not a number, you can check the response for another request. 在简单的情况下,您可以尝试分析响应,在您的情况下,它是多个卧室,如果它不是数字,您可以检查另一个请求的响应。 The problem here is that you should do it for all responses and for open text responses it will be hard to distinguish between a legal answer or a topic change. 这里的问题是你应该对所有回复和开放文本回复都这样做,很难区分合法答案或主题变化。

So, you should implement it using an intent approach. 因此,您应该使用intent方法实现它。

First, you need an intent detector, you can use Luis as it is highly integrated with the bot framework or implement your own intent detector. 首先,您需要一个意图检测器,您可以使用Luis,因为它与bot框架高度集成或实现您自己的意图检测器。

In in you case, this detector should detect the intent - I want to rent a house (a car and so on). 在你的情况下,这个探测器应该检测意图 - I want to rent a house (汽车等)。

var intents = new builder.IntentDialog({ recognizers: [luis] });

See https://docs.botframework.com/en-us/node/builder/chat/IntentDialog These code examples are for Node.Js but the same approach should works for .Net. 请参阅https://docs.botframework.com/en-us/node/builder/chat/IntentDialog这些代码示例适用于Node.Js,但相同的方法适用于.Net。

Then, for each intent you should register an appropriate action that starts an waterfall dialog that gets all necessary data. 然后,对于每个意图,您应该注册一个适当的操作,启动一个获取所有必要数据的瀑布式对话框。

bot.beginDialogAction("RentHouseAction", RentHouseDialog.name+":/", { matches: "RentHouseAction"});

where RentHouseAction is the action you define in Luis RentHouseDialog is a waterfall dialog that is reside in the library. 其中RentHouseAction是你在Luis RentHouseDialog中定义的动作,它是一个驻留在库中的瀑布对话框。

bot.library(RentHouseDialog);

Note that as the RentHouseDialog dialog finishes it will return to the place where the previous dialog has stopped. 请注意,当RentHouseDialog对话框完成时,它将返回上一个对话框已停止的位置。 So, it again asks - How many bedrooms . 所以,它再次问 - How many bedrooms To prevent this behavior you should detect that your previous dialog hasn't finished yet (you can use the state for it where you collect the answers) and call session.replaceDialog('<>'); 要防止出现这种情况,您应该检测到您之前的对话框尚未完成(您可以使用状态为其收集答案)并调用session.replaceDialog('<>'); .

I hope it helps you. 我希望它对你有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM