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.9 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
  1. using Autofac;
  2. using Microsoft.Bot.Builder.Dialogs;
  3. using Microsoft.Bot.Builder.Dialogs.Internals;
  4. using Microsoft.Bot.Connector;
  5. using System.Diagnostics;
  6. using System.Linq;
  7. using System.Net.Http;
  8. using System.Threading.Tasks;
  9. using System.Web.Http;
  10. using System.Web.Http.Description;
  11. namespace simpleSendMessage
  12. {
  13. [BotAuthentication]
  14. public class MessagesController : ApiController
  15. {
  16. /// <summary>
  17. /// POST: api/Messages
  18. /// receive a message from a user and send replies
  19. /// </summary>
  20. /// <param name="activity"></param>
  21. [ResponseType(typeof(void))]
  22. public virtual async Task<HttpResponseMessage> Post([FromBody] Activity activity)
  23. {
  24. if (activity != null)
  25. {
  26. // one of these will have an interface and process it
  27. switch (activity.GetActivityType())
  28. {
  29. case ActivityTypes.Message:
  30. //We start with the root dialog
  31. await Conversation.SendAsync(activity, () => new RootDialog());
  32. break;
  33. case ActivityTypes.ConversationUpdate:
  34. //IConversationUpdateActivity update = activity;
  35. //using (var scope = DialogModule.BeginLifetimeScope(Conversation.Container, activity))
  36. //{
  37. // var client = scope.Resolve<IConnectorClient>();
  38. // if (update.MembersAdded.Any())
  39. // {
  40. // var reply = activity.CreateReply();
  41. // foreach (var newMember in update.MembersAdded)
  42. // {
  43. // if (newMember.Id != activity.Recipient.Id)
  44. // {
  45. // reply.Text = $"Welcome {newMember.Name}!";
  46. // }
  47. // else
  48. // {
  49. // reply.Text = $"Welcome {activity.From.Name}";
  50. // }
  51. // await client.Conversations.ReplyToActivityAsync(reply);
  52. // }
  53. // }
  54. //}
  55. break;
  56. case ActivityTypes.ContactRelationUpdate:
  57. case ActivityTypes.Typing:
  58. case ActivityTypes.DeleteUserData:
  59. case ActivityTypes.Ping:
  60. default:
  61. Trace.TraceError($"Unknown activity type ignored: {activity.GetActivityType()}");
  62. break;
  63. }
  64. }
  65. return new HttpResponseMessage(System.Net.HttpStatusCode.Accepted);
  66. }
  67. }
  68. }
Tip!

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

Comments

Loading...