无法使用 Bot Framework SDK v4 在 MS Teams 中呈现自适应卡

Not able to render Adaptive card in MS Teams using Bot Framework SDK v4

我正在尝试在 MS Teams 中呈现自适应卡片并收到消息 "The specified card version is not supported." 我正在使用 Bot Framework SDK v4 - node.js

下面是代码片段:下面 welcome.json

中的自适应卡片
{
"contentType": "application/vnd.microsoft.card.adaptive",
"content": {
    "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
    "type": "AdaptiveCard",
    "version": "1.0",
    "body": [
        {
           "type": "TextBlock",
           "text": "Default text input"
        }
    ],
    "actions": [
        {
           "type": "Action.Submit",
           "title": "OK"
        }
    ]
   }  
}

Node.js代码:

const { ActivityTypes, CardFactory } = require('botbuilder');
const WelcomeDialogCard = require('./Welcome.json');
let strJson = JSON.stringify(WelcomeDialogCard );
const cardJson = JSON.parse(strJson);
const confirmationCard = CardFactory.adaptiveCard(cardJson);
await turnContext.sendActivity({ attachments: [confirmationCard ] });

您的适配卡似乎未正确格式化。 type、version、body 和 action 属性都应该在 JSON 对象的顶层。看看下面的例子。

自适应卡片

{
    "contentType": "application/vnd.microsoft.card.adaptive",
    "type": "AdaptiveCard",
    "version": "1.0",
    "body": [
        {
            "type": "TextBlock",
            "text": "Default"
        }
    ],
    "actions": [{
        "type": "Action.Submit",
        "title": "OK"
    }]
}

节点

const WelcomeDialogCard = require('./Welcome.json');

const confirmationCard = CardFactory.adaptiveCard(WelcomeDialogCard)
await turnContext.sendActivity({ attachments: [confirmationCard] });

我强烈建议使用 AdaptiveCard Designer 来帮助创建您的卡片,并注意您不必对 AdaptiveCard 进行字符串化和解析。

希望对您有所帮助!