Building bots for businesses has been gaining popularity since the introduction of Microsoft’s Bot Framework. It allows developers to create bots and make them available in an array of channels with the same codebase.

A common scenario when developing bots is having different dialogs handle different use cases. In my previous post, we created a custom dialog that can handle an addition of 2 integers. Now, let’s extend that to handle other arithmetic operations.

Getting Started

Using our previous solution, we developed the ArithmeticDialog which handles addition. Let’s try to extend our bot by handling other operations and following the flow below:

Bot Framework: 03 - Nested Dialogs

We can reuse our existing ArithmeticDialog code for the four operations. We will create AdditionDialog, SubtractionDialog, MultiplicationDialog, and DivisionDialog. The ArithmeticDialog will be used to route the conversation to any of the other dialogs.

  1. Create the four dialogs and copy the logic from the ArithmeticDialog.
  • Remember to update the arithmetic operation in the ResumeGetSecondNumber method.

  • You should have the following in your solution:

  1. Define an enum for the operations.

  1. Update the ArithmeticDialog.cs to handle the other dialogs:

  • The StartAsync basically just calls the ShowArithmeticOptions method.
  • ShowArithmeticOptions prompts the user a choice based on the ArithmeticOperations enum using the PromptDialog.Choice() method.
  • When the user selects an option, the ChoiceReceivedAsync will be called.
  • The ChoiceReceivedAsync will evaluate the option selected, and based on that, will call the appropriate child dialog.
  • Once the child dialogs are completed, the ChildDialogComplete will be called.
  • Below is the code for AdditionDialog.cs (you can use the same code for the other 3 operations).


Press F5 to run the solution.


In this post we have used a dialog to route the conversation to a number of child dialogs. I hope this will be helpful in your bot development.

Please share if this helps you. 🙂