I am creating a chatBot using microsoft Bot framework using SDKV4 in C#. The BOT has multiple waterfall dialogs. The channel is Web Chat Channel.
In this one dialog class shows few choice options in form of buttons using Prompt Options. Normally, if the choice list is simple like Option1 ,Option2 so on till Option6 the buttons will be displayed properly. But If i have choices which have text of greater length like the values provided in the below code:
return await stepContext.PromptAsync(
"choicePrompt",
new PromptOptions
{
Prompt = stepContext.Context.Activity.CreateReply("Based on the access privileges assigned to you by your admin, below are the options you can avail. Please click/choose any one from the following: "),
Choices = new[] { new Choice { Value = "Show My VMs" }, new Choice { Value = "Show VMs Status" }, new Choice { Value = "Start VM" }, new Choice { Value = "Stop VM" }, new Choice { Value = "Request Model/License" }, new Choice { Value = "Request For New VM" }, new Choice { Value = "Extend My Existing VM" }, new Choice { Value = "Logout" }, new Choice { Value = "Help" } }.ToList(),
RetryPrompt = stepContext.Context.Activity.CreateReply("Sorry, I did not understand that. Please choose any one from the options displayed below: "),
});
On executing the code the values provided in the choice list will not be rendered as buttons but instead as list of numbered bullet-ed text options something like below:
Now, if i remove the spaces between the words i.e if i modify/rewrite one of the option as only "RequestModel/License" (without spaces) like wise if is remove the space for all the text which have more than 2-3 words, on executing the code now the choices will be displayed as Buttons as expected.
So, coming to my query/issue: How can i still use choices in prompt options as shown in above code(with longer string values) and still make the buttons to be displayed?
Please note that i am a bit new to coding hence i would humbly request to provide detailed steps if this is behavior is achievable.
Thanks in Advance
Regards
ChaitanyaNG
If you are asking if there is a way to force buttons to be displayed, it is likely not possible. The length is different by channel (you may find buttons in webchat are rendered as numbered list in Teams, for example) and cannot be changed. In examining the class I saw some things that supposedly would override this behavior, but none of it worked.
If you just want to send a different value than the button displays, you can do that by adding an action attribute to the choice. The title
is what is displayed on the button and the value
is what will be passed to stepContext.result (or whatever your context object is named). I don't know the C# syntax, but in nodejs the choice definition would be
{
value: 'Request Model/License',
action: {
type: 'imBack',
title: 'RequestModel/License',
value: 'Request Model/License'
},
synonyms: ['Model','License']
}
Obviously you don't have to use synonyms, but that can be helpful too when someone might manually type something similar instead of using the buttons. For what it's worth, I like abbreviating to "Req Model/License" instead of running the words together but that's your personal preference.