DialogStack.Forward在Context.Forward工作的地方不起作用

时间:2017-09-21 20:58:23

标签: c# bots botframework

我有一个场景,我想使用Context.Forward将上下文转发到另一个对话框,它完美地运行。现在,如果我更新代码以获取对话框堆栈并使用DialogStack.Forward,则会导致Stack为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);

1 个答案:

答案 0 :(得分:0)

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;                
            }
        }