Allow users to multiselect option in BotFramework - c#

I would like my Bot make surveys. The problem is that in some questions, the user could select more than 1 answer.
How could I implement this scenario? Is there an official sample on how to do it with version 3 of the SDK?
Thank you!

The problem is that in some questions, the user could select more than 1 answer.
To enable user to select more than 1 answer to question(s), you can use AdaptiveChoiceSetInput to achieve the requirement. The following code snippet is for your reference.
card.Body.Add(new AdaptiveTextBlock()
{
Text = "Q1:xxxxxxxx?",
Size = AdaptiveTextSize.Default,
Weight = AdaptiveTextWeight.Bolder
});
card.Body.Add(new AdaptiveChoiceSetInput()
{
Id = "choiceset1",
Choices = new List<AdaptiveChoice>()
{
new AdaptiveChoice(){
Title="answer1",
Value="answer1"
},
new AdaptiveChoice(){
Title="answer2",
Value="answer2"
},
new AdaptiveChoice(){
Title="answer3",
Value="answer3"
}
},
Style = AdaptiveChoiceInputStyle.Expanded,
IsMultiSelect = true
});
Test result:

Related

How to mirror AdaptiveChoiceSetInput behavior on mobile and desktop devices?

Working on a bot for teams using the Bot Framework SDK, I noticed that the AdaptiveChoiceSetInput (dropdowns) in cards don't behave the same way on mobile and desktop devices.
On desktop Teams, if a dropdown does not have a value, it defaults to a placeholder Select. This automatic defaulting also allows for validation to force a choice to be selected from the dropdown.
On mobile Teams, if a dropdown does not have a value, it instead defaults to the first choice. This is obviously incorrect as it makes it appear like a choice is selected in the dropdown, when it's really null.
A solution I tried was to manually add a default choice with value of null so that it would automatically set itself on mobile if the value was null. This caused an issue where the card did not appear on a mobile device.
Another solution was to add a value, like 0. Although it's likely possible to make things work this way, it lead to some complicated code I never finished because on desktop I had to account for the placeholder and the manually added default choice, and figure out how to prevent the form to be submitted with the manually added default choice.
How can I make the AdaptiveChoiceSetInput behave the same way on mobile version of Teams as in the desktop version?
Here's the relevant code:
private async Task<Attachment> GetEditableOrder(OrderModel order)
{
List<AdaptiveChoice> orderAdaptiveChoices = _context.GetOrderAdaptiveChoices(order.id);
var card = new AdaptiveCard(new AdaptiveSchemaVersion(1, 0));
card.Body.Add(new AdaptiveColumnSet
{
Columns = new List<AdaptiveColumn>
{
new AdaptiveColumn
{
Items = new List<AdaptiveElement>
{
new AdaptiveTextBlock
{
Text = "**Order**"
}
}
},
new AdaptiveColumn
{
Items = new List<AdaptiveElement>
{
new AdaptiveChoiceSetInput
{
Id = "orderId",
Choices = orderAdaptiveChoices,
Value = order.Id.ToString(),
Style = AdaptiveChoiceInputStyle.Compact,
Placeholder = "Select",
IsRequired = true,
ErrorMessage = "Selection required."
}
}
}
}
});
card.Actions.Add(new AdaptiveSubmitAction
{
Type = AdaptiveSubmitAction.TypeName,
Title = "Submit",
Data = new JObject {
{ "submitLocation", "editOrder" }
},
});
Attachment attachment = new Attachment()
{
ContentType = "application/vnd.microsoft.card.adaptive",
Content = card
};
return attachment;
}
I solved my issue by manually adding an additional default choice titled "Select" with the value of an empty string. The values null and 0 did not work due to the issues I mentioned in my question. But an empty string seems to behave the same way as the placeholder in desktop version of Teams.
So, to make the dropdown in the cards behave the same way on desktop and mobile version of Teams, simply prepend a default AdaptiveChoice to your list with the value of an empty string:
orderAdaptiveChoices.Insert(0, new AdaptiveChoice { Value = "", Title = "Select" });
Whenever it is selected on either device, it will function the same way as the placeholder that is available only on desktop Teams.

Using Microsoft Planner API, how to add comments and attachments to Planner Tasks

Im currently trying to make a quick planner interface using C#, basically trying to move hundreds of Trello boards over to planner.
Ive found the examples to create boards, buckets, tasks etc
An example on how to add task is below
var createdTask = await _graphClient.Planner.Tasks.Request().AddAsync(
new PlannerTask
{
DueDateTime = DateTimeOffset.UtcNow.AddDays(7),
Title = "Do the dishes",
Details = new PlannerTaskDetails
{
Description = "Do the dishes that are remaining in the sink"
},
Assignments = assignments,
PlanId = planId,
BucketId = bucketId,
}
);
What I cant find however is how to add comments and attachments, I'm probs missing something really obvious but how do I add them lol
Thanks

How to use AllowPartialMatches in Microsoft.Bot.Builder.Dialogs.Choices?

