Nico Degraef
Nico Degraef

Reputation: 155

Advanced FormFlow in Bot Framework - Set Templates via code

I am using Formflow to generated the necessary questions in order to get all data from the user. Since I am supporting multiple languages, I cannot just use the attributes. So I read up about it and noticed RView can be used to generated resource files. However, as I already have my resource files split up and ordered, I am trying to reuse those.

Using the FieldReflector, I can do this quite easily

form.Field(new FieldReflector<HolidayPlanningFlowForm>(nameof(StartDate),true)
           .SetType(typeof(string))
           .SetFieldDescription(Resources.HolidayResources.Planning_FlowStartDate_Describe)
           .SetPrompt(new PromptAttribute(Resources.HolidayResources.Planning_FlowStartDate_Prompt)));

So, nice. But I cannot figure out where to defined my templates for TemplateUsage.NotUnderstood or TemplateUsage.DateTimeHelp for example. In the reference, there is a method available on Field, ReplaceTemplate(), but this reflector returns an IField and can't figure out how to get this to work.

Anyone experience in this with the best option (I really don't want to use RView ;))

Upvotes: 1

Views: 204

Answers (1)

Eric Dahlvang
Eric Dahlvang

Reputation: 8292

I think the issue here is .SetType(typeof(string)) If that is changed to typeof(DateTime) then .ReplaceTemplate() will function as expected:

public static IForm<TermFormFlow> BuildForm()
{
    return new FormBuilder<TermFormFlow>()
            .Message("Bla Bla")
            .Field(new FieldReflector<TermFormFlow>(nameof(DateOfBirth), true)
                        .ReplaceTemplate(new TemplateAttribute(TemplateUsage.NotUnderstood, "I do not understand \"{0}\".", "Try again, I don't get \"{0}\"."))
                        .ReplaceTemplate(new TemplateAttribute(TemplateUsage.DateTimeHelp, "This field should be in the format '01/01/2018'", "Please enter a date or time"))
                        .SetType(typeof(DateTime))
                        .SetFieldDescription(Resources.HolidayResources.Planning_FlowStartDate_Describe)
                        .SetPrompt(new PromptAttribute(Resources.HolidayResources.Planning_FlowStartDate_Prompt)))
            .AddRemainingFields()
            .Build();      
}

Upvotes: 1

Related Questions