我试图在MS Teams中呈现自适应卡,并收到消息“不支持指定的卡版本。” 我正在使用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 ] });
答案 0 :(得分:1)
看来您的自适应卡格式不正确。类型,版本,主体和操作属性都应位于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进行字符串化和解析。
希望这会有所帮助!