Bot Framework Adpative Forms - Submit Action not working - botframework

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.

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

Create a group chat using proactive message bot framework

I'm working on a adaptive card and having a button on card which is a choice card as show card, on click of submit of that choice card i want to start a group chat with the select users.
I'm trying to do it using proactive message for group chat but didnt got any internet ref for the code using c#.
Can anyone suggest some ref for that.
var conversationParameters = new ConversationParameters
{
IsGroup = true,
Members = new ChannelAccount[] { channelAccount1, channelAccount2, activity.Recipient, activity.From },
Activity = (Activity)message
};
var identity = new MicrosoftAppCredentials(MicrosoftAppId, MicrosoftAppPassword);
MicrosoftAppCredentials.TrustServiceUrl(activity.ServiceUrl);
var connectorClient = new ConnectorClient(new Uri(activity.ServiceUrl), identity);
ConversationResourceResponse CreateConversationResponse = await connectorClient.Conversations.CreateConversationAsync(conversationParameters);
I'm getting bad request error

Text not wrapping in hero card

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

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 )

Is it possible to launch native apps using Microsoft bot framework?

I am creating a Cortana skill on the Cortana canvas, I have a button.
I wanted to know if it possible to have an 'imback' type of button to open a webpage.
Ye, for example
var message = context.MakeMessage() as IMessageActivity;
message.ChannelData = JObject.FromObject(new
{
action = new { type = "LaunchUri", uri = "skype:echo123?call" }
});
await context.PostAsync(message);
this code will start a call with echo123 user on skype
Reference: https://learn.microsoft.com/en-us/cortana/tutorials/bot-skills/bot-entity-channel-data
You can supply an openUrl to a card action, or even use ChannelData to send a LaunchUri command, deep linking to an application. (I haven't tried this, but I assume 'http://websitename.com' will launch in the Cortana host platform's default browser.)
activity.ChannelData = new {
action = new { type = "LaunchUri", uri = "http://websitename.com"}
};

Resources