IVR: Screening & Recording with Ruby and Rails

Stranded aliens can call an agent and receive instructions on how to get off of Earth safely. In this tutorial, we'll show you the key bits of code that allow an agent to send a caller to voicemail, and later read transcripts and listen to voicemails.

When our alien caller chooses a planet, we need to figure out where to route the call. Depending on their input we will route this call to an extension. Extensions are used to look up an agent. Any string can be used to define an extension.

Once we look up the agent, we can use the <Dial> verb to dial the agent's phone number and try to connect the call.

classTwilioController<ApplicationControllerdefindexrendertext:"Dial Me."end# POST ivr/welcomedefivr_welcomeresponse=Twilio::TwiML::VoiceResponse.newgather=Twilio::TwiML::Gather.new(num_digits:'1',action:menu_path)gather.play(url:"http://howtodocs.s3.amazonaws.com/et-phone.mp3",loop:3)response.append(gather)renderxml:response.to_send# GET ivr/selectiondefmenu_selectionuser_selection=params[:Digits]caseuser_selectionwhen"1"output="To get to your extraction point, get on your bike and go down the street. Then Left down an alley. Avoid the police cars. Turn left into an unfinished housing development. Fly over the roadblock. Go passed the moon. Soon after you will see your mother ship."twiml_say(output,true)when"2"list_planetselseoutput="Returning to the main menu."twiml_say(output)endend# POST/GET ivr/planetsdefplanet_selectionuser_selection=params[:Digits]caseuser_selectionwhen"2"connect_to_extension("Brodo")when"3"connect_to_extension("Dugobah")when"4"connect_to_extension("113")elseoutput="Returning to the main menu."twiml_say(output)endend# POST ivr/screen_calldefscreen_callcustomer_phone_number=params[:From]response=Twilio::TwiML::VoiceResponse.newgather=Twilio::TwiML::Gather.new(num_digits:'1',action:ivr_agent_screen_path)gather.say("You have an incoming call from an Alien with phone number#{customer_phone_number.chars.join(",")}.")gather.say("Press any key to accept.")# will return status no-answer since this is a Number callbackresponse.say("Sorry, I didn't get your response.")response.hangupresponse.append(gather)renderxml:response.to_send# POST ivr/agent_screendefagent_screenagent_selected=params[:Digits]ifagent_selectedresponse=Twilio::TwiML::VoiceResponse.newresponse.say("Connecting you to the E.T. in distress. All calls are recorded.")endrenderxml:response.to_send# POST ivr/agent_voicemaildefagent_voicemailstatus=params[:DialCallStatus]||"completed"recording=params[:RecordingUrl]# If the call to the agent was not successful, or there is no recording,# then record a voicemailif(status!="completed"||recording.nil?)response=Twilio::TwiML::VoiceResponse.newresponse.say("It appears that planet is unavailable. Please leave a message after the beep.",voice:'alice',language:'en-GB')response.record(finish_on_key:"*",transcribe:true,max_length:'20',transcribe_callback:"/recordings/create?agent_id=#{params[:agent_id]}")response.say("I did not receive a recording.",voice:'alice',language:'en-GB')# otherwise end the callelseresponse=Twilio::TwiML::VoiceResponse.newresponse.hangupendrenderxml:response.to_sendprivatedeftwiml_say(phrase,exit=false)# Respond with some TwiML and say something.# Should we hangup or go back to the main menu?response=Twilio::TwiML::VoiceResponse.newresponse.say(phrase,voice:'alice',language:'en-GB')ifexitresponse.say("Thank you for calling the ET Phone Home Service - the adventurous alien's first choice in intergalactic travel.")response.hangupelseresponse.redirect(welcome_path)endrenderxml:response.to_senddeftwiml_dial(phone_number)response=Twilio::TwiML::VoiceResponse.newresponse.dial(phone_number)renderxml:response.to_senddeflist_planetsmessage="To call the planet Broh doe As O G, press 2. To call the planet DuhGo bah, press 3. To call an oober asteroid to your location, press 4. To go back to the main menu, press the star key."response=Twilio::TwiML::VoiceResponse.newgather=Twilio::TwiML::Gather.new(num_digits:'1',action:planets_path)gather.say(message,voice:'alice',language:'en-GB',loop:3)response.append(gather)renderxml:response.to_senddefconnect_to_extension(extension)agent=Agent.find_by(extension:extension)response=Twilio::TwiML::VoiceResponse.newdial=Twilio::TwiML::Dial.new(action:ivr_agent_voicemail_path(agent_id:agent.id))dial.number(agent.phone_number,url:ivr_screen_call_path)response.append(dial)renderxml:response.to_sendend

app/controllers/twilio_controller.rb

Route the call to an agent

app/controllers/twilio_controller.rb

With this information, we present aliens with a list of available agents so they can pick one. Let's see how we look up an agent.

