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.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
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
76
77
78
79
80
81
82
  1. namespace LuisBot
  2. {
  3. using System;
  4. using System.Diagnostics;
  5. using System.Net;
  6. using System.Net.Http;
  7. using System.Threading.Tasks;
  8. using System.Web.Configuration;
  9. using System.Web.Http;
  10. using Dialogs;
  11. using Microsoft.Bot.Builder.Dialogs;
  12. using Microsoft.Bot.Connector;
  13. using Services;
  14. [BotAuthentication]
  15. public class MessagesController : ApiController
  16. {
  17. private static readonly bool IsSpellCorrectionEnabled = bool.Parse(WebConfigurationManager.AppSettings["IsSpellCorrectionEnabled"]);
  18. private readonly BingSpellCheckService spellService = new BingSpellCheckService();
  19. /// <summary>
  20. /// POST: api/Messages
  21. /// Receive a message from a user and reply to it
  22. /// </summary>
  23. public async Task<HttpResponseMessage> Post([FromBody]Activity activity)
  24. {
  25. if (activity.Type == ActivityTypes.Message)
  26. {
  27. if (IsSpellCorrectionEnabled)
  28. {
  29. try
  30. {
  31. activity.Text = await this.spellService.GetCorrectedTextAsync(activity.Text);
  32. }
  33. catch (Exception ex)
  34. {
  35. Trace.TraceError(ex.ToString());
  36. }
  37. }
  38. await Conversation.SendAsync(activity, () => new RootLuisDialog());
  39. }
  40. else
  41. {
  42. this.HandleSystemMessage(activity);
  43. }
  44. var response = Request.CreateResponse(HttpStatusCode.OK);
  45. return response;
  46. }
  47. private Activity HandleSystemMessage(Activity message)
  48. {
  49. if (message.Type == ActivityTypes.DeleteUserData)
  50. {
  51. // Implement user deletion here
  52. // If we handle user deletion, return a real message
  53. }
  54. else if (message.Type == ActivityTypes.ConversationUpdate)
  55. {
  56. // Handle conversation state changes, like members being added and removed
  57. // Use Activity.MembersAdded and Activity.MembersRemoved and Activity.Action for info
  58. // Not available in all channels
  59. }
  60. else if (message.Type == ActivityTypes.ContactRelationUpdate)
  61. {
  62. // Handle add/remove from contact lists
  63. // Activity.From + Activity.Action represent what happened
  64. }
  65. else if (message.Type == ActivityTypes.Typing)
  66. {
  67. // Handle knowing tha the user is typing
  68. }
  69. else if (message.Type == ActivityTypes.Ping)
  70. {
  71. }
  72. return null;
  73. }
  74. }
  75. }
Tip!

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

Comments

Loading...