public HttpResponseMessage Department(string companyId, string id, string callSid) { var callWaitUrl = _accountSettings.GetSetting("CallWaitUrl"); var queueMessageUrl = _accountSettings.GetSetting("JoiningQueueMessageUrl"); var endPoint = _endpointResolverService.Get(int.Parse(id)); var response = new TwilioResponse(); response.Play(queueMessageUrl); var attributes = new { action = "api/CallStatus/Update?callId=null", method = "POST", waitUrl = callWaitUrl }; response.Enqueue($"Department_{endPoint.EndpointId}", attributes); _callService.UpdateCallBySid(new Call { Sid = callSid, CallStatus = CallStatus.Queued, DateReceived = DateTime.Now, QueueId = int.Parse(id) }); _logger.Debug($"Twiml generated for call {callSid}. {response.Element}"); return Request.CreateResponse(HttpStatusCode.OK, response.Element, new XmlMediaTypeFormatter()); }
public ActionResult Play(string recordingUrl) { var response = new TwilioResponse(); response.Play(recordingUrl); 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); }
// // 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); }
// /Voice/HandleRecord public TwiMLResult HandleRecord(VoiceRequest request) { var response = new TwilioResponse(); response.Say("Listen to your recorded message."); response.Play(request.RecordingUrl); response.Say("Goodbye."); return TwiML(response); }
public TwiMLResult Index(VoiceRequest request) { // Get information about the incoming call, like the city associated // with the phone number (if Twilio can discover it) var city = request.FromCity; var response = new TwilioResponse(); response.Say($"Never gonna give you up {city}", new {voice = "alice"}); response.Play("https://demo.twilio.com/docs/classic.mp3"); return TwiML(response); }
internal void SayOrPlay(TwilioResponse response, string message) { if (isImplementedAsMP3) { response.Play(message); } else { response.Say(message, new { language = culture }); } }
// /Voice public TwiMLResult Index(VoiceRequest request) { var response = new TwilioResponse(); response.Say("Hello. It's me.", new {voice = "alice", language = "en-GB"}); response.Play("http://howtodocs.s3.amazonaws.com/ahoyhoy.mp3"); response.BeginGather(new {numDigits = "1", action = "/Voice/HandleGather"}); response.Say("To speak to a real person, press 1.\n" + "Press 2 to record a message for a Twilio educator.\n" + "Press any other key to start over."); response.EndGather(); return TwiML(response); }
public ActionResult WaitInQueue(string CurrentQueueSize, string QueuePosition) { var response = new TwilioResponse(); var context = GlobalHost.ConnectionManager.GetHubContext<Hubs.QueueHub>(); context.Clients.All.reportQueueSize(CurrentQueueSize); response.Say(string.Format("You are number {0} in the queue. Please hold.", QueuePosition)); response.Play("http://demo.brooklynhacker.com/music/ramones.mp3"); return TwiML(response); }
public TwilioResponse Inbound() { var response = new TwilioResponse(); if (settings.WorkingHours != null && settings.WorkingHours.Enabled) { if (!(settings.WorkingHours.From <= DateTime.UtcNow.TimeOfDay && settings.WorkingHours.To >= DateTime.UtcNow.TimeOfDay)) { return AddVoiceMail(response); } } if (settings.AvailableOperators.Any()) { if (!string.IsNullOrEmpty(settings.GreetingAudio)) { response.Play(settings.GreetingAudio); } response.Enqueue(settings.Queue.Name, new { method = "GET", action = GetEcho("enqueue"), waitUrl = GetEcho("wait"), waitUrlMethod = "GET" }); } return AddVoiceMail(response); }
public TwilioResponse ListenToPublicBroadcasts(VoiceRequest request, int profileId, int idx) { var response = new TwilioResponse(); PublicBroadcast broadcast; try { broadcast = broadcastManager.GetAll().Skip(idx).Take(1).FirstOrDefault(); } catch (Exception) { broadcast = null; } if (broadcast == null) { response.Say("No more broadcasts found, returning to the main menu"); response.Redirect(ivrRouteProvider.GetUrlMethod(IVRRoutes.PLAY_MAIN_MENU)); return response; } var fromProfile = profileManager.GetProfile(broadcast.FromProfileId); response.Say(string.Format("Playing broadcast from {0}", fromProfile.FullName)); response.Play(broadcast.Url); response.BeginGather(new { action = ivrRouteProvider.GetUrlMethod(IVRRoutes.BROADCAST_RESPONSE_SELECTION, profileId, idx), playBeep = true, numDigits = 1 }); response.Say("Press one to reply privately to this broadcast."); response.Say("Press two to reply publicly to this broadcast."); response.Say("Press three to listen to the next broadcast."); if (broadcast.BroadcastReplies.Count > 0) { response.Say("Press four to listen to responses to this broadcast"); } response.EndGather(); return response; }
// // GET: /Twilio/ public ActionResult Index() { var response = new TwilioResponse(); response.Play("http://cloud.faithcomesbyhearing.com/mp3audiobibles2/ENGESVO2DA/A19__090_Psalms______ENGESVO2DA.mp3"); return new TwiMLResult(response); }
private TwilioResponse AddVoiceMail(TwilioResponse response) { return settings.VoiceMail == null || !settings.VoiceMail.Enabled ? response : response.Play(settings.VoiceMail.Url).Record(new { method = "GET", action = GetEcho("voiceMail"), maxLength = settings.VoiceMail.TimeOut }); }
public TwilioResponse PlayRecordedVoiceMessage(VoiceRequest request, int profileId, int? recordingIdx) { var response = new TwilioResponse(); var voiceMessages = profileManager.GetRecordings(profileId); if (voiceMessages == null || voiceMessages.Count == 0) { response.Say("You have no voice messages"); response.Redirect(routeProvider.GetUrlMethod(IVRRoutes.PLAY_MAIN_MENU)); return response; } if (recordingIdx.HasValue && recordingIdx.Value >= voiceMessages.Count) { response.Say("No more messages."); response.Redirect(routeProvider.GetUrlMethod(IVRRoutes.PLAY_MAIN_MENU)); return response; } Recording voiceMessage; if (recordingIdx.HasValue) { voiceMessage = voiceMessages[recordingIdx.Value]; } else { recordingIdx = 0; voiceMessage = voiceMessages[recordingIdx.Value]; } try { var profile = profileManager.GetProfile(voiceMessage.FromProfileId); response.Say(string.Format("Playing message {0} from {1}", recordingIdx + 1, profile.FullName)); } catch (Exception) { response.Say(string.Format("Playing message {0}", recordingIdx + 1)); } response.Play(voiceMessage.Url); response.BeginGather(new { numDigits = 1, action = string.Format("/IVRMain/PlayRecordedMessage_Response?profileId={0}&recordingIdx={1}&fromProfileId={2}", profileId, recordingIdx.Value, voiceMessage.FromProfileId) }); response.Say("Press one to repeat this message"); response.Say("Press two to delete this message"); response.Say("Press three to reply to this message"); response.Say("Press four to go to the next message"); response.EndGather(); return response; }
public TwiMLResult ConsultantAfterCallResponse(CallContextModel model, string digits) { var response = new TwilioResponse(); var message = ConferenceConst.AcctionCompleted; var specialist = new UserDto(); var call = new CallDto(); bool canWaiveFee = true; int transcriptSuccess = 2; try { if (digits.Equals("2") || digits.Equals("3") || digits.Equals("4") || digits.Equals("5")) { call = Services.Call.GetByCallSid(Request["CallSid"]); if (string.IsNullOrWhiteSpace(model.RecordUrl)) { model.RecordSid = call.RecordSid; model.RecordDuration = call.RecordDuration; model.RecordUrl = call.RecordUrl; } // Get specialist if (model.IsCustomer) // Caller is customer { specialist = Services.Users.GetUserById(model.ReceiverId); } else { specialist = Services.Users.GetUserById(model.CallerId); } int startingTime = Convert.ToInt32(Services.SystemConfig.GetByKey(ParamatricBusinessRules.STARTING_TIME.ToString()).Value); if (call.Duration <= startingTime) { canWaiveFee = false; } } switch (digits) { case "1": // Dictate your follow up action var statusCallBack = Utilities.FormatLink(Url.Action("VoiceMail", "Conference", model)); Services.Call.RedirectToVoiceMail(Request["CallSid"], statusCallBack); break; case "2": // Transcript consultation // Send transcription request transcriptSuccess = SendTranscriptionRequest(specialist.Id.ToString(), specialist.UserName, specialist.Email, call.RecordUrl, call.RecordDuration, call.Booking); if (transcriptSuccess == 0) { message = ConferenceConst.BalanceNotEnoughForTranscript; } else if (transcriptSuccess == 1) { message = ConferenceConst.TranscriptError; } break; case "3": // Play consultation record response.Pause(5); response.Play(model.RecordUrl); break; case "4": // Play consultation record and transcription // Play consultation record response.Pause(5); response.Play(model.RecordUrl); // Send transcription request transcriptSuccess = SendTranscriptionRequest(specialist.Id.ToString(), specialist.UserName, specialist.Email, call.RecordUrl, call.RecordDuration, call.Booking); if (transcriptSuccess == 0) { message = ConferenceConst.BalanceNotEnoughForTranscript; } else if (transcriptSuccess == 1) { message = ConferenceConst.TranscriptError; } break; case "5": // Waive consultation fee if (canWaiveFee) { response.Redirect(Url.Action("WaiveFeeAction", model)); } else { response.Redirect(Url.Action("ConsultantAfterCall", model)); } break; default: response.Redirect(Url.Action("ConsultantAfterCall", model)); return new TwiMLResult(response); } } catch (Exception e) { // Log Log.Error("Consultant after call response. Error: ", e); // Error response.Say(ConferenceConst.ErrorMessage, new { voice = VoiceInConference, language = LanguageInConference }); response.Hangup(); } response.Say(message, new { voice = VoiceInConference, language = LanguageInConference }); response.Redirect(Url.Action("ConsultantAfterCall", model)); return new TwiMLResult(response); }
public HttpResponseMessage QueueWait() { var holdMusic = _accountSettings.GetSetting("HoldMusicUrl"); var response = new TwilioResponse(); response.Play(holdMusic); return Request.CreateResponse(HttpStatusCode.OK, response.Element, new XmlMediaTypeFormatter()); }
public ActionResult Lookup(string callsid, string pid) { var packageService = new PackageService(); Task<Package>.Factory.StartNew( p => packageService.LocatePackage(pid), new Dictionary<string, string>() { { "CallSid", callsid }, { "FoundRedirectUrl", Url.Action("Complete", null, null, Request.Url.Scheme) }, { "NotFoundRedirectUrl", Url.Action("NotFound", null, null, Request.Url.Scheme) }, { "ErrorRedirectUrl", Url.Action("Error", null, null, Request.Url.Scheme) } }, CancellationToken.None ).ContinueWith(t => { Dictionary<string, string> state = (Dictionary<string, string>)t.AsyncState; if (t.IsCanceled || t.IsFaulted) { RedirectCall(state["CallSid"], state["ErrorRedirectUrl"]); } if (t.Result == null) { RedirectCall(state["CallSid"], state["NotFoundRedirectUrl"]); } else { string url = string.Format("{0}?s={1}", state["FoundRedirectUrl"], t.Result.Status); RedirectCall(state["CallSid"], url); } return; } ); var response = new TwilioResponse(); response.Play( Url.AbsoluteContent("~/Content/Audio/clocktickfast.mp3", Request.Url.AbsoluteUri), new { loop = "true" }); return TwiML(response); }
public TwilioResponse ListenToBroadcastReplies(VoiceRequest request, int profileId, int lastBroadcastIdx, int subBroadcastIdx) { var response = new TwilioResponse(); PublicBroadcast broadcast; try { broadcast = broadcastManager.GetAll().Skip(lastBroadcastIdx).Take(1).FirstOrDefault(); } catch (Exception) { broadcast = null; } if (broadcast == null) { response.Say("Broadcast not found, returning to the main menu"); response.Redirect(ivrRouteProvider.GetUrlMethod(IVRRoutes.PLAY_MAIN_MENU)); return response; } if (broadcast.BroadcastReplies == null || broadcast.BroadcastReplies.Count == 0) { response.Say("Broadcast has no replies, returning to the main menu"); response.Redirect(ivrRouteProvider.GetUrlMethod(IVRRoutes.PLAY_MAIN_MENU)); return response; } var reply = broadcast.BroadcastReplies.Skip(subBroadcastIdx).Take(1).FirstOrDefault(); if (reply == null) { response.Say("No more replies, returning to the main menu"); response.Redirect(ivrRouteProvider.GetUrlMethod(IVRRoutes.PLAY_MAIN_MENU)); return response; } var fromProfile = profileManager.GetProfile(reply.FromProfileId); response.Say(string.Format("Playing broadcast reply from {0}", fromProfile.FullName)); response.Play(reply.Url); if (broadcast.BroadcastReplies.Count - subBroadcastIdx <= 0) { response.Say("That was the last reply to this broadcast."); } response.BeginGather(new { action = ivrRouteProvider.GetUrlMethod(IVRRoutes.BROADCAST_REPLY_RESPONSE_SELECTION, profileId, lastBroadcastIdx, subBroadcastIdx), playBeep = true, numDigits = 1 }); response.Say("Press one to reply privately to this broadcast."); response.Say("Press two to reply publicly to this broadcast."); if (broadcast.BroadcastReplies.Count - subBroadcastIdx > 0) { response.Say("Press three to listen to the next broadcast reply"); } response.Say("Press four to listen to the next public broadcast"); response.Say("Press five to add person as a favourite"); response.EndGather(); return response; }
public HttpResponseMessage Message(string companyId, string departmentId, string messageId, string callSid) { var message = _directoryService.GetMessageById(int.Parse(messageId)); string media; var response = new TwilioResponse(); switch (message.MessageType) { case MessageType.Gumtree: media = ConfigurationManager.AppSettings.Get("GumtreeMessageUrl"); response.Play(media); break; case MessageType.Zoopla: media = ConfigurationManager.AppSettings.Get("ZooplaMessageUrl"); var silence = ConfigurationManager.AppSettings.Get("SilenceUrl"); //silence needed as zoopla IVR will cut off the first 2 seconds of the message file without it response.Play(silence); response.Play(media); response.Dial("+441202638560"); break; } _callService.UpdateCallBySid(new Call { Sid = callSid, CallStatus = CallStatus.MessageDelivered, DateReceived = DateTime.Now, QueueId = int.Parse(messageId) }); _logger.Debug($"Twiml generated for call {callSid}. {response.Element}"); return Request.CreateResponse(HttpStatusCode.OK, response.Element, new XmlMediaTypeFormatter()); }