classTwilioController<ApplicationControllerdefindexrendertext:"Dial Me."end# POST ivr/welcomedefivr_welcomeresponse=Twilio::TwiML::VoiceResponse.newgather=Twilio::TwiML::Gather.new(num_digits:'1',action:menu_path)gather.play(url:"http://howtodocs.s3.amazonaws.com/et-phone.mp3",loop:3)response.append(gather)renderxml:response.to_send# GET ivr/selectiondefmenu_selectionuser_selection=params[:Digits]caseuser_selectionwhen"1"output="To get to your extraction point, get on your bike and go down the street. Then Left down an alley. Avoid the police cars. Turn left into an unfinished housing development. Fly over the roadblock. Go passed the moon. Soon after you will see your mother ship."twiml_say(output,true)when"2"list_planetselseoutput="Returning to the main menu."twiml_say(output)endend# POST/GET ivr/planetsdefplanet_selectionuser_selection=params[:Digits]caseuser_selectionwhen"2"connect_to_extension("Brodo")when"3"connect_to_extension("Dugobah")when"4"connect_to_extension("113")elseoutput="Returning to the main menu."twiml_say(output)endend# POST ivr/screen_calldefscreen_callcustomer_phone_number=params[:From]response=Twilio::TwiML::VoiceResponse.newgather=Twilio::TwiML::Gather.new(num_digits:'1',action:ivr_agent_screen_path)gather.say("You have an incoming call from an Alien with phone number#{customer_phone_number.chars.join(",")}.")gather.say("Press any key to accept.")# will return status no-answer since this is a Number callbackresponse.say("Sorry, I didn't get your response.")response.hangupresponse.append(gather)renderxml:response.to_send# POST ivr/agent_screendefagent_screenagent_selected=params[:Digits]ifagent_selectedresponse=Twilio::TwiML::VoiceResponse.newresponse.say("Connecting you to the E.T. in distress. All calls are recorded.")endrenderxml:response.to_send# POST ivr/agent_voicemaildefagent_voicemailstatus=params[:DialCallStatus]||"completed"recording=params[:RecordingUrl]# If the call to the agent was not successful, or there is no recording,# then record a voicemailif(status!="completed"||recording.nil?)response=Twilio::TwiML::VoiceResponse.newresponse.say("It appears that planet is unavailable. Please leave a message after the beep.",voice:'alice',language:'en-GB')response.record(finish_on_key:"*",transcribe:true,max_length:'20',transcribe_callback:"/recordings/create?agent_id=#{params[:agent_id]}")response.say("I did not receive a recording.",voice:'alice',language:'en-GB')# otherwise end the callelseresponse=Twilio::TwiML::VoiceResponse.newresponse.hangupendrenderxml:response.to_sendprivatedeftwiml_say(phrase,exit=false)# Respond with some TwiML and say something.# Should we hangup or go back to the main menu?response=Twilio::TwiML::VoiceResponse.newresponse.say(phrase,voice:'alice',language:'en-GB')ifexitresponse.say("Thank you for calling the ET Phone Home Service - the adventurous alien's first choice in intergalactic travel.")response.hangupelseresponse.redirect(welcome_path)endrenderxml:response.to_senddeftwiml_dial(phone_number)response=Twilio::TwiML::VoiceResponse.newresponse.dial(phone_number)renderxml:response.to_senddeflist_planetsmessage="To call the planet Broh doe As O G, press 2. To call the planet DuhGo bah, press 3. To call an oober asteroid to your location, press 4. To go back to the main menu, press the star key."response=Twilio::TwiML::VoiceResponse.newgather=Twilio::TwiML::Gather.new(num_digits:'1',action:planets_path)gather.say(message,voice:'alice',language:'en-GB',loop:3)response.append(gather)renderxml:response.to_senddefconnect_to_extension(extension)agent=Agent.find_by(extension:extension)response=Twilio::TwiML::VoiceResponse.newdial=Twilio::TwiML::Dial.new(action:ivr_agent_voicemail_path(agent_id:agent.id))dial.number(agent.phone_number,url:ivr_screen_call_path)response.append(dial)renderxml:response.to_sendend

app/controllers/twilio_controller.rb

Find an agent by extension

app/controllers/twilio_controller.rb

Now that our user has chosen their agent, our next step is to connect the call to that agent.

classTwilioController<ApplicationControllerdefindexrendertext:"Dial Me."end# POST ivr/welcomedefivr_welcomeresponse=Twilio::TwiML::VoiceResponse.newgather=Twilio::TwiML::Gather.new(num_digits:'1',action:menu_path)gather.play(url:"http://howtodocs.s3.amazonaws.com/et-phone.mp3",loop:3)response.append(gather)renderxml:response.to_send# GET ivr/selectiondefmenu_selectionuser_selection=params[:Digits]caseuser_selectionwhen"1"output="To get to your extraction point, get on your bike and go down the street. Then Left down an alley. Avoid the police cars. Turn left into an unfinished housing development. Fly over the roadblock. Go passed the moon. Soon after you will see your mother ship."twiml_say(output,true)when"2"list_planetselseoutput="Returning to the main menu."twiml_say(output)endend# POST/GET ivr/planetsdefplanet_selectionuser_selection=params[:Digits]caseuser_selectionwhen"2"connect_to_extension("Brodo")when"3"connect_to_extension("Dugobah")when"4"connect_to_extension("113")elseoutput="Returning to the main menu."twiml_say(output)endend# POST ivr/screen_calldefscreen_callcustomer_phone_number=params[:From]response=Twilio::TwiML::VoiceResponse.newgather=Twilio::TwiML::Gather.new(num_digits:'1',action:ivr_agent_screen_path)gather.say("You have an incoming call from an Alien with phone number#{customer_phone_number.chars.join(",")}.")gather.say("Press any key to accept.")# will return status no-answer since this is a Number callbackresponse.say("Sorry, I didn't get your response.")response.hangupresponse.append(gather)renderxml:response.to_send# POST ivr/agent_screendefagent_screenagent_selected=params[:Digits]ifagent_selectedresponse=Twilio::TwiML::VoiceResponse.newresponse.say("Connecting you to the E.T. in distress. All calls are recorded.")endrenderxml:response.to_send# POST ivr/agent_voicemaildefagent_voicemailstatus=params[:DialCallStatus]||"completed"recording=params[:RecordingUrl]# If the call to the agent was not successful, or there is no recording,# then record a voicemailif(status!="completed"||recording.nil?)response=Twilio::TwiML::VoiceResponse.newresponse.say("It appears that planet is unavailable. Please leave a message after the beep.",voice:'alice',language:'en-GB')response.record(finish_on_key:"*",transcribe:true,max_length:'20',transcribe_callback:"/recordings/create?agent_id=#{params[:agent_id]}")response.say("I did not receive a recording.",voice:'alice',language:'en-GB')# otherwise end the callelseresponse=Twilio::TwiML::VoiceResponse.newresponse.hangupendrenderxml:response.to_sendprivatedeftwiml_say(phrase,exit=false)# Respond with some TwiML and say something.# Should we hangup or go back to the main menu?response=Twilio::TwiML::VoiceResponse.newresponse.say(phrase,voice:'alice',language:'en-GB')ifexitresponse.say("Thank you for calling the ET Phone Home Service - the adventurous alien's first choice in intergalactic travel.")response.hangupelseresponse.redirect(welcome_path)endrenderxml:response.to_senddeftwiml_dial(phone_number)response=Twilio::TwiML::VoiceResponse.newresponse.dial(phone_number)renderxml:response.to_senddeflist_planetsmessage="To call the planet Broh doe As O G, press 2. To call the planet DuhGo bah, press 3. To call an oober asteroid to your location, press 4. To go back to the main menu, press the star key."response=Twilio::TwiML::VoiceResponse.newgather=Twilio::TwiML::Gather.new(num_digits:'1',action:planets_path)gather.say(message,voice:'alice',language:'en-GB',loop:3)response.append(gather)renderxml:response.to_senddefconnect_to_extension(extension)agent=Agent.find_by(extension:extension)response=Twilio::TwiML::VoiceResponse.newdial=Twilio::TwiML::Dial.new(action:ivr_agent_voicemail_path(agent_id:agent.id))dial.number(agent.phone_number,url:ivr_screen_call_path)response.append(dial)renderxml:response.to_sendend

