// // GET: /TwilioApp/ public ActionResult Receive() { var twiml = new Twilio.TwiML.TwilioResponse(); twiml.Say("Hello Monkey!"); return new TwiMLResult(twiml); }
protected void Page_Load( object sender, EventArgs e ) { Twilio.TwiML.TwilioResponse twml = new Twilio.TwiML.TwilioResponse(); string digits = Request[ "Digits" ]; if( string.IsNullOrEmpty( digits ) ) { twml.Say( "Sorry, we did not recieve the numbers you entered. " ); } else { string[] split = digits.Trim().Split( '*' ); foreach( var digitGroup in split ) { List<string> symbols = SymbolsToKeyPadNumbers.Map( digitGroup ); if( symbols == null || symbols.Count == 0 ) { twml.Say( "Sorry, no symbols found using the digits " + digitGroup + ". " ); } else { RemoteBatsLastSale.XigniteBATSLastSale bats = new RemoteBatsLastSale.XigniteBATSLastSale(); bats.HeaderValue = new RemoteBatsLastSale.Header(); bats.HeaderValue.Username = Shared.XigniteAuthenticationToken; string s = StringJoiner<string>.Join( symbols, "," ); try { StringBuilder sb = new StringBuilder(); RemoteBatsLastSale.LastSaleQuote[] quotes = bats.GetLastSales( s.ToUpper() ); for( int i = 0; i < quotes.Length; i++ ) { if( quotes[ i ].Outcome == RemoteBatsLastSale.OutcomeTypes.Success ) { sb.AppendFormat( "The latest price for {0} as of {2} is {1}. ", quotes[ i ].CompanyName, quotes[ i ].Last, quotes[ i ].Time ); } } twml.Say( sb.ToString(), new { voice = "woman" } ); } catch( Exception ex ) { twml.Say( "Sorry, couldn't fetch any quotes for " + digitGroup + ". " ); } } } } twml.Redirect( "PhoneCallMenu.xml", "GET" ); var doc = twml.ToXDocument(); Response.ContentType = "application/xml"; doc.Save( Response.Output ); }
protected void Page_Load( object sender, EventArgs e ) { string from = Request[ "From" ]; string to = Request[ "To" ]; string body = Request[ "Body" ]; string[] symbols = null; if( string.IsNullOrEmpty( body ) == false ) { body = body.Trim(); if( string.IsNullOrEmpty( body ) == false ) { symbols = body.Split( new string[] { ",", ";" }, StringSplitOptions.RemoveEmptyEntries ); } } Twilio.TwiML.TwilioResponse twml = new Twilio.TwiML.TwilioResponse(); if( symbols == null || symbols.Length == 0 ) { twml.Sms( "No Symbols Found" ); } else { RemoteBatsLastSale.XigniteBATSLastSale bats = new RemoteBatsLastSale.XigniteBATSLastSale(); bats.HeaderValue = new RemoteBatsLastSale.Header(); bats.HeaderValue.Username = Shared.XigniteAuthenticationToken; string s = StringJoiner<string>.Join( symbols, "," ); try { StringBuilder sb = new StringBuilder(); RemoteBatsLastSale.LastSaleQuote[] quotes = bats.GetLastSales( s.ToUpper() ); for( int i = 0; i < quotes.Length; i++ ) { if( quotes[ i ].Outcome == RemoteBatsLastSale.OutcomeTypes.Success ) { sb.AppendFormat( "{0}: {1} @ {2}\r\n", quotes[ i ].Symbol, quotes[ i ].Last, quotes[ i ].Time ); } } twml.Sms( sb.ToString() ); } catch( Exception ) { twml.Sms( "Sorry, couldn't fetch any quotes." ); } } var doc = twml.ToXDocument(); Response.ContentType = "application/xml"; doc.Save( Response.Output ); }
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(); }
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); }
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()); } }