Adding contexts outside extensions.conf to inherited system

I am not very experienced with asterisk configuration, but I have inherited responsibility for a non-standard existing setup that is managed entirely by editing config files on the server. Right now, it is basically set up like this:

  • All phones that connect to asterisk are given an entry in users.conf.
  • All users are assigned a phone by name under the [globals] context in extensions.conf, like so: JOHN = SIP/phone1
  • The actual extensions are assigned to users in ext-folks.conf, such as exten => 333,1,Dial(${JOHN})

I need to make one of the extensions defined in ext-folks.conf behave differently based on whether it is being called during business hours or not. I tried to do this based on the examples found here, like so:

exten => 333,1,NoOp(Incoming call...)
  same => n,GotoIfTime(09:00-16:58,mon-fri,*,*?during-hours,s,1)
  same => n,GotoIfTime(10:00-15:28,sat-sun,*,*?during-hours,s,1)
  same => n(during-hours)
    same => n,NoOp(During business time, dialing...)
    same => n,Dial(${USER1},25,hkt)
    same => n,Dial(${USER2},25,hkt)
    same => n,VoiceMail(333@default,u)
    same => n,Hangup
  same => n,Goto(off-hours,s,1)
  same => n(off-hours)
    same => n,NoOp(Off hours, going to voicemail...)
    same => n,VoiceMail(333@default,u)
    same => n,Hangup

The GotoIfTime is working correctly but it cannot find the during-hours or off-hours contexts so the call is 603 declined: “sent to invalid extension but no invalid handler: context,exten,priority=during-hours,s,1”.

Given the file structure above, wherein exten is not present in the same file as contexts, where do I define the [during-hours] and [off-hours] contexts so that they will be recognized by exten?

Try this:

 same => n,GotoIfTime(09:00-16:58,mon-fri,*,*?during-hours)
  same => n,GotoIfTime(10:00-15:28,sat-sun,*,*?during-hours:off-hours)

Also, include at least a Noop call on the lines that define the labels.

I’ve never seen a dialplan without an action on every priority, but can’t say for certain that what you have won’t work.

Good point there @david551, I didn’t notice the missing applications on the labels, those are necessary.

@david551 @johnkiniston Thank you both for your help! I was able to get it working by changing the GotoIfTime placement and adding NoOp to the label definitions.