首页 文章

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

提问于
浏览
1

大家好我正在使用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 方法永远不会被调用isas我指定上下文应该在StartAsync方法中等待它

1 回答

  • 1

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

相关问题