enumsbotframeworkformflow

bot builder form flow with enum


I have a bot builder project using a form flow dialog which is working fine except for a problem with recognising the response to the selection of an enum.

[Serializable]
public class ContactBot
{
    [Template(TemplateUsage.EnumSelectOne,"How do you like to be addressed - {||}", "Please select a title to address you by - {||}")]
    public TitleBot? Title { get; set; }

    [Prompt("What's your first name?", FieldCase = CaseNormalization.InitialUpper)]
    public String FirstName { get; set; }

    [Prompt("and your last name?", FieldCase = CaseNormalization.InitialUpper)]
    public String LastName { get; set; }

    [Prompt("I'll need your email address to confirm the appraisal")]
    [Pattern(RegexConstants.Email)]
    public String Email { get; set; }

    [Prompt("and a phone number, preferably a mobile, to contact you to arrange an appointment")]
    [Pattern(RegexConstants.Phone)]
    public String Phone { get; set; }

    public static IForm<ContactBot> BuildContactForm()
    {
        return new FormBuilder<ContactBot>()
            .Message("Firstly, can you give me some detail about yourself?")
            .Field(nameof(Title))
            .Field(nameof(FirstName))
            .Field(nameof(LastName))
            .Field(nameof(Email))
            .Field(nameof(Phone))
            .Confirm("You have provided the following: \r\r Name: {Title} {FirstName} {LastName} \r\r Email: {Email} \r\r Phone: {Phone} \r\r Is this correct? ")
            .Build();
    }

and the enum

public enum TitleBot
{
    Mr,
    Mrs,
    Ms,
    Miss,
    Dr
}

When I select Ms, Miss or Dr, the bot accepts this as a valid option and moves to the next prompt. However, when I select Mr or Mrs, I am asked to choose between Mr and Mrs and whatever I choose results in a Mr (or Mrs) is not a title option - What is happening?

Image of bot displaying enumeration:

display

Image of bot responses to enum selection:

bot responses to enum selection


Solution

  • I was able to differentiate between Mr and Mrs using the Terms attribute.

    public enum TitleBot
    {
        [Terms("Mr")]
        Mr=1,
        [Terms("Mrs")]
        Mrs,
        Ms,
        Miss,
        Dr
    }
    

    Selecting Mr Selecting Mr

    Selecting Mrs Selecting Mrs