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

MS Teams Beta版自适应卡片摘要显示异常求助

MS Teams Beta版卡片摘要显示异常:自定义Summary被替换为"Sent a card"

问题描述

在新版MS Teams Beta(版本:23202.1509.2295.2283)中发送卡片时,通过activity.Summary设置的自定义摘要无法正常显示,聊天列表和通知区域只会显示默认文本"Sent a card"。但相同代码在MS Teams Classic(版本:1.6.00.22904)中运行正常,自定义摘要能正确展示。尝试过发送不同类型的自适应卡片,问题依旧;切换回Classic客户端则恢复正常。

相关代码

卡片创建代码

public override Attachment Attachment()
{
    Attachment attachment;
    if (PostImageId.Length == 6)
    {
        var card = new ThumbnailCard
        {
            Title = PostTitle,
            Subtitle = string.Join(", ", PostTags),
            Text = PostDescription,
            Images = new List<CardImage>(),
            Buttons = new List<CardAction>()
        };
        card.Images.Add(new CardImage { Url = PostImageSource });
        
        if (!string.IsNullOrWhiteSpace(TeamsUrl))
        {
            card.Buttons.Add(new CardAction
            {
                Type = "openUrl",
                Title = "Open in Teams",
                Value = TeamsUrl.Replace("null", $"\"post|{PostId}|{PostSourceId}\"")
            });
        }

        if (!string.IsNullOrWhiteSpace(SPUrl))
        {
            card.Buttons.Add(new CardAction
            {
                Type = "openUrl",
                Title = "Open in SharePoint",
                Value = $"{SPUrl}?postId={PostId}&sourceId={PostSourceId}"
            });
        }
        attachment = card.ToAttachment();
    }
    else
    {
        var postCardAttempt = (AdaptiveHeroCardTeamsAttempt)this;
        attachment = AdaptiveCardHelper.GetHeroCard(postCardAttempt);  
    }

    return attachment;
}

发送卡片并设置摘要的代码

public async Task<SendResult> SendAsync(NotificationTeamsAttempt attempt)
{
    try
    {
        if (string.IsNullOrWhiteSpace(attempt.ConversationId))
            throw new Exception("Conversation Id is required.");
        if (string.IsNullOrWhiteSpace(attempt.ServiceUrl))
            throw new Exception("Service Url is required.");

        using (var connector = new ConnectorClient(new Uri(attempt.ServiceUrl), _clientId, _clientSecret))
        {
            var activity = MessageFactory.Text("");
            activity.Attachments.Add(attempt.Attachment());
            activity.Summary = attempt.Summary();
            var response = await connector.Conversations.SendToConversationAsync(attempt.ConversationId, activity);
            return new SendResult
            {
                IsSuccess = true,
                DispatchId = response.Id
            };
        }
    }
    catch (Exception exception)
    {
        return new SendResult
        {
            IsSuccess = false,
            Exception = exception
        };
    }
}

原因分析

  1. Beta版客户端字段优先级变更:Teams Beta版对纯卡片消息的摘要渲染逻辑进行了调整,不再优先读取activity.Summary,而是默认使用"Sent a card",需要通过卡片自身的元数据来指定摘要。
  2. 空文本消息触发默认逻辑:当前代码使用MessageFactory.Text("")创建空文本的Activity,Beta版可能将这类消息判定为纯卡片消息,直接启用默认摘要规则。

解决方法

1. 调整缩略卡片的摘要设置

生成缩略卡片的Attachment后,手动为其Content添加summary属性,补充Activity的Summary设置:

attachment = card.ToAttachment();
// 给缩略卡片的Content添加summary字段
dynamic content = attachment.Content;
content.summary = attempt.Summary();
attachment.Content = content;

2. 为自适应卡片添加Teams扩展属性

如果是自适应卡片,需要在卡片结构中添加Microsoft Teams专属的summary扩展属性,而不是仅依赖Activity的Summary:

// 假设AdaptiveCardHelper.GetHeroCard返回的是AdaptiveCard对象,调整如下:
var adaptiveCard = new AdaptiveCard(new AdaptiveSchemaVersion(1, 4));
// 设置卡片标题、内容等原有逻辑...
// 添加Teams扩展的summary
adaptiveCard.Extensions.Add("msteams", new JObject { ["summary"] = attempt.Summary() });
// 转换为Attachment
attachment = new Attachment
{
    ContentType = AdaptiveCard.ContentType,
    Content = adaptiveCard
};

3. 避免使用空文本消息

将空文本消息替换为带附件的消息,同时设置Text字段作为补充:

// 替换原有的MessageFactory.Text("")
var activity = MessageFactory.Attachment(attempt.Attachment());
activity.Summary = attempt.Summary();
// 设置Text字段,辅助Beta版识别自定义摘要
activity.Text = attempt.Summary();

验证建议

  • 测试调整后的代码,确认Beta版客户端是否能正确展示自定义摘要。
  • 若问题仍存在,查看Teams Beta版的官方更新日志,确认是否有相关API变更;或提交反馈给Microsoft Teams开发者支持。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.12 21:47:34