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

MessagesController.cs 2.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
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
  1. using System.Net;
  2. using System.Net.Http;
  3. using System.Threading.Tasks;
  4. using System.Web.Http;
  5. using Microsoft.Bot.Connector;
  6. using Microsoft.Bot.Builder.Dialogs;
  7. using BasicMultiDialogBot.Dialogs;
  8. namespace BasicMultiDialogBot
  9. {
  10. [BotAuthentication]
  11. public class MessagesController : ApiController
  12. {
  13. /// <summary>
  14. /// POST: api/Messages
  15. /// Receive a message from a user and reply to it
  16. /// </summary>
  17. public async Task<HttpResponseMessage> Post([FromBody]Activity activity)
  18. {
  19. if (activity.Type == ActivityTypes.Message)
  20. {
  21. /* Creates a dialog stack for the new conversation, adds RootDialog to the stack, and forwards all
  22. * messages to the dialog stack. */
  23. await Conversation.SendAsync(activity, () => new RootDialog());
  24. }
  25. else
  26. {
  27. HandleSystemMessage(activity);
  28. }
  29. var response = Request.CreateResponse(HttpStatusCode.OK);
  30. return response;
  31. }
  32. private Activity HandleSystemMessage(Activity message)
  33. {
  34. if (message.Type == ActivityTypes.DeleteUserData)
  35. {
  36. // Implement user deletion here
  37. // If we handle user deletion, return a real message
  38. }
  39. else if (message.Type == ActivityTypes.ConversationUpdate)
  40. {
  41. // Handle conversation state changes, like members being added and removed
  42. // Use Activity.MembersAdded and Activity.MembersRemoved and Activity.Action for info
  43. // Not available in all channels
  44. }
  45. else if (message.Type == ActivityTypes.ContactRelationUpdate)
  46. {
  47. // Handle add/remove from contact lists
  48. // Activity.From + Activity.Action represent what happened
  49. }
  50. else if (message.Type == ActivityTypes.Typing)
  51. {
  52. // Handle knowing tha the user is typing
  53. }
  54. else if (message.Type == ActivityTypes.Ping)
  55. {
  56. }
  57. return null;
  58. }
  59. }
  60. }
Tip!

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

Comments

Loading...