Articles → MICROSOFT BOT FRAMEWORK → Dialog Chain In Microsoft Bot Framework

Dialog Chain In Microsoft Bot Framework






What Is A Dialog Chain?




  1. Strings are hard-coded.
  2. The syntax is cumbersome (so many if and else).


  1. Dialog chains use regular expressions instead of the hard-coded string.
  2. Uses fluent interface. Fluent interface means writing the code in a more readable form.

Example




  1. Create a new class "MyDialogChain".
  2. Add the following code inside the class.
using Microsoft.Bot.Builder.Dialogs;
using System.Linq;
using System.Text.RegularExpressions;

namespace Bot_Application1.Dialogs {
	public class MyDialogChain {
		public static readonly IDialog < string > dialog = Chain.PostToChain().Select(x = >x.Text).Switch(
		Chain.Case(
		new Regex("^hi", RegexOptions.IgnoreCase), (context, text) = >Chain.Return("Good day!!!").PostToUser()), 
    Chain.Case(
		new Regex("^how are you", RegexOptions.IgnoreCase), (context, text) = >Chain.Return("I am fine, thanks for asking. How may I help you?").PostToUser()), 
    Chain.Default < string, IDialog < string >> ((context, text) = >Chain.Return("I didn't get your question").PostToUser())).Unwrap();
	}
}




Picture showing calling the MyDialogChain class inside the MessageController
Click to Enlarge


Output


Picture showing the output of dialog chain in Microsoft bot framework
Click to Enlarge


Posted By  -  Karan Gupta
 
Posted On  -  Monday, October 12, 2020

Query/Feedback


Your Email Id
 
Subject
 
Query/FeedbackCharacters remaining 250