这是一张带有Input.ChoiceSet的基本卡片:
{
"type": "AdaptiveCard",
"body": [
{
"type": "Container",
"items": [
{
"type": "Input.ChoiceSet",
"id": "first",
"placeholder": "Placeholder text",
"choices": [
{
"title": "SharePoint",
"value": "SharePoint"
},
{
"title": "Azure",
"value": "Azure"
},
{
"title": "O365",
"value": "O365"
}
],
"style": "expanded"
}
]
}
],
"actions": [
{
"type": "Action.Submit",
"title": "Submit"
}
],
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"version": "1.0"
}
然后,在您的机器人中,按照以下答案处理用户输入:
基本上,你会想要:
发送卡片
在发送卡片后立即发送空白文本提示来捕获卡片的输入(如第一个链接中所述)
在下一步中使用 if 或 switch 语句来根据用户的输入确定接下来要显示的卡片。您可以选择使用第二个链接更动态地创建卡片
AdaptiveCards Designer 很不错,但是它缺少设置actions 属性的能力。您可以手动添加(就像我在上面所做的那样):
"actions": [
{
"type": "Action.Submit",
"title": "Submit"
}
],
使用图片
如果您想使用图片而不是 ChoiceSet,您可以执行以下操作:
{
"type": "AdaptiveCard",
"body": [
{
"type": "Container",
"items": [
{
"type": "Image",
"id": "choice1",
"selectAction": {
"type": "Action.Submit",
"title": "choice1",
"data": {
"choice": 1
}
},
"url": "https://acuvate.com/wp-content/uploads/2017/02/Microsoft-Botframework.fw_-thegem-person.png",
"altText": ""
},
{
"type": "Image",
"id": "choice2",
"selectAction": {
"type": "Action.Submit",
"title": "choice2",
"data": {
"choice": 2
}
},
"url": "https://acuvate.com/wp-content/uploads/2017/02/Microsoft-Botframework.fw_-thegem-person.png",
"altText": ""
},
{
"type": "Image",
"id": "choice3",
"selectAction": {
"type": "Action.Submit",
"title": "choice3",
"data": {
"choice": 3
}
},
"url": "https://acuvate.com/wp-content/uploads/2017/02/Microsoft-Botframework.fw_-thegem-person.png",
"altText": ""
}
]
}
],
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"version": "1.0"
}
重要的部分是确保Action.Submit:
- 在图片上
- 有
data,您将使用它来捕获用户选择的选项