Advertisement
Guest User

Untitled

a guest
Jul 17th, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. [BotAuthentication]
  2. public class MessagesController : ApiController
  3. {
  4. /// <summary>
  5. /// POST: api/Messages
  6. /// receive a message from a user and send replies
  7. /// </summary>
  8. /// <param name="activity"></param>
  9. [ResponseType(typeof(void))]
  10. public virtual async Task<HttpResponseMessage> Post([FromBody] Activity activity)
  11. {
  12. // check if activity is of type message
  13. if (activity != null && activity.GetActivityType() == ActivityTypes.Message)
  14. {
  15. ConnectorClient connector = new ConnectorClient(new Uri(activity.ServiceUrl));
  16. Random random = new Random();
  17.  
  18. string resposta = string.Empty;
  19. if (activity.Text.ToLower().StartsWith("guid"))
  20. resposta = Guid.NewGuid().ToString();
  21. else if (activity.Text.ToLower().StartsWith("empty"))
  22. resposta = Guid.Empty.ToString();
  23.  
  24. // return our reply to the user
  25. if (!string.IsNullOrEmpty(resposta))
  26. {
  27. Activity reply = activity.CreateReply(resposta);
  28. await connector.Conversations.ReplyToActivityAsync(reply);
  29. }
  30. }
  31. else
  32. {
  33. HandleSystemMessage(activity);
  34. }
  35. return new HttpResponseMessage(System.Net.HttpStatusCode.Accepted);
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement