Correct way to nest an IVR - Nested Gather ?

218 views
Skip to first unread message

Nate Smith

unread,
Apr 3, 2018, 3:01:54 PM4/3/18
to Twilio Functions
Hello,

What is the correct way to have an IVR with nested options? For example something like a main menu that differentiates between English and Spanish. Then, provide sub-options again for the user.

This is code I have but it seems to have unpredictable behavior. If I hang up midway through a call and call back, sometimes it will start at the sub menu instead of the main "outer" menu.

Do I need to create separate functions for each sub-IVR? If so, how do Functions call each other?

/**
 *  Spanish / English Menu
 */
exports.handler = function(context, event, callback) {
  let twiml = new Twilio.twiml.VoiceResponse()
  switch (event.Digits) {
    case '1':
      //English Menu starts here
      exports.handler = function(context,event,callback){
     
      let twimlInner = new Twilio.twiml.VoiceResponse()
      switch (event.Digits){
        case '1':
          twimlInner.say("English1");
          break
        case '2':
          twimlInner.play('English2')
          break
        default:
          twimlInner.say('EnglighElse.')
      }
        callback(null,twimlInner)
      }     
      twiml.gather({numDigits: 1}).say('Choose an option')
     
      break
    case '2':
      //Spanish starts here
      exports.handler = function(context,event,callback){
      let twimlInner = new Twilio.twiml.VoiceResponse()
     
      switch (event.Digits){
        case '1':
          twimlInner.say("spanish")
          break
        case '2':
          twimlInner.say("spanish2")
          break
        default:
          twimlInner.say({voice:'man',language:"es-MX"},"marque 3.')
      }
        callback(null,twimlInner)
      }     
      twiml.gather({numDigits: 1}).say({voice:'man',language:"es-MX"},'Marque 3.')
      break
    default:
      twiml.say('For english, press 1')
      twiml.gather({numDigits: 1}).say({voice:'man',language:"es-MX"},'Para español, marque 2')               
  }
 
  callback(null, twiml)
}

Chris Corcoran

unread,
Apr 6, 2018, 5:55:46 PM4/6/18
to Twilio Functions
Hi Nate,

Thanks for your interest in Twilio Functions, I think we need to reach out to Twilio Support here for more guidance. The behavior you're referring to doesn't seem related to functions. Please contact them by email sup...@twilio.com.

Thanks Again,
Chris Corcoran
Product Manager, Twilio Runtime
Reply all
Reply to author
Forward
0 new messages