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

如何通过API在Teams频道帖子中提及Bot而非用户

Teams Bot端到端测试中Adaptive Card提及Bot的问题解决

问题背景

我们正在为Teams Bot编写端到端测试,通过另一个Bot在频道发送消息模拟对话,但用提及用户的相同方法提及Bot时出现异常。使用的Adaptive Card代码如下:

{
  "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
  "type": "AdaptiveCard",
  "version": "1.5",
  "body": [
    {
      "type": "TextBlock",
      "text": "Mention a user by AAD Object Id: Hello <at>${userName} AAD</at>"
    }
  ],
  "msteams": {
    "entities": [
      {
        "type": "mention",
        "text": "<at>${userName} AAD</at>",
        "mentioned": {
          "id": "${userAAD}",
          "name": "${userName}"
        }
      }
    ]
  }
}

提及内容虽显示高亮文本,但解析后的对象显示为“Unknown User”。2020年该功能尚不可用,询问2024年是否已支持,并请求指导如何通过Adaptive Card或Botframework API正确提及Bot。

2024年支持情况及正确实现方式

  • 支持状态:2024年Teams已支持在Adaptive Card中提及Bot,核心区别是要使用Bot的Microsoft App ID作为提及ID,而非用户的AAD对象ID。
  • 正确的Adaptive Card配置:
    修改msteams.entities中的提及对象,将mentioned.id替换为目标Bot的Microsoft App ID,同时确保标签文本与实体配置完全匹配:
    {
      "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
      "type": "AdaptiveCard",
      "version": "1.5",
      "body": [
        {
          "type": "TextBlock",
          "text": "提及Bot:Hello <at>${botName}</at>"
        }
      ],
      "msteams": {
        "entities": [
          {
            "type": "mention",
            "text": "<at>${botName}</at>",
            "mentioned": {
              "id": "${botMicrosoftAppId}",
              "name": "${botName}"
            }
          }
        ]
      }
    }
    
  • Botframework API实现方式:
    使用Botframework SDK时,可通过Mention类构造提及对象,指定Mentioned.Id为Bot的Microsoft App ID、Mentioned.Name为Bot名称,将该提及实体添加到活动的Entities集合中,同时在消息文本中插入对应的标签即可。

关键注意事项

  • 必须使用Bot的Microsoft App ID,不能复用用户的AAD对象ID逻辑。
  • 标签内的文本需与entities中text字段完全一致,否则会出现解析失败的情况。
  • 发送消息的Bot需拥有频道发送权限,且目标Bot已加入当前团队或频道。

内容的提问来源于stack exchange,提问作者Mateusz Szostok

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.01 20:44:50