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")
            {
                // calculate something for us to return
                int length = (message.Text ?? string.Empty).Length;


                // return our reply to the user
                //return message.CreateReplyMessage("Hello World !!!");
                string   NewsString;
                NewsLUIS StLUIS = await GetEntityFromLUIS(message.Text);

                if (StLUIS.intents.Count() > 0)
                {
                    switch (StLUIS.intents[0].intent)
                    {
                    case "GetTopNews":
                        NewsString = GetListData(StLUIS.entities[0].entity);
                        break;

                    case "GoToGoogle":
                        NewsString = "Please click on hyperlink to search more https://www.google.com/#q=" + message.Text;
                        //await GetListData(StLUIS.entities[0].entity);
                        break;

                    default:
                        NewsString = "Sorry, I am still process of learning human. Try in other words..";
                        break;
                    }
                }
                else
                {
                    NewsString = "Sorry, I am not getting you...";
                }

                // return our reply to the user
                return(message.CreateReplyMessage(NewsString));
            }
            else
            {
                return(HandleSystemMessage(message));
            }
        }
Ejemplo n.º 2
0
        private static async Task <NewsLUIS> GetEntityFromLUIS(string Query)
        {
            Query = Uri.EscapeDataString(Query);
            NewsLUIS Data = new NewsLUIS();

            using (HttpClient client = new HttpClient())
            {
                string RequestURI       = "https://api.projectoxford.ai/luis/v1/application?id=908f2c82-436a-4ee1-b931-076db449168e&subscription-key=4360ab34eaae45c8b9506a4c75e9e1e7&q=" + Query;
                HttpResponseMessage msg = await client.GetAsync(RequestURI);

                if (msg.IsSuccessStatusCode)
                {
                    var JsonDataResponse = await msg.Content.ReadAsStringAsync();

                    Data = JsonConvert.DeserializeObject <NewsLUIS>(JsonDataResponse);
                }
            }
            return(Data);
        }