0
votes

I have created a dispatcher, on getting a value of particular intent I called a child dialog as shown below:

if (topIntent == "NewRequest")
{
    await dc.BeginDialogAsync(nameof(RequestForm));
    // await dc.BeginDialogAsync("RequestForm",null,cancellationToken);
} else if(topIntent == "Mailbox")
{
    await MaiboxAsync(dc, cancellationToken);
}

protected async Task MaiboxAsync(DialogContext dc, CancellationToken cancellationToken = default(CancellationToken))
{
    await dc.BeginDialogAsync(nameof(MailboxAccessForm));
}

Whenever the top intent is new request or mailbox I get this error:

Error: Exception caught : DialogContext.BeginDialogAsync(): A dialog with an id of 'requestForm' wasn't found. The dialog must be included in the current or parent DialogSet

I have added the dialogs in DialogBot.cs file as shown below:

public class DialogBot<T> : ActivityHandler where T : Dialog
{
    protected readonly Dialog Dialog;
    // protected readonly BotState ConversationState;
    protected readonly BotState UserState;
    protected readonly ILogger Logger;
    private IBotServices BotServices;
    private IEnumerable<WaterfallStep> waterfallSteps;
    private ConversationState ConversationState;

    // private DialogSet _dialogs;
    private DialogSet Dialogs { get; set; }
    // private IConfiguration configuration;

    public DialogBot(IBotServices botServices, ConversationState conversationState, UserState userState, T dialog, ILogger<DialogBot<T>> logger)
    {
        ConversationState = conversationState;
        UserState = userState;
        Dialog = dialog;
        Logger = logger;
        BotServices = botServices;
        RegisterDialogs();
        Dialogs = new DialogSet(conversationState.CreateProperty<DialogState>(nameof(DialogBot<T>)));

        Dialogs.Add(new WaterfallDialog("MainDialog", new WaterfallStep[]
        {
            async (dc, cancellationToken) =>
            {
                // Start the ChoiceFlowDialog that was loaded earlier
                // This will take the conversation through the 
                // 'waterfall' steps defined in the choiceFlow.json file
                    return await dc.BeginDialogAsync(nameof(RequestForm));
            }
        }));
     }

    private void RegisterDialogs()
    {
        Dialogs = new DialogSet(ConversationState.CreateProperty<DialogState>                (nameof(DialogBot<T>)));
        Dialogs.Add(new WaterfallDialog("CreateTeamForm", waterfallSteps));
        Dialogs.Add(new WaterfallDialog("DistributionListForm", waterfallSteps));
        Dialogs.Add(new WaterfallDialog("FeedbackForm", waterfallSteps));
        Dialogs.Add(new WaterfallDialog("LicenseRequestForm", waterfallSteps));
        Dialogs.Add(new WaterfallDialog("MailboxAccessForm", waterfallSteps));
        Dialogs.Add(new WaterfallDialog("RequestForm", waterfallSteps));
        Dialogs.Add(new WaterfallDialog("ServiceNowIncidentCreation", waterfallSteps));
        Dialogs.Add(new WaterfallDialog("SharedMailboxForm", waterfallSteps));
    }
}

In my startup.cs class I made these following changes:

services.AddTransient<IBot, DialogBot<MainDialog>>();
services.AddTransient<RequestFormForm>();
services.AddTransient<MailboxAccessForm>();

Where am I going wrong?

I have gone through some similar link on Stack Overflow but none of them resolved my issue.

https://github.com/microsoft/botframework-solutions/blob/master/templates/Virtual-Assistant-Template/csharp/Sample/VirtualAssistantSample/Dialogs/MainDialog.cs#L77

How do I add multiple ComponentDialogs?

1
Not sure if this was intended but you have in your Startup.cs services.AddTransient<RequestFormForm>();, this might be a spelling mistake. It's weird that it's saying id requestForm wasn't found because all the rest of your RequestForm are uppercase. Can you look in your code for the lowercase version requestForm and replace it with RequestForm?craigbot

1 Answers

0
votes

You get an error like

Error: Exception caught : DialogContext.BeginDialogAsync(): A dialog with an id of "yourDialog" wasn't found.

any time that your dialogs aren't properly added to the DialogSet. Ensure that whenever you're calling a dialog, it has previously been added to the DialogSet somewhere in the code that has already executed. In your case, it's likely that you call this two separate times:

Dialogs = new DialogSet(conversationState.CreateProperty<DialogState>(nameof(DialogBot<T>)));

You're calling it once in the DialogBot constructor (as you should) and then again in RegisterDialogs (you shouldn't). Instead, you might want to do something like:

Dialogs = new DialogSet(conversationState.CreateProperty<DialogState>(nameof(DialogBot<T>)));
RegisterDialogs();

[...]
private void RegisterDialogs(DialogSet dialogs)
{
    Dialogs.Add(new CreateTeamForm(UserState));
    [...]
}

It's also possible that your RequestForm Dialog isn't passing the same name with something like:

public RequestForm(....)
    : base(nameof(RequestForm)

I also notice that sometimes you're using "RequestForm" and sometimes you're using nameof(RequestForm). Better to stick with something consistent (I prefer nameof(RequestForm))


Now that I've seen your code, I'll point out some other issues. It appears you're trying to merge some of the old methods of adding dialogs with some of the newer methods. Best to just stick to one. For your code, I'd just stick to the older method. One of the big issues with what you're trying to do is that in DialogBot, every Dialog uses the same waterfallSteps, which hasn't been defined. Then, within each dialog, you're using AddDialog(new WaterfallDialog(nameof(WaterfallDialog), waterfallSteps));. So you're adding the same WaterfallDialog to each dialog. The last AddDialog that gets called is going to overwrite the others.

To get started fixing your code:

  1. Remove the AddTransient<XYZDialog/Form> from startup.cs
  2. Use the code I edited above to register each of your dialogs
  3. You'll need to change the UserState to UserState type and not BotState

That being said, I highly, highly recommend:

  1. Downloading either the old Basic Bot or the new Core Bot
  2. Read through it and make sure you understand exactly how the Dialogs are being called and constructed
  3. You may also consider re-writing your bot to use either the new or old style--but sticking to just one style--and testing each dialog after you add it. I think part of the reason that your issue was difficult to track down is that you added too much, too fast, without testing in between.