app/controllers/twilio_controller.rb

Connect the call to an Agent

app/controllers/twilio_controller.rb

Our agent can now be called, but how does our agent interact with this feature? Let's dig into what is happening in the agent's screening call.

When our agent picks up the phone, we use a <Gather> verb to ask them if they want to accept the call.

If the agent responds by entering any digit, the response will be processed by our ivr/agent_screen route. This will <Say> a quick message and continue with the original <Dial> command to connect the two parties.

classTwilioController<ApplicationControllerdefindexrendertext:"Dial Me."end# POST ivr/welcomedefivr_welcomeresponse=Twilio::TwiML::VoiceResponse.newgather=Twilio::TwiML::Gather.new(num_digits:'1',action:menu_path)gather.play(url:"http://howtodocs.s3.amazonaws.com/et-phone.mp3",loop:3)response.append(gather)renderxml:response.to_send# GET ivr/selectiondefmenu_selectionuser_selection=params[:Digits]caseuser_selectionwhen"1"output="To get to your extraction point, get on your bike and go down the street. Then Left down an alley. Avoid the police cars. Turn left into an unfinished housing development. Fly over the roadblock. Go passed the moon. Soon after you will see your mother ship."twiml_say(output,true)when"2"list_planetselseoutput="Returning to the main menu."twiml_say(output)endend# POST/GET ivr/planetsdefplanet_selectionuser_selection=params[:Digits]caseuser_selectionwhen"2"connect_to_extension("Brodo")when"3"connect_to_extension("Dugobah")when"4"connect_to_extension("113")elseoutput="Returning to the main menu."twiml_say(output)endend# POST ivr/screen_calldefscreen_callcustomer_phone_number=params[:From]response=Twilio::TwiML::VoiceResponse.newgather=Twilio::TwiML::Gather.new(num_digits:'1',action:ivr_agent_screen_path)gather.say("You have an incoming call from an Alien with phone number#{customer_phone_number.chars.join(",")}.")gather.say("Press any key to accept.")# will return status no-answer since this is a Number callbackresponse.say("Sorry, I didn't get your response.")response.hangupresponse.append(gather)renderxml:response.to_send# POST ivr/agent_screendefagent_screenagent_selected=params[:Digits]ifagent_selectedresponse=Twilio::TwiML::VoiceResponse.newresponse.say("Connecting you to the E.T. in distress. All calls are recorded.")endrenderxml:response.to_send# POST ivr/agent_voicemaildefagent_voicemailstatus=params[:DialCallStatus]||"completed"recording=params[:RecordingUrl]# If the call to the agent was not successful, or there is no recording,# then record a voicemailif(status!="completed"||recording.nil?)response=Twilio::TwiML::VoiceResponse.newresponse.say("It appears that planet is unavailable. Please leave a message after the beep.",voice:'alice',language:'en-GB')response.record(finish_on_key:"*",transcribe:true,max_length:'20',transcribe_callback:"/recordings/create?agent_id=#{params[:agent_id]}")response.say("I did not receive a recording.",voice:'alice',language:'en-GB')# otherwise end the callelseresponse=Twilio::TwiML::VoiceResponse.newresponse.hangupendrenderxml:response.to_sendprivatedeftwiml_say(phrase,exit=false)# Respond with some TwiML and say something.# Should we hangup or go back to the main menu?response=Twilio::TwiML::VoiceResponse.newresponse.say(phrase,voice:'alice',language:'en-GB')ifexitresponse.say("Thank you for calling the ET Phone Home Service - the adventurous alien's first choice in intergalactic travel.")response.hangupelseresponse.redirect(welcome_path)endrenderxml:response.to_senddeftwiml_dial(phone_number)response=Twilio::TwiML::VoiceResponse.newresponse.dial(phone_number)renderxml:response.to_senddeflist_planetsmessage="To call the planet Broh doe As O G, press 2. To call the planet DuhGo bah, press 3. To call an oober asteroid to your location, press 4. To go back to the main menu, press the star key."response=Twilio::TwiML::VoiceResponse.newgather=Twilio::TwiML::Gather.new(num_digits:'1',action:planets_path)gather.say(message,voice:'alice',language:'en-GB',loop:3)response.append(gather)renderxml:response.to_senddefconnect_to_extension(extension)agent=Agent.find_by(extension:extension)response=Twilio::TwiML::VoiceResponse.newdial=Twilio::TwiML::Dial.new(action:ivr_agent_voicemail_path(agent_id:agent.id))dial.number(agent.phone_number,url:ivr_screen_call_path)response.append(dial)renderxml:response.to_sendend

app/controllers/twilio_controller.rb

Handle agent screening and acceptance of incoming calls

app/controllers/twilio_controller.rb

Now our agent can interact with the call, but what if our agent is currently out? In these cases it's helpful to have voicemail set up.

When Twilio makes a request to our Call action method, it will pass a DialCallStatus argument to tell us the call status. If the status is "completed", we hang up. Otherwise, we need to <Say> a quick prompt and then <Record> a voicemail from the alien caller.

We also specify an action for <Record>. This route will be called after the call and recording have finished. The route will say "Goodbye" and then <Hangup>.

