Ejemplo n.º 1
0
        public async Task <bool> UpdateUtteranceAsync(string intent, string utterance)
        {
            string jsonRep;
            HttpResponseMessage        resp1, resp2;
            IntentUtterance            utterance2Add;
            Task <HttpResponseMessage> httpResponseMessage;


            debug = "I'm going to send the http requests to LUIS\r\n";

            if (dBAccess.WasSeen(intent, utterance))
            {
                utterance2Add       = new IntentUtterance(intent, utterance);
                jsonRep             = JsonConvert.SerializeObject(utterance2Add);
                httpResponseMessage = HttpSendPostAsync(jsonRep, ESteps.Add);
                resp1 = await httpResponseMessage;
                if (!resp1.IsSuccessStatusCode)
                {
                    throw new Exception("Error...could not add the utterance to LUIS, reason = " + resp1.ReasonPhrase);
                }
                string x = await resp1.Content.ReadAsStringAsync();

                debug += "\r\nFirst Response = " + x + "\r\n";
                httpResponseMessage = HttpSendPostAsync(jsonRep, ESteps.Train);   /* To kick start training process */
                resp2 = await httpResponseMessage;
                x     = await resp2.Content.ReadAsStringAsync();

                debug += "Response from training order\r\n" + x + "\r\n\r\n";

                if (!resp2.IsSuccessStatusCode)
                {
                    throw new Exception("Error...could not train LUIS, reason = " + resp2.ReasonPhrase);
                }

                /*
                 *  We will need to wait
                 *  until LUIS is trained
                 */
                return(true);
            }
            else
            {
                debug += "nothing got sent";
                return(false);
            }
        }