Asterisk Auto Attendant Example
Asterisk Auto Attendant Example
An auto attendant is an IVR that answers the main number, plays a menu, and routes the caller based on digits. The important parts are not just Background() and WaitExten(). You also need clean timeout handling, invalid input handling, an operator escape, and a predictable after-hours path.
Dialplan
[from-trunk]
exten => s,1,NoOp(Main number auto attendant)
same => n,Answer()
same => n,GotoIfTime(09:00-17:00,mon-fri,*,*?main-aa,s,1)
same => n,Goto(after-hours,s,1)
[main-aa]
exten => s,1,Set(TIMEOUT(response)=6)
same => n,Set(TIMEOUT(digit)=3)
same => n,Background(custom/main-menu)
same => n,WaitExten(6)
; 1 for sales
exten => 1,1,NoOp(Route to sales queue)
same => n,Goto(queues,sales,1)
; 2 for support
exten => 2,1,NoOp(Route to support queue)
same => n,Goto(queues,support,1)
; 3 for company directory
exten => 3,1,Directory(default,internal,f)
same => n,Goto(main-aa,s,1)
; 0 for operator
exten => 0,1,NoOp(Route to operator)
same => n,Dial(PJSIP/100,20)
same => n,Goto(after-hours,s,1)
; No input
exten => t,1,Playback(custom/no-selection)
same => n,Goto(main-aa,s,1)
; Invalid input
exten => i,1,Playback(pbx-invalid)
same => n,Goto(main-aa,s,1)
[after-hours]
exten => s,1,Playback(custom/after-hours)
same => n,Voicemail(100@default,u)
same => n,Hangup()
Prompt script
Record custom/main-menu with simple language:
Thank you for calling Example Company. For sales, press 1. For support, press 2. For the company directory, press 3. For the operator, press 0.
Avoid long introductions before the options. Repeat callers should not have to wait through branding before pressing a digit.
How it works
Background() plays the prompt while allowing digit input. If the caller presses a valid extension, Asterisk jumps immediately. If no digit is pressed, the t extension handles timeout. If the caller presses a digit that is not defined, the i extension handles invalid input.
TIMEOUT(response) controls how long Asterisk waits for the first digit. TIMEOUT(digit) controls how long it waits between digits when a multi-digit extension is possible.
Production checklist
- Put emergency and operator routes outside complicated menu logic.
- Keep
iandtextensions in every IVR context. - Make after-hours behavior explicit instead of falling through.
- Test from a cell phone and a desk phone because DTMF transport problems often appear only on one path.
- Keep prompts short and name them consistently under
custom/.
See Also
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.