classTwilioController<ApplicationControllerdefindexrendertext:"Dial Me."end# POST ivr/welcomedefivr_welcomeresponse=Twilio::TwiML::VoiceResponse.newgather=Twilio::TwiML::Gather.new(num_digits:'1',action:menu_path)gather.play(url:"http://howtodocs.s3.amazonaws.com/et-phone.mp3",loop:3)response.append(gather)renderxml:response.to_send# GET ivr/selectiondefmenu_selectionuser_selection=params[:Digits]caseuser_selectionwhen"1"output="To get to your extraction point, get on your bike and go down the street. Then Left down an alley. Avoid the police cars. Turn left into an unfinished housing development. Fly over the roadblock. Go passed the moon. Soon after you will see your mother ship."twiml_say(output,true)when"2"list_planetselseoutput="Returning to the main menu."twiml_say(output)endend# POST/GET ivr/planetsdefplanet_selectionuser_selection=params[:Digits]caseuser_selectionwhen"2"connect_to_extension("Brodo")when"3"connect_to_extension("Dugobah")when"4"connect_to_extension("113")elseoutput="Returning to the main menu."twiml_say(output)endend# POST ivr/screen_calldefscreen_callcustomer_phone_number=params[:From]response=Twilio::TwiML::VoiceResponse.newgather=Twilio::TwiML::Gather.new(num_digits:'1',action:ivr_agent_screen_path)gather.say("You have an incoming call from an Alien with phone number#{customer_phone_number.chars.join(",")}.")gather.say("Press any key to accept.")# will return status no-answer since this is a Number callbackresponse.say("Sorry, I didn't get your response.")response.hangupresponse.append(gather)renderxml:response.to_send# POST ivr/agent_screendefagent_screenagent_selected=params[:Digits]ifagent_selectedresponse=Twilio::TwiML::VoiceResponse.newresponse.say("Connecting you to the E.T. in distress. All calls are recorded.")endrenderxml:response.to_send# POST ivr/agent_voicemaildefagent_voicemailstatus=params[:DialCallStatus]||"completed"recording=params[:RecordingUrl]# If the call to the agent was not successful, or there is no recording,# then record a voicemailif(status!="completed"||recording.nil?)response=Twilio::TwiML::VoiceResponse.newresponse.say("It appears that planet is unavailable. Please leave a message after the beep.",voice:'alice',language:'en-GB')response.record(finish_on_key:"*",transcribe:true,max_length:'20',transcribe_callback:"/recordings/create?agent_id=#{params[:agent_id]}")response.say("I did not receive a recording.",voice:'alice',language:'en-GB')# otherwise end the callelseresponse=Twilio::TwiML::VoiceResponse.newresponse.hangupendrenderxml:response.to_sendprivatedeftwiml_say(phrase,exit=false)# Respond with some TwiML and say something.# Should we hangup or go back to the main menu?response=Twilio::TwiML::VoiceResponse.newresponse.say(phrase,voice:'alice',language:'en-GB')ifexitresponse.say("Thank you for calling the ET Phone Home Service - the adventurous alien's first choice in intergalactic travel.")response.hangupelseresponse.redirect(welcome_path)endrenderxml:response.to_senddeftwiml_dial(phone_number)response=Twilio::TwiML::VoiceResponse.newresponse.dial(phone_number)renderxml:response.to_senddeflist_planetsmessage="To call the planet Broh doe As O G, press 2. To call the planet DuhGo bah, press 3. To call an oober asteroid to your location, press 4. To go back to the main menu, press the star key."response=Twilio::TwiML::VoiceResponse.newgather=Twilio::TwiML::Gather.new(num_digits:'1',action:planets_path)gather.say(message,voice:'alice',language:'en-GB',loop:3)response.append(gather)renderxml:response.to_senddefconnect_to_extension(extension)agent=Agent.find_by(extension:extension)response=Twilio::TwiML::VoiceResponse.newdial=Twilio::TwiML::Dial.new(action:ivr_agent_voicemail_path(agent_id:agent.id))dial.number(agent.phone_number,url:ivr_screen_call_path)response.append(dial)renderxml:response.to_sendend

Redirect a call to voicemail and end the call

When we tell Twilio to record, we have a few options we can pass to the <Record> verb.

Here we instruct <Record> to stop the recording at 20 seconds, to transcribe the call, and to send the transcription to the agent when it's complete.

Notice we redirect to a URL that is specific to this agent. This is a convenient way to specify which agent was called to produce the voice message. This way we can also save the associated agent together with the voicemail.

classTwilioController<ApplicationControllerdefindexrendertext:"Dial Me."end# POST ivr/welcomedefivr_welcomeresponse=Twilio::TwiML::VoiceResponse.newgather=Twilio::TwiML::Gather.new(num_digits:'1',action:menu_path)gather.play(url:"http://howtodocs.s3.amazonaws.com/et-phone.mp3",loop:3)response.append(gather)renderxml:response.to_send# GET ivr/selectiondefmenu_selectionuser_selection=params[:Digits]caseuser_selectionwhen"1"output="To get to your extraction point, get on your bike and go down the street. Then Left down an alley. Avoid the police cars. Turn left into an unfinished housing development. Fly over the roadblock. Go passed the moon. Soon after you will see your mother ship."twiml_say(output,true)when"2"list_planetselseoutput="Returning to the main menu."twiml_say(output)endend# POST/GET ivr/planetsdefplanet_selectionuser_selection=params[:Digits]caseuser_selectionwhen"2"connect_to_extension("Brodo")when"3"connect_to_extension("Dugobah")when"4"connect_to_extension("113")elseoutput="Returning to the main menu."twiml_say(output)endend# POST ivr/screen_calldefscreen_callcustomer_phone_number=params[:From]response=Twilio::TwiML::VoiceResponse.newgather=Twilio::TwiML::Gather.new(num_digits:'1',action:ivr_agent_screen_path)gather.say("You have an incoming call from an Alien with phone number#{customer_phone_number.chars.join(",")}.")gather.say("Press any key to accept.")# will return status no-answer since this is a Number callbackresponse.say("Sorry, I didn't get your response.")response.hangupresponse.append(gather)renderxml:response.to_send# POST ivr/agent_screendefagent_screenagent_selected=params[:Digits]ifagent_selectedresponse=Twilio::TwiML::VoiceResponse.newresponse.say("Connecting you to the E.T. in distress. All calls are recorded.")endrenderxml:response.to_send# POST ivr/agent_voicemaildefagent_voicemailstatus=params[:DialCallStatus]||"completed"recording=params[:RecordingUrl]# If the call to the agent was not successful, or there is no recording,# then record a voicemailif(status!="completed"||recording.nil?)response=Twilio::TwiML::VoiceResponse.newresponse.say("It appears that planet is unavailable. Please leave a message after the beep.",voice:'alice',language:'en-GB')response.record(finish_on_key:"*",transcribe:true,max_length:'20',transcribe_callback:"/recordings/create?agent_id=#{params[:agent_id]}")response.say("I did not receive a recording.",voice:'alice',language:'en-GB')# otherwise end the callelseresponse=Twilio::TwiML::VoiceResponse.newresponse.hangupendrenderxml:response.to_sendprivatedeftwiml_say(phrase,exit=false)# Respond with some TwiML and say something.# Should we hangup or go back to the main menu?response=Twilio::TwiML::VoiceResponse.newresponse.say(phrase,voice:'alice',language:'en-GB')ifexitresponse.say("Thank you for calling the ET Phone Home Service - the adventurous alien's first choice in intergalactic travel.")response.hangupelseresponse.redirect(welcome_path)endrenderxml:response.to_senddeftwiml_dial(phone_number)response=Twilio::TwiML::VoiceResponse.newresponse.dial(phone_number)renderxml:response.to_senddeflist_planetsmessage="To call the planet Broh doe As O G, press 2. To call the planet DuhGo bah, press 3. To call an oober asteroid to your location, press 4. To go back to the main menu, press the star key."response=Twilio::TwiML::VoiceResponse.newgather=Twilio::TwiML::Gather.new(num_digits:'1',action:planets_path)gather.say(message,voice:'alice',language:'en-GB',loop:3)response.append(gather)renderxml:response.to_senddefconnect_to_extension(extension)agent=Agent.find_by(extension:extension)response=Twilio::TwiML::VoiceResponse.newdial=Twilio::TwiML::Dial.new(action:ivr_agent_voicemail_path(agent_id:agent.id))dial.number(agent.phone_number,url:ivr_screen_call_path)response.append(dial)renderxml:response.to_sendend

