Microsoft Bot Framework中Adaptive Cards无法渲染问题求助
排查Adaptive Cards表单空白渲染问题
核心问题:Validation属性格式不兼容Adaptive Cards 1.2
你的Adaptive Cards指定了1.2版本,但Input.Text的validation采用了旧版本语法:1.2版本中该属性需为包含regex和errorMessage的对象,而非直接传入正则字符串;同时原error属性已被errorMessage替代。语法不兼容会导致卡片解析失败,最终显示空白。
修正后的Adaptive Cards JSON
{ "$schema": "http://adaptivecards.io/schemas/adaptive-card.json", "version": "1.2", "type": "AdaptiveCard", "body": [ { "type": "TextBlock", "text": "Please input ClientId, RequestId, TimeStamp, name of your Team", "weight": "bolder", "size": "medium", "style": "heading", "wrap": true }, { "type": "TextBlock", "text": "Please also upload the ESRP Logs and your build logs after creating ticket to the Portal.", "isSubtle": true, "wrap": true }, { "type": "Input.Text", "label": "Your Onboarding ClientId", "id": "ClientId", "validation": { "regex": "^[{]?[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}[}]?$", "errorMessage": "Please enter your ClientId in the specified format" }, "isRequired": true }, { "type": "Input.Text", "id": "RequestId", "label": "RequestId", "validation": { "regex": "^[{]?[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}[}]?$", "errorMessage": "Please enter a valid RequestId" } }, { "type": "Input.Text", "id": "TimeStamp", "label": "TimeStamp" }, { "type": "Input.Text", "id": "TeamName", "label": "TeamName" } ], "actions": [ { "type": "Action.Submit", "title": "Submit" } ] }
额外排查步骤
- 验证卡片语法:将JSON粘贴到Adaptive Cards可视化编辑器,检查是否存在语法或兼容性报错。
- 确认Bot发送方式:确保发送卡片时,Attachment的ContentType设置为
application/vnd.microsoft.card.adaptive,示例C#代码:
var adaptiveCardAttachment = new Attachment() { ContentType = "application/vnd.microsoft.card.adaptive", Content = JsonConvert.DeserializeObject(yourCardJson) }; var reply = MessageFactory.Attachment(adaptiveCardAttachment); await turnContext.SendActivityAsync(reply, cancellationToken);
- 版本兼容性:若使用的Bot Framework SDK或聊天渠道对1.2版本支持有限,可尝试将卡片版本降级到1.1或1.0后测试渲染效果。
- 渠道特性限制:不同聊天渠道对Adaptive Cards属性支持存在差异,比如部分渠道不支持
style: heading,可暂时移除该属性测试是否能正常渲染。
内容的提问来源于stack exchange,提问作者Ashutosh Kumar
相关产品推荐
相关产品推荐

