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

时光总嘲笑我的痴心妄想 提交于 2019-12-11 09:01:51

问题


I am trying to render Adaptive card in MS Teams and getting Message "The specified card version is not supported." I am using Bot Framework SDK v4 - node.js

Below is code Snippets: below Adaptive card in 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 Code:

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 ] });

回答1:


It looks like your adaptive card wasn't formatted correctly. The type, version, body, and action attributes should all be in the top level of the JSON object. Take a look at the example below.

AdaptiveCard

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

Node

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

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

I would highly recommend using the AdaptiveCard Designer to help create your cards, and note you shouldn't have to stringify and parse the AdaptiveCard.

Hope this helps!



来源:https://stackoverflow.com/questions/54863084/not-able-to-render-adaptive-card-in-ms-teams-using-bot-framework-sdk-v4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!