如何在LUIS对话框中调用LUIS对话框? [英] How to call LUIS Dialog inside LUIS Dialog?

查看:97
本文介绍了如何在LUIS对话框中调用LUIS对话框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的机器人具有两个意图的LUIS对话框.我从我的MessageController调用LUIS对话框.如果检测到该意图,则启动一个子对话框.子对话框完成后,我调用context.Done("response from user")..在此之后,调用ChlildDialogDone任务.

My bot has LUIS dialog with a couple of intents. I call LUIS dialog from my MessageController. If the intent is detected, I start a child dialog. When the child dialog is done, I call context.Done("response from user"). After that ChlildDialogDone task is called.

ChildDialogDone任务内部,我想再次调用LUIS对话框以检测用户消息的意图(该消息涉及ChildDialogDone).现在在ChildDialogDone中,我有context.Wait(MessageReceived).当执行此行代码时,什么都没有发生,我的机器人正在等待用户的下一条消息.

Inside ChildDialogDone task I want to call the LUIS dialog again to detect the intent of user's message (which comes to ChildDialogDone ). Now inside ChildDialogDone I have context.Wait(MessageReceived). When this line of code is executed, nothing happens, my bot is waiting for the next message from user.

这是代码:

    [Serializable]
        public partial class DefiningIntentDialog : LuisDialog<object>
        {

            [LuisIntent("")]
            public async Task NoIntent(IDialogContext context, LuisResult result)
            {        
                var dialog = new GreetingsDialog();
                dialog.InitialMessage = result.Query;
                context.Call(dialog, GreetingDialogDone);      
            }

            [LuisIntent("Email")]
            public virtual async Task ConfirmationEmail(IDialogContext context, LuisResult result)
            {
                await context.Forward(new EmailDialog, EmailDialogDone, "message", CancellationToken.None);
            }

            private async Task EmailDialogDone(IDialogContext context, IAwaitable<string> argument)
            {
                var messageHandled = await argument;

                context.Wait(MessageReceived);
            }
      }

因此在EmailDialogDone内部,我收到了一些来自用户的消息,我想再次使用此消息执行DefiningIntent对话框.我该怎么办?

So inside EmailDialogDone I have some message from user and I want to execute DefiningIntent dialog with this message again. How can I do it?

推荐答案

您可以重复LUIS对话框的MessegaReceived上的逻辑,以实现所需的操作.基本上,此代码应与您所需的代码保持一致:

You could repeat the logic that is on the MessegaReceived of the LUIS dialog, to achieve what you want to do. Basically, this code should be pretty aligned to what you need:

var tasks = this.services.Select(s => s.QueryAsync(messageHandled, CancellationToken.None)).ToArray();
var winner = this.BestResultFrom(await Task.WhenAll(tasks));

IntentActivityHandler handler = null;
if (winner == null || !this.handlerByIntent.TryGetValue(winner.BestIntent.Intent, out handler))
{
    handler = this.handlerByIntent[string.Empty];
}

if (handler != null)
{
    await handler(context, null, winner?.Result);
}

用"this"引用事物的代码段是您继承的LUIS对话框的一部分.

The pieces of the code that are referring to things with "this" are part of the LUIS Dialog you are inherited from.

  • services是基于LuisModel属性实例化的LuisServices的集合.
  • IntentActivityHandler是LuisIntent装饰的方法正在使用方法签名实现"的处理程序.
  • handlerbyIntent是一个Dictionary,其键是对话框的意图名称,而handler是需要为该意图调用的方法.

检查,以了解更多详细信息和确保您使用的是BotBuilder SDK的最新版本(本文发布时:v3.2.1)

Check this for more details and make sure you are using the latest version of the BotBuilder SDK (at the moment of this post: v3.2.1)

这篇关于如何在LUIS对话框中调用LUIS对话框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