Search code examples
botframework

How to switch Dialogs in BotFramework SDK3 C#


I'm trying to add a timeout Dialog using proactiveMessages. If user doesn't reply to [A dialog], [timeout dialog] comes out. So I think timeout dialog should be the current dialog. But do I to close other dialog [A dialog]?

According this, it seems context.EndConversation was not working in MS Teams. Of course I have tried again. It is still not working.

I also tried the way below. But it seems not working either.

      using (var scope = DialogModule.BeginLifetimeScope(Conversation.Container, context.Activity.AsMessageActivity()))
        {

            var botData = scope.Resolve<IBotData>();
            await botData.LoadAsync(default(CancellationToken));
            var stack = scope.Resolve<IDialogStack>();
            stack.Reset();
            await botData.FlushAsync(default(CancellationToken));
        }

Any suggestions about changing the dialog?


Solution

  • There are two methods of redirecting dialog flow within a C# bot.

    you can use context.Forward() to send a user to a new dialog starting with a message that you are currently processing:

    await context.Forward(new NewOrderDialog(), this.ResumeAfterNewOrderDialog, message, CancellationToken.None);

    or you can use context.call() to send a user to a new dialog and start from scratch there:

    context.Call(new AgeDialog(this.name), this.AgeDialogResumeAfter);

    The "ResumeAfter" functions can be defined anywhere (including a function within the new dialog itself) and setting these to where you would like to redirect the user after they have finished with your timeout dialog will allow you to determine the flow.