Ejemplo n.º 1
0
        /// <summary>
        /// POST: api/Messages
        /// Receive a message from a user and reply to it
        /// </summary>
        public async Task <Message> Post([FromBody] Message message)
        {
            if (message.Type == "Message")
            {
                var userid = message?.From?.Id;
                if (string.IsNullOrEmpty(userid))
                {
                    return(message.CreateReplyMessage("Struggling to get a user id..."));
                }

                // Lookup the user id to see if we have a token already..
                var token = _creds.GetToken(userid);

                if (message.Text == "token")
                {
                    return(message.CreateReplyMessage($"Token is {token}"));
                }

                string prompt = "";
                if (string.IsNullOrEmpty(token))
                {
                    var loginUri = new Uri($"http://*****:*****@"%h")} hrs {sleepSpan.ToString(@"%m")} mins";
                                var totalSleepStr = $"{totalSpan.ToString(@"%d")} days {totalSpan.ToString(@"%h")} hrs {totalSpan.ToString(@"%m")} mins";

                                prompt = $"You have tracked {num} sleeps - average sleep per night {avSleepStr} for a total of {totalSleepStr}";
                            }
                            catch (Exception ex)
                            {
                            }
                        }
                        break;
                    }

                    if (string.IsNullOrEmpty(prompt))
                    {
                        prompt = "Please ask a question to the MS Health Bot";
                    }
                }
                // return our reply to the user
                return(message.CreateReplyMessage(prompt));
            }
            else
            {
                return(HandleSystemMessage(message));
            }
        }