5.2. Multilevel IVR systems

The problem with multilevel IVRs is that the caller has to enter single digits multiple times (oftentimes the same digit), but gets a different response depending on the menu level. Because a number can only be used once in a given context, the caller would be stuck on the first menu level. If we need multiple menus which provide different responses for the same digits, we must place the submenus in different contexts ([cafeteria] in our example). We jump between these contexts using the application Goto() (see Section B.49, “Goto()). Let's assume you have the following sound files stored in /var/lib/asterisk/sounds/:
  • mainmenu.gsm
    "Press 1 for sales, 2 for service, or 3 for the cafeteria."
  • cafeteria.gsm
    "Press 1 to hear the menu for this week or 2 to hear the menu for next week."
  • cafeteria-menu-this-week.gsm
    "Monday: Noodles with pesto sauce. Tuesday: Pork chops..."
  • cafeteria-menu-next-week.gsm
    "Monday: Stew, featuring noodles, basil and, um, pork chops..."
If sales is at extension 100 and the service department is at 150, the dialplan for this IVR would look like this:
; The menu is repeated until the caller provides input.
exten => 30,1,Answer()
exten => 30,2,Background(mainmenu)
exten => 30,3,Background(silence/3)
exten => 30,4,Goto(2)

exten => 1,1,Dial(SIP/100)

exten => 2,1,Dial(SIP/150)

; Goto() jumps to another context ([cafeteria])
exten => 3,1,Goto(cafeteria,100,1)

exten => i,1,Goto(30,2)

exten => 100,1,Background(cafeteria)
exten => 100,2,Background(silence/3)
exten => 100,3,Goto(1)

exten => 1,1,Playback(cafeteria-menu-this-week)
exten => 1,2,Wait(2)
exten => 1,3,Goto(1)

exten => 2,1,Playback(cafeteria-menu-next-week)
exten => 2,2,Wait(2)
exten => 2,3,Goto(1)

; Invalid input sends the caller back to the main menu
exten => i,1,Goto(example-ivr,30,2)

IVR depth

Even though it is technically possible to support an unlimited number of IVR levels, in practice it is advisable to keep the number of menu levels to a maximum of three. Many callers hang up after the third menu level.