Articles → MICROSOFT BOT FRAMEWORK → Dialog Chain In Microsoft Bot Framework
Dialog Chain In Microsoft Bot Framework
What Is A Dialog Chain?
- Strings are hard-coded.
- The syntax is cumbersome (so many if and else).
- Dialog chains use regular expressions instead of the hard-coded string.
- Uses fluent interface. Fluent interface means writing the code in a more readable form.
Example
- Create a new class "MyDialogChain".
- 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();
}
}
Click to Enlarge
Output
Click to Enlarge