예제 #1
0
        /// <summary>
        /// POST: api/Messages
        /// Receive a message from a user and reply to it
        /// </summary>
        public async Task <HttpResponseMessage> Post([FromBody] Activity activity)
        {
            if (!DbController.DoesUserExist(activity.From.Name))
            {
                DbController.CreateUser(activity.From.Name);
                AddToReplyQueue("Hi there! This is the first time you're using Poolio, please make sure to update your address. Say \"update address\" for more info.");
            }

            if (activity.Type == ActivityTypes.Message)
            {
                ConnectorClient connector = new ConnectorClient(new Uri(activity.ServiceUrl));

                var intents = await _luisController.GetIntents(activity.Text);

                ProcessIntents(intents, activity);

                // return our reply to the user
                var replyMessage = GenerateReply();

                Activity reply = activity.CreateReply(!string.IsNullOrEmpty(replyMessage) ? replyMessage : "Sorry, I couldn't understand that. Try saying \"I need a ride\" or \"Become a driver\"");
                await connector.Conversations.ReplyToActivityAsync(reply);
            }
            else
            {
                HandleSystemMessage(activity);
            }

            return(Request.CreateResponse(HttpStatusCode.OK));
        }