我正在尝试在json
文件的自适应卡中检索选择。
因此,当选择过敏选项'peanut'
时,我想将其分配给变量。但代码不断抛出错误。
自适应卡代码:
{
"type": "message",
"speak": "...",
"attachments": [
{
"contentType": "application/vnd.microsoft.card.adaptive",
"content": {
"type": "AdaptiveCard",
"version": "1.0",
"body": [
{
"type": "TextBlock",
"text": "Almost there...",
"size": "large",
"weight": "bolder"
}
],
"actions": [
{
"type": "Action.ShowCard",
"title": "Beef",
"card": {
"type": "AdaptiveCard",
"body": [
{
"type": "TextBlock",
"text": "What are you allergic to?",
"size": "medium",
"wrap": true
},
{
"type": "Input.ChoiceSet",
"value": "BeefAllergy",
"id": "BeefAllergy",
"style": "expanded",
"isMultiSelect": false,
"isCompact": false,
"choices": [
{
"title": "Peanut",
"value": "peanut"
},
{
"title": "Seafood",
"value": "seafood"
}
]
}
],
"actions": [
{
"type": "Action.Submit",
"title": "Next",
"data": {
"mealOptions": "beef"
}
}
]
}
}
]
}
}
]
}
以下是我尝试将其存储在变量中的方法:
lunchAllergy= session.message.attachments.content.actions.card.body[1].choices[1].value
session.send(lunchallergy)
这是错误:
错误:无法读取未定义
的属性“操作”
答案 0 :(得分:1)
在我的自适应卡内容测试中,实际上,当您的用户点击Action.Submit
按钮时,您的机器人可以在session.message.value
中选择用户,并且您可以在变量中存储您想要的内容。
有关详细信息,请参阅https://github.com/Microsoft/BotBuilder-Samples/blob/master/Node/cards-AdaptiveCards/app.js处的示例。