为什么简历功能不适用于上下文。在机器人框架中前进?

时间:2018-02-01 08:31:23

标签: botframework

我是Bot框架中的新手,我遇到了这个问题:

我想从对话框移动到另一个对话框,回调函数适用于context.Call但不适用于context.Forward? 我尝试了多个解决方案,例如put this.CallbackFunctionName,但它没有工作。

这是我调用新对话框的代码:

switch (submitType)
{
    case "alarm":
        context.Call(new AlarmDialog(), ResumeAfterAlarmDialog);
        context.Done(true);
        return;

    case "game":
        await context.Forward(new AlarmDialog(), ResumeAfterAlarmDialog, value, CancellationToken.None);
        return;
    }

这里是我打电话的方法:

private async Task ResumeAfterAlarmDialog(IDialogContext context, IAwaitable<object> result)
{
    await context.PostAsync($"You are finish the alarm dialog");
    context.Wait(this.MessageReceivedAsync);
}

这是我对上下文的错误。前锋:

  

不能使用方法组作为动态调度操作的参数。您打算调用该方法吗?

这里是该类的完整实现:​​

    namespace CardEx.Dialogs
{
    [Serializable]
    public class RootDialog : IDialog<object>
    {
        public Task StartAsync(IDialogContext context)
        {
            context.Wait(MessageReceivedAsync);

            return Task.CompletedTask;
        }

        private async Task MessageReceivedAsync(IDialogContext context, IAwaitable<object> result)
        {
            var activity = await result as Activity;

            if (activity.Value != null)
            {
                // Got an Action Submit
                dynamic value = activity.Value;
                string submitType = value.Type.ToString();
                switch (submitType)
                {
                    case "alarm":

                        context.Call(new AlarmDialog(), ResumeAfterAlarmDialog);

                        return;

                    case "alarm2":
                        await context.Forward(new AlarmDialog(), ResumeAfterAlarmDialog, value, CancellationToken.None);
                        return;
                }
            }


            AdaptiveCard aCard = new AdaptiveCard()
            {
                Body = new List<AdaptiveElement>()
    {
            new AdaptiveTextBlock()
            {
                Text = "Welcome!",
                Weight = AdaptiveTextWeight.Bolder,
                Size = AdaptiveTextSize.Large
            },
            new AdaptiveTextBlock() { Text = "Please choose one of the following:" },

    },
                Actions = new List<AdaptiveAction>()
    {
        new AdaptiveSubmitAction()
        {
            Title = "Set an alarm",
            DataJson = "{ \"Type\": \"alarm\" }"
        },
        new AdaptiveSubmitAction()
        {
            Title = "Play a game",
            DataJson = "{ \"Type\": \"game\" }"
        }
    }
            };

            Attachment attachment = new Attachment()
            {
                ContentType = AdaptiveCard.ContentType,
                Content = aCard

            };

            var reply = context.MakeMessage();
            reply.Attachments.Add(attachment);

            await context.PostAsync(reply, CancellationToken.None);

            context.Wait(MessageReceivedAsync);
        }
        private async Task ResumeAfterAlarmDialog(IDialogContext context, IAwaitable<object> result)
        {
            await context.PostAsync($"You are finish the alarm dialog");
            context.Wait(this.MessageReceivedAsync);
        }

    }
}

谢谢。

1 个答案:

答案 0 :(得分:1)

  

不能使用方法组作为动态调度操作的参数。您打算调用该方法吗?

value中使用的参数context.Forward是动态类型,引发了此问题。

请尝试以下代码:

await context.Forward(new TestDialog(), ResumeAfterAlarmDialog, (object)value, CancellationToken.None);