classTwilioController<ApplicationControllerdefindexrendertext:"Dial Me."end# POST ivr/welcomedefivr_welcomeresponse=Twilio::TwiML::VoiceResponse.newgather=Twilio::TwiML::Gather.new(num_digits:'1',action:menu_path)gather.play(url:"http://howtodocs.s3.amazonaws.com/et-phone.mp3",loop:3)response.append(gather)renderxml:response.to_send# GET ivr/selectiondefmenu_selectionuser_selection=params[:Digits]caseuser_selectionwhen"1"output="To get to your extraction point, get on your bike and go down the street. Then Left down an alley. Avoid the police cars. Turn left into an unfinished housing development. Fly over the roadblock. Go passed the moon. Soon after you will see your mother ship."twiml_say(output,true)when"2"list_planetselseoutput="Returning to the main menu."twiml_say(output)endend# POST/GET ivr/planetsdefplanet_selectionuser_selection=params[:Digits]caseuser_selectionwhen"2"connect_to_extension("Brodo")when"3"connect_to_extension("Dugobah")when"4"connect_to_extension("113")elseoutput="Returning to the main menu."twiml_say(output)endend# POST ivr/screen_calldefscreen_callcustomer_phone_number=params[:From]response=Twilio::TwiML::VoiceResponse.newgather=Twilio::TwiML::Gather.new(num_digits:'1',action:ivr_agent_screen_path)gather.say("You have an incoming call from an Alien with phone number#{customer_phone_number.chars.join(",")}.")gather.say("Press any key to accept.")# will return status no-answer since this is a Number callbackresponse.say("Sorry, I didn't get your response.")response.hangupresponse.append(gather)renderxml:response.to_send# POST ivr/agent_screendefagent_screenagent_selected=params[:Digits]ifagent_selectedresponse=Twilio::TwiML::VoiceResponse.newresponse.say("Connecting you to the E.T. in distress. All calls are recorded.")endrenderxml:response.to_send# POST ivr/agent_voicemaildefagent_voicemailstatus=params[:DialCallStatus]||"completed"recording=params[:RecordingUrl]# If the call to the agent was not successful, or there is no recording,# then record a voicemailif(status!="completed"||recording.nil?)response=Twilio::TwiML::VoiceResponse.newresponse.say("It appears that planet is unavailable. Please leave a message after the beep.",voice:'alice',language:'en-GB')response.record(finish_on_key:"*",transcribe:true,max_length:'20',transcribe_callback:"/recordings/create?agent_id=#{params[:agent_id]}")response.say("I did not receive a recording.",voice:'alice',language:'en-GB')# otherwise end the callelseresponse=Twilio::TwiML::VoiceResponse.newresponse.hangupendrenderxml:response.to_sendprivatedeftwiml_say(phrase,exit=false)# Respond with some TwiML and say something.# Should we hangup or go back to the main menu?response=Twilio::TwiML::VoiceResponse.newresponse.say(phrase,voice:'alice',language:'en-GB')ifexitresponse.say("Thank you for calling the ET Phone Home Service - the adventurous alien's first choice in intergalactic travel.")response.hangupelseresponse.redirect(welcome_path)endrenderxml:response.to_senddeftwiml_dial(phone_number)response=Twilio::TwiML::VoiceResponse.newresponse.dial(phone_number)renderxml:response.to_senddeflist_planetsmessage="To call the planet Broh doe As O G, press 2. To call the planet DuhGo bah, press 3. To call an oober asteroid to your location, press 4. To go back to the main menu, press the star key."response=Twilio::TwiML::VoiceResponse.newgather=Twilio::TwiML::Gather.new(num_digits:'1',action:planets_path)gather.say(message,voice:'alice',language:'en-GB',loop:3)response.append(gather)renderxml:response.to_senddefconnect_to_extension(extension)agent=Agent.find_by(extension:extension)response=Twilio::TwiML::VoiceResponse.newdial=Twilio::TwiML::Dial.new(action:ivr_agent_voicemail_path(agent_id:agent.id))dial.number(agent.phone_number,url:ivr_screen_call_path)response.append(dial)renderxml:response.to_sendend

