Interactive voice response menus
Implementing a simple 'push-1, push-2' menu structure
The key to creating this menu is to create an Extension (defined as 205 below) to record your menu prompts. This will put the sound file in /tmp/asterisk-recording.gsm. You'll have to move that file each time its created to /var/lib/asterisk/sounds and rename it to something pertinent to your design so it can be called from the dial-plan. Notice the line under [mainmenu] exten => s,5,Background(sai-welcome). Thesai-welcome is one of those .gsm sound files. The rest of the dial-plan just defines what happens when each option is pushed. If you want to be able to have regular users update the voice prompts, see asterisk tips phrase recording menu.
extensions.conf
[mainmenu]
exten => s,1,Answer
exten => s,2,SetMusicOnHold(default)
exten => s,3,DigitTimeout,5
exten => s,4,ResponseTimeout,10
;SAI menu - 1 for tech support, 2 for voicemail, 3 for echo test
exten => s,5,Background(sai-welcome)
exten => s,6,Background(sai-choose)
; Tech Support
exten => 1,1,AGI(dima-test.agi)
exten => 1,2,SetGlobalVar(ACCOUNTCODE=${callerid})
exten => 1,3,SetVar(testcallerid=${callerid})
exten => 1,4,Background(sai-reptech-welcome)
exten => 1,5,Queue(rep-tech)
; Leave Voicemail
exten => 2,1,VoicemailMain()
exten => 2,2,Hangup
; Echo Test
exten => 3,1,Playback(demo-echotest)
exten => 3,2,Echo
exten => 3,3,Playback(demo-echodone)
exten => 3,4,Goto(mainmenu,s,6)
; EAGI Test
exten => 4,1,Answer()
exten => 4,2,Wait(1)
exten => 4,3,AGI(sai-repid.agi)
exten => 4,4,Wait(1)
exten => 4,5,Hangup
; Play Music-on-Hold
exten => 5,1,MusicOnHold(default)
exten => 5,2,Goto(mainmenu,s,6)
; #=hangup
exten => #,1,Playback(sai-thanks)
exten => #,2,Hangup
exten => t,1,Goto(#,1) ; If they take too long, give up
exten => i,1,Playback(invalid) ; "That's not valid, try again"
[default]
include => mainmenu
include => local
include => longdistance
include => joe-iax
include => npi-iax
; Record voice file to /tmp directory
exten => 205,1,Wait(2) ; Call 205 to Record new Sound Files
exten => 205,2,Record(/tmp/asterisk-recording:gsm) ; Press # to stop recording
exten => 205,3,Wait(2)
exten => 205,4,Playback(/tmp/asterisk-recording) ; Listen to your voice
exten => 205,5,wait(2)
exten => 205,6,Hangup
Example menu with timeout and invalid option. Works with Asterisk 1.6
exten => s,1,Set(NUMINVALID=0)
exten => s,2,Set(NUMTIMEOUTS=0)
exten => s,3,Background(thank-you-for-calling)
exten => s,4,Set(TIMEOUT(digit)=5)
exten => s,5,Set(TIMEOUT(response)=10)
exten => s,6,WaitExten(5)
exten => t,1,Set(NUMTIMEOUTS=$[${NUMTIMEOUTS}+1]})
exten => t,2,Gotoif($["${NUMTIMEOUTS}" < "3"]?s,3)
exten => t,3,Background(vm-goodbye)
exten => t,4,Hangup()
exten => i,1,Set(NUMINVALID=$[${NUMINVALID}+1]})
exten => i,2,Gotoif($["${NUMINVALID}" < "4"]?:10)
exten => i,3,Background(invalid)
exten => i,4,Goto(s,3)
exten => i,10,Playback(vm-goodbye)
exten => i,11,Hangup()
Implementing a high-density without wearing out your keyboard
Now consider an information delivery IVR, such as a bus schedule. The basic call flow goes something like:Hear initial greeting
Hear root menu
Descend into to menu 1
Descend into to submenu 2
Play information message at option 4
Return to submenu 2
Descend into to submenu 7
Return to root menu
{and so on...}
The schedule that prompted creation of this code has 136 possible menu/message combinations. ...