K48 K48 - 3 months ago 25
C# Question

Form Dialogs in MS Bot Framework ignore the first item in all enums

I am using MS bot framework and building a dialog form. For the options available to the user, I am using enums and this code to build the form:

return new FormBuilder<InsuranceDialogForm>()
.Message("Sure, I will need to ask you a couple of questions first.")
.Build();


And my enums look like this:

public class InsuranceDialogForm
{
//[Prompt("Are you our customer?")]
//Disabled prompt because otherwise choice buttons won't appear
public IsCurrentCustomer IsCurrentCustomer;

//[Prompt("Which type of insurance do you need?")]
public InsuranceType InsuranceType;

//[Prompt("Which country are you travelling to?")]
public string TravelDestination;

//[Prompt("Please select one:")]
public InsurancePackage InsurancePackage;
}

public enum IsCurrentCustomer
{
Yes, No
}

public enum InsuranceType
{
Travel, Vehicle, Life
}

public enum InsurancePackage
{
Basic, Standard, Executive
}

public enum WhoIsTravelling
{
Me, Family
}


The issue is that the bot ignores the first option from each enum. It is not available for selection in the buttons output by the bot, and if you type it manually, it will say ".... is not an option". So I have to use a workaround like this:

public enum IsCurrentCustomer
{
IGNORE, Yes, No
}


Meanwhile, Microsoft's examples don't have this issue. What could I be doing wrong?

Answer

0 value in enums is reserved for unknown values. Either you can supply an explicit one or start enumeration at 1.

From their sample code (https://github.com/Microsoft/BotBuilder/blob/master/CSharp/Samples/PizzaBot/Pizza.cs)

Either you explicitly set the first value of enum to 1, or include the unknown value in the enum (what you're doing).

// 1
public enum IsCurrentCustomer
{
    IGNORE, Yes, No
}

// 2

public enum IsCurrentCustomer
{
    Yes = 1, No
}
Comments