C# bot framework Align checkboxes in adaptive card along a row - c#

We have an adaptive card which is displayed after getting an answer from QnA. Within the card, we have choiceset displayed to let the user select the category he is interested in. Upon clicking select, the second level of options are given. However, we are planning to have the suboptions in the same card at first level. Is it possible to have checkboxes side by side in an adaptive card?
Code:
public List<Attachment> EmbedAdaptiveCategoryOptions()
{
#region populate choiceLists
List<AdaptiveChoice> OGChoice = new List<AdaptiveChoice>();
List<AdaptiveChoice> GeoChoice = new List<AdaptiveChoice>();
List<AdaptiveChoice> TechChoice = new List<AdaptiveChoice>();
List<AdaptiveChoice> ThemeChoice = new List<AdaptiveChoice>();
List<AdaptiveChoice> OKChoice = new List<AdaptiveChoice>();
List<string> OGids = new List<string>();
List<string> Geoids = new List<string>();
List<string> Techids = new List<string>();
List<string> themeids = new List<string>();
List<string> feedbackids = new List<string> { "I am good with the link already shared with me above!" };
List<CardAction> OGButtons = CreateOGButtons(out OGids);
foreach (var item in OGButtons)
{
OGChoice.Add(new AdaptiveChoice() { Title = item.Title, Value = item.Value.ToString() });
}
List<CardAction> GeoButtons = CreateGeoButtons(out Geoids);
foreach (var item in GeoButtons)
{
GeoChoice.Add(new AdaptiveChoice() { Title = item.Title, Value = item.Value.ToString() });
}
List<CardAction> techcardButtons = CreateTechButtons(out Techids);
foreach (var item in techcardButtons)
{
TechChoice.Add(new AdaptiveChoice() { Title = item.Title, Value = item.Value.ToString() });
}
List<CardAction> themecardButtons = CreateThemeButtons(out themeids);
foreach (var item in themecardButtons)
{
ThemeChoice.Add(new AdaptiveChoice() { Title = item.Title, Value = item.Value.ToString() });
}
List<CardAction> feedbackcardButtons = new List<CardAction>();
CardAction feedbackButton = new CardAction()
{
Value = "feedback",
Type = "imBack",
Title = "I am good with the link already shared with me above!"
};
feedbackcardButtons.Add(feedbackButton);
foreach (var item in feedbackcardButtons)
{
OKChoice.Add(new AdaptiveChoice() { Title = item.Title, Value = item.Value.ToString() });
}
#endregion
AdaptiveCard card = new AdaptiveCard();
List<Attachment> attachments = new List<Attachment>();
AdaptiveColumnSet Title = new AdaptiveColumnSet();
AdaptiveColumn titletext = new AdaptiveColumn();
titletext.Width = AdaptiveColumnWidth.Auto;
titletext.Items.Add(new AdaptiveTextBlock()
{
Weight = AdaptiveTextWeight.Bolder,
Wrap = true,
Text = "Are you interested in searching through the file? Please select the Category you would like to refine Credentials for:",
Size = AdaptiveTextSize.Medium
});
Title.Columns.Add(titletext);
card.Body.Add(Title);
AdaptiveColumnSet abc = new AdaptiveColumnSet();
AdaptiveColumn col1 = new AdaptiveColumn();
col1.Width = AdaptiveColumnWidth.Auto;
col1.Type = "TextBlock";
col1.Items.Add(new AdaptiveChoiceSetInput()
{
Choices = OGChoice,
Separator = true,
IsMultiSelect = true,
Type = "Input.ChoiceSet"
});
AdaptiveColumn col2 = new AdaptiveColumn();
col2.Width = AdaptiveColumnWidth.Auto;
col2.Type = "TextBlock";
//col2.Type = AdaptiveTextBlock.TYPE;
col2.Items.Add(new AdaptiveChoiceSetInput()
{
Choices = GeoChoice,
Separator = true,
IsMultiSelect = true,
Type = "Input.ChoiceSet"
});
AdaptiveColumn col3 = new AdaptiveColumn();
col3.Width = AdaptiveColumnWidth.Auto;
col3.Type = "TextBlock";
//col2.Type = AdaptiveTextBlock.TYPE;
col3.Items.Add(new AdaptiveChoiceSetInput()
{
Choices = TechChoice,
Separator = true,
IsMultiSelect = true,
Type = "Input.ChoiceSet"
});
AdaptiveColumn col4 = new AdaptiveColumn();
col4.Width = AdaptiveColumnWidth.Auto;
col4.Type = "TextBlock";
//col2.Type = AdaptiveTextBlock.TYPE;
col4.Items.Add(new AdaptiveChoiceSetInput()
{
Choices = ThemeChoice,
Separator = true,
IsMultiSelect = true,
Type = "Input.ChoiceSet"
});
AdaptiveColumn col5 = new AdaptiveColumn();
col5.Width = AdaptiveColumnWidth.Auto;
col5.Type = "TextBlock";
//col2.Type = AdaptiveTextBlock.TYPE;
col5.Items.Add(new AdaptiveChoiceSetInput()
{
Choices = OKChoice,
Separator = true,
IsMultiSelect = true,
Type = "Input.ChoiceSet"
});
abc.Columns.Add(col1);
abc.Columns.Add(col2);
abc.Columns.Add(col3);
abc.Columns.Add(col4);
abc.Columns.Add(col5);
card.Body.Add(abc);
List<AdaptiveAction> Actions = new List<AdaptiveAction>()
{
new AdaptiveSubmitAction()
{
Id = "selectBtn",
Title = "Select",
Speak = "<s>Search</s>",
DataJson = "{ \"Type\": \"SubmitQuestion\" }"
}
};
card.Actions.Add(Actions[0]);
Attachment attachment = new Attachment()
{
ContentType = AdaptiveCard.ContentType,
Content = card
};
attachments.Add(attachment);
return attachments;
}