classTwilioController<ApplicationControllerdefindexrendertext:"Dial Me."end# POST ivr/welcomedefivr_welcomeresponse=Twilio::TwiML::VoiceResponse.newgather=Twilio::TwiML::Gather.new(num_digits:'1',action:menu_path)gather.play(url:"http://howtodocs.s3.amazonaws.com/et-phone.mp3",loop:3)response.append(gather)renderxml:response.to_send# GET ivr/selectiondefmenu_selectionuser_selection=params[:Digits]caseuser_selectionwhen"1"output="To get to your extraction point, get on your bike and go down the street. Then Left down an alley. Avoid the police cars. Turn left into an unfinished housing development. Fly over the roadblock. Go passed the moon. Soon after you will see your mother ship."twiml_say(output,true)when"2"list_planetselseoutput="Returning to the main menu."twiml_say(output)endend# POST/GET ivr/planetsdefplanet_selectionuser_selection=params[:Digits]caseuser_selectionwhen"2"connect_to_extension("Brodo")when"3"connect_to_extension("Dugobah")when"4"connect_to_extension("113")elseoutput="Returning to the main menu."twiml_say(output)endend# POST ivr/screen_calldefscreen_callcustomer_phone_number=params[:From]response=Twilio::TwiML::VoiceResponse.newgather=Twilio::TwiML::Gather.new(num_digits:'1',action:ivr_agent_screen_path)gather.say("You have an incoming call from an Alien with phone number#{customer_phone_number.chars.join(",")}.")gather.say("Press any key to accept.")# will return status no-answer since this is a Number callbackresponse.say("Sorry, I didn't get your response.")response.hangupresponse.append(gather)renderxml:response.to_send# POST ivr/agent_screendefagent_screenagent_selected=params[:Digits]ifagent_selectedresponse=Twilio::TwiML::VoiceResponse.newresponse.say("Connecting you to the E.T. in distress. All calls are recorded.")endrenderxml:response.to_send# POST ivr/agent_voicemaildefagent_voicemailstatus=params[:DialCallStatus]||"completed"recording=params[:RecordingUrl]# If the call to the agent was not successful, or there is no recording,# then record a voicemailif(status!="completed"||recording.nil?)response=Twilio::TwiML::VoiceResponse.newresponse.say("It appears that planet is unavailable. Please leave a message after the beep.",voice:'alice',language:'en-GB')response.record(finish_on_key:"*",transcribe:true,max_length:'20',transcribe_callback:"/recordings/create?agent_id=#{params[:agent_id]}")response.say("I did not receive a recording.",voice:'alice',language:'en-GB')# otherwise end the callelseresponse=Twilio::TwiML::VoiceResponse.newresponse.hangupendrenderxml:response.to_sendprivatedeftwiml_say(phrase,exit=false)# Respond with some TwiML and say something.# Should we hangup or go back to the main menu?response=Twilio::TwiML::VoiceResponse.newresponse.say(phrase,voice:'alice',language:'en-GB')ifexitresponse.say("Thank you for calling the ET Phone Home Service - the adventurous alien's first choice in intergalactic travel.")response.hangupelseresponse.redirect(welcome_path)endrenderxml:response.to_senddeftwiml_dial(phone_number)response=Twilio::TwiML::VoiceResponse.newresponse.dial(phone_number)renderxml:response.to_senddeflist_planetsmessage="To call the planet Broh doe As O G, press 2. To call the planet DuhGo bah, press 3. To call an oober asteroid to your location, press 4. To go back to the main menu, press the star key."response=Twilio::TwiML::VoiceResponse.newgather=Twilio::TwiML::Gather.new(num_digits:'1',action:planets_path)gather.say(message,voice:'alice',language:'en-GB',loop:3)response.append(gather)renderxml:response.to_senddefconnect_to_extension(extension)agent=Agent.find_by(extension:extension)response=Twilio::TwiML::VoiceResponse.newdial=Twilio::TwiML::Dial.new(action:ivr_agent_voicemail_path(agent_id:agent.id))dial.number(agent.phone_number,url:ivr_screen_call_path)response.append(dial)renderxml:response.to_sendend

classTwilioController<ApplicationControllerdefindexrendertext:"Dial Me."end# POST ivr/welcomedefivr_welcomeresponse=Twilio::TwiML::VoiceResponse.newgather=Twilio::TwiML::Gather.new(num_digits:'1',action:menu_path)gather.play(url:"http://howtodocs.s3.amazonaws.com/et-phone.mp3",loop:3)response.append(gather)renderxml:response.to_send# GET ivr/selectiondefmenu_selectionuser_selection=params[:Digits]caseuser_selectionwhen"1"output="To get to your extraction point, get on your bike and go down the street. Then Left down an alley. Avoid the police cars. Turn left into an unfinished housing development. Fly over the roadblock. Go passed the moon. Soon after you will see your mother ship."twiml_say(output,true)when"2"list_planetselseoutput="Returning to the main menu."twiml_say(output)endend# POST/GET ivr/planetsdefplanet_selectionuser_selection=params[:Digits]caseuser_selectionwhen"2"connect_to_extension("Brodo")when"3"connect_to_extension("Dugobah")when"4"connect_to_extension("113")elseoutput="Returning to the main menu."twiml_say(output)endend# POST ivr/screen_calldefscreen_callcustomer_phone_number=params[:From]response=Twilio::TwiML::VoiceResponse.newgather=Twilio::TwiML::Gather.new(num_digits:'1',action:ivr_agent_screen_path)gather.say("You have an incoming call from an Alien with phone number#{customer_phone_number.chars.join(",")}.")gather.say("Press any key to accept.")# will return status no-answer since this is a Number callbackresponse.say("Sorry, I didn't get your response.")response.hangupresponse.append(gather)renderxml:response.to_send# POST ivr/agent_screendefagent_screenagent_selected=params[:Digits]ifagent_selectedresponse=Twilio::TwiML::VoiceResponse.newresponse.say("Connecting you to the E.T. in distress. All calls are recorded.")endrenderxml:response.to_send# POST ivr/agent_voicemaildefagent_voicemailstatus=params[:DialCallStatus]||"completed"recording=params[:RecordingUrl]# If the call to the agent was not successful, or there is no recording,# then record a voicemailif(status!="completed"||recording.nil?)response=Twilio::TwiML::VoiceResponse.newresponse.say("It appears that planet is unavailable. Please leave a message after the beep.",voice:'alice',language:'en-GB')response.record(finish_on_key:"*",transcribe:true,max_length:'20',transcribe_callback:"/recordings/create?agent_id=#{params[:agent_id]}")response.say("I did not receive a recording.",voice:'alice',language:'en-GB')# otherwise end the callelseresponse=Twilio::TwiML::VoiceResponse.newresponse.hangupendrenderxml:response.to_sendprivatedeftwiml_say(phrase,exit=false)# Respond with some TwiML and say something.# Should we hangup or go back to the main menu?response=Twilio::TwiML::VoiceResponse.newresponse.say(phrase,voice:'alice',language:'en-GB')ifexitresponse.say("Thank you for calling the ET Phone Home Service - the adventurous alien's first choice in intergalactic travel.")response.hangupelseresponse.redirect(welcome_path)endrenderxml:response.to_senddeftwiml_dial(phone_number)response=Twilio::TwiML::VoiceResponse.newresponse.dial(phone_number)renderxml:response.to_senddeflist_planetsmessage="To call the planet Broh doe As O G, press 2. To call the planet DuhGo bah, press 3. To call an oober asteroid to your location, press 4. To go back to the main menu, press the star key."response=Twilio::TwiML::VoiceResponse.newgather=Twilio::TwiML::Gather.new(num_digits:'1',action:planets_path)gather.say(message,voice:'alice',language:'en-GB',loop:3)response.append(gather)renderxml:response.to_senddefconnect_to_extension(extension)agent=Agent.find_by(extension:extension)response=Twilio::TwiML::VoiceResponse.newdial=Twilio::TwiML::Dial.new(action:ivr_agent_voicemail_path(agent_id:agent.id))dial.number(agent.phone_number,url:ivr_screen_call_path)response.append(dial)renderxml:response.to_sendend

