【发布时间】:2022-07-25 15:45:21
【问题描述】:
我正在使用 java (spring boot) 开发一个 Microsoft 团队机器人,它将消息发送给团队用户,我可以使用卡片发送消息。现在我正在尝试动态生成自适应卡。我已经创建了自适应卡片模板并且拥有数据,在自适应卡片设计器中一切正常。
问题是没有用于自适应卡片模板的Java SDK,只有C#和JavaScript SDK https://docs.microsoft.com/en-us/adaptive-cards/templating/sdk
使用 JavaScript,我们可以简单地将数据传递给模板以生成卡片,但我如何在 java spring boot 应用程序中做到这一点。
这是我的模板:
{
"$schema": "https://adaptivecards.io/schemas/adaptive-card.json",
"type": "AdaptiveCard",
"version": "1.3",
"body": [
{
"id": "messageBlock",
"type": "TextBlock",
"text": "${msg.message}",
"wrap": true
},
{
"id": "messageSeparator",
"type": "TextBlock",
"text": " ",
"separator": true,
"spacing": "Medium"
},
{
"id": "mediaContainer",
"type": "Container",
"$data": "${media}",
"items": [
{
"type": "ColumnSet",
"columns": [
{
"type": "Column",
"width": "auto",
"items": [
{
"type": "Image",
"$when": "${not(empty(icon))}",
"url": "${icon}",
"size": "Small"
}
]
},
{
"type": "Column",
"width": "stretch",
"items": [
{
"type": "TextBlock",
"$when": "${not(empty(fileName))}",
"text": "${fileName}",
"size": "Medium",
"wrap": true,
"weight": "Bolder",
"color": "Accent",
"height": "stretch"
}
],
"selectAction": {
"type": "Action.OpenUrl",
"url": "${url}",
"title": "View"
}
}
]
},
{
"type": "TextBlock",
"text": " ",
"wrap": true,
"separator": true,
"spacing": "Medium"
}
]
}
],
"actions": [
{
"$when": "${direction == 'Inbound'}",
"type": "Action.Submit",
"title": "Reply",
"data": {
"type": "task/fetch",
"submitLocation": "task/fetch"
}
}
]
}
和样本数据:
{
"direction": "Inbound",
"message": "test message",
"media": [
{
"url": "https://example.com/imageUrl1",
"icon" : "https://example.com/icon1",
"fileName": "file1.png",
"fileType": "png"
},
{
"url": "https://example.com/imageUrl2",
"icon" : "https://example.com/icon2",
"fileName": "image1.png",
"fileType": "png"
}
]
}
【问题讨论】:
-
@Sayali-MSFT 链接显示 javascript SDK 我需要 Java 实现模板
-
目前模板 SDK 可用于 .NET 和 NodeJS。 docs.microsoft.com/en-us/adaptive-cards/templating/#sdk-support
标签: java botframework microsoft-teams adaptive-cards