Asterisk "Night Service"

Posted on 2006-06-05
Last Modified: 2010-08-05
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.

Question by:bigbadchad
    LVL 36

    Assisted Solution

    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.

    Author Comment

    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?
    LVL 19

    Accepted Solution

    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.
    LVL 19

    Expert Comment

    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.


    Author Comment

    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.

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Join & Write a Comment

    Although VoiceOver IP has been around for a while, internet connections have only recently become fast enough to provide good call quality. Now, VoIP has become a real option for businesses looking at ways to improve their business model. In this ar…
    I recently purchased a Bluetooth headset called the Music Jogger (model BSH10). The control buttons on it look like this: One of my goals is to use it as the microphone and speakers for Skype calls. In that respect, it works well. However, I …
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now