我对在azure机器人中创建自适应卡的理解是通过硬编码。有没有更好的方法来创建自适应卡?因为想象一下,如果我们必须创建120张卡片。我们必须对文件进行硬编码,就像下面的代码一样,这不是一个好的做法。请帮帮我!谢谢
{
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"type": "AdaptiveCard",
"version": "1.0",
"body": [
{
"type": "Image",
"url":"google.image.com",
"size": "small"
}
],
"actions": [
{
"type": "Action.OpenUrl",
"title": "Google",
"url": "google.com"
}
]
}发布于 2019-04-16 02:55:06
有几种不同的方法可以做到这一点。给出卡片:
{
"type": "AdaptiveCard",
"body": [
{
"type": "Image",
"id": "img",
"selectAction": {
"type": "Action.OpenUrl",
"title": "Google",
"url": "http://www.google.com"
},
"url": "https://imgplaceholder.com/420x320/ff7f7f/333333/fa-image"
}
],
"actions": [
{
"type": "Action.OpenUrl",
"title": "Google",
"url": "http://www.google.com"
}
],
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"version": "1.0"
}它将呈现为:

假设我们使用以下命令导入它:
import * as cardJson from './adaptiveCard.json';然后我们的代码看起来像这样:
const card = CardFactory.adaptiveCard(cardJson);
const msg = MessageFactory.text('');
msg.attachments = [card];
await context.sendActivity(msg);1.直接编辑JSON
如果我们使用此命令来更改图像:
cardJson.body[0].url = 'https://skillbotbuilder.gallerycdn.vsassets.io/extensions/skillbotbuilder/skillbotbuilder/1.0/1546976085901/Microsoft.VisualStudio.Services.Icons.Default';我们得到:

因此,您可以将.json更多地用作模板,然后使用javascript在其基础上构建。或者:
2.使用不同类型的卡
Here's a link to other card types
然后您可以使用CardFactory来构建这些卡。
类似于上面的Hero Card将如下所示:
const hero = CardFactory.heroCard(
null,
CardFactory.images(['https://imgplaceholder.com/420x320/ff7f7f/333333/fa-image']),
CardFactory.actions([{
type: 'Action.OpenUrl',
title: 'Google',
value: 'Google.com'
}])
);https://stackoverflow.com/questions/55669536
复制相似问题