将Microsoft机器人的音频卡与Microsoft团队一起使用,请参阅机器人 UI 显示"Go back to the main window to see this content."



我可以运行这个Teams Bot示例:https://github.com/microsoft/BotBuilder-Samples/tree/main/samples/csharp_dotnetcore/57.teams-conversation-bot

当我需要添加AudioCard来播放mp3歌曲时,我更新了代码:

private async Task CardActivityAsync(ITurnContext<IMessageActivity> turnContext, bool update, CancellationToken cancellationToken)
{
var card = GetAudioCard();
await SendUpdatedCardAudio(turnContext, card, cancellationToken);
}
private static AudioCard GetAudioCard()
{
var audioCard = new AudioCard
{
Title = "I am your father",
Subtitle = "Star Wars: Episode V - The Empire Strikes Back",
Text = "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. The second installment in the original Star Wars trilogy, it was produced" +
" by Gary Kurtz for Lucasfilm Ltd. and stars Mark Hamill, Harrison Ford, Carrie Fisher, Billy Dee Williams," +
" Anthony Daniels, David Prowse, Kenny Baker, Peter Mayhew and Frank Oz.",
Image = new ThumbnailUrl
{
Url = "https://upload.wikimedia.org/wikipedia/en/3/3c/SW_-_Empire_Strikes_Back.jpg",
},
Media = new List<MediaUrl>
{
new MediaUrl()
{
Url = "https://wavlist.com/wav/father.wav",
},
},
Buttons = new List<CardAction>
{
new CardAction()
{
Title = "Read More",
Type = ActionTypes.OpenUrl,
Value = "https://en.wikipedia.org/wiki/The_Empire_Strikes_Back",
},
},
};
return audioCard;
}
private static async Task SendUpdatedCardAudio(ITurnContext<IMessageActivity> turnContext, AudioCard card, CancellationToken cancellationToken)
{
var attachments = new List<Attachment>();
var reply = MessageFactory.Attachment(attachments);
reply.Attachments.Add(card.ToAttachment());
await turnContext.SendActivityAsync(reply, cancellationToken);
}

以上修改参考本例:https://github.com/microsoft/BotBuilder-Samples/tree/main/samples/csharp_dotnetcore/06.using-cards

当我在Teams Bot中测试它时,我看到了以下回复:From Teams Bot

回复说:"回到主窗口查看此内容。"。

你知道为什么吗?谢谢。

回想一下" Bot框架";是微软提供的通用Bot创建框架,Teams只是其中一个特定的实现。因此,在Teams上下文中根本不支持某些事情。在本例中,按照这里的docs:

The following cards are implemented by the Bot Framework, but are not supported by Teams:
- ..
- Audio cards
- ..

所以你需要实现另一个解决方案的音频,不幸的是。你可以做的是提供一个链接到音频文件,或者播放器,诸如此类。另一种选择是实现一个任务模块(基本上是Teams中的一个弹出窗口),嵌入你自己的小型html5音频播放器。

相关内容

最新更新