简体   繁体   English

如何在LUIS Dialog中调用LUIS Dialog?

[英]How to call LUIS Dialog inside LUIS Dialog?

My bot has LUIS dialog with a couple of intents. 我的机器人有LUIS对话框,有几个意图。 I call LUIS dialog from my MessageController. 我从MessageController调用LUIS对话框。 If the intent is detected, I start a child dialog. 如果检测到意图,我会启动一个子对话框。 When the child dialog is done, I call context.Done("response from user"). 当子对话框完成后,我调用context.Done("response from user"). After that ChlildDialogDone task is called. 之后调用ChlildDialogDone任务。

Inside ChildDialogDone task I want to call the LUIS dialog again to detect the intent of user's message (which comes to ChildDialogDone ). ChildDialogDone任务中,我想再次调用LUIS对话框来检测用户消息的意图(来自ChildDialogDone )。 Now inside ChildDialogDone I have context.Wait(MessageReceived). 现在在ChildDialogDone我有context.Wait(MessageReceived). When this line of code is executed, nothing happens, my bot is waiting for the next message from user. 当执行这行代码时,没有任何反应,我的机器人正在等待来自用户的下一条消息。

Here is the code: 这是代码:

    [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);
            }
      }

So inside EmailDialogDone I have some message from user and I want to execute DefiningIntent dialog with this message again. 所以在EmailDialogDone中我有一些来自用户的消息,我想再次使用此消息执行DefiningIntent对话框。 How can I do it? 我该怎么做?

You could repeat the logic that is on the MessegaReceived of the LUIS dialog, to achieve what you want to do. 您可以重复LUIS对话框的MessegaReceived上的逻辑,以实现您想要做的事情。 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);
}

The pieces of the code that are referring to things with "this" are part of the LUIS Dialog you are inherited from. 引用具有“this”的内容的代码片段是您继承的LUIS Dialog的一部分。

  • services, are the collection of LuisServices instantiated based on your LuisModel attributes. services,是基于LuisModel属性实例化的LuisServices集合。
  • IntentActivityHandler is the handler that the LuisIntent decorated method are "implementing" with the method signature. IntentActivityHandler是LuisIntent修饰方法使用方法签名“实现”的处理程序。
  • handlerbyIntent is a Dictionary with the key being the intent names of your dialog and the handler being the method that needs to be called for that intent. handlerbyIntent是一个Dictionary,其键是对话框的intent name,处理程序是需要为该intent调用的方法。

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) 检查这一点以获取更多详细信息,并确保您使用的是最新版本的BotBuilder SDK(在本文发布时:v3.2.1)

There's no need to copy logic from MessegaReceived. 没有必要从MessegaReceived复制逻辑。 You can just call MessegaReceived: 你可以调用MessegaReceived:

private async Task EmailDialogDone(IDialogContext context, IAwaitable<string> argument)
{
   await MessageReceived(context, new AwaitableFromItem<IMessageActivity>((IMessageActivity)context.Activity));
}

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

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