为什么被调用的对话框在从另一个调用MessageReceivedAsync时不等待它

时间:2017-04-03 19:37:27

标签: c# botframework

大家好我正在使用Microsoft Bot Framework构建一个机器人,我做了一个调度对话框,当它从LUIS接收结果时调用另一个对话框,但当我使用context.Forward()方法调用下一个对话框时,它通过public async Task StartAsync(IDialogContext context) 但是我使用context.Wait(MessageReceivedAsync); 方法,我的对话框永远不会等待用户的消息继续执行,回到调用它的对话框。

我读了答案this similar question 但它并没有解决我的问题。

这就是我称之为对话的方式:

await context.Forward(scheduleDialog,ScheduleDialogTerminated,context.MakeMessage(), CancellationToken.None);

以下是Dialog:

public class ScheduleDialog : IDialog
    {
        IScheduler scheduler;
        string timeEntity;
        string appointmentEntity;
        string dateEntity;

        public ScheduleDialog(IScheduler scheduler, string date, string time, string appointment) : base()
        {
            dateEntity = date;
            timeEntity = time;
            appointmentEntity = appointment;

            this.scheduler = scheduler;
        }

        public async Task StartAsync(IDialogContext context)
        {
            string message = context.Activity.AsMessageActivity().Text;
            await context.PostAsync($"Scheduling... {message}");
            context.Wait(MessageReceivedAsync);
        }

        public async Task MessageReceivedAsync(IDialogContext context, IAwaitable<IMessageActivity> argument)
        {
            await context.PostAsync("Waiting for message...");
        }
    }

我永远不会调用MessageReceivedAsync方法我指定上下文应该在StartAsync方法中等待它

1 个答案:

答案 0 :(得分:1)

您需要在context.Wait(MessageReceivedAsync);方法的末尾添加MessageReceivedAsync