/// <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)); 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..."; } // return our reply to the user Activity reply = activity.CreateReply(StockRateString); await connector.Conversations.ReplyToActivityAsync(reply); } else { HandleSystemMessage(activity); } var response = Request.CreateResponse(HttpStatusCode.OK); return(response); }
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=7f626790-38d6-4143-9d46-fe85c56a9016&subscription-key=09f80de609fa4698ab4fe5249321d165&q=" + Query; HttpResponseMessage msg = await client.GetAsync(RequestURI); if (msg.IsSuccessStatusCode) { var JsonDataResponse = await msg.Content.ReadAsStringAsync(); Data = JsonConvert.DeserializeObject <StockLUIS>(JsonDataResponse); } } return(Data); }