c# - 如何使用自适应卡片从 FormFlow 中保存和检索用户响应?
问题描述
在使用BotBuilder ( Bot Framework )创建的 Bot 上下文中,我正在使用带有多选功能的自适应卡:
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);
现在,我想知道用户选择了哪些元素。
解决方案
我想知道用户选择了哪些元素。
您可以从消息Value
属性中获取用户的选择,以下代码片段适用于我,请参考。
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
:
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"
});
推荐阅读
- c# - C# 或 SQL 中的隔离级别 - 将使用哪一个?
- python - 文本 = sio.getvalue() ; 在“For”循环中返回“文本”无法识别
- angular - Angular @Optional 指令注入被忽略
- python - 检查列表的元素是否是同一列表中其他列表元素的子元素
- reactjs - 由于 Firebase 身份验证流程导致的循环依赖
- spring - Spring Boot REST 部署:我们需要 TomCat 吗?
- java - gitignore 文件不隐藏 github 的 .idea 目录
- python - Django,“django.contrib.auth.views”没有属性“登录”
- python - 气流 - 告诉 DAG 跳过每月 2 日的处理
- tesseract - Tesseract 给出警告信息