如何使用自适应卡从FormFlow保存和检索用户响应? [英] How to save and retrieve user responses from FormFlow with Adaptive Cards?

查看:80
本文介绍了如何使用自适应卡从FormFlow保存和检索用户响应?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用 Bot框架):

I'm using an Adaptive Card with a multiselect, in the context of Bot created with BotBuilder (Bot Framework):

var card = new AdaptiveCard();
card.Body.Add(new AdaptiveTextBlock()
{
    Text = "Q1:xxxxxxxx?",
    Size = AdaptiveTextSize.Default,
    Weight = AdaptiveTextWeight.Bolder
});

card.Body.Add(new AdaptiveChoiceSetInput()
{
    Id = "choiceset1",
    Choices = new List<AdaptiveChoice>()
    {
        new AdaptiveChoice(){
            Title="answer1",
            Value="answer1"
        },
        new AdaptiveChoice(){
            Title="answer2",
            Value="answer2"
        },
        new AdaptiveChoice(){
            Title="answer3",
            Value="answer3"
        }
    },
    Style = AdaptiveChoiceInputStyle.Expanded,
    IsMultiSelect = true
});

var message = context.MakeMessage();

message.Attachments.Add(new Attachment() { Content = card, ContentType =  "application/vnd.microsoft.card.adaptive"});    
await context.PostAsync(message);

现在,我想知道用户选择了哪些元素.

Now, I would like to know which elements the user has selected.

推荐答案

我想知道用户选择了哪些元素.

I would like to know which elements the user has selected.

您可以从消息Value属性中获得用户的选择,以下代码段对我有用,请参考它.

You can get user's selections from message Value property, the following code snippets work for me, please refer to it.

if (message.Value != null)
{
    var user_selections = Newtonsoft.Json.JsonConvert.DeserializeObject<userselections>(message.Value.ToString());

    await context.PostAsync($"You selected {user_selections.choiceset1}!");
    context.Wait(MessageReceivedAsync);
}

userselections类的定义:

The definition of userselections class:

public class userselections
{
    public string choiceset1 { get; set; }
}

测试结果:

更新:添加AdaptiveChoiceSetInput和AdaptiveSubmitAction的代码段

card.Body.Add(new AdaptiveChoiceSetInput()
{
    Id = "choiceset1",
    Choices = new List<AdaptiveChoice>()
    {
        new AdaptiveChoice(){
            Title="answer1",
            Value="answer1"
        },
        new AdaptiveChoice(){
            Title="answer2",
            Value="answer2"
        },
        new AdaptiveChoice(){
            Title="answer3",
            Value="answer3"
        }
    },
    Style = AdaptiveChoiceInputStyle.Expanded,
    IsMultiSelect = true
});


card.Actions.Add(new AdaptiveSubmitAction()
{
    Title = "submit"
});

这篇关于如何使用自适应卡从FormFlow保存和检索用户响应?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