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

标签 c# enums botframework

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

相关文章:

c# - 同一行中的两个 div

c# - ASP.NET Web 应用程序 - 自从从 mysql 切换到 access db 以来,我的数据库连接出现问题

java - 在多应用程序环境中处理枚举

swift - 非标称类型 "Self"不支持显式初始化(​​枚举的协议(protocol)扩展)

c# - 在 try-catch : bad practice? 中包含服务执行

c# - 如何获取字符串中尖括号内的子字符串

c - 为两个玩家随机生成一个枚举值

botframework - 微软机器人框架: Exception: The data is changed

c# - 如何获得 PromptDialog.Choice 功能并仍然允许 Bot Framework 中的其他用户响应?

c# - 客户端和服务器位于同一 Web 应用程序中的 Azure Bot 项目