You can align check boxes side-by-side in an AdaptiveCard by placing them in columns. Take a look at the AdaptiveCards documentation on columns and see the example below.
Screenshot
AdaptiveCard JSON
{
"type": "AdaptiveCard",
"body": [
{
"type": "TextBlock",
"horizontalAlignment": "Center",
"size": "Medium",
"text": "Horizontal Checkboxes",
"maxLines": 3
},
{
"type": "ColumnSet",
"separator": true,
"columns": [
{
"type": "Column",
"items": [
{
"type": "Input.Toggle",
"id": "option1",
"title": "Option 1",
"value": "true"
}
],
"width": "auto"
},
{
"type": "Column",
"items": [
{
"type": "Input.Toggle",
"id": "option2",
"title": "Option 2",
"value": "false"
}
],
"width": "auto"
},
{
"type": "Column",
"items": [
{
"type": "Input.Toggle",
"id": "option3",
"title": "Option 3",
"value": "true"
}
],
"width": "auto"
},
{
"type": "Column",
"items": [
{
"type": "Input.Toggle",
"id": "option4",
"title": "Option 4",
"value": "false"
}
],
"width": "auto"
}
]
}
],
"actions": [
{
"type": "Action.Submit",
"title": "Submit"
}
],
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"version": "1.0"
}
Also, I would recommend using the AdaptiveCard Designer to help format and create your cards.
Hope this helps!

Related

DocuSign : Template Radio Button Selection Programmatically through c#

