Our freePBX system uses 3 time conditions, which set the route for the incoming calls (main company number).
- *271 24h-service
- *272 holiday
- *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 ( https://gist.github.com/lgaetz/8545099 ) 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
timeconditions.php
<?php
/**** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** ****
* remotehintpoll.php
*
* Created by Lorne Gaetz [email protected]
*
* Latest version: https://gist.github.com/lgaetz/8545099
*
* 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
$debug=true;
// Remote server host/IP, AMI credentials and
$remote_server = "127.0.0.1";
$remote_name = "user";
$remote_secret = "password";
$remote_context = "from-internal";
// add time conditions (feature codes)
$remote_extension_tc1='*271';
$remote_extension_tc2='*272';
$remote_extension_tc3='*273';
// Connect to local machine with FreePBX bootstrap, requires FreePBX 2.9 or higher
if (!@include_once(getenv('FREEPBX_CONF') ? getenv('FREEPBX_CONF') : '/etc/freepbx.conf')) {
include_once('/etc/asterisk/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);
$remote->disconnect();
}
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);
$remote->disconnect();
}
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);
$remote->disconnect();
}
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
if(stripos($string1,'Idle')){
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