【问题标题】:Adaptive Card does not work if you use Direct Line App Service Extension如果您使用 Direct Line App Service Extension,则自适应卡不起作用
【发布时间】:2022-02-02 20:30:10
【问题描述】:

Web App Bot 在 MS Azure 上发布,我们使用 DirectLine 通道来呈现机器人。 其他一切都很好,但自适应卡片没有出现。

我尝试在 BOT 应用程序中将附件类型更改为自定义,并在网络聊天客户端应用程序中将其更改回自适应 crd,如下所示:

   const attachmentMiddleware = () => next => card => {
      if (card.attachment.contentType === 'application/vnd.microsoft.card.custom'){
        card.attachment.contentType = 'application/vnd.microsoft.card.adaptive'
      }
      return next(card)
    };

    window.WebChat.renderWebChat(
      {
        directLine: await window.WebChat.createDirectLineAppServiceExtension({
          domain: 'https://xxxxxxxxxxx.azurewebsites.net/.bot/v3/directline',
          token
        }),
        styleOptions: {
        adaptiveCardsParserMaxVersion: '1.2'
        }
      },
      document.getElementById('webchat')
    );

This is how it looks in the WebChat. The empty box is the card as I understood

以下是我发送的自适应卡的代码

  string[] paths = { ".", "Cards", "welcomeCard.json" };
    var fullPath = Path.Combine(paths);
    var adaptiveCard = File.ReadAllText(fullPath);
    return new Attachment()
    {
        //ContentType = "application/vnd.microsoft.card.adaptive",
        ContentType = "application/vnd.microsoft.card.custom",
        Content = JsonConvert.DeserializeObject(adaptiveCard),
    };

我之前使用 ContentType 作为 application/vnd.microsoft.card.adaptive 但根据我浏览过的一些文章,自适应卡在与 Direct Line App Service Extensions 一起使用时表现不同,因此在发送时我们应该使用 application/ vnd.microsoft.card.custom,然后从客户端应用程序将其转换为 application/vnd.microsoft.card.adaptive;但这对我也不起作用。

welcomeCard.json 的内容是 { "$schema": "http://adaptivecards.io/schemas/adaptive-card.json", "type": "AdaptiveCard", "version": "1.0", "body": [ { "type": “图片”,“网址”:“https://www.xxxxxxxx.com/ResourcePackages/xxxxxxx/images/svg/xxxxxxxxx.svg”,“尺寸”:“拉伸”},{“类型”:“文本块”, "spacing": "medium", "size": "default", "weight": "bolder", "text": "Welcome to Bot!", "wrap": true, "maxLines": 0 }, {" type": "TextBlock", "size": "default", "isSubtle": true, "text": "请选择您喜欢的语言继续。", "wrap": true, "maxLines": 0 } ], "actions": [ { "type": "Action.Submit", "title": "English", "data": "en" }, { "type": "Action.Submit", "title": "German ", "数据": "de" } ] }

我们可以在welcomeCard.Json 内容中看到自适应卡片的版本是1.0。 完全删除 styleOptions 没有任何效果。

我阅读了自述文件https://github.com/microsoft/BotFramework-WebChat#4121-patch-new-style-property-adaptivecardsparsermaxversion 并添加了“styleOptions”,但它并没有改变任何行为。

我们访问的CDN是:https://cdn.botframework.com/botframework-webchat/latest/webchat-minimal.js

【问题讨论】:

  • 您可以编辑您的帖子以包含您尝试发送的自适应卡片吗?另外,能否附上您正在访问的网络聊天 CDN 以及哪个版本?
  • 嗨@StevenKanberg,我已经更改了帖子。请看一下。谢谢你:)

标签: botframework direct-line-botframework azure-appservice web-chat


【解决方案1】:

显然,此问题与 webchat 最小捆绑包有关,您可以查看 github 文档和示例,在完整捆绑包的情况下加载自适应卡,但当我们使用最小版本 js 时会出错。 我在网络聊天中也遇到了类似的问题,我尝试将其更改为完整捆绑包并将自适应卡版本更改为 1.0

https://microsoft.github.io/BotFramework-WebChat/01.getting-started/a.full-bundle/https://microsoft.github.io/BotFramework-WebChat/01.getting-started/b.minimal-bundle/

让我知道这是否适合您。

【讨论】:

  • 很高兴您能够解决他的问题。值得注意的是,最小捆绑包不包括对自适应卡、认知服务和 Markdown-It 的支持(如本示例的 README.md 文件中所述)。
猜你喜欢
  • 2022-11-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-04-06
  • 1970-01-01
  • 2020-09-12
  • 1970-01-01
相关资源
最近更新 更多