LUIS/Bot Framework多个对话框,将意图处理移至另一个对话框

编程入门 行业动态 更新时间:2024-10-26 12:35:00
本文介绍了LUIS/Bot Framework多个对话框,将意图处理移至另一个对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我的目标是使用C#SDK将对话框和LUIS都实现到Microsoft Bot Framework应用程序中. 我尝试遵循此线程 github/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 github/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多个对话框,将意图处理移至另一个对话框

    本文发布于:2023-11-17 06:27:07,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1609151.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:对话框   多个   意图   移至   LUIS

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!