Call a PHP script on Ring Group

Greetings,

We are working on a script that will call a call monitoring php script sending the CDR and the GROUP ID to the script and then we will do additional processing (example send SMS to relevant persons or e-mail alerts, lookup the CDR in our databases etc.).

I would appreciate insights on the best way to do this in the FreePBX context of modifying the files.

At the moment we had an asterisk engineer get it working by:

Modifying /var/lib/asterisk/agi-bin/dialparties.agi

Modifying /etc/asterisk/sip_registrations_custom.conf

Then adding the new custom ring group that triggers the alert to the respective group.

It was working for a while but then stopped working.

Here is what we did to the agi script:

// Start with Arg Count set to 3 as two args are used
$arg_cnt = 3;
while($arg = get_var($AGI,“ARG”. $arg_cnt)) {
// not sure why, dialparties will get stuck in a loop if noresponse
if ($arg == ‘-’) {
debug(“get_variable got a “noresponse”! Exiting”,3);
exit($arg_cnt);
}
$extarray = preg_split( ‘/-/’, $arg );
foreach ( $extarray as $k ) {
$ext[] = $k;
debug(“Added extension $k to extension map”, 3);
if ($k == 1501){
$notifygroup = 1000; }
elseif ($k = 1502) {
$notifygroup = 1400; }
elseif ($k = 1503) {
$notifygroup2 = 1003; }
elseif ($k = 1504) {
$notifygroup2 = 1401; }
elseif ($k = 1505) {
$notifygroup2 = 1402; }
}
$arg_cnt++;
}

if ($notifygroup != 0) {
$curl = curl_init(“http://OURSITEGOESHERE/callmonitor.php?CDR=$cidnum&group=$notifygroup”);
curl_setopt($curl, CURLOPT_FAILONERROR, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($curl);
debug(“NOTIFIED GROUP $notifygroup WITH NUMBER $cidnum”, 3);
}

if ($notifygroup2 != 0) {
$curl = curl_init(“http:/OURSITEGOES HERE/callmonitors/terrafirma.php?CDR=$cidnum&group=$notifygroup2”);
curl_setopt($curl, CURLOPT_FAILONERROR, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($curl);
debug(“NOTIFIED GROUP $notifygroup2 WITH NUMBER $cidnum”, 3);
}

And:

To registrations_custom we did:

register=1501:[email protected]/1501
register=1502:[email protected]/1502
ETC. FOR OTHERS

It worked fine for a while but then stopped I think when I updated FreePBX.

I would appreciate insights from the community experts please and also best and most elegant way to acheive the same.

Martin

I expect the most stable method would be to put an AGI() call into ext-grp-custom that would run your AGI script of choice. Not sure if this is as flexible as you want, but at least you wouldn’t have to worry about mucking with built-in AGI and making sure it never gets overwritten.

Other option is to catch it before it hits the ring group (IVR or inbound route, for example) and point it to your custom dialplan which then sends the call on to ext-grp.

Thanks to all who replied, yes our contractor had modified:

Modifying /var/lib/asterisk/agi-bin/dialparties.agi

And just as stated when we updated FreePBX this got overwritten.

I would appreciate step by step guide how to implement without modifying dialparties.agi perhaps someone could PM me.

Martin

Please do not solicit for private help in the forums. Folks will either help you in public or not.

This is a very detailed request. You paid someone to do it once, you will probably have to pay someone to do it again, this time the correct way so it does not get overwritten.

Hint: Create your own AGI and call it from custom destination module.