运行 dc.BeginDialogAsync(...) 不会将对话框放入堆栈
Running dc.BeginDialogAsync(...) does not put a dialog on the stack
我正在尝试 运行 来自我的 MainDialog
的瀑布对话框。看来我运行await dc.BeginDialogAsync(nameof(OnboardingDialog));
的时候就进入了我的OnboardingDialog
的第一步,这很好。但是,当我响应该对话框中的第一个提示时,我将返回到我的 RouteDialog
。这似乎是因为在我的 DialogBot.cs
的 OnTurnAsync
方法中,dc.ActiveDialog
等于 null
,所以我的 MainDialog
被调用再次。这是我的 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);
}
当从 await dc.BeginDialogAsync(typeof(T).Name)
调用 MainDialog
时,它会调用 RouteAsync
方法,该方法可以简化为:
protected override async Task RouteAsync(DialogContext dc, CancellationToken cancellationToken = default(CancellationToken))
{
await dc.BeginDialogAsync(nameof(OnboardingDialog));
}
然后,当我响应 OnboardingDialog
中的第一步时,我只是再次点击 await dc.BeginDialogAsync(typeof(T).Name);
,因为 dc.ActiveDialog
为空,而不是让 [=30 继续我的对话=].
我在我的 DialogState
上尝试了一些使用 saving/setting 状态的操作,这些状态是从访问器创建的,但似乎没有任何东西让我的机器人意识到它应该在瀑布对话框中。我可以共享该项目,但不能在 public 位置。如果有人知道如何保存 ActiveDialog
的状态,请告诉我。谢谢。
OP 在评论中提到它只发生在 Cosmos 中。所以,.
还有,.
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
我正在尝试 运行 来自我的 MainDialog
的瀑布对话框。看来我运行await dc.BeginDialogAsync(nameof(OnboardingDialog));
的时候就进入了我的OnboardingDialog
的第一步,这很好。但是,当我响应该对话框中的第一个提示时,我将返回到我的 RouteDialog
。这似乎是因为在我的 DialogBot.cs
的 OnTurnAsync
方法中,dc.ActiveDialog
等于 null
,所以我的 MainDialog
被调用再次。这是我的 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);
}
当从 await dc.BeginDialogAsync(typeof(T).Name)
调用 MainDialog
时,它会调用 RouteAsync
方法,该方法可以简化为:
protected override async Task RouteAsync(DialogContext dc, CancellationToken cancellationToken = default(CancellationToken))
{
await dc.BeginDialogAsync(nameof(OnboardingDialog));
}
然后,当我响应 OnboardingDialog
中的第一步时,我只是再次点击 await dc.BeginDialogAsync(typeof(T).Name);
,因为 dc.ActiveDialog
为空,而不是让 [=30 继续我的对话=].
我在我的 DialogState
上尝试了一些使用 saving/setting 状态的操作,这些状态是从访问器创建的,但似乎没有任何东西让我的机器人意识到它应该在瀑布对话框中。我可以共享该项目,但不能在 public 位置。如果有人知道如何保存 ActiveDialog
的状态,请告诉我。谢谢。
OP 在评论中提到它只发生在 Cosmos 中。所以,
还有,
For now, it should work if you remove the
PartitionKey
parameter fromCosmosDbStorageOptions
. 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