public void ProcessRequest(HttpContext context)
 {
     context.Response.Clear();
     context.Response.ContentType = "text/xml";
     context.Response.ContentEncoding = System.Text.Encoding.UTF8;
     var twiml = new Twilio.TwiML.TwilioResponse();
     twiml.Dial(new Twilio.TwiML.Queue("QueueDemo"));
     context.Response.Write(twiml.ToString());
     context.Response.End();
 }
Exemple #2
0
        protected void Page_Load(object sender, EventArgs e)
        //public void ProcessRequest(HttpContext context)
        {
            string stockticker = "Hey there";

            stockticker = HttpContext.Current.Request.QueryString["Body"];
            if (string.IsNullOrEmpty(stockticker) == true)
            {
                stockticker = "Pizza 91011";
            }
            string[] st           = stockticker.Split(' ');
            string   zip          = "temp";
            int      stringLegnth = st.Length;

            if (stringLegnth > 1)
            {
                zip = st[1];
            }
            string item = st[0];



            string localsearchurl = "https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20local.search%20where%20zip%3D%27" + zip + "%27%20and%20query%3D%27" + item + "%27&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback=";


            Uri            urlCheck = new Uri(localsearchurl);
            HttpWebRequest request  = (HttpWebRequest)WebRequest.Create(urlCheck);

            request.Timeout = 15000;
            HttpWebResponse response;
            bool            result = true;

            try
            {
                response = (HttpWebResponse)request.GetResponse();
            }
            catch (Exception)
            {
                result = false;
            }
            string results = "";

            if (result == true)
            {
                using (WebClient wc = new WebClient())

                {
                    results = wc.DownloadString(localsearchurl.ToString());
                }


                JObject dataObject     = JObject.Parse(results);
                object  arraynull      = (object)dataObject["query"]["results"];
                string  arrayTwoNull   = Convert.ToString(arraynull);
                string  jsonthreearray = "";
                if (string.IsNullOrWhiteSpace(arrayTwoNull))
                {
                    jsonthreearray = "Not valid location/zip";
                }

                else
                {
                    string jsonarray    = (string)dataObject["query"]["results"]["Result"][0]["Title"];
                    string jsontwoarray = (string)dataObject["query"]["results"]["Result"][0]["Address"];
                    jsonthreearray = jsonarray + " " + jsontwoarray;
                }


                Response.ContentType = "text/xml";
                var twiml = new Twilio.TwiML.TwilioResponse();

                twiml.Message(jsonthreearray);
                Response.Write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + twiml.ToString());
            }
            else
            {
                string answer = "Not valid location/zip";
                Response.ContentType = "text/xml";
                var twiml = new Twilio.TwiML.TwilioResponse();

                twiml.Message(answer);
                Response.Write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + twiml.ToString());
            }
        }
Exemple #3
0
        public HttpResponseMessage Get(string target, string name)
        {
            try
            {
                var twiml = new Twilio.TwiML.TwilioResponse();

                var rand = new Random();
                var p    = new { voice = "man", language = "en-GB" };

                switch (rand.Next(3))
                {
                case 0:
                    twiml.Say(String.Format("Hi {0} this is {1}. Sorry to call, it's really embarrassing, but I've been arrested, please could you call me back asap", target, name), p);
                    break;

                case 1:
                    twiml.Say(String.Format("Hi {0} this is {1}. I just needed to call and tell you that I'm your telephone man", target, name), p);
                    twiml.Say("You just show me where you want it and I'll put it where I can", p);
                    twiml.Say("I can put it in the bedroom, I can put it in the hall", p);
                    twiml.Say("I can put it in the bathroom, I can hang it on the wall", p);
                    twiml.Say("You can have it with a buzz, you can have it with a ring", p);
                    twiml.Say("Because-a hey baby, I'm your telephone man", p);
                    break;

                case 2:
                    twiml.Say(String.Format("Hey {0} this is {1}. Just thought I should let you know you are AWESOME", target, name), p);
                    break;

                case 3:
                    twiml.Say(String.Format("Hi {0} this is {1}.", target, name), p);
                    twiml.Say(
                        "I met this guy last night and he came back to mine, he liked the dominatrix sorta stuff. He handcuffed me to my bed and put things in places that I don't even wanna talk about, but lets just say it hurts to poo now... anyway he ended up leaving, and left me handcuffed and I can't reach the keys. Can you please come and help!?", p);
                    break;
                }



                var resp = new HttpResponseMessage(HttpStatusCode.OK)
                {
                    Content = new StringContent("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + twiml.ToString(), Encoding.UTF8, "text/xml")     // Ooh, nasty XML formatting!
                };
                return(resp);
            }
            catch (Exception)
            {
            }

            var r = new HttpResponseMessage(HttpStatusCode.InternalServerError)
            {
                Content = new StringContent("exception", Encoding.UTF8, "text/xml")
            };

            return(r);
        }