/// <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); }
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=1c85d9de-7c8d-4ceb-ba11-860f02ce911b&subscription-key=fe48030063c6458587138c4dcd258737&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 <Message> Post([FromBody] Message message) { if (message.Type == "Messagess") { string StockRateString; HidenFunction(); StockLUIS StLUIS = await GetEntityFromLUIS(message.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 return(message.CreateReplyMessage(StockRateString)); } else { return(HandleSystemMessage(message)); } }