将 Microsoft Bot 的 AudioCard 与 Microsoft Teams 一起使用,看到 bot UI 显示“返回主窗口以查看此内容”。

戴维琴

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

当我需要添加一个声卡来播放 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 中对其进行测试时,我看到以下回复:来自 Teams Bot

回复说:“回到主窗口看看这个内容。”。

你知道为什么吗?谢谢。

希尔顿吉塞诺

回想一下,“Bot Framework”是来自 Microsoft 的通用 Bot 创建框架,而 Teams 只是一个特定的实现。因此,团队上下文中根本不支持某些内容。在这种情况下,根据此处的文档

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

- ..
- Audio cards
- ..

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

那你呢

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章