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 1.7 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
  1. using System;
  2. using System.Threading;
  3. using System.Threading.Tasks;
  4. using System.Web;
  5. using Microsoft.Bot.Builder.ConnectorEx;
  6. using Microsoft.Bot.Builder.Dialogs;
  7. using Microsoft.Bot.Connector;
  8. using Newtonsoft.Json;
  9. namespace startNewDialogWithPrompt
  10. {
  11. [Serializable]
  12. public class RootDialog : IDialog<object>
  13. {
  14. [NonSerialized]
  15. Timer t;
  16. public async Task StartAsync(IDialogContext context)
  17. {
  18. context.Wait(this.MessageReceivedAsync);
  19. }
  20. public virtual async Task MessageReceivedAsync(IDialogContext context, IAwaitable<IMessageActivity> result)
  21. {
  22. var message = await result;
  23. var conversationReference = message.ToConversationReference();
  24. ConversationStarter.conversationReference = JsonConvert.SerializeObject(conversationReference);
  25. //Prepare the timer to simulate a background/asynchonous process
  26. t = new Timer(new TimerCallback(timerEvent));
  27. t.Change(5000, Timeout.Infinite);
  28. var url = HttpContext.Current.Request.Url;
  29. //We echo the message regardless
  30. await context.PostAsync("Hello. In a few seconds I'll interrupt this dialog and bring another one with a prompt. You can also make me send a message by accessing: " +
  31. url.Scheme + "://" + url.Host + ":" + url.Port + "/api/CustomWebApi");
  32. context.Wait(MessageReceivedAsync);
  33. }
  34. public void timerEvent(object target)
  35. {
  36. t.Dispose();
  37. ConversationStarter.Resume(); //We don't need to wait for this, just want to start the interruption here
  38. }
  39. }
  40. }
Tip!

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

Comments

Loading...