使用Bot Framework SDK v4无法在MS Teams中呈现自适应卡 [英] Not able to render Adaptive card in MS Teams using Bot Framework SDK v4

查看:99
本文介绍了使用Bot Framework SDK v4无法在MS Teams中呈现自适应卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在MS Teams中呈现自适应卡,并收到消息不支持指定的卡版本." 我正在使用Bot Framework SDK v4-node.js

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

下面是代码段:在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 ] });

推荐答案

您的自适应卡格式似乎不正确.类型,版本,主体和操作属性都应位于JSON对象的顶层.看下面的例子.

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.

{
    "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进行字符串化和解析.

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.

希望这会有所帮助!

这篇关于使用Bot Framework SDK v4无法在MS Teams中呈现自适应卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