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
  1. namespace SimpleTaskAutomationBot.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. [Serializable]
  9. public class PromptStringRegex : Prompt<string, string>
  10. {
  11. private readonly Regex regex;
  12. public PromptStringRegex(string prompt, string regexPattern, string retry = null, string tooManyAttempts = null, int attempts = 3)
  13. : base(new PromptOptions<string>(prompt, retry, tooManyAttempts, attempts: attempts))
  14. {
  15. this.regex = new Regex(regexPattern, RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);
  16. }
  17. protected override bool TryParse(IMessageActivity message, out string result)
  18. {
  19. var quitCondition = message.Text.Equals("Cancel", StringComparison.InvariantCultureIgnoreCase);
  20. var validEmail = this.regex.Match(message.Text).Success;
  21. result = validEmail ? message.Text : null;
  22. return validEmail || quitCondition;
  23. }
  24. }
  25. }
Tip!

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

Comments

Loading...