I have 3 Dialogs, there is an InitialDialog, StepOneDialog and finally a EndDialog. Each Dialog invokes it's child by executing something like this:
await context.Forward(dialog, ResumeAfter, new Activity { }, CancellationToken.None); This works perfectly locally, but there is an issue when I publish this. It just get's stuck in a loop and I think it's because the Dialog doesn't exit properly. The InitialDialog is inheriting a LuisDialog. I have this code for one of the methods:
[LuisIntent("")] public async Task None(IDialogContext context, LuisResult result) { // Create our response var response = $"Sorry I did not understand your question."; // Post our response back to the user await context.PostAsync(response); // Exit the application context.Done(this); } As you can see, I invoke context.Done(this) to exit the Dialog, but I am not sure if that is correct. In other examples, they seem to use context.Wait(MessageReceived);
My other Dialogs implement IDialog<object> so I can't invoke MessageReceived. So in that case, I have set up a method like this:
private async Task ResumeAfter(IDialogContext context, IAwaitable<object> result) => context.Done(this); which I invoke like this:
private async Task GetAnswer(IDialogContext context, IAwaitable<string> result) { // Get our quest var questions = _group.Questions; var length = questions.Count; var question = _group.Questions[_currentQuestion]; var selectedAnswer = await result; // Assign our answer to our question foreach (var answer in question.Answers) if (answer.Text == selectedAnswer) question.Answer = answer; // If we have an answer, filter the products if (question.Answer != null) _productProvider.Score(await GetCurrentProducts(), _groups); // Increase our index _currentQuestion++; // If our current index is greater or equal than the length of the questions if (_currentQuestion == length) { // Create our dialog var dialog = _dialogFactory.CreateSecondStepDialog(_dialogFactory, _groupProvider, _questionProvider, _productProvider, await GetCurrentProducts()); // Otherwise, got to the next step await context.Forward(dialog, ResumeAfter, new Activity { }, CancellationToken.None); return; } // Ask our next question await AskQuestion(context, null); } As you can see, the context.Forward passes the method as a Delegate and is executed after the child Dialog is created. Can someone tell me if I am doing this right? Or if I need to change something.