I already have the radio button in DocuSign template, I want to select one of correct option from True and False programmatically. With the help of radioGroup.Radios.Add(, I am getting overwrite button on template button. Can you please suggest the solution how i can select radio button through c# code.
RadioGroup radioGroup = new RadioGroup { GroupName =
templateField.DocuSignFieldName, DocumentId = "1",
Radios = new List<Radio>() };
radioGroup.Radios.Add(
new Radio { PageNumber = "3", Value = "Radio 1",
XPosition = "52", YPosition = "344", Selected = "true",
TabId = templateField.DocuSignFieldName });
radioGroup.Radios.Add(
new Radio { PageNumber = "3", Value = "Radio 2",
XPosition = "85", YPosition = "344", Selected = "false",
TabId = templateField.DocuSignFieldName });
radioTabs.Add(radioGroup);
Your template has a radio group
When you use the API to send the envelope, you want to choose the initial value of the radio group. (If you want the radio buttons to be read-only, then use the locked attribute.)
You will need the tabId and value for the radio button you want to set.
Here is the request object that uses a template on the server, and then sets the name/email of the signer, and sets which radio button is selected.
{
"envelopeDefinition": {
"status": "sent",
"compositeTemplates": [
{
"compositeTemplateId": "1",
"serverTemplates": [
{
"sequence": "1",
"templateId": "12345-678-91023"
}
],
"inlineTemplates": [
{
"sequence": "1",
"recipients": {
"signers": [
{
"email": "larry#example.com",
"name": "Larry K",
"roleName": "Signer1",
"recipientId": "1",
"tabs": {
"radioGroupTabs": [
{
"groupName": "Radio Group 1",
"radios": [
{
"selected": "true",
"tabId": "615d0f54-8754-459e-9f79-e72ad427557c",
"value": "Radio3"
}
]
}
]
}
}
]
}
}
]
}
]
}
}
Here is the same JSON when it is created with the C# SDK
ServerTemplate serverTemplate1 = new ServerTemplate
{
Sequence = "1",
TemplateId = "12345-678-91023"
};
List<ServerTemplate> serverTemplates1 = new List<ServerTemplate> {serverTemplate1};
Radio radio1 = new Radio
{
Selected = "true",
TabId = "615d0f54-8754-459e-9f79-e72ad427557c",
Value = "Radio3"
};
List<Radio> radios1 = new List<Radio> {radio1};
RadioGroup radioGroupTab1 = new RadioGroup
{
GroupName = "Radio Group 1",
Radios = radios1
};
List<RadioGroup> radioGroupTabs1 = new List<RadioGroup> {radioGroupTab1};
Tabs tabs1 = new Tabs
{
RadioGroupTabs = radioGroupTabs1
};
Signer signer1 = new Signer
{
Email = "larry#example.com",
Name = "Larry K",
RecipientId = "1",
RoleName = "Signer1",
Tabs = tabs1
};
List<Signer> signers1 = new List<Signer> {signer1};
Recipients recipients1 = new Recipients
{
Signers = signers1
};
InlineTemplate inlineTemplate1 = new InlineTemplate
{
Recipients = recipients1,
Sequence = "1"
};
List<InlineTemplate> inlineTemplates1 = new List<InlineTemplate> {inlineTemplate1};
CompositeTemplate compositeTemplate1 = new CompositeTemplate
{
CompositeTemplateId = "1",
InlineTemplates = inlineTemplates1,
ServerTemplates = serverTemplates1
};
List<CompositeTemplate> compositeTemplates1 = new List<CompositeTemplate> {compositeTemplate1};
EnvelopeDefinition envelopeDefinition = new EnvelopeDefinition
{
CompositeTemplates = compositeTemplates1,
Status = "sent"
};
ApiClient apiClient = new ApiClient(basePath);
apiClient.Configuration.AddDefaultHeader("Authorization", "Bearer " + accessToken);
EnvelopesApi envelopesApi = new EnvelopesApi(apiClient);
try
{
EnvelopeSummary results = envelopesApi.CreateEnvelope(accountId, envelopeDefinition);
Console.WriteLine($"Envelope status: {results.Status}. Envelope ID: {results.EnvelopeId}");
return results.EnvelopeId;
}
catch (ApiException e)
{
Console.WriteLine("Exception while creating envelope!");
Console.WriteLine($"Code: {e.ErrorCode}\nContent: {e.ErrorContent}");
//Console.WriteLine(e.Message);
return "";
}
}
Please find the correct answer .
RadioGroup radioGroup = new RadioGroup
{
GroupName = templateField.DocuSignFieldName,
Radios = new List<Radio>()
};
if (_applicationAnswerMapService.GetRadioboxFieldValue(templateField, application) == "true")
{
radioGroup.Radios.Add(new Radio { Value = "Radio1", Selected = "true" });
}
else
{
radioGroup.Radios.Add(new Radio { Value = "Radio2", Selected = "false" });
}

