gpt4 book ai didi

c# - Dialog Stack.Forward 在 Context.Forward 工作的地方不起作用

转载 作者:太空宇宙 更新时间:2023-11-03 15:00:35 26 4
gpt4 key购买 nike

我有一个场景,我想使用 Context.Forward 将上下文转发到另一个对话框,它工作得很好。现在,如果我更新代码以获取对话框堆栈并使用 DialogStack.Forward,则会导致 Stack is Empty 异常。非常感谢任何指向此问题的指示。

using (var scope = DialogModule.BeginLifetimeScope(Conversation.Container, message))
{
var botData = scope.Resolve<IBotData>();
await botData.LoadAsync(default(CancellationToken));
var stack = scope.Resolve<IDialogStack>();

// DialogStack.Foward doesn't work
await stack.Forward(new FeedbackDialog(FeedbackContext.CreateLead.ToString(), this.GetService<IResourceManager>()), this.ResumeAfterFeedbackDialog, context.Activity.AsMessageActivity(), CancellationToken.None);
}

// Context.Forward works
await context.Forward(new FeedbackDialog(FeedbackContext.CreateLead.ToString(), this.GetService<IResourceManager>()), this.ResumeAfterFeedbackDialog, context.Activity.AsMessageActivity(), CancellationToken.None);

最佳答案

AlarmBot 示例中有一个示例执行类似的操作:

https://github.com/Microsoft/BotBuilder/blob/master/CSharp/Samples/AlarmBot/Models/ExternalEvent.cs

请尝试这样的事情:

编辑:

using (var scope = DialogModule.BeginLifetimeScope(Conversation.Container, activity))
{
var token = new CancellationToken();
var botData = scope.Resolve<IBotData>();
await botData.LoadAsync(token);
var task = scope.Resolve<IDialogTask>();

var child = new TestDialog();
var interruption = child.Do(new ResumeAfterCall().ResumeAfter);

try
{
task.Call(interruption, null);
await task.PollAsync(token);
}
finally
{
await botData.FlushAsync(token);
}
}

[Serializable]
public class ResumeAfterCall
{
public async Task<IMessageActivity> ResumeAfter(IBotContext context, IAwaitable<object> result)
{
return await result as IMessageActivity;
}
}

关于c# - Dialog Stack.Forward 在 Context.Forward 工作的地方不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46353038/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com