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 1.8 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
  1. namespace GetConversationMembersBot
  2. {
  3. using System;
  4. using System.Linq;
  5. using System.Net;
  6. using System.Net.Http;
  7. using System.Threading.Tasks;
  8. using System.Web.Http;
  9. using Microsoft.Bot.Builder.Dialogs;
  10. using Microsoft.Bot.Connector;
  11. [BotAuthentication]
  12. public class MessagesController : ApiController
  13. {
  14. /// <summary>
  15. /// POST: api/Messages
  16. /// Receive a message from a user and reply to it
  17. /// </summary>
  18. public async Task<HttpResponseMessage> Post([FromBody]Activity activity)
  19. {
  20. if (activity.Type == ActivityTypes.Message || activity.Type == ActivityTypes.ConversationUpdate)
  21. {
  22. await Conversation.SendAsync(activity, () => new GetConversationMembersDialog());
  23. }
  24. else
  25. {
  26. this.HandleSystemMessage(activity);
  27. }
  28. var response = Request.CreateResponse(HttpStatusCode.OK);
  29. return response;
  30. }
  31. private Activity HandleSystemMessage(Activity message)
  32. {
  33. if (message.Type == ActivityTypes.DeleteUserData)
  34. {
  35. // Implement user deletion here
  36. // If we handle user deletion, return a real message
  37. }
  38. else if (message.Type == ActivityTypes.ContactRelationUpdate)
  39. {
  40. // Handle add/remove from contact lists
  41. // Activity.From + Activity.Action represent what happened
  42. }
  43. else if (message.Type == ActivityTypes.Typing)
  44. {
  45. // Handle knowing tha the user is typing
  46. }
  47. else if (message.Type == ActivityTypes.Ping)
  48. {
  49. }
  50. return null;
  51. }
  52. }
  53. }
Tip!

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

Comments

Loading...