简体   繁体   English

文字未包装在英雄卡片中

[英]Text not wrapping in hero card

Im using a template from MS that allows me to use multi turn in QnA maker. 我使用MS的模板,允许我在QnA制造商中使用多转。 the problem is the text on the hero cards wont wrap. 问题是英雄卡上的文字不会换行。 From what i can see of the code the card title and subtitle are dynamically generated dependant on the existence of a prompt in Qna maker. 根据我所看到的代码,卡片标题和副标题是动态生成的,具体取决于Qna制造商中是否存在提示。

So far i've looked up on SO and can see the \\n\\n example but that wont apply in this case. 到目前为止,我已经查看了SO并且可以看到\\ n \\ n示例,但在这种情况下不适用。 or if it does could anyone help me with the correct syntax. 或者如果它确实可以帮助我使用正确的语法。 there doesn't seem to be any further advice. 似乎没有任何进一步的建议。

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;
    }
}

so the code creates the card and attaches it to the return message to the user. 所以代码创建卡并将其附加到返回消息给用户。 Can Anyone advise how to wrap the text on the card. 任何人都可以建议如何包装卡上的文字。

First of all hero cards will only let you display two lines of text, so if you want more number of lines to be shown, then I advise you to use adaptive cards. 首先,英雄卡只会让你显示两行文字,所以如果你想要显示更多行,那么我建议你使用自适应卡。 Currently formatting is not supported for hero cards. 目前英雄卡不支持格式化。

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;
 }

First, you should assign your returned QnA result to the 'text' field, not the 'title' field. 首先,您应该将返回的QnA结果分配给“文本”字段,而不是“标题”字段。 If you do so, you should find that there is no character limit. 如果您这样做,您应该发现没有字符限制。 I say 'should' because the number of lines of text a hero card can display is channel specific. 我说'应该'因为英雄卡可以显示的文本行数是特定于通道的。 At the time of this writing, I know for certain that web chat, Teams, and Facebook do not have a character limit (you will need to test others that interest you). 在撰写本文时,我确信网络聊天,团队和Facebook没有字符限制(您需要测试您感兴趣的其他人)。

As I don't know the channel you are trying to display your hero card over, your mileage may vary. 由于我不知道你试图显示你的英雄卡的频道,你的里程可能会有所不同。

Here is an example of a hero card with the text field taken from the docs. 这是一个英雄卡的示例,其中文本字段取自文档。 You can read more about hero cards here . 你可以在这里阅读更多关于英雄卡的信息 You can also reference this official sample from the Botbuilder-Samples repo. 您也可以参考Botbuilder-Samples回购中的官方样本

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;
}

Hope of help! 希望有所帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM