Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [BotAuthentication]
- public class MessagesController : ApiController
- {
- /// <summary>
- /// POST: api/Messages
- /// receive a message from a user and send replies
- /// </summary>
- /// <param name="activity"></param>
- [ResponseType(typeof(void))]
- public virtual async Task<HttpResponseMessage> Post([FromBody] Activity activity)
- {
- // check if activity is of type message
- if (activity != null && activity.GetActivityType() == ActivityTypes.Message)
- {
- ConnectorClient connector = new ConnectorClient(new Uri(activity.ServiceUrl));
- Random random = new Random();
- string resposta = string.Empty;
- if (activity.Text.ToLower().StartsWith("guid"))
- resposta = Guid.NewGuid().ToString();
- else if (activity.Text.ToLower().StartsWith("empty"))
- resposta = Guid.Empty.ToString();
- // return our reply to the user
- if (!string.IsNullOrEmpty(resposta))
- {
- Activity reply = activity.CreateReply(resposta);
- await connector.Conversations.ReplyToActivityAsync(reply);
- }
- }
- else
- {
- HandleSystemMessage(activity);
- }
- return new HttpResponseMessage(System.Net.HttpStatusCode.Accepted);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement