【发布时间】:2022-02-02 20:30:10
【问题描述】:
Web App Bot 在 MS Azure 上发布,我们使用 DirectLine 通道来呈现机器人。 其他一切都很好,但自适应卡片没有出现。
我尝试在 BOT 应用程序中将附件类型更改为自定义,并在网络聊天客户端应用程序中将其更改回自适应 crd,如下所示:
const attachmentMiddleware = () => next => card => {
if (card.attachment.contentType === 'application/vnd.microsoft.card.custom'){
card.attachment.contentType = 'application/vnd.microsoft.card.adaptive'
}
return next(card)
};
window.WebChat.renderWebChat(
{
directLine: await window.WebChat.createDirectLineAppServiceExtension({
domain: 'https://xxxxxxxxxxx.azurewebsites.net/.bot/v3/directline',
token
}),
styleOptions: {
adaptiveCardsParserMaxVersion: '1.2'
}
},
document.getElementById('webchat')
);
This is how it looks in the WebChat. The empty box is the card as I understood
以下是我发送的自适应卡的代码
string[] paths = { ".", "Cards", "welcomeCard.json" };
var fullPath = Path.Combine(paths);
var adaptiveCard = File.ReadAllText(fullPath);
return new Attachment()
{
//ContentType = "application/vnd.microsoft.card.adaptive",
ContentType = "application/vnd.microsoft.card.custom",
Content = JsonConvert.DeserializeObject(adaptiveCard),
};
我之前使用 ContentType 作为 application/vnd.microsoft.card.adaptive 但根据我浏览过的一些文章,自适应卡在与 Direct Line App Service Extensions 一起使用时表现不同,因此在发送时我们应该使用 application/ vnd.microsoft.card.custom,然后从客户端应用程序将其转换为 application/vnd.microsoft.card.adaptive;但这对我也不起作用。
welcomeCard.json 的内容是 { "$schema": "http://adaptivecards.io/schemas/adaptive-card.json", "type": "AdaptiveCard", "version": "1.0", "body": [ { "type": “图片”,“网址”:“https://www.xxxxxxxx.com/ResourcePackages/xxxxxxx/images/svg/xxxxxxxxx.svg”,“尺寸”:“拉伸”},{“类型”:“文本块”, "spacing": "medium", "size": "default", "weight": "bolder", "text": "Welcome to Bot!", "wrap": true, "maxLines": 0 }, {" type": "TextBlock", "size": "default", "isSubtle": true, "text": "请选择您喜欢的语言继续。", "wrap": true, "maxLines": 0 } ], "actions": [ { "type": "Action.Submit", "title": "English", "data": "en" }, { "type": "Action.Submit", "title": "German ", "数据": "de" } ] }
我们可以在welcomeCard.Json 内容中看到自适应卡片的版本是1.0。 完全删除 styleOptions 没有任何效果。
我阅读了自述文件https://github.com/microsoft/BotFramework-WebChat#4121-patch-new-style-property-adaptivecardsparsermaxversion 并添加了“styleOptions”,但它并没有改变任何行为。
我们访问的CDN是:https://cdn.botframework.com/botframework-webchat/latest/webchat-minimal.js
【问题讨论】:
-
您可以编辑您的帖子以包含您尝试发送的自适应卡片吗?另外,能否附上您正在访问的网络聊天 CDN 以及哪个版本?
-
嗨@StevenKanberg,我已经更改了帖子。请看一下。谢谢你:)
标签: botframework direct-line-botframework azure-appservice web-chat