Search code examples
c#botframework

How to pass a result when calling CancelAllDialogsAsync in bot framework?


We have been using the bot framework for a while now and are very happy with it. We use the stepContext.Parent.CancelAllDialogsAsync() method. This works fine but we want to pass a result or trigger some kind of action in the bot code. We would like to pass a value.

I noticed the optional eventName and eventValue parameters, but I cannot find any way to use them. I found this documentation for the method but the eventName and eventValue are not explained at all. https://learn.microsoft.com/en-us/dotnet/api/microsoft.bot.builder.dialogs.dialogcontext.cancelalldialogsasync?view=botbuilder-dotnet-stable.

I thought that it would trigger the DialogBot's OnEventActivityAsync method, but it doesn't.

Our use case is as follows: At some point in the conversation our bot asks the user a question. When the user doesn't answer the question multiple times, but instead keeps asking their own question we call CancelAllDialogsAsync. The bot will get back to the MainDialog and wait for user input, so the user will have to ask their question again. We don't want the user to have to ask agian, so we want to cancel all dialogs and go back to the MainDialog passing the users question so the MainDialog can pick a way to answer it.

Any help is appreciated.


Solution

  • Our solution is to store the utterance in the user state. The MainDialog checks the userstate if an utterance is stored. If so it will answer it. No utterance is stored in the user state the main dialog it will ask the user 'What can I do for you?'.