Example #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 (activity.Type == ActivityTypes.Message)
            {
                ConnectorClient connector = new ConnectorClient(new Uri(activity.ServiceUrl));
                // calculate something for us to return
                string    Answer;
                StockLUIS StLUIS = await GetEntityFromLUIS(activity.Text);

                if (StLUIS.intents.Count() > 0)
                {
                    switch (StLUIS.intents[0].intent)
                    {
                    case "getstock":
                        Answer = await GetStock(StLUIS.entities[0].entity);

                        break;

                    case "getgraph":
                        Answer = @"feature will be added soon";
                        break;

                    case "getprediction":
                        Answer = await GetPrediction(StLUIS.entities);

                        break;

                    case "highlow":
                        Answer = @"cant say right now..feature will be added soon";
                        break;

                    default:
                        Answer = @"Sorry, I am not getting you...";
                        break;
                    }
                }
                else
                {
                    Answer = "Sorry, I am not getting you...";
                }



                // return our reply to the user
                Activity reply = activity.CreateReply(Answer);
                await connector.Conversations.ReplyToActivityAsync(reply);
            }
            else
            {
                ConnectorClient connector = new ConnectorClient(new Uri(activity.ServiceUrl));
                Activity        reply     = HandleSystemMessage(activity);
                await connector.Conversations.ReplyToActivityAsync(reply);
            }
            var response = Request.CreateResponse(HttpStatusCode.OK);

            return(response);
        }
Example #2
0
        private static async Task <StockLUIS> GetEntityFromLUIS(string Query)
        {
            Query = Uri.EscapeDataString(Query);
            StockLUIS Data = new StockLUIS();

            using (HttpClient client = new HttpClient())
            {
                string RequestURI       = "https://api.projectoxford.ai/luis/v1/application?id=3afa3cd9-a634-40b9-a3fa-1c0d09d9195f&subscription-key=afdf376548c1426b830453f5c0a66c7e&q=" + Query;
                HttpResponseMessage msg = await client.GetAsync(RequestURI);

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

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