Articles → MICROSOFT BOT FRAMEWORK → Set The Order Of Questions In Formflow In Microsoft Bot Framework

Set The Order Of Questions In Formflow In Microsoft Bot Framework





public int Age; 
public string Name;




Picture showing the bot asking to enter the name and age from the user in the default order
Click to Enlarge



public static IForm < FormFlowDemo > GetForm() { 
    return new FormBuilder<FormFlowDemo>()
                        .Message("Welcome to support chat system. Please enter the following information to serve you better")
                        .Field(nameof(Name))
                        .Field(nameof(Age)).Build();
}




Picture showing the bot asking to enter the name and age from the user in the specified order
Click to Enlarge


Complete Code


using Microsoft.Bot.Builder.FormFlow; 
using System;
 
namespace Bot_Application1.Dialogs {  
    [Serializable]
    public class FormFlowDemo {
 
        public int Age;
        public string Name;
 
        public static IForm < FormFlowDemo > GetForm() {
            return new FormBuilder < FormFlowDemo > ().Message("Welcome to support chat system. Please enter the following information to serve you better").Field(nameof(Name)).Field(nameof(Age)).Build();
        }
    }
}



Validate Data Inside The Field Function






public static IForm <FormFlowDemo> GetForm() { 
    return new FormBuilder < FormFlowDemo>()
            .Message("Welcome to support chat system. Please enter the following information to open bank account").Field(nameof(Name))
            .Field(nameof(Age), validate: async(state, response) =>{
        var validation = new ValidateResult {
            IsValid = true,
            Value = response
        };
 
        if (Convert.ToInt32(response) < 18) {
            validation.IsValid = false;
            validation.Feedback = "You are eligible to open bank account as you are below 18 years of age";
        }
 
        return validation;
    }).Build();
}




Picture showing the validation message when user enters the age less than 18
Click to Enlarge


Posted By  -  Karan Gupta
 
Posted On  -  Friday, October 23, 2020

Query/Feedback


Your Email Id
 
Subject
 
Query/FeedbackCharacters remaining 250