Bot Framework Context Wait 不等待下一条消息

Bot Framework Context Wait not waiting for next message

我正在尝试使用 Microsoft Bot Framework 构建一个对话框,它可以帮助用户查询采购订单状态(目前,只是一个模拟)。我正在使用 LuisDialog,当它检测到 "ConsultPO" 意图时,它应该询问用户的 'customer id' 并等待来自用户的后续消息。但是,它一直返回到 Luis Dialog 的开头并处理意图,而不是从等待的方法中恢复。这是正确运行的意图代码:

        [LuisIntent("ConsultPO")]
    public async Task POIntent(IDialogContext context, LuisResult result)
    {
        string PO = "";
        foreach (var entity in result.Entities)
        {
            if (entity.Type == "purchaseOrder")
                PO = entity.Entity;
        }
        if (PO.Length != 0)
        {
            po_query = PO;
        }
        await context.PostAsync("Ok, can you confirm your customer id and I'll check for you?");
        context.Wait(confirmCustomer_getPO);
    }

这是我希望在用户回复后续消息后执行的代码:

        public async Task confirmCustomer_getPO(IDialogContext context, IAwaitable<object> argument)
    {
        await context.PostAsync("DEBUG TEST");
        IMessageActivity activity = (IMessageActivity)await argument;

        customer_query = activity.Text;
        if (po_query.Length > 0)
        {
            PurchaseOrder po = POservice.findPO(po_query, customer_query);
            await buildSendResponse(po, context);
//more non relevant code

当我在执行 context.Wait(confirmCustomer_getPO) 后回答机器人的询问时,它只是进入 LUIS,然后运行与 "None" 意图相对应的代码。消息 "DEBUG TEST" 从未发送。

为什么 "confirmCustomer_getPO" 从来没有接到电话?

编辑:

我在 StartAsync 方法中添加了一条调试消息。我不确定这是否应该发生,但每次我向机器人发送消息时它都会弹出,这让我相信每次我向机器人发送消息时对话框都会重新启动:

    public class EchoDialog : LuisDialog<object>
{
    public EchoDialog() : base(new LuisService(new LuisModelAttribute(
        ConfigurationManager.AppSettings["LuisAppId"], 
        ConfigurationManager.AppSettings["LuisAPIKey"], 
        domain: ConfigurationManager.AppSettings["LuisAPIHostName"])))
    {
    }

    public override Task StartAsync(IDialogContext context)
    {
        context.PostAsync("I'm in startAsync");
        return base.StartAsync(context);
    }

本地调试显示没有发生异常,并且从未到达等待方法中的任何断点,尽管确实发生了 context.Wait 调用。

经过一段时间的斗争,我自己弄清楚了这个问题。问题出在机器人商店。我使用的是无法正常工作的 InMemoryDataStore - 切换到 TableBotDataStore 解决了这个问题。 DataStore 的问题意味着状态没有被保存,所以我的 "waits" 和 "forwards" 没有被保存到对话框堆栈中——任何新的传入消息都被发送到 RootDialog。

损坏 - 在 global.asax.cs:

时不工作
Conversation.UpdateContainer(
    builder =>
    {
        builder.RegisterModule(new AzureModule(Assembly.GetExecutingAssembly()));
        var store = new InMemoryDataStore(); // volatile in-memory store

        builder.Register(c => store)
            .Keyed<IBotDataStore<BotData>>(AzureModule.Key_DataStore)
            .AsSelf()
            .SingleInstance();

    });
GlobalConfiguration.Configure(WebApiConfig.Register);

我将 store 更新为:

var store = new TableBotDataStore(ConfigurationManager.AppSettings["AzureWebJobsStorage"]);

通过我在 Azure 中的应用程序设置,在 web.config 中设置了有效的 "AzureWebJobsStorage" 设置,问题得到解决,无需对代码进行任何其他更改。