Search code examples
botframeworkadaptive-cards

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


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

Solution

  • 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!