You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Microsoft Teams机器人卡片在Android端无法更新问题求助

Teams Android端AdaptiveCard更新不生效问题

我基于NodeJS和Bot Framework 4.14.1开发Microsoft Teams机器人,通过TurnContext.sendActivity发送初始AdaptiveCard,用户点击卡片上的“Reports”按钮后,调用TurnContext.updateActivity更新卡片内容。该功能在Teams网页端完全正常,但在Android设备上操作无报错,却始终显示初始卡片,无法展示更新后的内容。

初始卡片和更新后卡片的JSON结构如下(已移除图片链接):

初始卡片JSON

{
   "type":"message",
   "inputHint":"acceptingInput",
   "attachments":[
      {
         "content":{
            "body":[
               {
                  "type":"ColumnSet",
                  "columns":[
                     {
                        "type":"Column",
                        "items":[
                           {
                              "url":"logo_img",
                              "size":"Small",
                              "type":"Image",
                              "style":"Person"
                           }
                        ],
                        "width":"auto",
                        "verticalContentAlignment":"Center"
                     },
                     {
                        "type":"Column",
                        "items":[
                           {
                              "size":"Large",
                              "text":"Hey, Pedro Clever! 👋",
                              "type":"TextBlock",
                              "wrap":true,
                              "weight":"Bolder"
                           },
                           {
                              "size":"Medium",
                              "text":"I’m your personal marketing assistant.",
                              "type":"TextBlock",
                              "wrap":true,
                              "spacing":"None",
                              "isSubtle":true
                           }
                        ],
                        "width":"stretch"
                     }
                  ],
                  "separator":true
               },
               {
                  "type":"Container",
                  "items":[
                     {
                        "text":"I can do so much, send you **reports**, **graphs**, notify you with **alerts** and much more.",
                        "type":"TextBlock",
                        "wrap":true
                     },
                     {
                        "url":"https://i.imgur.com/IRv8FWf.gif",
                        "type":"Image",
                        "width":"318px",
                        "altText":"",
                        "horizontalAlignment":"Center"
                     },
                     {
                        "text":"With what do you prefer to start?",
                        "type":"TextBlock",
                        "wrap":true
                     },
                     {
                        "id":"history",
                        "type":"Input.Text",
                        "value":"[]",
                        "isVisible":false
                     },
                     {
                        "type":"ActionSet",
                        "actions":[
                           {
                              "id":"commandsTutorial",
                              "data":{
                                 "action":"commandsTutorial"
                              },
                              "type":"Action.Submit",
                              "title":"Commands"
                           },
                           {
                              "id":"alertsTutorial",
                              "data":{
                                 "action":"alertsTutorial"
                              },
                              "type":"Action.Submit",
                              "title":"Alerts"
                           },
                           {
                              "id":"reportsTutorial",
                              "data":{
                                 "action":"reportsTutorial"
                              },
                              "type":"Action.Submit",
                              "title":"Reports"
                           },
                           {
                              "id":"shortcutsTutorial",
                              "data":{
                                 "action":"shortcutsTutorial"
                              },
                              "type":"Action.Submit",
                              "title":"Shortcuts"
                           }
                        ]
                     }
                  ]
               }
            ],
            "type":"AdaptiveCard",
            "$schema":"http://adaptivecards.io/schemas/adaptive-card.json",
            "version":"1.0"
         },
         "contentType":"application/vnd.microsoft.card.adaptive"
      }
   ],
   "attachmentLayout":"list"
}

更新后卡片JSON

