我正在使用 MS 机器人框架并构建一个对话表单。对于用户可用的选项,我使用枚举和此代码来构建表单:
return new FormBuilder<InsuranceDialogForm>()
.Message("Sure, I will need to ask you a couple of questions first.")
.Build();
我的枚举看起来像这样:
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
}
问题是机器人会忽略每个枚举中的第一个选项。它在机器人输出的按钮中不可用于选择,如果您手动输入它,它会说“.... is not an option”。所以我必须使用这样的解决方法:
public enum IsCurrentCustomer
{
IGNORE, Yes, No
}
同时,微软的例子没有这个问题。我做错了什么?
最佳答案
0 value in enums is reserved for unknown values. Either you can supply an explicit one or start enumeration at 1.
来自他们的示例代码 ( https://github.com/Microsoft/BotBuilder/blob/master/CSharp/Samples/PizzaBot/Pizza.cs )
要么您显式将枚举的第一个值设置为 1,要么在枚举中包含未知值(您正在做的事情)。
// 1
public enum IsCurrentCustomer
{
IGNORE, Yes, No
}
// 2
public enum IsCurrentCustomer
{
Yes = 1, No
}
关于c# - MS Bot Framework 中的表单对话框忽略所有枚举中的第一项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38865009/