c# - 操作留言卡未呈现
问题描述
我正在尝试发布 Messageback Adaptive 卡,但在模拟器中出现错误:无法呈现该卡。它要么格式不正确,要么使用了此主机不支持的功能。
我正在使用 AdaptiveCards 1.2.2 版本。我正在使用 C# 发布这张自适应卡,但我无法找出问题所在。
我的 Json 文件:
{
"type": "AdaptiveCard",
"selectAction": {
"type": "Action.Submit"
},
"body": [
{
"type": "TextBlock",
"text": "1:1 with John Doe",
"weight": "Bolder"
},
{
"type": "ColumnSet",
"columns": [
{
"type": "Column",
"items": [
{
"type": "Image",
"url": "https://images.idgesg.net/images/article/2019/04/google-calendar-android-100794956-large.jpg",
"altText": "Calendar",
"size": "small"
}
],
"width": "auto"
},
{
"type": "Column",
"items": [
{
"type": "TextBlock",
"text": "Tomorrow, 30 May"
}
],
"width": "stretch"
}
]
},
{
"type": "ColumnSet",
"columns": [
{
"type": "Column",
"items": [
{
"type": "Image",
"url": "https://pbs.twimg.com/profile_images/3647943215/d7f12830b3c17a5a9e4afcc370e3a37e_400x400.jpeg",
"altText": "Calendar",
"height": "20px"
}
],
"width": "auto"
},
{
"type": "Column",
"items": [
{
"type": "TextBlock",
"text": "John Doe",
"spacing": "Medium"
}
],
"width": "stretch"
}
]
},
{
"type": "TextBlock",
"text": "Slots available - **1 hr duration**",
"separator": true,
"spacing": "Medium",
"isSubtle": true
},
{
"type": "ColumnSet",
"columns": [
{
"type": "Column",
"items": [
{
"actions": [
{
"type": "Action.Submit",
"title": "11:00 AM",
"data": {
"msteams": {
"type": "messageBack",
"displayText": "11:00 AM",
"text": "text to bots",
"value": "{\"bfKey\": \"bfVal\", \"conflictKey\": \"from value\"}"
}
}
}
]
}
],
"width": "auto"
},
{
"actions": [
{
"type": "Action.Submit",
"title": "Cancel",
"data": {
"msteams": {
"type": "messageBack",
"displayText": "Cancel",
"text": "text to bots",
"value": "{\"bfKey\": \"bfVal\", \"conflictKey\": \"from value\"}"
}
}
},
{
"type": "Action.Submit",
"title": "Confirm",
"data": {
"msteams": {
"type": "messageBack",
"displayText": "Confirm",
"text": "text to bots",
"value": "{\"bfKey\": \"bfVal\", \"conflictKey\": \"from value\"}"
}
}
}
]
}
],
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"version": "1.0"
}
解决方案
测试自适应卡片的一种好方法是使用自适应卡片设计器或 Microsoft Teams 中 App Studio 中的卡片编辑器。如果未呈现预览,则说明您的卡有问题。
在您的情况下,您说您想使用 Adaptive Cards 1.2.2,但您包含"version": "1.0"
在您的 JSON 中。您可能想说"version": "1.2"
,但请记住,自适应卡的版本越高,能够渲染它的客户端就越少。
更重要的是,您actions
在列和列集中都放置了一个属性,并且它们都没有actions
属性。请参考架构以查看哪些元素具有哪些属性。您可能想要使用动作集(1.2 的功能),或者您可能只想actions
在卡片主体之外使用卡片本身的属性。
更重要的是,您的左括号比右括号多,因此您的 JSON 无效。我怀疑您忘记关闭最后一个列集及其columns
数组。请使用 Visual Studio Code 之类的编辑器自动设置 JSON 格式并确保其有效。在 Stack Overflow 问题中正确格式化 JSON 也是一种很好的礼仪,这样其他人就可以在不为您格式化的情况下阅读它。
请阅读我最新的博客文章,了解有关自适应卡片以及将它们与 Microsoft Bot Framework 一起使用的更多信息。
推荐阅读
- javascript - mongodb/mongoose 中的保存方法
- r - 如何合并两个数据框
- javascript - 如何导入另一个组件但不让其他元素呈现到 div?
- python - Kivy:更改画布矩形的 z-index
- python - 如何在python中创建一个while循环
- r - 在 R 中使用 DT 包对列进行分组
- javascript - Webpack 类型错误'TypeError [ERR_INVALID_ARG_TYPE]:“路径”参数必须是字符串类型。接收类型 boolean (true)'
- python - 将 postgres 原始查询转换为 Django ORM 查询并分组
- python-3.x - 无法使用硒(python)在网页上单击打印(图像元素)
- javascript - 如何制作单页导航?没有滚动,只是一个带有自己身体的导航