You need to enable JavaScript to run this app. Java环境下如何获取Teams Adaptive Card自适应卡片的用户输入值
优惠活动
大模型
产品
解决方案
定价
更多

Java环境下如何获取Teams Adaptive Card自适应卡片的用户输入值

Teams自适应卡片提交事件无法触发问题

以下是我在Teams中发送的Adaptive Card自适应卡片的JSON:

{
    "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
    "type": "AdaptiveCard",
    "version": "1.0",
    "body": [
        {
            "type": "Container",
            "items": [
                {
                    "type": "TextBlock",
                    "text": "Publish Adaptive Card schema",
                    "weight": "bolder",
                    "size": "medium"
                },
                {
                    "type": "ColumnSet",
                    "columns": [
                        {
                            "type": "Column",
                            "width": "auto",
                            "items": [
                                {
                                    "type": "Image",
                                    "url": "https://pbs.twimg.com/profile_images/3647943215/d7f12830b3c17a5a9e4afcc370e3a37e_400x400.jpeg",
                                    "size": "medium",
                                    "style": "person"
                                }
                            ]
                        },
                        {
                            "type": "Column",
                            "width": "stretch",
                            "items": [
                                {
                                    "type": "TextBlock",
                                    "text": "Matt Hidinger",
                                    "weight": "bolder",
                                    "wrap": true
                                },
                                {
                                    "type": "TextBlock",
                                    "spacing": "none",
                                    "text": "Created Tuesday, Feb 14, 2017",
                                    "isSubtle": true,
                                    "wrap": true
                                }
                            ]
                        }
                    ]
                }
            ]
        },
        {
            "type": "Container",
            "items": [
                {
                    "type": "TextBlock",
                    "text": "Now that we have defined the main rules and features of the format, we need to produce a schema and publish it to GitHub. The schema will be the starting point of our reference documentation.",
                    "wrap": true
                },
                {
                    "type": "FactSet",
                    "facts": [
                        {
                            "title": "Board:",
                            "value": "Adaptive Card"
                        },
                        {
                            "title": "List:",
                            "value": "Backlog"
                        },
                        {
                            "title": "Assigned to:",
                            "value": "Matt Hidinger"
                        },
                        {
                            "title": "Due date:",
                            "value": "Not set"
                        }
                    ]
                }
            ]
        }
    ],
    "actions": [
        {
            "type": "Action.ShowCard",
            "title": "Set due date",
            "card": {
                "version": "1.0",
                "type": "AdaptiveCard",
                "body": [
                    {
                        "type": "Input.Date",
                        "id": "dueDate",
                        "title": "Select due date"
                    }
                ],
                "actions": [
                    {
                        "type": "Action.Submit",
                        "title": "OK"
                    }
                ]
            }
        },
        {
            "type": "Action.ShowCard",
            "title": "Comment",
            "card": {
                "version": "1.0",
                "type": "AdaptiveCard",
                "body": [
                    {
                        "type": "Input.Text",
                        "id": "comment",
                        "isMultiline": true,
                        "placeholder": "Enter your comment"
                    }
                ],
                "actions": [
                    {
                        "type": "Action.Submit",
                        "title": "OK"
                    }
                ]
            }
        },
        {
            "type": "Action.OpenUrl",
            "title": "View",
            "url": "http://adaptivecards.io"
        }
    ]
}

问题描述

用户输入内容并点击OK提交后,当前机器人仅返回"Echo:"。已实现获取Activity的相关逻辑,但用户点击OK按钮时该方法不会被触发。

解决方案

  • 调整Activity监听范围:Teams中Adaptive Card的Action.Submit触发的是invoke类型的Activity,而非普通message类型。你需要在机器人的消息处理入口,新增对type = invoke且name = adaptiveCard/action类型请求的处理逻辑,原有仅监听message类型的逻辑自然无法捕获提交事件。
  • 提取用户提交数据:成功捕获invoke请求后,用户在卡片中填写的内容会存储在activity.value.data字段中,你可以直接通过你定义的输入控件id(比如dueDate、comment)提取对应内容。
  • 构造合法响应:处理完invoke请求后需要先返回200状态码的空响应告知Teams请求处理成功,再主动调用消息发送接口,将提取到的用户输入内容作为回复发送到当前会话,即可替换原有仅返回"Echo:"的效果。

内容的提问来源于stack exchange,提问作者Shubha K.V

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.20 06:06:03