Пример #1
0
        public definitionsSay buscarColleccionesTest([FromForm] string Memory)
        {
            //var jsonObject = new JObject();
            //dynamic d = JObject.Parse(Memory);
            //string filter = d.twilio.collected_data.collect_buscar_producto.answers.producto_busqueda.answer;

            sCollection collections;

            var client = new RestClient("https://ezelab.myshopify.com/admin/api/2020-10/smart_collections.json?fields=id,title,handle");

            client.Timeout = -1;
            var request = new RestRequest(Method.GET);

            request.AddHeader("Authorization", "Basic Y2Y5Yjc1MjQ5YjkzMDhiODdkOGIyNmI4OGM2NzEzYTA6c2hwcGFfMDkxMWNkODBhMzYzMmQ5MzEyODE5MTM5ZDJiYTkzOWY=");
            request.AddHeader("Cookie", "_master_udr=eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaEpJaWszTUdFMFpUSTBaQzFrT1RZeExUUTFaV0V0WVRjNFppMWtOMkV6TnpFd1lqQm1OMllHT2daRlJnPT0iLCJleHAiOiIyMDIyLTA3LTAzVDIwOjEyOjQyLjA1N1oiLCJwdXIiOiJjb29raWUuX21hc3Rlcl91ZHIifX0%3D--1e7946d971f744818706ad361f949d1fb9718c68; _secure_admin_session_id_csrf=86009cb6da5c57a5eac86a9ea2dc0447; _secure_admin_session_id=86009cb6da5c57a5eac86a9ea2dc0447; __cfduid=d3fa2dbec9914f470e845022dbb39e1d71593806347; _orig_referrer=https%3A%2F%2Fcf9b75249b9308b87d8b26b88c6713a0%3A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%40ezelab.myshopify.com%2Fadmin%2Fapi%2F2020-07%2Fproducts.json%26fields%3Dchivas; _shopify_y=88933032-3e5f-4ae7-8cd5-e2a4b8020e51; _y=88933032-3e5f-4ae7-8cd5-e2a4b8020e51; _landing_page=%2Fadmin%2Fauth%2Flogin");
            IRestResponse response = client.Execute(request);

            collections = JsonConvert.DeserializeObject <sCollection>(response.Content);

            definitionsSay twilio  = new definitionsSay();
            List <Action>  actions = new List <Action>();

            List <SmartCollection> list = collections.smart_collections;

            if (list.Count > 0)
            {
                ActionQuestion question = new ActionQuestion();
                Collect        c        = new Collect();
                c.name = "collect_listarproducto";
                List <Question> qs = new List <Question>();
                Question        q  = new Question();
                q.name     = "nombre_coleccion";
                q.question = "Genial, que es lo que mas te interesa de todo esto?";

                foreach (SmartCollection sm in list)
                {
                    q.question += "\n - *" + sm.title + "*";
                }
                q.question += "\n - *Ver todos los productos*";
                q.type      = "";
                qs.Add(q);
                c.questions = qs;
                OnComplete o = new OnComplete();
                Redirect   r = new Redirect();
                r.method      = "POST";
                r.uri         = "https://a2klab.azurewebsites.net/api/Shopify/obtenerColleccion";
                o.redirect    = r;
                c.on_complete = o;

                question.collect = c;
                actions.Add(question);
            }
            else
            {
                Actionshow a = new Actionshow();
                Show       s = new Show();
                s.body = "No encontré nada para ofrecerte";
                a.show = s;
                actions.Add(a);
                ActionSay say = new ActionSay();
                say.say = "En que mas te puedo ayudar?";
                actions.Add(say);
            }

            twilio.actions = actions;
            return(twilio);
        }
