Asterisk time based routing.


This is a very common requirement that route the calls to Voice-mail after office hours. Or you can transfer the calls to your cell phone after certain time say 6:00pm. In Asterisk you can also control the call location based on time and date.

exten => start,1,Verbose(2,Entering our auto-attedant)
same => n,Answer()
same => n,Playback(silence/1)
; We’re closed on New Years Eve, New Years Day, Christmas Eve, and Christmas Day
same => n,GotoIfTime(*,*,31,dec?holiday,1)
same => n,GotoIfTime(*,*,1,jan?holiday,1)
same => n,GotoIfTime(*,*,24,dec?holiday,1)
same => n,GotoIfTime(*,*,25,dec?holiday,1);
We can set auto-attendant dialplan to check for national holidays, if that is true,jump to “exten => holiday,1,Verbose(2,We’re closed for a holiday.)”
; Our operational hours are Monday-Friday, 9:00am to 5:00pm.
same => n,GotoIfTime(0900-1700,mon-fri,*,*?open,1:closed,1) ; It true jump to exten open, else jump to exten closed.
exten => open,1,Verbose(2,We’re open!)
same => n,Background(custom/open-greeting)
exten => closed,1,Verbose(2,We’re closed.)
same => n,Playback(custom/closed-greeting)
same => n,Voicemail(general-mailbox@default,u)
same => n,Hangup()
exten => holiday,1,Verbose(2,We’re closed for a holiday.)
same => n,Playback(custom/closed-holiday)
same => n,Voicemail(general-mailbox@default,u)
same => n,Hangup()
GotoIfTime() application is not only good for an auto-attendant but it can be used anywhere in the dialplan. For example sometimes we just want to forward calls to different people based on time, such as when support staff is not in the office on weekends, but are on call:
exten => 100,1,Verbose(2,Calling Support Staff.)
same => n,GotoIfTime(*,sat&sun,*,*?on_call,1)
same => n,Dial(SIP/support,30)
same => n,Voicemail(support@default,u)
same => n,Hangup()
exten => on_call,1,Verbose(2,Calling On-Call Support Staff.)
same => n,Dial(SIP/didforsale/8888888888&SIP/didforsale/8555555555,30)
same => n,Voicemail(support@default,u)
same => n,Hangup()