private static async Task <BookLUIS> GetEntityFromLUIS(string query) { query = Uri.EscapeDataString(query); BookLUIS _data = new BookLUIS(); using (HttpClient client = new HttpClient()) { string requestURI = $"<<your LUIS api key>>"; HttpResponseMessage msg = await client.GetAsync(requestURI); if (msg.IsSuccessStatusCode) { var JsonDataResponse = await msg.Content.ReadAsStringAsync(); _data = JsonConvert.DeserializeObject <BookLUIS>(JsonDataResponse); } } return(_data); }
private async Task MessageReceivedAsync(IDialogContext context, IAwaitable <IMessageActivity> result) { var message = await result; string _bookingExample; BookLUIS _bookLUIS = await GetEntityFromLUIS(message.Text); if (_bookLUIS.intents.Count() > 0) { switch (_bookLUIS.intents[0].intent) { case "Saludo": await context.PostAsync("Hola!, ¿cuál es tu nombre?"); break; case "nombres": var _entities = _bookLUIS.entities.Where(x => x.type == "detalle_nombre"); if (_entities.Count() > 0) { var _userName = _entities.First().entity; _userName = char.ToUpper(_userName[0]) + _userName.Substring(1); //Save the user name context.UserData.SetValue("UserName", _userName); await context.PostAsync($"Hola {_userName}, ¿Desde y hacia dónde quieres viajar?"); } break; case "AgendaViaje": var entityFrom = _bookLUIS.entities.Where(x => x.type == "Location::FromLocation"); var entityTo = _bookLUIS.entities.Where(x => x.type == "Location::ToLocation"); string _message = string.Empty; if (entityFrom.Count() > 0) { context.UserData.SetValue("bookFrom", entityFrom.First().entity); } else { PromptDialog.Text(context, null , "¿Desde y hacia dónde quieres viajar?" , "No logramos entender" ); return; } if (entityTo.Count() > 0) { context.UserData.SetValue("bookTo", entityTo.First().entity); } else { PromptDialog.Text(context, null , "¿Desde y hacia dónde quieres viajar?" , "No logramos entender" ); return; } PromptDialog.Text(context , AfterEmailAskAsync , $"Perfecto { context.UserData.GetValue<string>("UserName")}, enviaremos un mail con la información de las fechas disponibles, regálanos un email" , "" ); break; default: await context.PostAsync("Lo sentimos, no entendemos la petición, ¿Es posible que seas un poco más descriptivo?, gracias!"); break; } } }