I am facing a similar issue like this question but in C#, the bot stucks in the first IDialog that I call, it can be either one but after it enters one it doesn't leave. I choose the dialog with a simple condition:
if (!IsCommonExpresion(activity.Text))
{
await Conversation.SendAsync(activity, () => new MemeBotDialog());
}
else
{
await Conversation.SendAsync(activity, () => new LocalDialog());
return Request.CreateResponse(HttpStatusCode.OK);
}
I guess I need to use something like the Node.Js "endDialog()" method but I don't know if it does exist on C#
I'm guessing that you could use IDialogContext done method
I just did a small test where I used Done instead of wait, and it seemingly returned to my default response without crashing.
I have not tested with multiple dialogs though.
@erlendw i have tryied it, it didn't work
I made it work by doing context.Reset();, after the point in which I know I wanted to finish the dialog. That resets the dialog stack. The main problem about this is that it resets the bots state, so if you were storing some state that was important to you, you will lose it. In my case, that wasn't needed so it worked fine for me.
However, this approach could be helpful for you : Terminate all dialogs in ms bot (Check the first answer, is very neat and I think it does what you need)
Let me know if that works for you!
@piffarettig It doesn't work for my bot, it saves data that I cannot lose by resetting the context. Thank you
@msft-shahins or @willportnoy can you comment on this with respect to the new stack manipulation stuff?
@fercom I would use a root dialog to dispatch between the MemebotDialog and LocalDialog dialogs instead of trying to do it outside the Conversation.SendAsync.
@willportnoy I already tried this, but everytime it enters a dialog, even from the message controller, it doesn't allows to enter a diferent dialog, it keeps stuck in the first dialog it enters
Yes, because you can only choose one root dialog, and that single root dialog will get restarted when it finishes automatically. Since the dialog is stateful, you cannot just switch root dialogs on every incoming message.
@willportnoy Okay, so, how do I dispatch one dialog from another one?
Use IDialogStack.Call off the context argument passed to the dialog methods.
@fercom here is an example on how you can develop a multi dialog bot and use context.Call(...) to call into different child dialogs: https://github.com/Microsoft/BotBuilder-Samples/tree/master/CSharp/core-MultiDialogs.
As @willportnoy mentioned you cannot dynamically switch between root dialogs since dialog system is stateful. If you really want to switch to another root dialog, you can reset the dialog stack and send the message to the new root. Here is an example showing how you can achieve this:
async Task ResetStackAndSend(Activity activity, Func<IDialog<object>> makeRoot, CancellationToken token)
{
using (var scope = DialogModule.BeginLifetimeScope(Conversation.Container, activity))
{
var botData = scope.Resolve<IBotData>();
await botData.LoadAsync(token);
scope.Resolve<IDialogStack>().Reset();
DialogModule_MakeRoot.Register(scope, makeRoot);
using (new LocalizedScope(activity.Locale))
{
await scope.Resolve<IPostToBot>().PostAsync(activity, token);
}
}
}
@msft-shahins Ok, I will check it out, thank you!