在Adaptive Card中@Teams标签失败问题求助(Bot Framework)
Teams Adaptive Card标签提及失效的修复方案
你当前的问题在于误用了用户提及的实体格式,Teams标签的提及结构和用户/机器人完全不同,不能用Mention类和ChannelAccount来构造。以下是修正后的实现方式:
核心修正点
- 标签提及的实体必须指定
type="mention",且mentioned字段的type为"tag" - 需要传入标签的ID(而非邮箱)和显示名称
- 文本块中的
<at>标签名</at>必须与实体中的name严格一致
修正后的代码示例
new AdaptiveCard(new AdaptiveSchemaVersion(1, 2)) { Body = new List<AdaptiveElement> { new AdaptiveTextBlock { Text = "Mention test: <at>mytag</at>" } }, AdditionalProperties = new SerializableDictionary<string, object>() { { "msteams", new { width = "full", entities = new [] { new { type = "mention", text = "<at>mytag</at>", mentioned = new { type = "tag", id = "YOUR_TEAMS_TAG_ID", // 替换为实际的Teams标签ID name = "mytag" // 必须和文本中的<at>内容一致 } } } } } } };
关键说明
- 替换
YOUR_TEAMS_TAG_ID为你实际的Teams标签ID,可通过Graph API获取团队标签信息得到 - 实体中的
name必须和文本块里<at>包裹的内容完全匹配,否则提及不会生效 - 不要使用标准的
Mention类,它是为用户/机器人提及设计的,不支持标签类型
内容的提问来源于stack exchange,提问作者Joery
相关产品推荐
相关产品推荐

