How to call LUIS Dialog inside LUIS Dialog?

My bot has a LUIS dialog with several intentions. I call the LUIS dialog from my MessageController. If an intent is detected, I start a child dialog. When the child dialog is complete, I call context.Done("response from user"). After that, the ChlildDialogDone task is ChlildDialogDone .

Inside the ChildDialogDone task ChildDialogDone I want to call the LUIS dialog again to determine the intent of the user message (which comes in 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 the 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 a message from the user, and I want to start the DefiningIntent dialog again with this message. How can i do this?

+6
source share
2 answers

You could repeat the logic that is on MessegaReceived from the LUIS dialog to achieve what you want to do. Basically, this code should be well aligned with 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); } 

Pieces of code related to things with "this" are part of the LUIS dialog you inherited from.

  • is a collection of LuisServices based on your LuisModel attributes.
  • The IntentActivityHandler is a handler that the LuisIntent-styled method "implements" using the method signature.
  • handlerbyIntent is a dictionary with the key being the intent names of your dialogue, and the handler is the method that must be called for this intent.

Check this box for more details and make sure you are using the latest BotBuilder SDK (at the time of publication: v3. 2.1)

+4
source

No need to copy logic from MessegaReceived. You can simply call MessegaReceived:

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

All Articles