Asterisk "Night Service"

We just installed an Asterisk PBX for a customer and there is one last piece of the puzzle that we cannot seem to figure out.  EE has yet to fail me so I have confidence that someone has the answer.

The customer used to forward their calls to an answering service using the call forward codes on the lines.  We also changed them over to a PRI so now we have to forward the lines inside the system using a trunk-to-trunk connection.  We were able to get a quick fix by forwarding one of the phones that rings manually.  The problem is that when the receptionist leaves, she used to forward the calls to where they would ring everywhere so someone who was still in the building could answer the call then when the last person would leave, they would forward the calls to the answering service.  I was hoping somebody knew of a way to call forward a phone from another extension or use a code to change the destination of an incoming call, what we typically call "night service".

In our research we couldn't find anything where Asterisk offered sifferent ringing modes.  We were thinking we might have to build some sort of macro to modify the destinations in the extensions.conf file but we didn't know if there was a better or easier way to accomplish this.

Who is Participating?
feptiasConnect With a Mentor Commented:
It should be possible to assign a dial code for the receptionists phone that sets or resets a value stored in the internal database. Then, in the context that normally directs the calls to the receptionist during the day, you could first check the value of that variable in the database to decide where to send the call.

Here's some ideas for the extensions.conf file (not tested or guaranteed, but taken from code that I know works):
Receptionist dials 1111 to put the system into night mode:
exten => 1111,1,Set(DB(PBX/NightMode)=1)

Receptionist dials 2222 to reset the system back into day mode:
exten => 2222,1,Set(DB(PBX/NightMode)=0)

In the context that normally routes the calls to the receptionist you could add some lines like this:
exten => 0,1,Set(foo=${DB(PBX/NightMode)})            ; lookup night mode state in DB
exten => 0,2,Gotoif($["${foo}" = "1"] ? 8:3)
exten => 0,3,Dial .........                                      ; ring the day mode number(s)

exten => 0,8,Dial .........                                      ; ring the night mode number(s)

I use a lot of Asterisk code like this to distribute incoming calls to different destinations. You have to be a bit careful with the opening/closing brackets and the fiddly syntax.
grbladesConnect With a Mentor Commented:
Have a look at

Using this method you can have two contexts. One will cause the operator phone to ring normally while the other will ring all phones or whatever you wish.
bigbadchadAuthor Commented:
For the most part, that looks like what we might end up doing but the customer is requesting that it not be an automatic change if possible.  Are there any possibilities that require user intervention?
Hi bigbadchad

Were those suggestions for manually operated night mode any help? Do you need any further explanation or is anything missing? Please let us know.

bigbadchadAuthor Commented:
Well, ends up that one of our guys wrote a script that gets called when they dial a code to automatically modify the extensions.conf file so we never really got to test either scenario.  Both of them seem like they would have been a good solution.  Even though I was unable to test them, I am splitting the points.  

Thanks for the quick response guys.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.