Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

PromptStringRegex.cs 1.1 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
  1. namespace ContosoFlowers.BotAssets.Dialogs
  2. {
  3. using System;
  4. using System.Text.RegularExpressions;
  5. using Microsoft.Bot.Builder.Dialogs;
  6. using Microsoft.Bot.Builder.Dialogs.Internals;
  7. using Microsoft.Bot.Connector;
  8. using Properties;
  9. [Serializable]
  10. public class PromptStringRegex : Prompt<string, string>
  11. {
  12. private readonly Regex regex;
  13. public PromptStringRegex(string prompt, string regexPattern, string retry = null)
  14. : base(new PromptOptions<string>(prompt, retry))
  15. {
  16. this.regex = new Regex(regexPattern, RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);
  17. }
  18. protected override bool TryParse(IMessageActivity message, out string result)
  19. {
  20. var quitCondition = message.Text.Equals("B", StringComparison.InvariantCultureIgnoreCase) || message.Text.Equals("Back", StringComparison.InvariantCultureIgnoreCase);
  21. var validEmail = this.regex.Match(message.Text).Success;
  22. result = validEmail ? message.Text : null;
  23. return validEmail || quitCondition;
  24. }
  25. }
  26. }
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...