Text not wrapping in hero card - botframework

Im using a template from MS that allows me to use multi turn in QnA maker. 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.
So far i've looked up on SO and can see the \n\n example but that wont apply in this case. 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, you should assign your returned QnA result to the 'text' field, not the 'title' field. 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).
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.
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://learn.microsoft.com/bot-framework") },
};
return heroCard;
}
Hope of help!

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

Related

Change notification text when bot sends an adaptive card in Microsoft Teams?

I am developing a bot with microsoft BotFramework.When bot sends an adaptive card the notification text is "Sent a Card".
Is there a way to modify this text?
Yes, you can change the text on the notification using "Summary" property of an activity.
You can go ahead and try out this sample code:
var response = MessageFactory.Text(string.Empty);
AdaptiveCard ad = new AdaptiveCard();
ad.Body = new List<AdaptiveElement>() {
new AdaptiveTextBlock()
{
Text= "testing",
Id ="testing"
}
};
Attachment att = new Attachment()
{
Content=ad,
ContentType= AdaptiveCard.ContentType
};
response.Attachments.Add(att);
response.Summary = "showing custom greeeting from the Bot - rather than send a card";
context.SendActivityAsync(response, cancellationToken);

Cannot display more than 6 adaptive actions in an Adaptive card in Teams

I am new to bot framework and c# - we implemented a bot using a QnA maker knowledge base. I am trying to use adaptive cards with Adaptive Submit Actions.
Everything works perfectly in the WebChat, however in Teams I cannot display more than 6 submit actions at the same time...
Please find a test code below:
var demoActionList = new List<AdaptiveAction>();
for (int i=0; i<20; i++)
{
demoActionList.Add(
new AdaptiveSubmitAction()
{
Type = "Action.Submit",
Title = "title + "+i,
Data = new QnABot.Dialog.MsTeamsDataResponseWrapper() { MsTeamsResponse = new QnABot.Dialog.MsTeamsResponse() { Value = "title + " + i } }
});
}
var plCard = new AdaptiveCard(new AdaptiveSchemaVersion(1, 0));
plCard.Actions = demoActionList;
var attachment = new Attachment()
{
ContentType = AdaptiveCard.ContentType,
Content = plCard
};
chatActivity.Attachments.Add(attachment);
If I run this code in the webchat I will see all the 20 submit actions in the adaptive cards, however in ms teams I see only 6
Please see the example with teams, and the example with the webchat
Any idea how to display all the submit actions in the card with ms teams?
Teams does support carousels, so you could have multiple card attachments in a single activity like this.
This is a known hard limit in Teams right now - see this answer from someone at Microsoft not long ago: Can I show more than one button/option in teams using cards? which includes some suggested workarounds.
update: I'm also wondering if list cards might be of interest - it would look a bit similar to the web chat example you showed above - basically a long list of options.

How the bot's cards containg qnaid and context behave like QnA test?

In the test in QnA portal like the below screenshot, those buttons are created by the follow-up prompts from QnA, and when click those buttons, the next Http request contains all the prompts information like text and qnaid. Those the next response will be the answer of the specific qnaid.
But in the Bot -qnamaker-prompting Sampleenter link description here, when click the button, the Http request just contain the text as questions, thus the QnA will not get the answer bind with the qnaid. The answer may will not bind with qnaid and just context.
enter image description here
So anyone have ideas on how to create a bot like QnA test?
Generally, this is how you can get the same returned results generated from the getAnswers() API call as you get from QnA.
First, pass the current context into getAnswers() (which contains the user's message: "help", "Where did trees come from", "Why is the sky blue?", etc.) and then map the result to a variable:
const stepResults = turnContext.context;
let qnaResults = await this.qnaMaker.getAnswers(stepResults);
After validating a response is returned, you can pass the result text into an activity:
await innerDc.prompt('ConfirmPrompt', qnaResults[0].context.prompts[0].displayText);
Logging the above qnaResults[0].context.prompts shows the returned prompt values align with request payload seen in devtools:
With regards to the sample you linked, the prompt value is the returned QnAPrompts[] results (i.e. the follow-up prompt). If a prompt is present in the overall QnA results, it is parsed and displayed as a button. The displayText is coming from that prompt.
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;
}
Hope of help!

Adaptive Cards: Payment Request

