1
votes

Using Microsoft Bot Framework v4, I have 3 dialogs that create a loop. When I implement them as illustrated below, since Bot Framework v4 requires you to initialize each dialog in the constructor, the Bot errors out with a Stack overflow exception. I'm wondering if anyone has created a bot with this type of flow without exceptions.

Here are the 3 dialogs: Create a contact, Update a contact and search for a contact.

  1. Search for a contact may not find a contact and so provides the ability to create a contact.

  2. Update a contact allows for the user to search for a contact.

  3. Create a contact will create a contact, then check if there is a duplicate, if there is, then allows you to update the contact instead of creating.

The circular reference is (Create a contact => Update a contact => Search for a contact => Create a contact).

The flow may not always require you to enter each piece of information, but the dialogs need to Add dialog in the constructor so you can call "BeginDialogAsync" if needed.

Any help on how to manage this flow would be greatly appreciated.

1
Hi Nate and welcome to SO! Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. - vzwick
Thanks for the input, I'm wondering how to create a circular reference in bot framework as illustrated without having it error out. - Nate Hadro

1 Answers

0
votes

We found one possible solution to fix this for anyone else running into this issue:

In the SearchContactsDialog we overrode ContinueDialogAsync:

public override Task<DialogTurnResult> ContinueDialogAsync(DialogContext outerDc, CancellationToken cancellationToken = default(CancellationToken))
    {
        if (_createAContactChoice.Synonyms.Select(s => s.ToLower()).Contains(outerDc.Context.Activity.Text?.ToLower()))
        {
            return outerDc.ReplaceDialogAsync(nameof(CreateContactDialog), null, cancellationToken);
        }
        return base.ContinueDialogAsync(outerDc, cancellationToken);
    }

This statement essentially checks to see if the activity text is "Create a new contact" or whatever we specified for that option and then replaces the existing dialog with the CreateContactDialog.

This works, but in the parent dialog you need to include CreateContactDialog as well as "SearchContactsDialog".

It's not ideal, but the only solution we could get working.