{
   "type":"message",
   "inputHint":"acceptingInput",
   "attachments":[
      {
         "type":"AdaptiveCard",
         "$schema":"http://adaptivecards.io/schemas/adaptive-card.json",
         "content":{
            "body":[
               {
                  "type":"ColumnSet",
                  "columns":[
                     {
                        "type":"Column",
                        "items":[
                           {
                              "url":"logo_img",
                              "size":"Small",
                              "type":"Image",
                              "style":"Person"
                           }
                        ],
                        "width":"auto",
                        "verticalContentAlignment":"Center"
                     },
                     {
                        "type":"Column",
                        "items":[
                           {
                              "size":"Large",
                              "text":"Hey, Pedro Clever! 👋",
                              "type":"TextBlock",
                              "wrap":true,
                              "weight":"Bolder"
                           },
                           {
                              "size":"Medium",
                              "text":"I’m your personal marketing assistant.",
                              "type":"TextBlock",
                              "wrap":true,
                              "spacing":"None",
                              "isSubtle":true
                           }
                        ],
                        "width":"stretch"
                     }
                  ],
                  "separator":true
               },
               {
                  "type":"Container",
                  "items":[
                     {
                        "text":"1️⃣ How do scheduled reports work?",
                        "type":"TextBlock",
                        "wrap":true
                     },
                     {
                        "text":"2️⃣ How do recurring messages work?",
                        "type":"TextBlock",
                        "wrap":true,
                        "spacing":"Small"
                     },
                     {
                        "text":"3️⃣ What are Smart Reports?",
                        "type":"TextBlock",
                        "wrap":true,
                        "spacing":"Small"
                     },
                     {
                        "type":"ActionSet",
                        "actions":[
                           {
                              "id":"reportsFirst",
                              "data":{
                                 "step":0,
                                 "action":"reportsTutorialStep"
                              },
                              "type":"Action.Submit",
                              "title":"1️⃣"
                           },
                           {
                              "id":"reportsSecond",
                              "data":{
                                 "step":1,
                                 "action":"reportsTutorialStep"
                              },
                              "type":"Action.Submit",
                              "title":"2️⃣"
                           },
                           {
                              "id":"reportsThird",
                              "data":{
                                 "step":2,
                                 "action":"reportsTutorialStep"
                              },
                              "type":"Action.Submit",
                              "title":"3️⃣"
                           }
                        ]
                     },
                     {
                        "id":"history",
                        "type":"Input.Text",
                        "value":"[\"reportsTutorial\"]",
                        "isVisible":false
                     },
                     {
                        "type":"Container",
                        "items":[
                        ],
                        "isVisible":false
                     },
                     {
                        "text":"Continue with:",
                        "type":"TextBlock",
                        "wrap":true,
                        "isVisible":false
                     },
                     {
                        "type":"ActionSet",
                        "actions":[
                           {
                              "id":"commandsTutorial",
                              "data":{
                                 "action":"commandsTutorial"
                              },
                              "type":"Action.Submit",
                              "title":"Commands"
                           },
                           {
                              "id":"alertsTutorial",
                              "data":{
                                 "action":"alertsTutorial"
                              },
                              "type":"Action.Submit",
                              "title":"Alerts"
                           },
                           {
                              "id":"shortcutsTutorial",
                              "data":{
                                 "action":"shortcutsTutorial"
                              },
                              "type":"Action.Submit",
                              "title":"Shortcuts"
                           }
                        ]
                     }
                  ]
               }
            ]
         },
         "version":"1.2",
         "contentType":"application/vnd.microsoft.card.adaptive"
      }
   ],
   "attachmentLayout":"list"
}

可能的原因及解决办法

1. AdaptiveCard版本不统一

初始卡片用的是version":"1.0",更新后卡片是version":"1.2"。Teams Android端对跨版本的卡片更新兼容性可能有问题,建议把两张卡片的版本统一:

  • 要么都用1.0,要么都用1.2,优先选1.0这种低版本,兼容性更好。

2. 卡片结构格式不一致

对比两张卡片的JSON结构能发现:

  • 初始卡片里,AdaptiveCard的type、$schema、version都在content对象内部;
  • 更新后卡片把type":"AdaptiveCard"、$schema、version移到了content外面,和contentType同级。

这种结构差异会导致Android端无法正确解析更新请求,必须把更新后卡片的结构调整成和初始卡片一致:
保证type、$schema、version都放在content对象里,参考初始卡片的格式。

3. 确认更新时用对了Activity ID

调用TurnContext.updateActivity必须用初始发送卡片时返回的Activity ID。如果ID错了(比如用了对话ID),Android端会直接忽略更新请求。

  • 发初始卡片时,保存返回的Activity ID:
const initialActivity = await context.sendActivity(initialCard);
// 把initialActivity.id存下来,后面更新要用
  • 更新时传入这个ID:
await context.updateActivity({
  id: initialActivity.id,
  ...updatedCard
});

4. 排查Android客户端缓存

Teams Android端可能缓存了旧卡片,试试这些操作:

  • 退出Teams重新登录;
  • 清除Teams应用的缓存(在设备设置里找到Teams,选清除缓存);
  • 换个新的对话窗口测试,避开历史缓存。

5. 检查更新卡片的JSON有效性

确保更新后的JSON没有语法错误,所有字段格式正确。可以用Adaptive Cards官方设计工具验证两张卡片的渲染效果,确认更新后的卡片能正常显示。


内容的提问来源于stack exchange,提问作者Antonio Pizarro

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.02 03:35:54