Bot 框架用户选择的按钮文本未显示在 bot 中

Bot framework user selected button text is not displaying in bot

我正在使用 ms 机器人框架开发 Microsoft 团队机器人。在那里,我使用自适应卡片来显示描述和两个按钮。

当用户点击按钮时,我需要将 json 数据传递给后端。如果我在按钮操作上传递字符串数据 ("data": "ONE"),那么我可以读取后端中的参数,并且用户单击的按钮文本会出现在 bot 中。请看下面的代码和输出图像

{
    "contentType": "application/vnd.microsoft.card.adaptive",
    "content": {
        "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
        "type": "AdaptiveCard",
        "version": "1.0",
        "body": [
            {
                "type": "TextBlock",
                "text": "Hi, this is your Botzer personal assistant , how can I help you? <a href=\"https://www.powerupcloud.com/blogs/\" target=\"_blank\">Click Here </a>",
                "weight": "bolder",
                "isSubtle": false,
                "wrap": true
            }
        ],
        "actions": [
            {
                "type": "Action.Submit",
                "title": "ONE",
                "data": "ONE"
            },
            {
                "type": "Action.Submit",
                "title": "TWO",
                "data": "TWO"
            }
        ]
    }
}

但是,当我在按钮操作上发送 json 数据时 ("data": { "id": "action2", "name": "two", "value": "TWO"}) 那个时候我可以在后端读取数据。但是,按钮文本不会出现在机器人上。请看下面的代码和输出图像

    "contentType": "application/vnd.microsoft.card.adaptive",
    "content": {
        "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
        "type": "AdaptiveCard",
        "version": "1.0",
        "body": [
            {
                "type": "TextBlock",
                "text": "Choose the number",
                "weight": "bolder",
                "isSubtle": false,
                "wrap": true
            }
        ],
        "actions": [
            {
                "type": "Action.Submit",
                "title": "ONE",
                "data": {
                    "id": "action1",
                    "name": "one",
                    "value": "ONE"}
            },
            {
                "type": "Action.Submit",
                "title": "TWO",
                "data": {
                    "id": "action2",
                    "name": "two",
                    "value": "TWO"}
            }
        ]
    }
}

您想要的是消息返回,它结合了字符串提交操作和对象提交操作的功能。由于你的自适应卡中没有任何输入,你可以将其替换为英雄卡并直接使用 messageBack 动作。如果您仍想使用自适应卡片,那么您很幸运,因为 Teams 实际上具有允许您将消息放回自适应卡片的特殊功能。您可以在链接到 post Hessel 的博客的“团队中的自适应卡片”部分了解如何执行此操作,或者您可以直接咨询 documentation