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

SurveyDialog.cs 1.5 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
  1. namespace CreateNewConversationBot
  2. {
  3. using System;
  4. using System.Threading.Tasks;
  5. using Microsoft.Bot.Builder.Dialogs;
  6. using Microsoft.Bot.Builder.FormFlow;
  7. [Serializable]
  8. public sealed class SurveyDialog : IDialog<object>
  9. {
  10. public async Task StartAsync(IDialogContext context)
  11. {
  12. var form = new FormDialog<Survey>(new Survey(), BuildSurveyForm, FormOptions.PromptInStart);
  13. context.Call(form, this.OnSurveyCompleted);
  14. }
  15. private static IForm<Survey> BuildSurveyForm()
  16. {
  17. return new FormBuilder<Survey>()
  18. .AddRemainingFields()
  19. .Build();
  20. }
  21. private async Task OnSurveyCompleted(IDialogContext context, IAwaitable<Survey> result)
  22. {
  23. try
  24. {
  25. var survey = await result;
  26. await context.PostAsync($"Got it... {survey.Name} you've been programming for {survey.YearsCoding} years and use {survey.Language}.");
  27. }
  28. catch (FormCanceledException<Survey> e)
  29. {
  30. string reply;
  31. if (e.InnerException == null)
  32. {
  33. reply = "You have canceled the survey";
  34. }
  35. else
  36. {
  37. reply = $"Oops! Something went wrong :( Technical Details: {e.InnerException.Message}";
  38. }
  39. await context.PostAsync(reply);
  40. }
  41. context.Done(string.Empty);
  42. }
  43. }
  44. }
Tip!

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

Comments

Loading...