Time-Based Routing
Need custom routing, time conditions, or queue logic? Contact me.
Time-Based Routing
Route incoming calls differently depending on the time of day, day of week, and holidays.
Requirements
- Defined business hours
- Separate contexts for open/closed/holiday handling
Dialplan
[incoming]
exten => s,1,Answer()
same => n,GotoIfTime(*,*,25,dec?holiday,s,1)
same => n,GotoIfTime(*,*,1,jan?holiday,s,1)
same => n,GotoIfTime(09:00-17:00,mon-fri,*,*?open,s,1)
same => n,Goto(closed,s,1)
[open]
exten => s,1,NoOp(Business hours -- route to queue)
same => n,Goto(main-queue,s,1)
[closed]
exten => s,1,NoOp(After hours)
same => n,Playback(custom/after-hours)
same => n,Goto(voicemail-main,s,1)
[holiday]
exten => s,1,NoOp(Holiday greeting)
same => n,Playback(custom/holiday-greeting)
same => n,Goto(voicemail-main,s,1)
How it works
- GotoIfTime(time,dow,dom,month?context,ext,pri): Evaluates the current time against the given pattern. If it matches, execution jumps to the specified destination.
- Pattern fields: The four fields are: time range, day-of-week, day-of-month, and month. Use
*as a wildcard for any field. - Evaluation order matters: Asterisk evaluates
GotoIfTimetop to bottom. Place more specific rules (holidays) before general ones so they are evaluated first. - Fallthrough: If no
GotoIfTimematches, execution continues to the next priority, which is theGoto(closed,...)fallback.
Tips
- For dynamic holidays, store dates in AstDB and check with
GotoIf($[${DB_EXISTS(holidays/${date})}]?holiday,s,1). - Use
IFTIMEinIF()expressions for more complex conditional logic. - Set the system timezone in
/etc/asterisk/asterisk.confunder[options]withdefaultlanguageand ensure your OS timezone is correct.
User Notes
No notes yet. Be the first to contribute a tip or example.
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.