Пример #2
0
        public definitionsSay flight([FromForm] string Memory)
        {
            var     jsonObject     = new JObject();
            dynamic d              = JObject.Parse(Memory.Replace("messaging.whatsapp", "messaging_whatsapp"));
            string  phone          = d.twilio.messaging_whatsapp.From;
            string  filter         = d.twilio.collected_data.collect_estado_vuelo.answers.vuelo_busqueda.answer;
            string  filterOriginal = filter.ToUpper();

            var client = new RestClient("https://api.aa2000.com.ar/api/Vuelos?idarpt=EZE");

            client.Timeout = -1;
            var request = new RestRequest(Method.GET);

            request.AddHeader("key", globalK.Replace("pelufo/", ""));
            IRestResponse response = client.Execute(request);
            List <Flight> vuelos   = JsonConvert.DeserializeObject <List <Flight> >(response.Content);

            filter = Tokenize(filter); // Tokenizo el texto

            // Replica filtro y busco en la list original
            List <Flight> list = vuelos;

            definitionsSay twilio  = new definitionsSay();
            List <Action>  actions = new List <Action>();

            if (!filter.Trim().Equals("") && (vuelos.Count > 0))
            {
                // Se fija si alguna aerolínea coincide
                list = vuelos.Where(x => x.aerolinea.ToUpper().Replace(" ", "").Replace("S", "").Contains(filter.ToUpper().Replace(" ", "").Replace("S", ""))).ToList();
                // Si no es una aerolínea busco por el destino u origen
                list = (list.Count == 0)? vuelos.Where(x => x.destorig.ToUpper().Replace(" ", "").Contains(filter.ToUpper().Replace(" ", ""))).ToList() : list;
                // Si no encontré nada busco por el numero de vuelo
                list = (list.Count == 0)? vuelos.Where(x => (x.idaerolinea.ToUpper() + x.nro.ToUpper()).Replace("-", "").Replace(" ", "").Contains(filter.ToUpper().Replace("-", "").Replace(" ", ""))).ToList() : list;

                if (filterOriginal.Contains("HORA")) // esta preguntando por una hora?
                {
                    list = (list.Count == 0)? vuelos.Where(x => x.stda.ToUpper().Replace(":", "").Contains(filter.ToUpper().Replace(":", ""))).ToList() : list;
                }

                if (list.Count > 1) // Si es mas de uno retorno la lista de opciones pero no lo dejo registrarse
                {
                    foreach (Flight p in list)
                    {
                        Actionshow a = new Actionshow();
                        Show       s = new Show();
                        s.body = ((p.mov.Equals("D"))? "*Partida*" : "*Arribo*") + " de la aerolínea *" + p.aerolinea + "*"
                                 + "\n - Nro vuelo: " + p.nro
                                 + "\n - " + ((p.mov.Equals("D"))? "Con destino: " : "Desde origen: ") + p.destorig
                                 + "\n - Hora estimada " + ((p.mov.Equals("D"))? "de partida: ": "de arribo: ") + ((p.term == null) ? "sin estima" : p.term)
                                 + "\n - Hora programada: " + p.stda
                                 + "\n - " + ((p.mov.Equals("D"))? "Checkin Nro: 0" + p.chk_from + " al 0" + p.chk_to : "Puerta: " + ((p.gate.Equals("") ? "no asignada" : p.gate)))
                                 + "\n - Terminal: " + ((p.term == null) ? "no asignada" : p.term)
                                 + "\n - Estado: *" + ((p.estes.Equals("")) ? "sin estado" : p.estes) + "*";
                        s.images = new List <a2klab.Controllers.Image>();
                        a2klab.Controllers.Image image = new a2klab.Controllers.Image();
                        image.label = "logo aerolinea";
                        image.url   = "http://a2klab.azurewebsites.net/img/" + p.idaerolinea + "_200.jpg";
                        s.images.Add(image);
                        a.show = s;
                        actions.Add(a);
                    }

                    ActionSay say = new ActionSay();
                    say.say = "Esto es lo que he encontrado... Si buscas nuevamente, pero mas especifico puedo avisarte los cambios de estado.";
                    actions.Add(say);
                }
                else if (list.Count == 1) // Si es una opción lo dejo registrarse
                {
                    foreach (Flight p in list)
                    {
                        Actionshow a = new Actionshow();
                        Show       s = new Show();
                        s.body = ((p.mov.Equals("D"))? "*Partida*" : "*Arribo*") + " de la aerolínea *" + p.aerolinea + "*"
                                 + "\n - Nro vuelo: " + p.nro
                                 + "\n - " + ((p.mov.Equals("D"))? "Con destino: " : "Desde origen: ") + p.destorig
                                 + "\n - Hora estimada " + ((p.mov.Equals("D"))? "de partida: ": "de arribo: ") + ((p.term == null) ? "sin estima" : p.term)
                                 + "\n - Hora programada: " + p.stda
                                 + "\n - " + ((p.mov.Equals("D"))? "Checkin Nro: 0" + p.chk_from + " al 0" + p.chk_to : "Puerta: " + ((p.gate.Equals("") ? "no asignada" : p.gate)))
                                 + "\n - Terminal: " + ((p.term == null) ? "no asignada" : p.term)
                                 + "\n - Estado: *" + ((p.estes.Equals("")) ? "sin estado" : p.estes) + "*";
                        s.images = new List <a2klab.Controllers.Image>();
                        a2klab.Controllers.Image image = new a2klab.Controllers.Image();
                        image.label = "logo aerolinea";
                        image.url   = "http://a2klab.azurewebsites.net/img/" + p.idaerolinea + "_200.jpg";
                        s.images.Add(image);
                        a.show = s;
                        actions.Add(a);

                        Data dto = new Data();
                        dto.phone    = phone;
                        dto.flightId = p.id;
                        dto.flight   = p.nro;
                        setData(dto); // Guardo lo que busco

                        ActionQuestion question = new ActionQuestion();
                        Collect        c        = new Collect();
                        c.name = "collect_notificarvuelo";
                        List <Question> qs = new List <Question>();
                        Question        q  = new Question();
                        q.name     = "notificar_sino";
                        q.question = "Quieres que te avise de los cambios de estado de este vuelo?";
                        q.type     = "Custom.SI_NO";
                        qs.Add(q);
                        c.questions = qs;
                        OnComplete o = new OnComplete();
                        Redirect   r = new Redirect();
                        r.method = "POST";
                        //r.uri = "https://a2klab.azurewebsites.net/api/bot/Test";
                        r.uri         = "https://a2klab.azurewebsites.net/api/Flight/suscribe";
                        o.redirect    = r;
                        c.on_complete = o;

                        question.collect = c;
                        actions.Add(question);
                    }
                }
                else // Sino lo mando a freír churros
                {
                    ActionSay say = new ActionSay();
                    say.say = "No pude encontrar nada relacionado con " + filter + ", si queres volver a intentarlo indicame *busca vuelo* nuevamente.";
                    actions.Add(say);
                }
            }
            else
            {
                ActionSay say = new ActionSay();
                say.say = "Aparentemente hay un problema buscando eso (" + filter + "). Si quieres buscar algo mas estare aca...";
                actions.Add(say);
            }

            twilio.actions = actions;
            return(twilio);
        }