private static async Task <StockLUIS> GetEntityFromLUIS(string Query) { Query = Uri.EscapeDataString(Query); StockLUIS Data = new StockLUIS(); using (HttpClient client = new HttpClient()) { string RequestURI = "https://westus.api.cognitive.microsoft.com/luis/v2.0/apps/8e3c2107-eadc-4731-88a1-961cb250f5fd?subscription-key=e24b3becca7e445ea16cc3ce74d45cb9&timezoneOffset=0&verbose=true&q=" + Query; HttpResponseMessage msg = await client.GetAsync(RequestURI); if (msg.IsSuccessStatusCode) { var JsonDataResponse = await msg.Content.ReadAsStringAsync(); Data = JsonConvert.DeserializeObject <StockLUIS>(JsonDataResponse); } } return(Data); }
/// <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 == "Message") { string StockRateString; StockLUIS StLUIS = await GetEntityFromLUIS(activity.Text); if (StLUIS.intents.Count() > 0) { switch (StLUIS.intents[0].intent) { case "StockPrice": StockRateString = await GetStock(StLUIS.entities[0].entity); break; case "StockPrice2": StockRateString = await GetStock(StLUIS.entities[0].entity); break; default: StockRateString = "Sorry, I am not getting you..."; break; } } else { StockRateString = "Sorry, I am not getting you..."; } HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, StockRateString); // return our reply to the user return(response); } return(null); }