4
votes

I need to have a perl or php script run every time a call is answered (by a person using a sip phone).

I am using FreePBX, and that system will be used to manage extensions, so whatever I do I need to make sure that adding a new extension or modifying one from the FreePBX interface won't wipe out the part that calls the script.

The person may dial the extension directly, have gotten to the extension via a Ring Group or IVR, or they may have been transferred. The script needs to run in all cases.

I know I need to add a line in one of the configuration files along the lines of:

exten => s,n,System(myperlscript.pl "caller=${ARG1} exten=${ARG2} called=${ARG3}")

That is just a sample bit of code, and I can most likely figure out that part.

The problem is I don't know what configuration file to put it in, or where to put it in that file.

1
I'm looking for something VERY similar, but to run a script when a specific extension answers and finishes a call. Any ideas?!daneee
The code below would pass the specific extension to the php script, so you could just have the PHP not do anything unless it matches the extension you want. I'm too rusty to remember how to trigger something at the end of a call. I would think in that same file you can run another php script via AGI. Do you need to trigger something in realtime? If not you could just access the call logs in the MySQL database. You would have the extension, and all of the details of the call available there. That would just be some simple queries for that and it wouldn't interfere with the phone system.Developer Gee

1 Answers

0
votes

I figured it out, so I'll put the answer on here in case it helps anyone.

Within the FreePBX web admin there are two files

/libararies/extensions.class.php /modules/core/functions.inc.php

In extensions.class.php I added the following class

class ext_crmagi extends extension {
    var $pri;
    var $ext;
    var $context;

function ext_crmagi($pri, $ext = false, $context = false) {
    if ($context !== false && $ext === false) {
        trigger_error("\$ext is required when passing \$context in ext_crmagi::ext_crmagi()");
    }

    $this->pri = $pri;
    $this->ext = $ext;
    $this->context = $context;
}

function incrementContents($value) {
    $this->pri += $value;
}

function output() {
    return 'AGI(myphpscript.php, ${CALLERID(num)}, ${CALLERID(name)}, ${EXTEN}, ${SIPCALLID}, ${UNIQUEID})' ;
}
}

The in functions.inc.php I added

$ext->add('ext-local', $exten['extension'], '', new ext_crmagi('',''));

Then anytime you use the web interface to add an extension it will add in the agi script as well, allowing you to use php to interface with asterisk.