Basic IVR Menu
Basic IVR Menu
A simple auto-attendant that plays a greeting and routes callers based on their keypress input.
Requirements
- Sound files:
custom/welcome(or use built-in prompts) - At least two destination contexts or extensions to route to
Dialplan
[ivr-main]
exten => s,1,Answer()
same => n,Set(TIMEOUT(response)=5)
same => n,Set(TIMEOUT(digit)=3)
same => n(loop),Background(custom/welcome)
same => n,WaitExten()
; Caller pressed 1 -- Sales
exten => 1,1,Goto(sales,s,1)
; Caller pressed 2 -- Support
exten => 2,1,Goto(support,s,1)
; Caller pressed 0 -- Operator
exten => 0,1,Goto(operator,s,1)
; Invalid input
exten => i,1,Playback(pbx-invalid)
same => n,Goto(s,loop)
; Timeout -- no input
exten => t,1,Playback(vm-goodbye)
same => n,Hangup()
How it works
- Answer and set timeouts:
TIMEOUT(response)sets how longWaitExten()waits for a digit when called without an explicit argument.TIMEOUT(digit)sets the inter-digit timeout for multi-digit extensions. Defining both at the top means you only need to change them in one place, even across a multi-level menu. - Background(): Plays the audio file while listening for DTMF. This is the key difference from
Playback(), which ignores keypresses. - WaitExten(): Waits for input after
Background()finishes, using theTIMEOUT(response)value set above. - Extension matching: Each DTMF digit is matched as an extension in the current context. Extensions
i(invalid) andt(timeout) are special handlers.
Tips
- Record your greeting with
Record()and save it ascustom/welcome.gsm(or.wav). - For multi-level IVRs, create separate contexts for each menu level and
Goto()between them. - Add
exten => #,1,Goto(s,loop)to let callers replay the menu.
User Notes
Know a tip or gotcha for this topic? Share it below and help others.
Contribute a note
Share a tip, gotcha, or practical example. Keep it under 2000 characters. No questions (use the Asterisk community forums for support). Wrap code in backticks.