Asterisk IVR: Basic IVR Configuration (Latest Versions)
Updated guide for modern Asterisk (PJSIP era): basic ivr configuration with real configs, common mistakes, and troubleshooting steps.
A basic IVR is the most common starting point for businesses using Asterisk. It answers calls, plays a menu prompt, waits for keypad input (DTMF), and routes the caller to the correct destination.
This article gives a production-ready basic IVR configuration for modern Asterisk (PJSIP). It includes proper handling for:
- Valid menu choices (1,2,3...)
- Invalid input (i)
- No input timeout (t)
- Repeat menu logic (limited loops)
- Fallback to queue or voicemail
What You Need Before Building IVR
- A working inbound route (from your SIP trunk/provider)
- PJSIP endpoints for agents (e.g., 1001, 1002)
- Optional: queue configured for support/sales
- Custom prompts installed (recommended)
You can build IVR even with only one extension, but it becomes most useful with multiple destinations.
Where IVR Logic Is Written
IVR is dialplan logic, usually inside:
/etc/asterisk/extensions.conf
After changes, you reload dialplan:
asterisk -rx "dialplan reload"
Basic IVR Menu Prompt (Custom Audio)
Example custom menu file:
/var/lib/asterisk/sounds/custom/main-menu.wav
Prompt script example:
- “Thank you for calling.”
- “Press 1 for Sales.”
- “Press 2 for Support.”
- “Press 3 to leave a message.”
IVR uses Background() (not Playback) to listen for digits.
Basic IVR Configuration (Recommended Template)
[main-ivr]
exten => s,1,Answer()
same => n,Set(TIMEOUT(digit)=3)
same => n,Set(TIMEOUT(response)=5)
; Loop control (avoid infinite looping)
same => n,Set(IVR_TRIES=$[${IF($["${IVR_TRIES}"=""]?0:${IVR_TRIES})}+1])
same => n,GotoIf($[${IVR_TRIES} > 3]?fail,1)
same => n,Background(custom/main-menu)
same => n,WaitExten(5)
; Press 1 → Sales (ring group or agent)
exten => 1,1,Playback(custom/connecting-sales)
same => n,Dial(PJSIP/1001&PJSIP/1002,20)
same => n,GotoIf($["${DIALSTATUS}"="ANSWER"]?done,1)
same => n,Goto(fail,1)
; Press 2 → Support queue
exten => 2,1,Playback(custom/connecting-support)
same => n,Queue(support,tT)
same => n,Goto(done,1)
; Press 3 → Voicemail
exten => 3,1,Playback(custom/leave-message)
same => n,Voicemail(1000@default,u)
same => n,Goto(done,1)
; Invalid option
exten => i,1,Playback(pbx-invalid)
same => n,Goto(main-ivr,s,1)
; Timeout (no input)
exten => t,1,Playback(custom/no-input)
same => n,Goto(main-ivr,s,1)
; Fallback after too many tries or call not connected
exten => fail,1,Playback(custom/all-agents-busy)
same => n,Queue(support,tT)
same => n,Voicemail(1000@default,u)
same => n,Goto(done,1)
exten => done,1,Hangup()
This template is safe for production because it:
- Captures DTMF reliably using Background()
- Limits loops using IVR_TRIES
- Has clear fallback routing
Connecting IVR to Incoming Calls
Example inbound context routes calls to IVR:
[from-trunk]
exten => s,1,Goto(main-ivr,s,1)
If your provider sends DID numbers, route by DID:
[from-trunk]
exten => _X.,1,Goto(main-ivr,s,1)
DTMF Notes for SIP Trunks and PJSIP
If callers cannot press options, it is usually DTMF mismatch. Modern systems typically use:
- RFC2833 (Asterisk setting:
dtmf_mode=rfc4733) - Sometimes inband or SIP INFO depending on provider
In PJSIP, DTMF is set per endpoint/trunk. If IVR fails externally but works internally, check trunk DTMF configuration.
Testing the IVR Properly
- Test from internal extensions (simple)
- Test from an external mobile number (real-world)
- Test menu selection and timeout behavior
Watch logs:
asterisk -rvvv
Common IVR Problems and Fixes
Caller Hears Prompt but Key Press Does Not Work
- DTMF mode mismatch on trunk
- Using Playback() instead of Background()
Prompt Does Not Play
- File missing or wrong path
- Incorrect audio format
IVR Loops Forever
- No loop limit logic
- Fix using IVR_TRIES counter
Best Practices for Simple Professional IVRs
- Keep menu short (3–5 options)
- Always provide fallback to queue or voicemail
- Repeat menu only once or twice
- Use human voice prompts for trust
- Use different prompts for sales vs support
Key Takeaway
A basic IVR in Asterisk is dialplan logic: Answer + Background + WaitExten + routing extensions.
The difference between a demo IVR and a production IVR is: timeout handling, invalid input handling, loop control, and fallbacks.
Want to see API-driven CRM + Telecom workflows in action? Try the WhatsApp bot or explore the demos.
Comments (0)
Be the first to comment.