System.Text.Json Serialize multiple objects/array

Could someone help me. I'm having problem serializing multiple elements.
I'm getting this result which has multiple root elements.
[
{
"TITLE": "title1",
"Total EP": 16,
"Current EP": 1,
"URL": "https://www...",
}
]
[
{
"TITLE": "title2",
"Total EP": 16,
"Current EP": 2,
"URL": "https://www...",
}
]
[
{
"TITLE": "title3",
"Total EP": 16,
"Current EP": 3,
"URL": "https://www....",
}
]
How I can make the result like this? I don't want to have multiple objects. instead I want them merge in the same object.
[
{
"TITLE": "title",
"Total EP": 16,
"Current EP": 1,
"URL": "https://www...",
},
{
"TITLE": "title",
"Total EP": 16,
"Current EP": 2,
"URL": "https://www...",
},
{
"TITLE": "title",
"Total EP": 16,
"Current EP": 3,
"URL": "https://www....",
}
]
This is the code I'm using u
var total = root.Get("total")?.GetInt32();
var title = root.Get("title")?.GetString();
foreach (var url in root.Get("response")?.EnumerateArray()) {
var currentEp = url.Get("number")?.GetInt32();
var url = url.Get("url")?.GetString();
var options = new JsonWriterOptions {
Indented = true
};
using (var stream = new MemoryStream()) {
using (var writer = new Utf8JsonWriter(stream, options)) {
writer.WriteStartObject();
writer.WriteString("TITLE", title);
writer.WriteNumber("Total EP", total);
writer.WriteNumber("Current EP", currentEp);
writer.WriteString("URL", url);
writer.WriteEndObject();
}
string json = Encoding.UTF8.GetString(stream.ToArray());
Console.WriteLine(json);
}
}
Here's the example of json.
{
"pagination":{
"previous":null,
"next":null
},
"total":10,
"title": main title,
"response":[
{
"url":"https.....id1", //URL have different ids
"number":"1",
},
{
"url":"https.....id2",
"number":"2",
},
{
"url":"https.....id3",
"number":"3",
},
{
"url":"https.....id4",
"number":"4",
},
{
"url":"https.....id5",
"number":"5",
},
]
}
Thank you for the help.
Try this code
using (var stream = new MemoryStream())
{
var options = new JsonWriterOptions
{
Indented = true
};
using (var writer = new Utf8JsonWriter(stream, options))
{
writer.WriteStartArray();
for (int i = 0; i < 10; i++)
{
var currentEp = i;
var total = i;
var title = $"title{i}";
var url = $"url:{i}";
writer.WriteStartObject();
writer.WriteString("TITLE", title);
writer.WriteNumber("Total EP", total);
writer.WriteNumber("Current EP", currentEp);
writer.WriteString("URL", url);
writer.WriteEndObject();
}
writer.WriteEndArray();
}
string json2 = Encoding.UTF8.GetString(stream.ToArray());
Console.WriteLine(json2);
}

Create private message for each signer