I'm using Microsoft BotFramework with Microsoft.Bot.Builder 4.0 library in C#.
I want to use Dialogs.Choices, and have been able to get simple ChoicePrompt working. However, the above link does not help much in understanding the namespace in depth. Online demos and samples are very basic, so I have to guess & experiment to understand the functionality.
Specifically, I'm looking at AllowPartialMatches, which appears to support some kind of fuzzy/similarity match. I.e. user types something without exact match, and the prompt finds the 'nearest' match. Is my guess correct?
Can someone explain and provide examples? Thanks?
In the waterfall dialog, create the dialog step as:
AddDialog(new ChoicePrompt(UNSPSCPrompt){
RecognizerOptions = new FindChoicesOptions()
{ AllowPartialMatches = true }
});
In the dialog step itself:
var choices = new List<Choice>
{
new Choice()
{
Value = "itm001",
Synonyms = new List<string> {"hotdog", "hot dog"},
Action = new CardAction()
{
Type = ActionTypes.ImBack,
Title = "Buy a hotdog",
Value = "hotdog"
}
},
new Choice()
{
Value = "itm002",
Synonyms = new List<string> {"bulldog", "bull dog"},
Action = new CardAction()
{
Type = ActionTypes.ImBack,
Title = "Buy a bulldog",
Value = "bulldog"
}
},
};
return await stepContext.PromptAsync("myPrompt",
new PromptOptions {
Prompt = MessageFactory.Text("What can I offer you?"),
RetryPrompt = MessageFactory.Text("I dont have that"),
Choices = choices,
Style = ListStyle.HeroCard
}, cancellationToken);
This will make utterance "a hot one" match "hot dog".
However, "hotdogs" will match nothing, i.e. tokens (words) need exact match.
"dog" will match either of the choices, and it seems that only the 'top' score is returned. (Fully implemented?)

How to setup Project Backlog in TFS pro grammatically?

I have look around the other post about this Project Backlog, but i want to those missing field in this image here
I need those missing fields like workitem, Title, Assigned To, State, Effort, Business.
I have this code with me right now.
/ Set up default team sprint date and time
var teamConfig = _tfs.GetService<TeamSettingsConfigurationService>();
var css = _tfs.GetService<ICommonStructureService4>();
string rootNodePath = string.Format("\\{0}\\Iteration\\Release 1\\Sprint 1", _selectedTeamProject.Name);
var pathRoot = css.GetNodeFromPath(rootNodePath);
css.SetIterationDates(pathRoot.Uri, DateTime.Now.AddDays(-5), DateTime.Now.AddDays(7));
var configs = teamConfig.GetTeamConfigurationsForUser(new[] { _selectedTeamProject.Uri });
var team = configs.Where(c => c.TeamName == "Demo").FirstOrDefault();
var ts = team.TeamSettings;
ts.BacklogIterationPath = string.Format(#"{0}\Release 1", _selectedTeamProject.Name);
ts.IterationPaths = new string[] { string.Format(#"{0}\Release 1\Sprint 1", _selectedTeamProject.Name), string.Format(#"{0}\Release 1\Sprint 2", _selectedTeamProject.Name) };
var tfv = new TeamFieldValue();
tfv.IncludeChildren = true;
tfv.Value = _selectedTeamProject.Name;
ts.TeamFieldValues = new []{tfv};
teamConfig.SetTeamSettings(team.TeamId, ts);
According to your screenshot, seems you are using the Work item Summary web part. After the upgrade to TFS2018, your TFS SharePoint sites will display, but all integration functionality is disabled.
The official recommended way is using TFS Dashboards for a better way to create dashboards. From that it's more easy to track/display the fields in a work item.
You could directly use some 3-party Work Item widget such as this one which also provides a summary for a selected work item.
To get or update work items such as product backlog fields pro grammatically, you could use Rest API-- Get a list of work items to handle this. It will also return all related fields name and value. Which also include a C# (GetWorkItemsByIDs method) sample code. About how to customize a dashboard in sharepoint, please take a look at this thread.

How to autoformat code on array initialization?

Every time I have array initialization and try to format the code by pressing CTRL+K and CTRL+D, the code indent doesn't get formatted automatically.
Sample code.
var users = new[]
{
new User(),
new User ( ),
new User { Id = 1 },
new User { Id = 1 } ,
new User { Id = 1 } ,
new User { Id = 1 },
};
Expected result.
var users = new[]
{
new User(),
new User(),
new User { Id = 1 },
new User { Id = 1 },
new User { Id = 1 },
new User { Id = 1 },
};
My indenting setting.
Already tried installing Code Maid and pressing shortcut in the following menu (Format Document, Format Selection).
Select your block of code and use CTRL+E , \ which deletes horizontal white space. Then tabify the code as desired.
You can also find this under EDIT --> ADVANCED --> Delete horizontal white space from your Visual Studio menu.
Check out this CodeMaid -Extension for Visual studio.
Highlight that section of the text and try to press CTRL+K+F or CTRL+K, CTRL+F

Categories