当卡片有超过 5 个动作时,自适应卡片不会在 Spfx 上呈现
Adaptive Cards don't render on Spfx when the card has more than 5 actions
问题:不呈现超过五个动作
背景:
我正在将 BotFramework-WebChat 与 SharePoint Framework 集成,一切正常。但是,当我尝试在 WebChat 中显示具有超过 5 个操作的自适应卡片时,聊天显示我是一张带有文本 "Can't render card" 的卡片,但如果在 BotFramework-Emulator 中测试工作或 Console Directline 工作正常。
For testing proposes I wrote a C# method in which you pass the number of actions, that you want to show in the chat.
使用自适应卡测试
问题:如果有五个以上的操作
,则呈现带有消息"Can't render card"的卡片
Excepected : 渲染一张超过五个动作的自适应卡片
私有异步任务 MessageReceivedAsync(IDialogContext 上下文,IAwaitable 参数)
{
var message = await 参数;
var reply = context.MakeMessage();
if (message.Text.Equals("3 btn"))
{
reply.Attachments.Add(GetAdaptativeCard(3));
reply.Value = " { nombre : 'BTN'}";
}
else if (message.Text.Equals("5 btn"))
{
reply.Attachments.Add(GetAdaptativeCard(5));
reply.Value = " { nombre : 'BTN'}";
}
else if (message.Text.Equals("7 btn"))
{
reply.Attachments.Add(GetAdaptativeCard(7));
reply.Value = " { nombre : 'BTN'}";
}
else if (message.Text.Equals("18 btn"))
{
reply.Attachments.Add(GetAdaptativeCard(18));
reply.Value = " { nombre : 'BTN'}";
}
else
if (message.Text.Equals("gif"))
{
reply.Attachments.Add(GetAnimationCard());
await context.PostAsync(reply);
}
private Attachment GetAdaptativeCard(int numberOfButtons) {
var actions = new List<ActionBase>();
for (int i = 0; i < numberOfButtons; i++)
{
actions.Add(new SubmitAction()
{
Title = i.ToString(),
Speak = "<s>Search</s>",
DataJson = "{ \"Type\": \"HotelSearch\" }"
});
}
AdaptiveCard card = new AdaptiveCard()
{
Body = new List<CardElement>()
{
new Container()
{
Speak = "<s>Hello!</s><s>How many buttons are in the chat?(18)</s>",
Items = new List<CardElement>()
{
new ColumnSet()
{
Columns = new List<Column>()
{
new Column()
{
Size = ColumnSize.Auto,
Items = new List<CardElement>()
{
new Image()
{
Url = "https://placeholdit.imgix.net/~text?txtsize=65&txt=Adaptive+Cards&w=300&h=300",
Size = ImageSize.Medium,
Style = ImageStyle.Person
}
}
},
new Column()
{
Size = ColumnSize.Stretch,
Items = new List<CardElement>()
{
new TextBlock()
{
Text = "Hello!",
Weight = TextWeight.Bolder,
IsSubtle = true
}
}
}
}
}
}
}
},
// Buttons
Actions = actions
};
return new Attachment()
{
ContentType = AdaptiveCard.ContentType,
Content = card
};
}
截图:
使用 HeroCard 测试:
我只是尝试使用 HeroCard 而不是 AdaptiveCard。在这种情况下,当超过 5 个按钮时,只显示前 5 个按钮。 也许这是一个限制?
问题:卡片只渲染前五个动作
Excepected : 渲染超过五个动作的英雄卡片
private Attachment GetHeroCard(int numbersOfButtons)
{
var actions = new List<CardAction>();
for (int i = 0; i < numbersOfButtons; i++)
{
actions.Add(new CardAction(ActionTypes.OpenUrl, $"Get Started {i}", value: "https://docs.microsoft.com/bot-framework"));
}
HeroCard card = new HeroCard()
{
Title = "BotFramework Hero Card",
Subtitle = "Your bots — wherever your users are talking",
Text = "Build and connect intelligent bots to interact with your users naturally wherever they are, from text/sms to Skype, Slack, Office 365 mail and other popular services.",
Images = new List<CardImage> { new CardImage("https://sec.ch9.ms/ch9/7ff5/e07cfef0-aa3b-40bb-9baa-7c9ef8ff7ff5/buildreactionbotframework_960.jpg") },
Buttons = actions
};
return card.ToAttachment();
}
这是网络聊天自适应卡片的一个限制。幸运的是有一个解决方法。
如果不进行任何更改,您将看到 5 个限制 Actions
当您转到 visualizer 并添加超过 5 个操作(例如
时,您会看到这一点
{
"type": "Action.OpenUrl",
"title": "View",
"url": "http://adaptivecards.io"
},
{
"type": "Action.OpenUrl",
"title": "View",
"url": "http://adaptivecards.io"
},
{
"type": "Action.OpenUrl",
"title": "View",
"url": "http://adaptivecards.io"
},
{
"type": "Action.OpenUrl",
"title": "View",
"url": "http://adaptivecards.io"
},
{
"type": "Action.OpenUrl",
"title": "View",
"url": "http://adaptivecards.io"
},
{
"type": "Action.OpenUrl",
"title": "View",
"url": "http://adaptivecards.io"
}
你会得到这个错误:
不过,您可以更改此设置。可以通过在 visualizer 特别是 maxactions
字段中编辑主机配置文件来实现。 webchat 还包含一个主机配置文件,因此理论上您只需编辑该文件即可。
"actions": {
"maxActions": 20,
"spacing": "default",
"buttonSpacing": 8,
"showCard": {
"actionMode": "inline",
"inlineTopMargin": 8
},
"actionsOrientation": "vertical",
"actionAlignment": "stretch"
},
问题:不呈现超过五个动作
背景:
我正在将 BotFramework-WebChat 与 SharePoint Framework 集成,一切正常。但是,当我尝试在 WebChat 中显示具有超过 5 个操作的自适应卡片时,聊天显示我是一张带有文本 "Can't render card" 的卡片,但如果在 BotFramework-Emulator 中测试工作或 Console Directline 工作正常。
For testing proposes I wrote a C# method in which you pass the number of actions, that you want to show in the chat.
使用自适应卡测试
问题:如果有五个以上的操作
,则呈现带有消息"Can't render card"的卡片Excepected : 渲染一张超过五个动作的自适应卡片 私有异步任务 MessageReceivedAsync(IDialogContext 上下文,IAwaitable 参数) { var message = await 参数; var reply = context.MakeMessage();
if (message.Text.Equals("3 btn"))
{
reply.Attachments.Add(GetAdaptativeCard(3));
reply.Value = " { nombre : 'BTN'}";
}
else if (message.Text.Equals("5 btn"))
{
reply.Attachments.Add(GetAdaptativeCard(5));
reply.Value = " { nombre : 'BTN'}";
}
else if (message.Text.Equals("7 btn"))
{
reply.Attachments.Add(GetAdaptativeCard(7));
reply.Value = " { nombre : 'BTN'}";
}
else if (message.Text.Equals("18 btn"))
{
reply.Attachments.Add(GetAdaptativeCard(18));
reply.Value = " { nombre : 'BTN'}";
}
else
if (message.Text.Equals("gif"))
{
reply.Attachments.Add(GetAnimationCard());
await context.PostAsync(reply);
}
private Attachment GetAdaptativeCard(int numberOfButtons) {
var actions = new List<ActionBase>();
for (int i = 0; i < numberOfButtons; i++)
{
actions.Add(new SubmitAction()
{
Title = i.ToString(),
Speak = "<s>Search</s>",
DataJson = "{ \"Type\": \"HotelSearch\" }"
});
}
AdaptiveCard card = new AdaptiveCard()
{
Body = new List<CardElement>()
{
new Container()
{
Speak = "<s>Hello!</s><s>How many buttons are in the chat?(18)</s>",
Items = new List<CardElement>()
{
new ColumnSet()
{
Columns = new List<Column>()
{
new Column()
{
Size = ColumnSize.Auto,
Items = new List<CardElement>()
{
new Image()
{
Url = "https://placeholdit.imgix.net/~text?txtsize=65&txt=Adaptive+Cards&w=300&h=300",
Size = ImageSize.Medium,
Style = ImageStyle.Person
}
}
},
new Column()
{
Size = ColumnSize.Stretch,
Items = new List<CardElement>()
{
new TextBlock()
{
Text = "Hello!",
Weight = TextWeight.Bolder,
IsSubtle = true
}
}
}
}
}
}
}
},
// Buttons
Actions = actions
};
return new Attachment()
{
ContentType = AdaptiveCard.ContentType,
Content = card
};
}
截图:
使用 HeroCard 测试:
我只是尝试使用 HeroCard 而不是 AdaptiveCard。在这种情况下,当超过 5 个按钮时,只显示前 5 个按钮。 也许这是一个限制?
问题:卡片只渲染前五个动作
Excepected : 渲染超过五个动作的英雄卡片
private Attachment GetHeroCard(int numbersOfButtons)
{
var actions = new List<CardAction>();
for (int i = 0; i < numbersOfButtons; i++)
{
actions.Add(new CardAction(ActionTypes.OpenUrl, $"Get Started {i}", value: "https://docs.microsoft.com/bot-framework"));
}
HeroCard card = new HeroCard()
{
Title = "BotFramework Hero Card",
Subtitle = "Your bots — wherever your users are talking",
Text = "Build and connect intelligent bots to interact with your users naturally wherever they are, from text/sms to Skype, Slack, Office 365 mail and other popular services.",
Images = new List<CardImage> { new CardImage("https://sec.ch9.ms/ch9/7ff5/e07cfef0-aa3b-40bb-9baa-7c9ef8ff7ff5/buildreactionbotframework_960.jpg") },
Buttons = actions
};
return card.ToAttachment();
}
这是网络聊天自适应卡片的一个限制。幸运的是有一个解决方法。
如果不进行任何更改,您将看到 5 个限制 Actions
当您转到 visualizer 并添加超过 5 个操作(例如
{
"type": "Action.OpenUrl",
"title": "View",
"url": "http://adaptivecards.io"
},
{
"type": "Action.OpenUrl",
"title": "View",
"url": "http://adaptivecards.io"
},
{
"type": "Action.OpenUrl",
"title": "View",
"url": "http://adaptivecards.io"
},
{
"type": "Action.OpenUrl",
"title": "View",
"url": "http://adaptivecards.io"
},
{
"type": "Action.OpenUrl",
"title": "View",
"url": "http://adaptivecards.io"
},
{
"type": "Action.OpenUrl",
"title": "View",
"url": "http://adaptivecards.io"
}
你会得到这个错误:
不过,您可以更改此设置。可以通过在 visualizer 特别是 maxactions
字段中编辑主机配置文件来实现。 webchat 还包含一个主机配置文件,因此理论上您只需编辑该文件即可。
"actions": {
"maxActions": 20,
"spacing": "default",
"buttonSpacing": 8,
"showCard": {
"actionMode": "inline",
"inlineTopMargin": 8
},
"actionsOrientation": "vertical",
"actionAlignment": "stretch"
},