classTwilioController<ApplicationControllerdefindexrendertext:"Dial Me."end# POST ivr/welcomedefivr_welcomeresponse=Twilio::TwiML::VoiceResponse.newgather=Twilio::TwiML::Gather.new(num_digits:'1',action:menu_path)gather.play(url:"http://howtodocs.s3.amazonaws.com/et-phone.mp3",loop:3)response.append(gather)renderxml:response.to_send# GET ivr/selectiondefmenu_selectionuser_selection=params[:Digits]caseuser_selectionwhen"1"output="To get to your extraction point, get on your bike and go down the street. Then Left down an alley. Avoid the police cars. Turn left into an unfinished housing development. Fly over the roadblock. Go passed the moon. Soon after you will see your mother ship."twiml_say(output,true)when"2"list_planetselseoutput="Returning to the main menu."twiml_say(output)endend# POST/GET ivr/planetsdefplanet_selectionuser_selection=params[:Digits]caseuser_selectionwhen"2"connect_to_extension("Brodo")when"3"connect_to_extension("Dugobah")when"4"connect_to_extension("113")elseoutput="Returning to the main menu."twiml_say(output)endend# POST ivr/screen_calldefscreen_callcustomer_phone_number=params[:From]response=Twilio::TwiML::VoiceResponse.newgather=Twilio::TwiML::Gather.new(num_digits:'1',action:ivr_agent_screen_path)gather.say("You have an incoming call from an Alien with phone number#{customer_phone_number.chars.join(",")}.")gather.say("Press any key to accept.")# will return status no-answer since this is a Number callbackresponse.say("Sorry, I didn't get your response.")response.hangupresponse.append(gather)renderxml:response.to_send# POST ivr/agent_screendefagent_screenagent_selected=params[:Digits]ifagent_selectedresponse=Twilio::TwiML::VoiceResponse.newresponse.say("Connecting you to the E.T. in distress. All calls are recorded.")endrenderxml:response.to_send# POST ivr/agent_voicemaildefagent_voicemailstatus=params[:DialCallStatus]||"completed"recording=params[:RecordingUrl]# If the call to the agent was not successful, or there is no recording,# then record a voicemailif(status!="completed"||recording.nil?)response=Twilio::TwiML::VoiceResponse.newresponse.say("It appears that planet is unavailable. Please leave a message after the beep.",voice:'alice',language:'en-GB')response.record(finish_on_key:"*",transcribe:true,max_length:'20',transcribe_callback:"/recordings/create?agent_id=#{params[:agent_id]}")response.say("I did not receive a recording.",voice:'alice',language:'en-GB')# otherwise end the callelseresponse=Twilio::TwiML::VoiceResponse.newresponse.hangupendrenderxml:response.to_sendprivatedeftwiml_say(phrase,exit=false)# Respond with some TwiML and say something.# Should we hangup or go back to the main menu?response=Twilio::TwiML::VoiceResponse.newresponse.say(phrase,voice:'alice',language:'en-GB')ifexitresponse.say("Thank you for calling the ET Phone Home Service - the adventurous alien's first choice in intergalactic travel.")response.hangupelseresponse.redirect(welcome_path)endrenderxml:response.to_senddeftwiml_dial(phone_number)response=Twilio::TwiML::VoiceResponse.newresponse.dial(phone_number)renderxml:response.to_senddeflist_planetsmessage="To call the planet Broh doe As O G, press 2. To call the planet DuhGo bah, press 3. To call an oober asteroid to your location, press 4. To go back to the main menu, press the star key."response=Twilio::TwiML::VoiceResponse.newgather=Twilio::TwiML::Gather.new(num_digits:'1',action:planets_path)gather.say(message,voice:'alice',language:'en-GB',loop:3)response.append(gather)renderxml:response.to_senddefconnect_to_extension(extension)agent=Agent.find_by(extension:extension)response=Twilio::TwiML::VoiceResponse.newdial=Twilio::TwiML::Dial.new(action:ivr_agent_voicemail_path(agent_id:agent.id))dial.number(agent.phone_number,url:ivr_screen_call_path)response.append(dial)renderxml:response.to_sendend

