Exemplo n.º 1
0
        private async Task interact(IDialogContext context, LuisResult result, string message)
        {
            string intent = "false";

            if (result.Intents.Count > 0)
            {
                intent = result.Intents[0].Intent;
            }

            string product = "None";

            foreach (var entity in result.Entities)
            {
                if (entity.Type == "product")
                {
                    {
                        product = entity.Entity;
                        break;
                    }
                }
            }

            await context.PostAsync(String.Format(message, product));

            lob.Text    = result.Query;
            lob.Intent  = intent;
            lob.Product = product;
            PostToLogicApp(lob);

            // Randomly select one of the two offers. Replace this with the line
            // below after the ML Web service is trained and deployed
            string offer = new Random().Next(2) == 0 ? offer1 : offer2;

            //string offer = await GetOptimalOfferFromMLService(intent, product);

            lob      = lob.Clone();
            lob.Text = offer;

            PromptDialog.Confirm(context, AfterConfirming_interaction, lob.Text, promptStyle: PromptStyle.None);
        }
Exemplo n.º 2
0
        private void PostToLogicApp(MsgObj data)
        {
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(logicAppURL);

            request.ContentType = "application/json";
            request.Method      = "POST";

            using (var streamWriter = new StreamWriter(request.GetRequestStream()))
            {
                string json = Newtonsoft.Json.JsonConvert.SerializeObject(data);

                streamWriter.Write(json);
                streamWriter.Flush();
                streamWriter.Close();
            }

            HttpWebResponse response = (HttpWebResponse)request.GetResponse();

            if (response.StatusCode == HttpStatusCode.OK)
            {
                //do something
            }
        }