I am currently working on a bot project where i am trying to utilize Microsoft adaptive cards to try send a PaymentRequest to the user. I created a dummy paymentrequest object and inserted it into a Hero card like the documentation says.
var methodList = new List<PaymentMethodData>();
var method = new PaymentMethodData()
{Data = new {supportedNetworks = new[] { "visa", "mastercard", "amex", "discover", "diners", "jcb", "unionpay"} }, SupportedMethods = new[] { "https://bobpay.xyz/pay" } };
methodList.Add(method);
var details = new PaymentDetails {};
var test = new PaymentRequest(null, methodList, details);
var heroCard = new HeroCard
{
Title = "Bob",
Subtitle = "The Builder",
Text = "Kunnen wij het maken!",
Images = new List<CardImage>
{
new CardImage
{
Url = "https://m.media-amazon.com/images/M/MV5BNjRlYjgwMWMtNDFmMy00OWQ0LWFhMTMtNWE3MTU4ZjQ3MjgyXkEyXkFqcGdeQXVyNzU1NzE3NTg#._V1_CR0,45,480,270_AL_UX477_CR0,0,477,268_AL_.jpg"
}
},
Buttons = new List<CardAction>
{
new CardAction
{
Title = "Buy",
Type = PaymentRequest.PaymentActionType,
Value = test,
}
}
};
replyMessage.Attachments.Add(heroCard.ToAttachment());
await context.PostAsync(replyMessage);
I took out a bunch of parameters from the PaymentRequest constructor because i was experimenting with trying to get some kind of feedback. With this i get back nothing but this url which crashed the browser when i try to run it.
"content": {
"buttons": [
{
"title": "Buy",
"type": "openUrl",
"value": "payment://{\"methodData\":[{\"supportedMethods\":[\"https://bobpay.xyz/pay\"],\"data\":{}}],\"details\":{}}"
}
],
I can't find any documentation on how to do this properly but it doesnt seem to say it is deprecated on the documention. I am using bot framework v3 if that helps. I feel like even without some parameters in the PaymentRequest it should still give me something when i click the button.
As stated in this documentation: bot-builder-dotnet-request-payment In order to use the Bot Builder Payments library, you must first:
Create and activate a Stripe account if you don't have one already.
Sign in to Seller Center with your Microsoft account.
Within Seller Center, connect your account with Stripe.
Within Seller Center, navigate to the Dashboard and copy the value of
MerchantID.
Update your bot's Web.config file to set MerchantId to the value that
you copied from the Seller Center Dashboard.
At this time, the Bot Framework SDK supports only Stripe payments directly. If you are using some other provider, you will need to add support for it manually.
Also note: as of 2.25.2019, Bot Builder V4 sdk does not have payments support built in. The Bot Builder V3 sdk does: https://github.com/Microsoft/BotBuilder-Samples/tree/v3-sdk-samples/CSharp/sample-payments (Also, the Bot Framework Emulator V4 does not yet support payments: https://github.com/Microsoft/BotFramework-Emulator/issues/1324 The V3 emulator can be downloaded from here: https://github.com/Microsoft/BotFramework-Emulator/releases/tag/v3.5.37 )

Bot Framework Adpative Forms - Submit Action not working

I am trying to create an Adaptive forms using c#. I have installed Microsoft.AdaptiveCards Nuget package with Version 0.5.1 and Bot Builder version is 3.14.1.1.
My card has rendered correctly in Skype channel. But on click of Submit button, Forms input data Json is not passing to the Bot framework Post Activity. Submit Type is "Action.Submit". But this is working in Web chat.
I am using the below code.
var Makedmessage = context.MakeMessage();
AdaptiveCards.AdaptiveCard card = new AdaptiveCards.AdaptiveCard();
Attachment attach = new Attachment();
attach.ContentType = AdaptiveCards.AdaptiveCard.ContentType;
card.Body = new List<CardElement>() { new TextBlock() { Text = "Present a form and submit it back to the originator" }, new TextInput() { Id = "firstName", Placeholder = "What is your first name?" }, new TextInput() { Id = "lastName", Placeholder = "What is your last name?" } };
card.Actions = new List<ActionBase>() { new SubmitAction() { Title = "Action.Submit" } };
attach.Content = card;
Makedmessage.AttachmentLayout = AttachmentLayoutTypes.Carousel;
Makedmessage.Attachments.Add(attach);
await context.PostAsync(Makedmessage, CancellationToken.None);
Also attached the Screenshot.
How can I resolve this?
Adaptive cards are still under development for Skype channel. You will have to look for other alternative feature like multi dialog or formflow by Bot Framework to get the details of the user.

Resources