How to call LUIS Dialog inside LUIS Dialog?

青春壹個敷衍的年華 提交于 2019-12-06 01:07:59

问题


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.

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.

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. How can I do it?


回答1:


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

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

  • services, are the collection of LuisServices instantiated based on your LuisModel attributes.
  • IntentActivityHandler is the handler that the LuisIntent decorated method are "implementing" with the method signature.
  • 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.

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)




回答2:


There's no need to copy logic from MessegaReceived. You can just call MessegaReceived:

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


来源:https://stackoverflow.com/questions/39781503/how-to-call-luis-dialog-inside-luis-dialog

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!