Microsoft Teams Bot使用AudioCard提示返回主窗口查看内容问题咨询
Teams Bot AudioCard显示异常问题原因及解决方案
问题原因
你遇到的提示是Teams对无法识别的卡片类型的默认占位反馈,核心原因如下:
- Bot Framework定义的原生AudioCard属于通用卡片类型,仅在网页端、Skype等少数渠道支持,微软Teams并未对该卡片类型做适配,发送AudioCard后就会出现你看到的占位提示。
- 补充注意:即便使用Teams支持的卡片类型,音频资源也需要满足两个要求:一是必须为公网可直接访问的HTTPS地址,无访问权限校验;二是编码格式优先使用MP3,兼容性优于WAV格式。
解决方案
改用Teams原生支持的自适应卡片(Adaptive Card)嵌入媒体控件实现音频播放,替换原有AudioCard逻辑即可,示例代码如下:
首先你需要先安装AdaptiveCards对应的NuGet依赖包,然后参考如下代码构造卡片:
using AdaptiveCards; using Newtonsoft.Json; // 构造适配Teams的音频自适应卡片 private static Attachment GetTeamsAudioCard() { var cardContent = new AdaptiveCard(new AdaptiveSchemaVersion(1, 4)) { Body = new List<AdaptiveElement>() { new AdaptiveTextBlock("I am your father") { Size = AdaptiveTextSize.Large, Weight = AdaptiveTextWeight.Bolder }, new AdaptiveTextBlock("Star Wars: Episode V - The Empire Strikes Back") { IsSubtle = true }, new AdaptiveTextBlock("The Empire Strikes Back (also known as Star Wars: Episode V – The Empire Strikes Back) is a 1980 American epic space opera film directed by Irvin Kershner. Leigh Brackett and Lawrence Kasdan wrote the screenplay, with George Lucas writing the film's story and serving as executive producer.") { Wrap = true }, new AdaptiveImage() { Url = new Uri("替换为你的封面图片公网地址") }, new AdaptiveMedia() { Sources = new List<AdaptiveMediaSource>() { new AdaptiveMediaSource("audio/mpeg", new Uri("替换为你的MP3格式音频公网地址")) } } }, Actions = new List<AdaptiveAction>() { new AdaptiveOpenUrlAction() { Title = "Read More", Url = new Uri("替换为你要跳转的详情页地址") } } }; return new Attachment() { ContentType = AdaptiveCard.ContentType, Content = cardContent }; } // 发送卡片逻辑无需大幅修改,直接添加上述构造的Attachment即可 private static async Task SendAudioCard(ITurnContext<IMessageActivity> turnContext, Attachment audioCard, CancellationToken cancellationToken) { var reply = MessageFactory.Attachment(audioCard); await turnContext.SendActivityAsync(reply, cancellationToken); }
内容的提问来源于stack exchange,提问作者Davy Chen
相关产品推荐
相关产品推荐

