ohmusama
ohmusama

Reputation: 4215

How can you inspect the Dialog Stack on Botframework

I'm implementing a feedback dialog, and want to drop into the dialog from anywhere using an IScorable and key off the word "feedback" and push my FeedbackDialog onto the stack.

I don't want this behavior while collecting feedback from the user. Is there a way to determine if my FeedbackDialog is already on the stack? So I don't accidentally double push it?

Upvotes: 2

Views: 797

Answers (1)

OmG
OmG

Reputation: 18858

You can resolve the stack like the following. First, register the necessary modules:

private void RegisterTypes()
{
    var builder = new ContainerBuilder();
    builder.RegisterModule(new DialogModule());
    builder.RegisterModule(new ReflectionSurrogateModule());
    builder.RegisterModule(new DialogModule_MakeRoot());
    // necessary configurations
    // ...
}

After that, resolve the stack:

using (var scope = DialogModule.BeginLifetimeScope(Conversation.Container, activity))
{
    var stack = scope.Resolve<IDialogStack>();
}

in stack.Frames you can find the list of the dialogs in order of them in the stack dialog(stack.Frames[0] is on the top of the stack). You can find the name of the dialog using Target property of a Frame, i.e., stack.Frames[0].Target. Therefore, you can find the FeedbackDialog in the stack if it exists using the following code:

stack.Frames.Any(x=> x.Target.GetType().UnderlyingSystemType.Name == "FeedbackDialog")

Upvotes: 4

Related Questions