Introduction
The Bot Framework enables you to build bots that support different types of interactions with users. You can design conversations in your bot to be freeform. Your bot can also have more guided interactions where it provides the user choices or actions. The conversation can use simple text strings or more complex rich cards that contain text, images, and action buttons. And, you can add natural language interactions, which let your users interact with your bots in a natural and expressive way.
Bot Builder SDK introduced Form Flow, it will automatically generate the dialog's conversation based on your property and type that was specified on a class. Bot Dialog also is more powerful but when handling a conversation like a registration or ordering, it requires more effort to complete the process using bot dialog.
In this article, I will help you to understand how to use Bot FormFlow and how you can use it to collect information from the users. We are creating a sample demo Bot for a bus booking bot.

Prerequisite
I have already explained about Bot framework Installation, deployment, and implementation in the below articles.
- Getting Started with Chatbot Using Azure Bot Service
- Getting Started with Bots Using Visual Studio 2017
- Deploying A Bot to Azure Using Visual Studio 2017
- How to Create ChatBot In Xamarin
- Getting Started with Dialog Using Microsoft Bot Framework
- Getting Started with Prompt Dialog Using Microsoft Bot Framework
Create New Bot Service
Let’s create a new Bot Service application using Visual Studio 2017. Open Visual Studio, select File menu, and create a new Project (Ctrl + Shift +N). Here, select Bot application.

The Bot application template is created with all the components and all required NuGet references installed in the solution. Just add a new class for BusFormFlow to the project.

In this solution, we have two main classes - MessagesController.cs and BusFormFlow.
Create New FormFlow Class
We can start creating a class that represents our form and creates properties for each field. Form fields can be one of the following types.
- Enum
- List of Enum
- Integral – sbyte, byte, short, ushort, int, uint, long, ulong
- Floating point – float, double
- String
- DateTime
FormFlow will automatically validate the type based on user input and reply with the validation message.
- Create a new enum field for the point from where the bus starts from.The bot output looks like below.
- /// <summary>
- /// From City Enum
- /// </summary>
- public enum FromCity
- {
- Bangalore,Chennai,Madurai,Trichy,Coimbatore,Tanjore,pudukkottai
- }

- Create a new enum field for bus end point.The bot output looks like below.
- /// <summary>
- /// To City Enum
- /// </summary>
- public enum ToCity
- {
- Bangalore, Chennai, Madurai, Trichy, Coimbatore, Tanjore, Pudukkottai
- }

- Create a new enum for bus type.The output looks like below.
- /// <summary>
- /// Bus Type Enum
- /// </summary>
- public enum BusType
- {
- AC, NonAC,Slepper, Siting
- }

- Create a new enum for gender.The output looks like below.
- /// <summary>
- /// Gender
- /// </summary>
- public enum Gender
- {
- Male,Female
- }

- Create a class for FormFlow with the [Serializable] attribute and create build form method for showing FormFlow.
- using Microsoft.Bot.Builder.FormFlow;
- using Microsoft.Bot.Builder.Dialogs;
- using System;
- namespace FormFlowBot.FormFlow
- {
- [Serializable]
- public class BusFormFlow
- {
- /// <summary>
- /// List of Form Flow
- /// </summary>
- public FromCity? FromAddress;
- public ToCity? ToAddress;
- public DateTime? StartDate;
- public BusType? BusTypes;
- public Gender? SelectGender;
- public string Name;
- public int Age;
- /// <summary>
- /// Build Form
- /// </summary>
- /// <returns></returns>
- public static IForm<BusFormFlow> BuildForm()
- {
- return new FormBuilder<BusFormFlow>()
- .Message("Welcome to the BotChat Bus Booking !")
- .OnCompletion(async (context, profileForm) =>
- {
- string message = "Your Bus booking Successfully Completed .You will get confirmation email and SMS .Thanks for using Chat Bot Bus Booking , Welcome Again !!! :)";
- await context.PostAsync(message);
- })
- .Build();
- }
- }
- }
Calling FormFlow
- The Messagescontroller class is added in the solution and adds the following MakeRootDialog from a Messagescontroller class.
- internal static IDialog<BusFormFlow> MakeRootDialog()
- {
- return Chain.From(() => FormDialog.FromForm(BusFormFlow.BuildForm));
- }
- Call MakeRootDialog from post method in MessagesController calss.
- /// <summary>
- /// POST: api/Messages
- /// Receive a message from a user and reply to it
- /// </summary>
- public async Task<HttpResponseMessage> Post([FromBody]Activity activity)
- {
- if (activity.Type == ActivityTypes.Message)
- {
- await Conversation.SendAsync(activity, MakeRootDialog);
- }
- else
- {
- HandleSystemMessage(activity);
- }
- var response = Request.CreateResponse(HttpStatusCode.OK);
- return response;
- }
Run Bot Application
The emulator is a desktop application that lets us test and debug our Bot on localhost. Now, you can click on "Run the application" in Visual Studio and execute in the browser.

Test application on Bot Emulator
You can follow the below steps for testing your bot application.
- Open Bot Emulator.
- Copy the above localhost URL and paste it in emulator e.g. - http://localHost:3979
- You can append the /api/messages in the above URL; e.g. - http://localHost:3979/api/messages.
- You won't need to specify Microsoft App ID and Microsoft App Password for localhost testing. So, click on "Connect".

Summary
In this article, we learned how to use FormFlow and collect information from the users. If you have any questions/ feedback/ issues, please write in the comment box.

Sanaj M ShajiPosted Aug 27, 2019, 1:42 PM
How we can incorporate bot framework in existing asp.net application with forms authentication
Pankaj KumarPosted May 6, 2019, 6:01 AM
Hi, how to manage this in LUIS ?
Ravi ChallaPosted Aug 1, 2018, 7:28 AM
Hi Mate, Nice Lectures you have on MS Bot Framework really useful.Is there a way i can embed a say Bing Map for instance if i need to provide location in a chatbot experience. In the Formflow .Thank you
Vinodh NarayananPosted Sep 12, 2017, 1:23 AM
Nice article. Thanks for sharing