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

SettingsScorable.cs 2.4 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
  1. namespace ContosoFlowers.Dialogs
  2. {
  3. using System;
  4. using System.Threading;
  5. using System.Threading.Tasks;
  6. using Microsoft.Bot.Builder.Dialogs;
  7. using Microsoft.Bot.Builder.Dialogs.Internals;
  8. using Microsoft.Bot.Builder.Internals.Fibers;
  9. using Microsoft.Bot.Builder.Scorables;
  10. using Microsoft.Bot.Connector;
  11. public class SettingsScorable : IScorable<IActivity, double>
  12. {
  13. private readonly IDialogTask task;
  14. private readonly IContosoFlowersDialogFactory dialogFactory;
  15. public SettingsScorable(IDialogTask task, IContosoFlowersDialogFactory dialogFactory)
  16. {
  17. SetField.NotNull(out this.task, nameof(task), task);
  18. SetField.NotNull(out this.dialogFactory, nameof(dialogFactory), dialogFactory);
  19. }
  20. public async Task<object> PrepareAsync(IActivity item, CancellationToken token)
  21. {
  22. var message = item as IMessageActivity;
  23. if (message != null && !string.IsNullOrWhiteSpace(message.Text))
  24. {
  25. if (message.Text.Equals("settings", StringComparison.InvariantCultureIgnoreCase))
  26. {
  27. return message.Text;
  28. }
  29. }
  30. return null;
  31. }
  32. public bool HasScore(IActivity item, object state)
  33. {
  34. return state != null;
  35. }
  36. public double GetScore(IActivity item, object state)
  37. {
  38. bool matched = state != null;
  39. var score = matched ? 1.0 : double.NaN;
  40. return score;
  41. }
  42. public async Task PostAsync(IActivity item, object state, CancellationToken token)
  43. {
  44. var message = item as IMessageActivity;
  45. if (message != null)
  46. {
  47. var settingsDialog = new SettingsDialog(this.dialogFactory);
  48. // wrap it with an additional dialog that will restart the wait for
  49. // messages from the user once the child dialog has finished
  50. var interruption = settingsDialog.Void<object, IMessageActivity>();
  51. // put the interrupting dialog on the stack
  52. this.task.Call(interruption, null);
  53. // start running the interrupting dialog
  54. await this.task.PollAsync(token);
  55. }
  56. }
  57. public Task DoneAsync(IActivity item, object state, CancellationToken token)
  58. {
  59. return Task.CompletedTask;
  60. }
  61. }
  62. }
Tip!

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

Comments

Loading...