首页 > 解决方案 > 机器人框架用户选择的按钮文本未显示在机器人中

问题描述

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

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

{
    "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"}
            }
        ]
    }
}

在此处输入图像描述

标签: jsonmicrosoft-teamsadaptive-cardsbotframework

解决方案


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


推荐阅读