public async Task <IActionResult> Post(IntentViewModel intent) { Intent reg = new Intent(); try { using (HttpClient client = new HttpClient()) { client.Timeout = new TimeSpan(0, 0, 0, 0, -1); string endpointLuis = config.GetValue <string>("endpointLuis"); string LuisAppId = config.GetValue <string>("LuisAppId"); string url = $"{endpointLuis}{LuisAppId}/versions/0.1/intents"; string LuisApiKey = config.GetValue <string>("LuisApiKey"); client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", LuisApiKey); IntentViewModel intentViewModel = intent; string objetoSerializado = JsonConvert.SerializeObject(intentViewModel); StringContent contenido = new StringContent(objetoSerializado, Encoding.UTF8, "application/json"); HttpResponseMessage response = await client.PostAsync(url, contenido); if (response.IsSuccessStatusCode) { string result = await response.Content.ReadAsStringAsync(); result = result.Replace("\"", string.Empty); reg = await GetLuisIntent(Guid.Parse(result)); reg.Answer = intent.Answer; _intentService.Insert(reg); } else { return(BadRequest(response)); } } } catch (Exception ex) { return(BadRequest(ex.Message)); } return(Ok(reg)); }
public IntentViewModel PostIntent() { IntentViewModel intent = null; using (var reader = new StreamReader(Request.Body)) { string body = reader.ReadToEnd(); intent = JsonConvert.DeserializeObject <IntentViewModel>(body); } var agent = builder.GetAgentByName(intent.Agent); intent.Id = Guid.NewGuid().ToString(); var domain = agent.Domains.First(x => x.DomainName == intent.Domain); domain.Intents.Add(intent.ToObject <IntentModel>()); builder.SaveAgent(agent); return(intent); }
public IntentViewModel PutIntent([FromRoute] string intentId) { IntentViewModel intent = null; using (var reader = new StreamReader(Request.Body)) { string body = reader.ReadToEnd(); intent = JsonConvert.DeserializeObject <IntentViewModel>(body); } var agent = builder.GetAgentByIntentId(intentId); var updateAgent = agent.Item1; var updateIntents = updateAgent.Domains.First(x => x.Id == agent.Item2.Id).Intents; var updateIntent = updateIntents.First(x => x.Id == agent.Item3.Id); updateIntent.IntentName = intent.IntentName; updateIntent.Examples = intent.Examples; builder.SaveAgent(updateAgent); return(intent); }