0

I'm trying to run a waterfall dialog from my MainDialog. It appears that when I run await dc.BeginDialogAsync(nameof(OnboardingDialog));, I am put into the first step of my OnboardingDialog, which is good. However, when I respond to the first prompt within that dialog, I am passed back into my RouteDialog. It seems like the reason for this is because within my DialogBot.cs's OnTurnAsync method, the dc.ActiveDialog is equal to null, and so my MainDialog gets called again. Here's my OnTurnAsync:

    public override async Task OnTurnAsync(ITurnContext turnContext, CancellationToken cancellationToken = default(CancellationToken))
    {
        var dc = await _dialogs.CreateContextAsync(turnContext);

        if (dc.ActiveDialog != null)
        {
            var result = await dc.ContinueDialogAsync();
        }
        else
        {
            await dc.BeginDialogAsync(typeof(T).Name);
        }

        // Save any state changes that might have occured during the turn.
        await ConversationState.SaveChangesAsync(turnContext, false, cancellationToken);
        await UserState.SaveChangesAsync(turnContext, false, cancellationToken);
    }

When MainDialog gets called from the await dc.BeginDialogAsync(typeof(T).Name), it hits the RouteAsync method which could be simplified to:

protected override async Task RouteAsync(DialogContext dc, CancellationToken cancellationToken = default(CancellationToken))
{
    await dc.BeginDialogAsync(nameof(OnboardingDialog));
}

Then, when I respond to the first step in OnboardingDialog, I just hit the await dc.BeginDialogAsync(typeof(T).Name); again as dc.ActiveDialog is null, instead of having my dialog continued by var result = await dc.ContinueDialogAsync().

I've tried a few things with saving/setting state on my DialogState created from accessors but nothing seems to make my bot aware that it should be in a waterfall dialog. I can share the project but not in a public place. Let me know if anyone has hints for how to save ActiveDialog's state. Thanks.

craigbot
  • 345
  • 1
  • 2
  • 15
  • Are you able to share a link to your repo? These kinds of issues can be difficult to debug without all of the code. At the very least, I'd need to see the code for your relevant Dialogs. Code for any other Activity handlers would be good, too (`OnMessageAsync`, `OnDialogAsync`, etc) – mdrichardson Jul 17 '19 at 17:51
  • For sure, can I share it to your e-mail? – craigbot Jul 17 '19 at 18:02
  • After some digging, it seems like it's actually an issue with CosmosDB. With `MemoryStorage` I'm able to see an ActiveDialog. Perhaps our connection isn't set up properly, but I can see everytime I start a new conversation with the bot that a new entry gets created in the table. Perhaps there's an access issue? – craigbot Jul 17 '19 at 18:05

1 Answers1

1

OP mentioned in comments it only happens in Cosmos. So, here's another user who just experienced this.

And, the answer.

For now, it should work if you remove the PartitionKey parameter from CosmosDbStorageOptions. You will likely need to delete your Container or use a different name, since yours is currently partitioned. Easiest to just delete your Container and let the bot make one for you.

There's currently a bug in all the Bot Builder SDKs around reading from partitioned databases when the partitionKey is supplied. Tracking the issue here

Community
  • 1
  • 1
mdrichardson
  • 7,141
  • 1
  • 7
  • 21
  • I just tried this and I got this error when I try to run the bot: `exception.Message: Cross partition query is required but disabled. Please set x-ms-documentdb-query-enablecrosspartition to true, specify x-ms-documentdb-partitionkey, or revise your query to avoid this exception. ActivityId: a60ccbcd-0d8b-4b26-9d51-a8618504868c, Microsoft.Azure.Documents.Common/2.4.0.0, Windows/10.0.16299 documentdb-netcore-sdk/2.1.2`. Do you know how I should get around this? – craigbot Jul 17 '19 at 19:02
  • @craigbot Just updated: You will likely need to delete your Container or use a different name, since yours is currently partitioned. – mdrichardson Jul 17 '19 at 19:03
  • Just got the same error after deleting the db and container then recreating them. I had to set the shard key as something but I'm not exactly sure what it is used for. Do you think that it matters what I set it to? – craigbot Jul 17 '19 at 19:10
  • Not sure what "shared key" you're referring to. Send your code to vDASHmicricATmicrosoftDOTcom, replacing the all-caps with the appropriate character. I'll take a look. – mdrichardson Jul 17 '19 at 19:16
  • I really did mean 'shard key'. It's a field that I have to set when creating a collection with the CosmosDB portal. I'll send the code though. – craigbot Jul 17 '19 at 19:18
  • Ohh...delete your container and let the bot make one. – mdrichardson Jul 17 '19 at 19:18
  • Alright, tried that. Got this error: `exception.Message: Shared throughput collection should have a partition key ActivityId: 9fb85e33-066b-441c-bd80-31e372fb990d, Microsoft.Azure.Documents.Common/2.4.0.0, Windows/10.0.16299 documentdb-netcore-sdk/2.1.2`. – craigbot Jul 17 '19 at 19:21
  • :( 1. Make sure your botbuilder-* and botframework-* packages are up to date. 2. Create the container manually with `/_partitionKey` as the key. – mdrichardson Jul 17 '19 at 19:25
  • Success! I tested this by first updating v4.4 to v4.5 and getting the container to be created by the bot, this did not work. I then manually created the container with the shard key as `_partitionKey`. Using the `/` within the shard key threw me an error. Thank you! – craigbot Jul 17 '19 at 19:39
  • Glad it worked! Sorry partitionKeys don't work out-of-the-box right now :( – mdrichardson Jul 17 '19 at 19:51