Asterisk Dialplan: Dialplan shortcuts (Latest Versions)
Updated guide for modern Asterisk (PJSIP era): dialplan shortcuts with real configs, common mistakes, and troubleshooting steps.
Writing Asterisk dialplan can quickly become long and repetitive. To solve this, Asterisk provides several dialplan shortcuts that make configurations cleaner, shorter, and easier to maintain.
These shortcuts are not just convenience features — they are essential for building large-scale production dialplans in modern Asterisk with PJSIP.
This guide explains the most important shortcuts developers and telecom engineers actually use in real deployments.
Why Dialplan Shortcuts Matter
- Reduce duplicate code
- Prevent priority numbering mistakes
- Improve readability for teams
- Make large dialplans maintainable
Without shortcuts, dialplan files become extremely difficult to manage.
Shortcut 1 — Using same => n Instead of Manual Priorities
Old style dialplan required numbering every step:
exten => 1000,1,Answer()
exten => 1000,2,Playback(hello-world)
exten => 1000,3,Hangup()
Modern dialplan uses:
exten => 1000,1,Answer()
same => n,Playback(hello-world)
same => n,Hangup()
Benefits:
- No need to track numbers manually
- Easier to insert new steps later
- Cleaner and safer production code
Shortcut 2 — Using Labels Inside Extensions
Labels allow jumping to meaningful names instead of numbers.
exten => 2000,1,Dial(PJSIP/1001,20)
same => n,GotoIf($["${DIALSTATUS}"="NOANSWER"]?voicemail)
same => n,Hangup()
same => n(voicemail),Voicemail(1001@default)
same => n,Hangup()
This is much easier than jumping to priority numbers like Goto(2000,5).
Shortcut 3 — Pattern Matching Instead of Listing Every Extension
Instead of defining:
exten => 1001,1,...
exten => 1002,1,...
exten => 1003,1,...
Use a pattern:
exten => _10XX,1,Dial(PJSIP/${EXTEN},20)
same => n,Hangup()
This single rule handles 1000-1099.
Shortcut 4 — Using Variables to Avoid Repetition
Variables reduce duplication:
exten => 3000,1,Set(TARGET=1001)
same => n,Dial(PJSIP/${TARGET},20)
same => n,Hangup()
This is useful for:
- Dynamic routing
- Database-driven dialing
- Reusable dial logic
Shortcut 5 — Using Includes to Split Large Dialplans
Large systems never keep everything in one context.
[from-internal]
include => internal-extensions
include => internal-features
include => outbound-calls
Benefits:
- Cleaner architecture
- Easier debugging
- Team-friendly structure
Shortcut 6 — Using h Extension for Hangup Logic
The special extension h runs when a call ends:
exten => h,1,NoOp(Call ended with status ${DIALSTATUS})
same => n,Hangup()
Useful for:
- Call logging
- API callbacks
- Recording cleanup
Shortcut 7 — Using s Extension for Inbound Calls
Many inbound trunks start at extension s:
[from-trunk]
exten => s,1,Answer()
same => n,Dial(PJSIP/1001,20)
same => n,Hangup()
This is standard behavior in SIP trunk routing.
Shortcut 8 — Using Functions Inside Dialplan
Functions provide dynamic behavior:
same => n,Set(CALLER=${CALLERID(num)})
same => n,NoOp(Caller number is ${CALLER})
Common real-world uses:
- Database lookups
- Time-based routing
- CRM integrations
Common Mistakes When Using Shortcuts
- Forgetting that pattern rules can override exact extensions
- Jumping to wrong labels in
Goto() - Using variables before setting them
- Placing includes in wrong order
Dialplan execution order always matters.
Production Dialplan Structure Using Shortcuts
[from-internal]
include => extensions
include => features
include => outbound
[extensions]
exten => _10XX,1,Dial(PJSIP/${EXTEN},20)
same => n,Hangup()
This structure scales from 10 users to thousands.
Key Takeaway
Dialplan shortcuts are not optional — they are required for building clean, scalable, and maintainable Asterisk systems.
Mastering: same => n, labels, patterns, variables, includes, and special extensions allows you to design telecom logic that works reliably in production.
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.