public void Can_Generate_Enqueue_With_Only_Options() { var response = new TwilioResponse(); response.Enqueue(new { action = "example.xml", method = "GET", waitUrl = "wait.xml", waitUrlMethod = "GET"}); Assert.IsTrue(IsValidTwiML(response.ToXDocument())); }
public ActionResult Play(string recordingUrl) { var response = new TwilioResponse(); response.Play(recordingUrl); return TwiML(response); }
// GET: api/TestTwiml public HttpResponseMessage Get(TwilioRequest req) { TwilioResponse res = new TwilioResponse(); res.Message("Hello There", new {voice = "alice"}); return Request.CreateResponse(HttpStatusCode.OK, res.Element); }
public TwiMLResult HandleSms(string Sid, string From, string To, string Body, string Status) { _db.Log.Insert(Text: String.Format("From: {0}, To: {1}, Body: {2}", From, To, Body)); var response = new TwilioResponse(); response.Say("Received"); return TwiML(response); }
public TwiMLResult Index(VoiceRequest request) { var response = new TwilioResponse(); object conferenceOptions; // If the caller is our MODERATOR, then start the conference when they // join and end the conference when they leave if (request.From == Moderator) { conferenceOptions = new { startConferenceOnEnter = true, endConferenceOnExit = true }; } else { // Otherwise have the caller join as a regular participant conferenceOptions = new {startConferenceOnEnter = false}; } response.DialConference("My conference", conferenceOptions); return TwiML(response); }
public TwilioResponse ResponseToSms(SmsRequest request) { var response = new TwilioResponse(); try { string outboundPhoneNumber = request.From; var client = new TwilioRestClient(accountSid, authToken); var call = client.InitiateOutboundCall( twilioPhoneNumber, outboundPhoneNumber, "http://refuniteivr.azurewebsites.net/api/IVREntry"); if (call.RestException == null) { response.Sms("starting call to " + outboundPhoneNumber); } else { response.Sms("failed call to " + outboundPhoneNumber + " " + call.RestException.Message); } return response; } catch (Exception ex) { response.Sms("exception: " + ex.Message); return response; } }
private static TwiMLResult Dial(string phoneNumber) { var response = new TwilioResponse(); response.Dial(phoneNumber); return new TwiMLResult(response); }
public TwilioResponse BroadcastReplyMenuSelection(VoiceRequest request, int profileId, int lastBroadcastIdx, int subBroadcastIdx) { var response = new TwilioResponse(); var selection = request.Digits; switch (selection) { case "1": response.Redirect(ivrRouteProvider.GetUrlMethod(IVRRoutes.BROADCASTS_REPLY_PRIVATELY, profileId, lastBroadcastIdx, subBroadcastIdx)); return response; case "2": response.Redirect(ivrRouteProvider.GetUrlMethod(IVRRoutes.BROADCASTS_REPLY_PUBLICLY, profileId, lastBroadcastIdx, subBroadcastIdx)); return response; case "3": response.Redirect(ivrRouteProvider.GetUrlMethod(IVRRoutes.BROADCASTS_PLAY_PUBLIC_REPLY, profileId, lastBroadcastIdx, ++subBroadcastIdx)); return response; case "4": response.Redirect(ivrRouteProvider.GetUrlMethod(IVRRoutes.BROADCASTS_LISTEN_TO_ALL_PUBLIC, profileId, ++lastBroadcastIdx)); return response; case "5": response.Redirect(ivrRouteProvider.GetUrlMethod(IVRRoutes.BROADCASTS_ADD_REPLIER_AS_FAVOURITE, profileId, lastBroadcastIdx, subBroadcastIdx)); return response; default: response.Redirect(ivrRouteProvider.GetUrlMethod(IVRRoutes.PLAY_MAIN_MENU)); return response; } }
public ActionResult Connect() { var response = new TwilioResponse(); response.Say("Connecting you to an agent"); return TwiML(response); }
//public HttpResponseMessage Get(VoiceRequest request) //{ // try // { // if (request != null) // { // repo.AddMessage(string.Format("unknown,\"{0}\",\"{1}\",starting", request.From, request.To)); // } // else // { // repo.AddMessage("unknown,unknown,unknown,starting"); // } // var response = new TwilioResponse(); // response.Say("G'day and welcome to the twilio monitoring thing...you should see your call appear on the web now..."); // //return response; // return this.Request.CreateResponse(HttpStatusCode.OK, response.Element, new XmlMediaTypeFormatter()); // } // catch (Exception ex) // { // var response = new TwilioResponse(); // response.Say(ex.Message); // response.Say(ex.StackTrace); // return this.Request.CreateResponse(HttpStatusCode.OK, response.Element, new XmlMediaTypeFormatter()); // } //} public HttpResponseMessage Post(VoiceRequest request) { try { if (request != null) { repo.AddMessage(string.Format("unknown,{0},{1},starting", request.From, request.To)); } else { repo.AddMessage("unknown,unknown,unknown,starting"); } var response = new TwilioResponse(); response.Say("G'day and welcome to the twilio monitoring thing...you should see your call appear on the web now..."); response.Pause(5); response.Say("Good bye..."); //return response; return this.Request.CreateResponse(HttpStatusCode.OK, response.Element, new XmlMediaTypeFormatter()); } catch (Exception ex) { var response = new TwilioResponse(); response.Say(ex.Message); response.Say(ex.StackTrace); return this.Request.CreateResponse(HttpStatusCode.OK, response.Element, new XmlMediaTypeFormatter()); } }
public ActionResult Hello() { var response = new TwilioResponse(); response.Say("Hello there! Your Twilio environment has been configured."); response.Say("Good luck during the workshop!", new { Voice = "woman" }); return TwiML(response); }
public TwilioResponseResult(Action<TwilioResponse> buildResponse) { var response = new TwilioResponse(); buildResponse(response); Content = response.Element.ToString(); ContentType = new MediaTypeHeaderValue("text/xml"); }
public ActionResult Index(VoiceRequest request) { var response = new TwilioResponse(); response.Say("Hello! You will get an SMS message soon."); response.Sms("This is the ship that made the Kessel Run in fourteen parsecs?"); return TwiML(response); }
public ActionResult Index(SmsRequest request) { var counter = 0; // get the session varible if it exists if (Session["counter"] != null) { counter = (int) Session["counter"]; } // increment it counter++; // save it Session["counter"] = counter; // make an associative array of senders we know, indexed by phone number var people = new Dictionary<string, string>() { {"+14158675309", "Rey"}, {"+14158675310", "Finn"}, {"+14158675311", "Chewy"} }; // if the sender is known, then greet them by name var name = "Friend"; if (people.ContainsKey(request.From)) { name = people[request.From]; } var response = new TwilioResponse(); response.Message($"{name} has messaged {request.To} {counter} times"); return TwiML(response); }
// /Voice public TwiMLResult Index(VoiceRequest request) { var response = new TwilioResponse(); response.Say("Hello. It's me."); response.Play("http://howtodocs.s3.amazonaws.com/ahoyhoy.mp3"); return TwiML(response); }
/// <summary> /// Action Method that returns the TwiML needed to connect an 'Agent' to the first call in the Queue /// </summary> /// <remarks>This method also includes the 'url' parameter in the generated TwiML. This allows you to provide a URL that can return TwiML that will be executed to the dequeued caller as a Whisper</remarks> /// <returns></returns> public ActionResult Dial() { var response = new TwilioResponse(); response.DialQueue("Demo Queue", new { url = Url.Action("Connect") }, new { }); return TwiML(response); }
public async Task<TwiMLResult> Index(string ServiceKey, string From, string To, string Body, string SmsSid) { var msg = "From: " + From + "\r\n" + Body; var pdEvent = new PagerDutyEvent() { service_key = ServiceKey, event_type = "trigger", description = msg.Substring(0,Math.Min(1024, msg.Length)) }; var tResp = new TwilioResponse(); try { using (var response = await _httpclient.PostAsJsonAsync<PagerDutyEvent>("https://events.pagerduty.com/generic/2010-04-15/create_event.json", pdEvent)) { if (response.IsSuccessStatusCode) { tResp.Sms("PagerDuty incident created."); } else { tResp.Sms("failed to create PagerDuty incident - statusCode " + response.StatusCode.ToString()); } } } catch { tResp.Sms("failed to create PagerDuty incident"); } return new TwiMLResult(tResp); }
// // GET: /Phone/ public ActionResult IncomingCall(string CallSid, string FromCity, string FromState, string FromZip, string FromCountry) { LocationalCall call = (LocationalCall)GetCall(CallSid); StateManager.AddNewCall(call); StateManager.AddToLog(CallSid, "Incoming call..."); call.City = FromCity; call.Country = FromCountry; call.ZipCode = FromZip; call.State = FromState; TwilioResponse response = new TwilioResponse(); response.BeginGather(new { action = Url.Action("ServiceRequest"), timeout = 120, method = "POST", numDigits = 1 }); response.Say("Welcome to the Bank of Griff."); response.Pause(); response.Say("Press 1 to manage your account."); response.Say("Press 2 to take out a loan."); response.Say("Press 3 to talk to a representative."); response.Pause(); response.EndGather(); return SendTwilioResult(response); }
public TwiMLResult CallBackAfterConference(CallContextModel model) { var callSid = Request["CallSid"]; var response = new TwilioResponse(); try { if (model.IsCustomer) { model.ReceiverSid = callSid; } else { model.CallerSid = callSid; } response.Say(ConferenceConst.ThankForConsultantAndFollowupAction, new { voice = VoiceInConference, language = LanguageInConference }); response.Redirect(Url.Action("ConsultantAfterCall", model)); return new TwiMLResult(response); } catch (Exception e) { Log.Error("Call back after conference. Error: ", e); // Error response.Say(ConferenceConst.ErrorMessage, new { voice = VoiceInConference, language = LanguageInConference }); response.Hangup(); } return new TwiMLResult(response); }
public void Can_Generate_Enqueue_With_Options_And_TaskAttributes_And_Priority_And_Timeout() { var response = new TwilioResponse(); response.Enqueue(new { action = "example.xml", method = "GET", waitUrl = "wait.xml", waitUrlMethod = "GET", workflowSid = "WFXXXXX" }, "{'task':'attributes'}", new {priority="10", timeout="30"}); Assert.IsTrue(IsValidTwiML(response.ToXDocument())); }
// // GET: /LookupCompliment/ public ActionResult Index() { WebRequest request = WebRequest.Create("http://www.flatterist.com/compliments.json"); request.Method = "GET"; request.ContentType = "application/json; charset=utf-8"; string jsonData = string.Empty; using (Stream s = request.GetResponse().GetResponseStream()) { using (StreamReader sr = new StreamReader(s)) { jsonData = sr.ReadToEnd(); } } var json = (IDictionary<string, object>)SimpleJson.DeserializeObject(jsonData); var results = (List<object>)json["compliments"]; int randomNumber = new Random().Next(results.Count); dynamic fileNameStuff = results[randomNumber]; dynamic fileName = fileNameStuff[0]; TwilioResponse tr = new TwilioResponse(); tr.Play("http://www.flatterist.com/" + fileName + ".mp3"); return TwiML(tr); }
public void Can_Generate_Enqueue_With_Options_And_TaskAttributes() { var response = new TwilioResponse(); response.Enqueue(new { action = "example.xml", method = "GET", waitUrl = "wait.xml", waitUrlMethod = "GET", workspaceSid = "WSXXXXX" }, "{'task':'attributes'}"); Assert.IsTrue(IsValidTwiML(response.ToXDocument())); }
// // GET: /CallCenter/ public ActionResult Index() { var response = new TwilioResponse(); response.Pause(5); response.Say("Thanks for calling the Music Store"); return TwiML(response); }
public void Can_Generate_Enqueue_With_Name() { var response = new TwilioResponse(); response.Enqueue("example"); Assert.IsTrue(IsValidTwiML(response.ToXDocument())); }
public void Can_Generate_Enqueue_With_Name_And_Options() { var response = new TwilioResponse(); response.Enqueue("example", new { action = "example.xml", method = "GET", waitUrl="wait.xml", waitUrlMethod="GET", workspaceSid="WSXXXXX" }); Assert.IsTrue(IsValidTwiML(response.ToXDocument())); }
public TwilioResponse PingTeamMember(string teamId, string callingPartyId, int idx) { var response = new TwilioResponse(); Contact contact = directory.GetTeamMember(teamId, idx); Team team = directory.GetTeam(teamId); if (contact != null) { if (idx == 0) { response.Say(string.Format("Now attempting to connect you to {0}", team.Name)); } else { response.Say("Trying next team member..."); } response.Say("We are now contacting " + contact.Name + ", please hold the line"); response.Dial(new Number(contact.MobileNumber, new { url = string.Format("/Router/PreConnect?callingPartyId={0}", callingPartyId) }), new { callerId = "+442033229301", timeLimit = 5, action = string.Format("/Router/NextTeamMember?callingPartyId={0}&TeamId={1}&Idx={2}", callingPartyId, teamId, idx) }); } else { response.Say("Couldn't find a team member..."); response.Hangup(); } return response; }
private TwiMLResult RedirectWelcome() { var response = new TwilioResponse(); response.Redirect(Url.Action("Welcome", "IVR")); return TwiML(response); }
public TwiMLResult Gather(VoiceRequest request) { var response = new TwilioResponse(); // If the user entered digits, process their request if (!string.IsNullOrEmpty(request.Digits)) { switch (request.Digits) { case "1": response.Say("You selected sales. Good for you!"); break; case "2": response.Say("You need support. We will help!"); break; default: response.Say("Sorry, I don't understand that choice.").Pause(); response.Redirect("/voice"); break; } } else { // If no input was sent, redirect to the /voice route response.Redirect("/voice"); } return TwiML(response); }
public TwiMLResult Index(VoiceRequest request) { var response = new TwilioResponse(); if (!string.IsNullOrEmpty(request.Digits)) { switch (request.Digits) { case "1": response.Say("You selected sales. Good for you!"); break; case "2": response.Say("You need support. We will help!"); break; default: response.Say("Sorry, I don't understand that choice.").Pause(); RenderMainMenu(response); break; } } else { // If no input was sent, use the <Gather> verb to collect user input RenderMainMenu(response); } return TwiML(response); }
public async Task<ActionResult> Index(string from, string body) { var request = new LightsRequest { Source = "twilio", From = from, Text = body }; var lightsResponse = await _lightsService.HandleRequestAsync(request); var response = new TwilioResponse(); if (_smsSettings.AllowResponses && lightsResponse.IsSuccess) { if (lightsResponse.IsScheduled && lightsResponse.ScheduledForUtc.HasValue) { response.Sms(string.Format("Ooops, you're in a queue! Don't worry, your lights have been scheduled for {0}. Merry Christmas from #157!", lightsResponse.ScheduledForUtc.Value.ToString("HH:mm"))); } else { response.Sms("Thanks! Your lights will be shown shortly. Merry Christmas from #157!"); } } return new TwiMLResult(response); }
public static HttpListenerResponse SendResponse(HttpListenerContext ctx) { HttpListenerRequest request = ctx.Request; HttpListenerResponse response = ctx.Response; response.StatusCode = (int)HttpStatusCode.OK; response.ContentType = "application/xml"; var twiml = new Twilio.TwiML.TwilioResponse(); twiml.Enqueue(new { workflowSid = "WW0123456789abcdef0123456789abcdef" }, "{\"account_number\":\"12345abcdef\"}"); response.StatusDescription = twiml.ToString(); return(response); }
public static HttpListenerResponse SendResponse(HttpListenerContext ctx) { HttpListenerRequest request = ctx.Request; HttpListenerResponse response = ctx.Response; response.StatusCode = (int)HttpStatusCode.OK; response.ContentType = "application/xml"; var twiml = new Twilio.TwiML.TwilioResponse(); var task = new Task("{\"account_number\":\"12345abcdef\"}", new { priority = "5", timeout = "200" }); twiml.EnqueueTask(new { workflowSid = "WW0123456789abcdef0123456789abcdef" }, task); // alternatively twiml.Enqueue(new { workflowSid = "WW0123456789abcdef0123456789abcdef" }, "{\"account_number\":\"12345abcdef\"}", new { priority = "5", timeout = "200" }); response.StatusDescription = twiml.ToString(); return(response); }