如何在 Microsoft Bot Framework 中检索 AdaptiveCard 发布的表单数据?

How to retrieve the form data posted by AdaptiveCard in Microsoft Bot Framework?

我创建了一个 Bot Framework 项目并使用 LUIS 意图和实体来填充 AdaptiveCard 的字段,然后将其附加到 Activity 并发布给用户。我在卡片中放置了一个SubmitAction,相关代码如下:

        [LuisIntent("Query GPN")]
    public async Task QueryGPN(IDialogContext context, IAwaitable<IMessageActivity> activity, LuisResult result)
    {
        EntityRecommendation GPN;

        AdaptiveCard gpnCard = new AdaptiveCard();

        gpnCard.Body.Add(new TextBlock()
        {
            Text = "GPN Lookup Form",
            Size = TextSize.Large,
            Weight = TextWeight.Bolder
        });

        gpnCard.Body.Add(new TextBlock()
        {
            Text = "GPN",
            Weight = TextWeight.Bolder
        });

        TextInput gpnInput = new TextInput()
        {
            Id = "GPN",
            IsMultiline = false
        };

        gpnCard.Body.Add(gpnInput);

        gpnCard.Actions.Add(new SubmitAction()
        {
            Title = "Submit"
        });

        if (result.TryFindEntity("GPN", out GPN))
        {
            await context.PostAsync($"You want to know about a GPN {GPN.Entity}? Prepopulating form.");
            gpnInput.Value = GPN.Entity;
        }
        else
        {
            await context.PostAsync("It seems like you wanted to know about a GPN, but I couldn't find a GPN in your request.");
        }

        Attachment gpnCardAttachment = new Attachment()
        {
            ContentType = AdaptiveCard.ContentType,
            Content = gpnCard
        };

        IMessageActivity gpnFormMessage = context.MakeMessage();
        gpnFormMessage.Attachments = new List<Attachment>();
        gpnFormMessage.Attachments.Add(gpnCardAttachment);

        await context.PostAsync(gpnFormMessage);

        context.Done<IMessageActivity>(null);
    }

我正在尝试在用户单击“提交”按钮时检索此表单的内容,这似乎向我的 MessagesController 中的 Post 方法发送了一条消息 Activity。但是,此消息的内容 activity 为空。如何从此消息 activity 中检索与提交操作关联的负载?在上面的示例中,我将如何检索 "GPN" 键的值?我试过查看附件,但似乎也没有:

        private async Task MessageReceivedAsync(IDialogContext context, IAwaitable<IMessageActivity> result)
    {
        try
        {
            IMessageActivity message = await result;

            if(message.Text == null)
            {
                await context.PostAsync("Received null message.");
                if (message.Attachments != null)
                {
                    await context.PostAsync($"Attachments: {message.Attachments.Count}");
                }
                else
                {
                    await context.PostAsync($"No attachments.");
                }

                if(message.ChannelData != null)
                {
                    await context.PostAsync("ChannelData contains something");
                }
                else
                {
                    await context.PostAsync($"No channel data.");
                }

                context.Wait(MessageReceivedAsync);
            }
            else
            {
                await context.Forward(new IntentDialog(), IntentDialogAfter, message, CancellationToken.None);
            }
        }
        catch (Exception e)
        {
            await context.PostAsync(e.Message);
        }
    }

单击 Submit 按钮后,尝试检查 MessageReceivedAsync 上消息的 Value 属性。

Here 是使用“提交”按钮并读取值的示例。