LUIS/Bot Framework多个对话框,将意图处理移至另一个对话框 [英] LUIS / Bot Framework multiple dialog, move intent handling to another dialog
问题描述
我的目标是使用C#SDK将对话框和LUIS都实现到Microsoft Bot Framework应用程序中. 我尝试遵循此线程 https://github.com/Microsoft /BotBuilder/issues/127 及其相关文章(最后引用),但无法使我的代码在实践中起作用.这是我的RootDialog类.请注意,我创建了一个处理"GetProduct"意图的方法,当它获得此意图时,应使用context.Forward()方法将LuisResult转发到ProductsDialog,但是我看到的只是直接进入了ResumeAfter方法. ,ProductsDialogCompleted.现在,这可能是我失败的地方,但是我找不到显示多个LUIS对话框的示例.
my goal is to implement both dialogs and LUIS into a Microsoft Bot Framework application using their C# SDK. I tried to follow this thread https://github.com/Microsoft/BotBuilder/issues/127 and their related posts (referenced at the end) but couldn't get my code working in practice. This is my RootDialog class. Note that I created a method which handles the "GetProduct" intent, when it gets this intent, it should forward the LuisResult to ProductsDialog using context.Forward() method, but instead what I see is just that it goes straight to the ResumeAfter method, ProductsDialogCompleted. Now, here is probably where I fail but I couldn't find an example showing multiple LUIS dialogs.
public class RootDialog : LuisDialog<object>
{
[LuisIntent("GetProduct")]
private async Task GetProduct(IDialogContext context, LuisResult result)
{
await context.PostAsync("Calling ProductsDialog...");
await context.Forward(Chain.From(() => new ProductsDialog()), ProductsDialogCompleted, context.Activity, CancellationToken.None);
}
private async Task ProductsDialogCompleted(IDialogContext context, IAwaitable<object> result)
{
var res = await result;
context.PostAsync("ProductsDialogCompleted" + result);
context.Wait(this.MessageReceived);
}
}
public class ProductsDialog : LuisDialog<object>
{
public async Task StartAsync(IDialogContext context)
{
await context.PostAsync("Entered ProductsDialog");
context.Wait(this.MessageReceived);
}
[LuisIntent("None")]
private async Task None(IDialogContext context, LuisResult result)
{
context.Done(true);
}
}
预期的行为如下
- 用户触发GetProduct意图
- 机器人创建了一个新对话框,并转到StartAsync方法,在此方法中它等待其他用户输入
- 用户触发无"意图
- 对话框关闭,返回true,并触发ProductsDialogCompleted.
似乎我没有正确绑定对话框.我该如何解决?
It seems like I'm not correctly binding the dialogs. How can I solve this?
添加了MessageController,版本为3.8.1
Added MessageController, version is 3.8.1
[BotAuthentication]
public class MessagesController : ApiController
{
/// <summary>
/// POST: api/Messages
/// Receive a message from a user and reply to it
/// </summary>
public async Task<HttpResponseMessage> Post([FromBody]Activity activity)
{
if (activity.Type == ActivityTypes.Message)
{
await Conversation.SendAsync(activity, () => new RootDialog());
}
else
{
HandleSystemMessage(activity);
}
var response = Request.CreateResponse(HttpStatusCode.OK);
return response;
}
private Activity HandleSystemMessage(Activity message)
{
if (message.Type == ActivityTypes.DeleteUserData)
{
// Implement user deletion here
// If we handle user deletion, return a real message
}
else if (message.Type == ActivityTypes.ConversationUpdate)
{
// Handle conversation state changes, like members being added and removed
// Use Activity.MembersAdded and Activity.MembersRemoved and Activity.Action for info
// Not available in all channels
}
else if (message.Type == ActivityTypes.ContactRelationUpdate)
{
// Handle add/remove from contact lists
// Activity.From + Activity.Action represent what happened
}
else if (message.Type == ActivityTypes.Typing)
{
// Handle knowing tha the user is typing
}
else if (message.Type == ActivityTypes.Ping)
{
}
return null;
}
}
推荐答案
尝试从context.Forward
调用中删除Chain.From(()
.不知道为什么要添加它,但根本不应该添加它.
Try removing the Chain.From(()
from the context.Forward
call. Not sure why you are adding it, but it shouldn't be there at all.
尝试:
await context.Forward(new ProductsDialog(), ProductsDialogCompleted, context.Activity, CancellationToken.None);
并且顺便说一句,如果您转发的消息符合None
意图,则由于您正在执行context.Done
,这将终止ProductsDialogCompleted
方法,这基本上结束了ProductsDialog
.
And btw, if the message you forward hits the None
intent the ProductsDialogCompleted
method will be hit because you are doing context.Done
, which basically ends the ProductsDialog
.
此外,请记住StartAsync
方法存在于LuisDialog<T>
基类中,因此您需要添加override
关键字.
Also, have in mind the StartAsync
method is present in the LuisDialog<T>
base class, so you need to add the override
keyword.
这篇关于LUIS/Bot Framework多个对话框,将意图处理移至另一个对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!