Botframework-sdk: [Code Examples] Do not work "Advanced features of FormFlow" example from documentation

Created on 5 Sep 2017  路  7Comments  路  Source: microsoft/botframework-sdk

Bot Info

  • SDK Platform: .NET
  • Active Channels: Emulator

Issue Description

There is a bot created from the template http://aka.ms/bf-bc-vstemplate
In the created project I was update Bot Builder Package.
I try to understand examples of FormFlow from the documentatio: https://docs.microsoft.com/uk-ua/bot-framework/dotnet/bot-builder-dotnet-formflow-advanced

I'm trying to run this example:

public static IForm<SandwichOrder> BuildForm()
{
    return new FormBuilder<SandwichOrder>()
        .Message("Welcome to the sandwich order bot!")
        .Field(nameof(Sandwich))
        .Field(nameof(Length))
        .Field(nameof(Bread))
        .Field(nameof(Cheese))
        .Field(nameof(Toppings),
            validate: async (state, value) =>
            {
                var values = ((List<object>)value).OfType<ToppingOptions>();
                var result = new ValidateResult { IsValid = true, Value = values };
                if (values != null && values.Contains(ToppingOptions.Everything))
                {
                    result.Value = (from ToppingOptions topping in Enum.GetValues(typeof(ToppingOptions))
                                    where topping != ToppingOptions.Everything && !values.Contains(topping)
                                    select topping).ToList();
                }
                return result;
            })
        .Message("For sandwich toppings you have selected {Toppings}.")
        .Build();
}

I go to the step with a choice of Toppings and was writing "Everything". In response comes:

Exception: The given key was not present in the dictionary.
[File of type 'text/plain']

If I write Olives, there is no error and the answer is the expected: "For sandwich toppings you have selected Olives."

What am I doing wrong?

Most helpful comment

This page https://docs.microsoft.com/uk-ua/bot-framework/dotnet/bot-builder-dotnet-formflow-advanced

states:

public enum ToppingOptions
{
    // This starts at 1 because 0 is the "no value" value
    [Terms("except", "but", "not", "no", "all", "everything")]
    Everything = 1,
    ...
}

Note the comment:
// This starts at 1 because 0 is the "no value" value

All 7 comments

I'm really not sure what you are doing wrong, I just tested the annotated sandwich bot and was able to select "Everything" by typing in "Everything". Have you modified the code at all? I was not able to reproduce.
image

@JasonSowers, could you see my solution, please?

Please try replacing you ToppingsOptions enum with this:

    public enum ToppingOptions
    {
        [Terms("except", "but", "not", "no", "all", "everything")]
        Everything=1,
        Avocado, BananaPeppers, Cucumbers, GreenBellPeppers, Jalapenos,
        Lettuce, Olives, Pickles, RedOnion, Spinach, Tomatoes        
    };

Thank you so much! It worked!

Could you explain why work code:

public enum ToppingOptions
    {
        Everything=1,
        Avocado, BananaPeppers, Cucumbers, GreenBellPeppers, Jalapenos,
        Lettuce, Olives, Pickles, RedOnion, Spinach, Tomatoes        
    };

and do not work

public enum ToppingOptions
    {
        Avocado, BananaPeppers, Cucumbers, GreenBellPeppers, Jalapenos,
        Lettuce, Olives, Pickles, RedOnion, Spinach, Tomatoes,
        Everything
    };

?

To e perfectly honest I'm not exactly sure, it is just the way it is coded in the example . Formflow is kind of black box to me, Sorry I do not have a concrete answer for you. Maybe someone else can jump in and explain

This page https://docs.microsoft.com/uk-ua/bot-framework/dotnet/bot-builder-dotnet-formflow-advanced

states:

public enum ToppingOptions
{
    // This starts at 1 because 0 is the "no value" value
    [Terms("except", "but", "not", "no", "all", "everything")]
    Everything = 1,
    ...
}

Note the comment:
// This starts at 1 because 0 is the "no value" value

@JasonSowers, you still helped me a lot!

@EricDahlvang, thank you!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

daveta picture daveta  路  3Comments

kenyeung128 picture kenyeung128  路  3Comments

somprabhsharma picture somprabhsharma  路  3Comments

Vigneshramkumar picture Vigneshramkumar  路  3Comments

verdysh picture verdysh  路  3Comments