如果您使用 Direct Line App Service Extension,自适应卡将不起作用

Adaptive Card does not work if you use Direct Line App Service Extension

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 ": "Image", "url": "https://www.xxxxxxxx.com/ResourcePackages/xxxxxxx/images/svg/xxxxxxxxx.svg", "size": "stretch" }, { "type": "TextBlock ", "spacing": "medium", "size": "default", "weight": "bolder", "text": "Welcome to Bot!", "wrap": true, "maxLines": 0 }, { "type": "TextBlock", "size": "default", "isSubtle": true, "text": "Please select your preferred language to continue.", "wrap": true, "maxLines ": 0 } ], "actions": [ { "type": "Action.Submit", "title": "English", "data": "en" }, { "type": "Action.Submit", "title": "德语", "data": "de" } ] }

从welcomeCard.Json内容中可以看出适配卡的版本是1.0。 完全删除 styleOtptions 没有任何效果。

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

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

显然这个问题与 webchat 最小包相关,您可以查看 github 文档和示例,在 full-bundle 的情况下加载了自适应卡片,但是当我们使用最小版本 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/

让我知道这是否适合您。