Record During Dial() - Unusual Problem Requires Creative Solution

Thanks everyone, I managed to solve the problem.

So my initial intuition was right, I was able to solve the issue by using pre-bridge handlers in combination with an AGI script that uses the AMI API to stop the monitor on the original (caller) channel.

The Solution

(in case anyone needs to do this in the future)

:one: The dial() command should look something like this:


exten => 300,n,Dial(SIP/110,30,itTm(stdmusic)M(answered^${CHANNEL}))

:two: The macro should look something like this:


[macro-answered]
exten => s,1,AGI(stop_monitor.agi,${ARG1})

:three: The stop_monitor.agi script should look something like this:


#!/usr/bin/php -q
<?php
$channel = $argv[1];
$socket = fsockopen("localhost","5038", $errno, $errstr, 2);
fputs($socket, "Action: Login\r\n");
fputs($socket, "UserName: <AMI username>\r\n");
fputs($socket, "Secret: <AMI password>\r\n\r\n");

fputs($socket, "Action: StopMonitor\r\n");
fputs($socket, "Channel: $channel\r\n\r\n");
fputs($socket, "Action: Logoff\r\n\r\n");
$wrets=fgets($socket,128);

while (!feof($socket)) { $wrets .= fread($socket, 8192); }
fclose($socket);
?>

Note: remember to setup an Asterisk Manager Interface (AMI) account beforehand. You can do this through FreePBX (if you have it installed) and through the unembedded FreePBX option on Elastix.

Note 2: the AGI script should go in /var/lib/asterisk/agi-bin or wherever your default AGI path is. Also don’t forget to chmod (set the access permissions for) the script file so that it’s executable (755 should do the trick).

1 Like