According to the DocuSign Documentation, it is possible to send an envelope where each signer in the envelope receives a "Private Message". I have reviewed the DocuSign REST API documentation and was unable to find any reference to a private message, or details on how to create one.
Could someone provide details on the REST API implementation of the "private message" feature? Additionally an example the DocuSign .Net SDK would be great.
You can specify the emailNotification property for each recipient. Documentation here
Here is a sample createEnvelope request.
POST /v2/accounts/{accountId}/envelopes
{
"status": "sent",
"recipients": {
"signers": [
{
"email": "janedoe#acme.com",
"name": "jane doe",
"recipientId": 1,
"emailNotification": {
"emailSubject": "Please sign the document(s) (jane doe)",
"emailBody": "Hello Jane Doe,\r\n\r\nYour have a new document to view and sign. Please click on the View Documents link below, review the content, and sign the document. ",
"supportedLanguage": "en"
},
"tabs": {"signHereTabs": [ { "documentId": "1", "pageNumber": "1", "xPosition": "80", "yPosition": "80"}]}
},
{
"email": "johnsmith#acme.com",
"name": "john smith",
"recipientId": 2,
"emailNotification": {
"emailSubject": "Please sign the document(s) (john smith)",
"emailBody": "Hello john smith,\r\n\r\nYour have a new document to view and sign. Please click on the View Documents link below, review the content, and sign the document. ",
"supportedLanguage": "en"
},
"tabs": {"signHereTabs": [ { "documentId": "1", "pageNumber": "1", "xPosition": "80", "yPosition": "180"}]}
}
]
},
"documents": [
{
"documentId": "1", "name": "Contract", "fileExtension": "txt", "documentBase64": "RG9jIFRXTyBUV08gVFdP"
}
]
}
Using the C# SDK
Complete code here
public void CreateEnvelopeSeparateEmailNotificationForRecipients()
{
string accountID = Init();
byte[] fileBytes = System.IO.File.ReadAllBytes(#"C:\temp\test.pdf");
var envDef = new EnvelopeDefinition()
{
Status = "sent",
Recipients = new Recipients()
{
Signers = new List<Signer>()
{
new Signer()
{
Email = "janedoe#acme.com",
Name = "jane doe",
RecipientId = "1",
RoutingOrder = "1",
EmailNotification = new RecipientEmailNotification()
{
EmailSubject = "Please sign the document(s) (jane doe)",
EmailBody = "This is email body for Jane Doe"
},
Tabs = new Tabs() { SignHereTabs = new List<SignHere>(){ new SignHere() { DocumentId = "1", XPosition = "100",YPosition = "300", PageNumber = "1" } } }
},
new Signer()
{
Email = "johnsmith#acme.com",
Name = "JohnSmith",
RecipientId = "2",
RoutingOrder = "1",
EmailNotification = new RecipientEmailNotification()
{
EmailSubject = "Please sign the document(s) (John Smith)",
EmailBody = "This is email body for John Smith"
},
Tabs = new Tabs() { SignHereTabs = new List<SignHere>(){ new SignHere() { DocumentId = "1", XPosition = "200",YPosition = "300", PageNumber = "1" } } }
}
}
},
Documents = new List<Document>()
{
new Document()
{
DocumentBase64 = System.Convert.ToBase64String(fileBytes),
Name = "Contract",
DocumentId = "1"
}
}
};
EnvelopesApi envelopesApi = new EnvelopesApi();
EnvelopeSummary envelopeSummary = envelopesApi.CreateEnvelope(accountID, envDef);
}

'Newtonsoft.Json.Linq.JArray' to 'System.Web.UI.WebControls.ListItemCollection'

I have a Json file as shown below. I want to convert only the option node in the JSON file into a C# ListItemCollection object
ASP.net File:
var path = Server.MapPath(#"~/json.json");
using (StreamReader r = new StreamReader(path,false))
{
string json = r.ReadToEnd();
dynamic arr = JsonConvert.DeserializeObject(json);
ListItemCollection licRB = new ListItemCollection();
licRB = arr.AnswerRadioButton.option;<<-- run time error is produced here
}
JSON File:
{ "FormTitle": "This is Form Title from JSON",
"TitleQuestion1": "This is the Title of Question 1",
"TextQuestion1": "1- This is the text of Quextion Number 1",
"AnswerRadioButton": {
"visible": "true",
"title": "Radio Button Title",
"FieldsetRBStyle": { "border": "1px" },
"option" : [
{
"text": "text1",
"value": "v1",
"checked": "false"
},
{
"text": "text2",
"value": "v2",
"checked": "true"
},
{
"text": "text3",
"value": "v3",
"checked": "false"
},
{
"text": "text4",
"value": "v4",
"checked": "true"
}
] }}
Assuming that you have the required classes (e.g. using this tool) you can access the options like this:
var test = JsonConvert.DeserializeObject<RootObject>(json);
var options = test.AnswerRadioButton.option;

Newtonsoft JSON - create JArray in JArray

I am trying to create JSON array using Newtonsoft JSON API but its giving me error. I want to achieve structure like
[
{
"id":"26",
"appsurvey":"1",
"fk_curriculumid":"70",
"status":"Completed",
"lastaccessedon":"2014-06-20 09:18:54",
"questions":[
{
"feedback":"6",
"questionid":"1"
},
{
"feedback":"8",
"questionid":"2"
},
{
"feedback":"1",
"questionid":"3"
}
],
"fk_clientid":"24",
"learnerid":"260"
}
]
I want ot add questions array for multiple time but it is giving me error
Can not add property questions to Newtonsoft.Json.Linq.JObject. Property with the same name already exists on object.
Here is my code:
JArray surveytrackingA = new JArray();
/*code to add
[
{"id":"26",
"appsurvey":"1",
"fk_curriculumid":"70",
"status":"Completed",
"lastaccessedon":"2014-06-20 09:18:54"}]
*/
for (int i = 0; i < surveytrackingA.Count; i++)
{
JObject surveytrackD = (JObject)surveytrackingA[i];
string queryOne = "select * from table101 where fk_curriculumid='"
+ surveytrackD["fk_curriculumid"].ToString()
+ "' and fk_surveyid='"
+ surveytrackD["appsurvey"].ToString() + "'";
JArray questionsA = new JArray();
using (var stmt = await App.localDB.PrepareStatementAsync(queryOne))
{
while (await stmt.StepAsync())
{
JObject questionD = new JObject();
questionD.Add("questionid", stmt.GetTextAt(5));
questionD.Add("feedback", stmt.GetTextAt(6));
questionsA.Add(questionD);
}
}
surveytrackD.Add("questions", questionsA); /*error occurred here when second question array is getting inserted in surveyTrackD*/
surveytrackingA.Add(surveytrackD);
}
Can anyone please correct me. Thanks in advance.
Update:
surveytrackD have the json data,
{
"fk_clientid": "24",
"learnerid": "260",
"appsurvey": "1",
"id": "26",
"fk_curriculumid": "70",
"status": "completed",
"lastaccessedon": "2014-06-20 09:18:54"
}
You can achieve the same result (JArray in JArray) using regular C# classes and at the end serialize to JSon.
I posted a sample in Github; here a fragment of the code that produces your expected output:
var Surveys = new List<SurveytrackD>();
Surveys.Add( new SurveytrackD { id = "26", appsurvey = "1", fk_curriculumid = "70", status = "Completed", learnerid = "240" } );
Surveys.Add( new SurveytrackD { id = "27", appsurvey = "1", fk_curriculumid = "71", status = "Completed", learnerid = "241" });
foreach (var survey in Surveys)
{
survey.questions = new List<Question>();
survey.questions.Add(new Question { questionid = "1", feedback = "0" });
survey.questions.Add(new Question { questionid = "2", feedback = "1" });
}
var json = JsonConvert.SerializeObject(Surveys, Formatting.Indented);
Console.WriteLine(json);
The output is:
[
{
"fk_clientid": null,
"learnerid": "240",
"appsurvey": "1",
"id": "26",
"fk_curriculumid": "70",
"status": "Completed",
"lastaccessedon": null,
"questions": [
{
"feedback": "0",
"questionid": "1"
},
{
"feedback": "1",
"questionid": "2"
}
]
},
{
"fk_clientid": null,
"learnerid": "241",
"appsurvey": "1",
"id": "27",
"fk_curriculumid": "71",
"status": "Completed",
"lastaccessedon": null,
"questions": [
{
"feedback": "0",
"questionid": "1"
},
{
"feedback": "1",
"questionid": "2"
}
]
}
]

Categories

Resources