Bot框架转发类型参数错误

时间:2017-05-15 16:45:32

标签: c# botframework

我正在接下来error 尝试使用MS Bot框架示例调用另一个对话框时。这是我的代码:



using System;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Connector;

namespace ReadMeBot.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 != null && activity.Text.ToLower().Contains("what is"))
            {
                await
                    context.Forward(new InternetSearchDialog(), this.ResumeAfterInternetSearchDialog, activity, CancellationToken.None);
            }

            // calculate something for us to return
            int length = (activity.Text ?? string.Empty).Length;

            // return our reply to the user
            await context.PostAsync($"You sent {activity.Text} which was {length} characters. Thank you!");

            context.Wait(MessageReceivedAsync);
        }

        private async Task ResumeAfterInternetSearchDialog(IDialogContext context, IAwaitable<string> result)
        {
            
        }
    }
}
&#13;
&#13;
&#13;

我该如何解决这个问题?我google了一下,似乎没有人有这个问题。我做错了什么?

1 个答案:

答案 0 :(得分:0)

由于您要转发到另一个对话框,因此您无需在此对话框中等待。你想要调用context.Wait然后在简历中。

如果您将代码更改为以下内容,事情应该按预期工作:

[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 != null && activity.Text.ToLower().Contains("what is"))
        {
            await
                context.Forward(new InternetSearchDialog(), this.ResumeAfterInternetSearchDialog, activity, CancellationToken.None);
        }
        else
        {
            // calculate something for us to return
            int length = (activity.Text ?? string.Empty).Length;

            // return our reply to the user
            await context.PostAsync($"You sent {activity.Text} which was {length} characters. Thank you!");
            context.Wait(MessageReceivedAsync);
        }       
    }

    private async Task ResumeAfterInternetSearchDialog(IDialogContext context, IAwaitable<string> result)
    {
        context.Wait(MessageReceivedAsync);
    }
}