c# - 可能的 HeroCard 或 Azure 测试 Web 聊天图像缓存问题

标签 c# azure botframework adaptive-cards

我在 Azure 门户的 Web 聊天测试模拟器上遇到了我认为可能是 HeroCards 的缓存问题。由于 Cortana 不支持 AdaptiveCards,为了完全调试我的机器人,我暂时将 AdaptiveCard 渲染为图像,然后将该图像添加到 HeroCard。然后我将 HeroCard 作为附件添加到回复中。

我发现,如果我在网络聊天的 Azure 测试中输入第一个问题 (A),模拟器中会显示正确的图像,但是如果我问不同的问题 (B),则会显示相同的卡片。我可以看到缓存图像文件夹中的图像正在发生变化,但无法弄清楚为什么卡总是相同的。

我在卡片标题上添加了时间戳,以证明它不是同一张卡片。这是问题 A 中的代码。问题 B 的代码仅在生成的 AdaptiveCard 方面有所不同。

    SingleDayCompactCard card = new SingleDayCompactCard(p1, p2, p3);
    // Start of temporary code
    Activity reply = activity.CreateReply();
    reply.Attachments = new List<Attachment>();
    Attachment attachment = await AdaptiveCardToHeroAttachment(card);
    reply.Attachments.Add(attachment);
    // end of temporary code - remove when Cortana supports Adaptive cards
    ConnectorClient connector = new ConnectorClient(new Uri(activity.ServiceUrl));
    await connector.Conversations.ReplyToActivityAsync(reply);


    async Task<Attachment> AdaptiveCardToHeroAttachment(AdaptiveCard card)
    {
        AdaptiveHostConfig hostConfig = new AdaptiveHostConfig()
        {
            SupportsInteractivity = false
        };

        string path = HttpContext.Current.Request.MapPath(@"\cache\temp.png");

        // Create a renderer
        AdaptiveCardRenderer renderer = new AdaptiveCardRenderer(hostConfig);
        RenderedAdaptiveCardImage raci = null;
        try
        {
            AdaptiveCardParseResult parseResult = AdaptiveCard.FromJson(card.ToJson());
            AdaptiveCard c = parseResult.Card;
            raci =
                await renderer.RenderCardToImageAsync(c, true);
        }
        catch (Exception e)
        {

        }

        using (System.IO.FileStream output = new System.IO.FileStream(path, FileMode.Create, FileAccess.Write))
        {
            await raci.ImageStream.CopyToAsync(output);
            await output.FlushAsync();
            output.Close();
        }

        HeroCard hero = new HeroCard();
        hero.Title = DateTime.Now.ToLongTimeString();
        hero.Images.Add(new CardImage("http://localhost:3979/cache/temp.png"));
        return hero.ToAttachment();
    }

最佳答案

非常感谢埃里克

关闭浏览器缓存不起作用,但使用 base64 编码图像的第二个建议却成功了。

我删除了这段代码,并将其替换为base64编码图像链接中的代码

        HeroCard hero = new HeroCard();
        hero.Title = DateTime.Now.ToLongTimeString();
        hero.Images.Add(new CardImage("http://localhost:3979/cache/temp.png"));
        return hero.ToAttachment();

所以这条线一定是罪魁祸首

CardImage("http://localhost:3979/cache/temp.png "));

再次感谢

关于c# - 可能的 HeroCard 或 Azure 测试 Web 聊天图像缓存问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48233591/

相关文章:

c# - appsetting 节点中的子 appsettings c#

azure - 通过 terraform 进行 Elasticsearch 升级的正确方法

c# - 更改 Microsoft Bot Framework 中的消息流

botframework - 未显示 Ms Teams Bot 图标

node.js - 在网络聊天中测试机器人不会返回回复。机器人返回 503 错误

c# - 依赖注入(inject)初始化

c# - 静态类与 protected 构造函数

c# - 对 IE 工具栏中实例的静态引用

azure - 如何在azure AD上向我自己的应用程序添加应用程序权限

Azure B2C无法访问图形API