classTwilioController<ApplicationControllerdefindexrendertext:"Dial Me."end# POST ivr/welcomedefivr_welcomeresponse=Twilio::TwiML::VoiceResponse.newgather=Twilio::TwiML::Gather.new(num_digits:'1',action:menu_path)gather.play(url:"http://howtodocs.s3.amazonaws.com/et-phone.mp3",loop:3)response.append(gather)renderxml:response.to_send# GET ivr/selectiondefmenu_selectionuser_selection=params[:Digits]caseuser_selectionwhen"1"output="To get to your extraction point, get on your bike and go down the street. Then Left down an alley. Avoid the police cars. Turn left into an unfinished housing development. Fly over the roadblock. Go passed the moon. Soon after you will see your mother ship."twiml_say(output,true)when"2"list_planetselseoutput="Returning to the main menu."twiml_say(output)endend# POST/GET ivr/planetsdefplanet_selectionuser_selection=params[:Digits]caseuser_selectionwhen"2"connect_to_extension("Brodo")when"3"connect_to_extension("Dugobah")when"4"connect_to_extension("113")elseoutput="Returning to the main menu."twiml_say(output)endend# POST ivr/screen_calldefscreen_callcustomer_phone_number=params[:From]response=Twilio::TwiML::VoiceResponse.newgather=Twilio::TwiML::Gather.new(num_digits:'1',action:ivr_agent_screen_path)gather.say("You have an incoming call from an Alien with phone number#{customer_phone_number.chars.join(",")}.")gather.say("Press any key to accept.")# will return status no-answer since this is a Number callbackresponse.say("Sorry, I didn't get your response.")response.hangupresponse.append(gather)renderxml:response.to_send# POST ivr/agent_screendefagent_screenagent_selected=params[:Digits]ifagent_selectedresponse=Twilio::TwiML::VoiceResponse.newresponse.say("Connecting you to the E.T. in distress. All calls are recorded.")endrenderxml:response.to_send# POST ivr/agent_voicemaildefagent_voicemailstatus=params[:DialCallStatus]||"completed"recording=params[:RecordingUrl]# If the call to the agent was not successful, or there is no recording,# then record a voicemailif(status!="completed"||recording.nil?)response=Twilio::TwiML::VoiceResponse.newresponse.say("It appears that planet is unavailable. Please leave a message after the beep.",voice:'alice',language:'en-GB')response.record(finish_on_key:"*",transcribe:true,max_length:'20',transcribe_callback:"/recordings/create?agent_id=#{params[:agent_id]}")response.say("I did not receive a recording.",voice:'alice',language:'en-GB')# otherwise end the callelseresponse=Twilio::TwiML::VoiceResponse.newresponse.hangupendrenderxml:response.to_sendprivatedeftwiml_say(phrase,exit=false)# Respond with some TwiML and say something.# Should we hangup or go back to the main menu?response=Twilio::TwiML::VoiceResponse.newresponse.say(phrase,voice:'alice',language:'en-GB')ifexitresponse.say("Thank you for calling the ET Phone Home Service - the adventurous alien's first choice in intergalactic travel.")response.hangupelseresponse.redirect(welcome_path)endrenderxml:response.to_senddeftwiml_dial(phone_number)response=Twilio::TwiML::VoiceResponse.newresponse.dial(phone_number)renderxml:response.to_senddeflist_planetsmessage="To call the planet Broh doe As O G, press 2. To call the planet DuhGo bah, press 3. To call an oober asteroid to your location, press 4. To go back to the main menu, press the star key."response=Twilio::TwiML::VoiceResponse.newgather=Twilio::TwiML::Gather.new(num_digits:'1',action:planets_path)gather.say(message,voice:'alice',language:'en-GB',loop:3)response.append(gather)renderxml:response.to_senddefconnect_to_extension(extension)agent=Agent.find_by(extension:extension)response=Twilio::TwiML::VoiceResponse.newdial=Twilio::TwiML::Dial.new(action:ivr_agent_voicemail_path(agent_id:agent.id))dial.number(agent.phone_number,url:ivr_screen_call_path)response.append(dial)renderxml:response.to_sendend

classTwilioController<ApplicationControllerdefindexrendertext:"Dial Me."end# POST ivr/welcomedefivr_welcomeresponse=Twilio::TwiML::VoiceResponse.newgather=Twilio::TwiML::Gather.new(num_digits:'1',action:menu_path)gather.play(url:"http://howtodocs.s3.amazonaws.com/et-phone.mp3",loop:3)response.append(gather)renderxml:response.to_send# GET ivr/selectiondefmenu_selectionuser_selection=params[:Digits]caseuser_selectionwhen"1"output="To get to your extraction point, get on your bike and go down the street. Then Left down an alley. Avoid the police cars. Turn left into an unfinished housing development. Fly over the roadblock. Go passed the moon. Soon after you will see your mother ship."twiml_say(output,true)when"2"list_planetselseoutput="Returning to the main menu."twiml_say(output)endend# POST/GET ivr/planetsdefplanet_selectionuser_selection=params[:Digits]caseuser_selectionwhen"2"connect_to_extension("Brodo")when"3"connect_to_extension("Dugobah")when"4"connect_to_extension("113")elseoutput="Returning to the main menu."twiml_say(output)endend# POST ivr/screen_calldefscreen_callcustomer_phone_number=params[:From]response=Twilio::TwiML::VoiceResponse.newgather=Twilio::TwiML::Gather.new(num_digits:'1',action:ivr_agent_screen_path)gather.say("You have an incoming call from an Alien with phone number#{customer_phone_number.chars.join(",")}.")gather.say("Press any key to accept.")# will return status no-answer since this is a Number callbackresponse.say("Sorry, I didn't get your response.")response.hangupresponse.append(gather)renderxml:response.to_send# POST ivr/agent_screendefagent_screenagent_selected=params[:Digits]ifagent_selectedresponse=Twilio::TwiML::VoiceResponse.newresponse.say("Connecting you to the E.T. in distress. All calls are recorded.")endrenderxml:response.to_send# POST ivr/agent_voicemaildefagent_voicemailstatus=params[:DialCallStatus]||"completed"recording=params[:RecordingUrl]# If the call to the agent was not successful, or there is no recording,# then record a voicemailif(status!="completed"||recording.nil?)response=Twilio::TwiML::VoiceResponse.newresponse.say("It appears that planet is unavailable. Please leave a message after the beep.",voice:'alice',language:'en-GB')response.record(finish_on_key:"*",transcribe:true,max_length:'20',transcribe_callback:"/recordings/create?agent_id=#{params[:agent_id]}")response.say("I did not receive a recording.",voice:'alice',language:'en-GB')# otherwise end the callelseresponse=Twilio::TwiML::VoiceResponse.newresponse.hangupendrenderxml:response.to_sendprivatedeftwiml_say(phrase,exit=false)# Respond with some TwiML and say something.# Should we hangup or go back to the main menu?response=Twilio::TwiML::VoiceResponse.newresponse.say(phrase,voice:'alice',language:'en-GB')ifexitresponse.say("Thank you for calling the ET Phone Home Service - the adventurous alien's first choice in intergalactic travel.")response.hangupelseresponse.redirect(welcome_path)endrenderxml:response.to_senddeftwiml_dial(phone_number)response=Twilio::TwiML::VoiceResponse.newresponse.dial(phone_number)renderxml:response.to_senddeflist_planetsmessage="To call the planet Broh doe As O G, press 2. To call the planet DuhGo bah, press 3. To call an oober asteroid to your location, press 4. To go back to the main menu, press the star key."response=Twilio::TwiML::VoiceResponse.newgather=Twilio::TwiML::Gather.new(num_digits:'1',action:planets_path)gather.say(message,voice:'alice',language:'en-GB',loop:3)response.append(gather)renderxml:response.to_senddefconnect_to_extension(extension)agent=Agent.find_by(extension:extension)response=Twilio::TwiML::VoiceResponse.newdial=Twilio::TwiML::Dial.new(action:ivr_agent_voicemail_path(agent_id:agent.id))dial.number(agent.phone_number,url:ivr_screen_call_path)response.append(dial)renderxml:response.to_sendend