文字未环绕在英雄卡片中
Text not wrapping in hero card
我使用的是 MS 的模板,它允许我在 QnA maker 中使用多轮。问题是英雄卡片上的文字不会换行。从我看到的代码来看,卡片标题和副标题是根据 Qna maker 中是否存在提示动态生成的。
到目前为止,我已经查看了 SO 并且可以看到 \n\n 示例,但这不适用于这种情况。或者如果可以的话,任何人都可以用正确的语法帮助我。似乎没有任何进一步的建议。
public static Activity GetHeroCard(string cardTitle, QnAPrompts[]
prompts)
{
var chatActivity = Activity.CreateMessageActivity();
var buttons = new List<CardAction>();
var sortedPrompts = prompts.OrderBy(r => r.DisplayOrder);
foreach (var prompt in sortedPrompts)
{
buttons.Add(
new CardAction()
{
Value = prompt.DisplayText,
Type = ActionTypes.ImBack,
Title = prompt.DisplayText,
});
}
var plCard = new HeroCard()
{
Title = cardTitle,
Subtitle = string.Empty,
Buttons = buttons
};
var attachment = plCard.ToAttachment();
chatActivity.Attachments.Add(attachment);
return (Activity)chatActivity;
}
}
因此代码会创建卡片并将其附加到发送给用户的 return 消息中。任何人都可以建议如何包装卡片上的文字。
首先英雄卡片只会让你显示两行文字,所以如果你想要显示更多的行数,那么我建议你使用自适应卡片。目前英雄卡不支持格式化。
public static AdaptiveCard AdaptiveCard(string subtitle)
{
AdaptiveCard card = new AdaptiveCard();
card.Body.Add(new AdaptiveTextBlock()
{
Text = string.IsNullOrEmpty(subtitle) ? string.Empty : subtitle,
Speak =text ,
Wrap = true,
});
return card;
}
首先,您应该将返回的 QnA 结果分配给 'text' 字段,而不是 'title' 字段。如果这样做,您应该 会发现没有 字符限制。我说 'should' 是因为英雄卡可以显示的文本行数是特定于频道的。在撰写本文时,我确定网络聊天、Teams 和 Facebook 没有字符限制(您需要测试您感兴趣的其他人)。
由于我不知道您尝试显示英雄卡的频道,因此您的里程数可能会有所不同。
这是一张英雄卡片的示例,其文本字段取自文档。您可以从 Botbuilder-Samples 存储库中阅读更多关于英雄卡 here. You can also reference this official sample 的信息。
public static HeroCard GetHeroCard()
{
var heroCard = new HeroCard
{
Title = "BotFramework Hero Card",
Subtitle = "Microsoft Bot Framework",
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 = new List<CardAction> { new CardAction(ActionTypes.OpenUrl, "Get Started", value: "https://docs.microsoft.com/bot-framework") },
};
return heroCard;
}
希望得到帮助!
我使用的是 MS 的模板,它允许我在 QnA maker 中使用多轮。问题是英雄卡片上的文字不会换行。从我看到的代码来看,卡片标题和副标题是根据 Qna maker 中是否存在提示动态生成的。
到目前为止,我已经查看了 SO 并且可以看到 \n\n 示例,但这不适用于这种情况。或者如果可以的话,任何人都可以用正确的语法帮助我。似乎没有任何进一步的建议。
public static Activity GetHeroCard(string cardTitle, QnAPrompts[]
prompts)
{
var chatActivity = Activity.CreateMessageActivity();
var buttons = new List<CardAction>();
var sortedPrompts = prompts.OrderBy(r => r.DisplayOrder);
foreach (var prompt in sortedPrompts)
{
buttons.Add(
new CardAction()
{
Value = prompt.DisplayText,
Type = ActionTypes.ImBack,
Title = prompt.DisplayText,
});
}
var plCard = new HeroCard()
{
Title = cardTitle,
Subtitle = string.Empty,
Buttons = buttons
};
var attachment = plCard.ToAttachment();
chatActivity.Attachments.Add(attachment);
return (Activity)chatActivity;
}
}
因此代码会创建卡片并将其附加到发送给用户的 return 消息中。任何人都可以建议如何包装卡片上的文字。
首先英雄卡片只会让你显示两行文字,所以如果你想要显示更多的行数,那么我建议你使用自适应卡片。目前英雄卡不支持格式化。
public static AdaptiveCard AdaptiveCard(string subtitle)
{
AdaptiveCard card = new AdaptiveCard();
card.Body.Add(new AdaptiveTextBlock()
{
Text = string.IsNullOrEmpty(subtitle) ? string.Empty : subtitle,
Speak =text ,
Wrap = true,
});
return card;
}
首先,您应该将返回的 QnA 结果分配给 'text' 字段,而不是 'title' 字段。如果这样做,您应该 会发现没有 字符限制。我说 'should' 是因为英雄卡可以显示的文本行数是特定于频道的。在撰写本文时,我确定网络聊天、Teams 和 Facebook 没有字符限制(您需要测试您感兴趣的其他人)。
由于我不知道您尝试显示英雄卡的频道,因此您的里程数可能会有所不同。
这是一张英雄卡片的示例,其文本字段取自文档。您可以从 Botbuilder-Samples 存储库中阅读更多关于英雄卡 here. You can also reference this official sample 的信息。
public static HeroCard GetHeroCard()
{
var heroCard = new HeroCard
{
Title = "BotFramework Hero Card",
Subtitle = "Microsoft Bot Framework",
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 = new List<CardAction> { new CardAction(ActionTypes.OpenUrl, "Get Started", value: "https://docs.microsoft.com/bot-framework") },
};
return heroCard;
}
希望得到帮助!