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

RootDialog.cs 3.0 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
  1. namespace MultiDialogsBot.Dialogs
  2. {
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Threading;
  6. using System.Threading.Tasks;
  7. using Microsoft.Bot.Builder.Dialogs;
  8. using Microsoft.Bot.Connector;
  9. [Serializable]
  10. public class RootDialog : IDialog<object>
  11. {
  12. private const string FlightsOption = "Flights";
  13. private const string HotelsOption = "Hotels";
  14. public async Task StartAsync(IDialogContext context)
  15. {
  16. context.Wait(this.MessageReceivedAsync);
  17. }
  18. public virtual async Task MessageReceivedAsync(IDialogContext context, IAwaitable<IMessageActivity> result)
  19. {
  20. var message = await result;
  21. if (message.Text.ToLower().Contains("help") || message.Text.ToLower().Contains("support") || message.Text.ToLower().Contains("problem"))
  22. {
  23. await context.Forward(new SupportDialog(), this.ResumeAfterSupportDialog, message, CancellationToken.None);
  24. }
  25. else
  26. {
  27. this.ShowOptions(context);
  28. }
  29. }
  30. private void ShowOptions(IDialogContext context)
  31. {
  32. PromptDialog.Choice(context, this.OnOptionSelected, new List<string>() { FlightsOption, HotelsOption }, "Are you looking for a flight or a hotel?", "Not a valid option", 3);
  33. }
  34. private async Task OnOptionSelected(IDialogContext context, IAwaitable<string> result)
  35. {
  36. try
  37. {
  38. string optionSelected = await result;
  39. switch (optionSelected)
  40. {
  41. case FlightsOption:
  42. context.Call(new FlightsDialog(), this.ResumeAfterOptionDialog);
  43. break;
  44. case HotelsOption:
  45. context.Call(new HotelsDialog(), this.ResumeAfterOptionDialog);
  46. break;
  47. }
  48. }
  49. catch (TooManyAttemptsException ex)
  50. {
  51. await context.PostAsync($"Ooops! Too many attemps :(. But don't worry, I'm handling that exception and you can try again!");
  52. context.Wait(this.MessageReceivedAsync);
  53. }
  54. }
  55. private async Task ResumeAfterSupportDialog(IDialogContext context, IAwaitable<int> result)
  56. {
  57. var ticketNumber = await result;
  58. await context.PostAsync($"Thanks for contacting our support team. Your ticket number is {ticketNumber}.");
  59. context.Wait(this.MessageReceivedAsync);
  60. }
  61. private async Task ResumeAfterOptionDialog(IDialogContext context, IAwaitable<object> result)
  62. {
  63. try
  64. {
  65. var message = await result;
  66. }
  67. catch (Exception ex)
  68. {
  69. await context.PostAsync($"Failed with message: {ex.Message}");
  70. }
  71. finally
  72. {
  73. context.Wait(this.MessageReceivedAsync);
  74. }
  75. }
  76. }
  77. }
Tip!

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

Comments

Loading...