MS Bot Framework 中的表单对话框忽略所有枚举中的第一项

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

我正在使用 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
}

同时,Microsoft 的示例没有此问题。我做错了什么?

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
}

枚举变量必须可以为空。

public class InsuranceDialogForm
{
    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;
}

+1 到 kienct89

抱歉,我无法对您的问题添加评论,但如果您还没有解决提示问题,请仅供参考。

目前您有以下内容:

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

将其更改为以下内容现在将允许使用枚举值进行提示:

[Prompt("Are you our customer?" {||})]    
public IsCurrentCustomer IsCurrentCustomer;

基本上只要在枚举提示的后面加上{||},选项就会出现。

HTH