Monitor multiple time conditions (If-then-construct)

Our freePBX system uses 3 time conditions, which set the route for the incoming calls (main company number).

  1. *271 24h-service
  2. *272 holiday
  3. *273 standard business hours

TC1 non-match links to TC2, which in case of a non-match links to TC3.
TimeCondition 1 and 2 are connected to online calendars using the new calendar module. TimeCondition 3 uses a TimeGroup (Mo-Fr 8-18h, Sa 8-12h). The holiday online calendar generates Austrian holiday dates and the 24h-service-calendar contains, in our case, a 24h-event every 9th day.
Based on this setting with these 3 TimeConditions, one can cover almost all possible scenarios. A 24h-service-event overrules both other time conditions. A holiday-event overrules the standard-business-hours.

Now…the problem!
It is not possible to monitor the freePBX phone system with multiple time conditions. Are we open or are we closed? You cant tell…

I don’t know how to write a php script, therefore I used the script from lgaetz ( ) and adapted it.

This is my current script. It gives you the following outputs in the terminal (which can be used to display it on a phone): 24h-service, holiday, we are open, we are closed


    /**** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** 
     * remotehintpoll.php
     * Created by Lorne Gaetz [email protected] 
     * Latest version:
     * Licensed under GNU GPL version 2 or any later verison.
     * Version history:
     *			2014-01-21  Initial commit for single extension
     *			2017-06-22  Add support to poll a range of extensions and update a local dynamic hint	
     *			2019-02-11  adapted & abused by R. Stindl
     **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** ****/
    // set to true to echo debug

    // Remote server host/IP, AMI credentials and 
    $remote_server = "";
    $remote_name = "user";
    $remote_secret = "password";
    $remote_context = "from-internal";

    // add time conditions (feature codes)

    // Connect to local machine with FreePBX bootstrap, requires FreePBX 2.9 or higher
    if ([email protected]_once(getenv('FREEPBX_CONF') ? getenv('FREEPBX_CONF') : '/etc/freepbx.conf')) {
    // connect to remote Asterisk machine using AMI credentials and get status of Extension 103
    $remote = new AGI_AsteriskManager();
    if ($remote->connect($remote_server, $remote_name, $remote_secret)) {
    		$foo1[$remote_extension] = $remote->ExtensionState($remote_extension_tc1, $remote_context);

    else {
    	output("Can not connect to remote AGI");
    $string1 = print_r($foo1, true); 

    if ($remote->connect($remote_server, $remote_name, $remote_secret)) {
    		$foo2[$remote_extension] = $remote->ExtensionState($remote_extension_tc2, $remote_context);

    else {
    	output("Can not connect to remote AGI");
    $string2 = print_r($foo2, true); 

    if ($remote->connect($remote_server, $remote_name, $remote_secret)) {
    		$foo3[$remote_extension] = $remote->ExtensionState($remote_extension_tc3, $remote_context);

    else {
    	output("Can not connect to remote AGI");
    $string3 = print_r($foo3, true); 
//now you have to list your time condition in a logical order, Idle stands for a match, InUse for a non-match
    	echo "24h-service";
    } elseif(stripos($string2,'Idle')){
    	echo "holiday";
    } elseif(stripos($string3,'Idle')){
    	echo "we are open";
    } elseif(stripos($string3,'InUse')){
    	echo "we are closed";
    } else {
        echo "Houston, we have a problem";

Ideas, suggestions, corrections and thoughts…are welcome :wink:

You are including the freepbx framework so you don’t need to start another ami session. Just use the ami that is already provided to you and already logged in

$astman = FreePBX::create()->astman

There is no need to connect either. It’s already connected.

I see…thanks…problem is that I don’t know nothing about php (and AMI). I just searched for some php commands which would extract the combined extension state info out of the arrays…and played around with them until I got it working…
I still wait for my Digium D65 and will try to implement it later.

EDIT: I will try to remove all the remote-server stuff, later in the evening.

Currently working on this script, which is still rough, but you can probably adapt it for your purposes

1 Like

Wonderful…thank you so much!!!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.