How to include contexts based on time and date
The Asterisk dial plan, extensions.conf lets you include contexts based on time and/or date.
Syntax:
include => <context>,<times>,<weekdays>,<mdays>,<months>
Example:
; First, let’s do the holidays.
include => holiday,*,*,1,jan
include => holiday,*,*,31,may
include => holiday,*,*,4,jul
include => holiday,*,*,6,sep
include => holiday,17:00-23:59,*,24,nov
include => holiday,*,*,25,nov
include => holiday,17:00-23:59,*,24,dec
include => holiday,*,*,25,dec
include => holiday,17:00-23:59,*,31,dec
; These are the days we’re open.
include => day,09:00-19:59,mon-fri,*,*
include => day,10:00-14:59,sat,*,*
; If we’re not open, we’re closed.
include => night
Example from Troy Settle
- Asterisk config extensions.conf: The dial plan
- Asterisk cmd GotoIfTime: Conditional goto based on time/date
I ran into a problem with this. The night context is always included in this scenario, and if the night context contains the same extensions as the day context, Asterisk will continue with the night context if the extensions match:
exten => s,8,BackGround(to-hear-menu-again)
will jump to:
exten => s,9,BackGround()
To prevent this, specify an explicit night include:
include => night,15:00-9:59,sat,*,*
include => night,*,sun,*,*