0

我正在尝试在json文件的自适应卡中检索选择。So when the allergic option 'peanut'is selected, I want to assign it to a variable. 但是代码不断抛出错误。

自适应卡码:

{
    "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)

这是错误:

错误:无法读取未定义的属性“操作”

4

1 回答 1

1

在我对自适应卡片内容的测试中,实际上,当您的用户单击Action.Submit按钮时,您的机器人可以在 中获取用户选择session.message.value,并且您可以将所需内容存储在变量中。

在此处输入图像描述

有关详细信息,您可以参考https://github.com/Microsoft/BotBuilder-Samples/blob/master/Node/cards-AdaptiveCards/app.js上的示例。

于 2017-11-20T08:40:57.363 回答