There are some very handy functions for AMI described in Digium docs that are not included in FreePBX’s Asterisk Manager Class (php-asmanager.php), which is, IMHO an essential tool for FreePBX development and customization.
I needed them for a project where I have to put call control buttons on the client’s CRM form. (Actually and FOP2 mini-browser frame.) They have about 500 agents and over 1000 queues, and each queue only has a half dozen or so other escalation and up-sell queues they can transfer to. When an agent gets a call, I have to populate a SELECT from which the agent will select the queue or extension to transfer the call, and the blind or attended transfer method.
I was trying all manner of unusual solutions, all resulting in very UNelegant code, until I decided to try to add them into php-asmanager.php. Should have started there, it was far easier than I thought. Which led me to wonder WHY they weren’t there in the first place. Oversight? More likely doing this is considered a bad idea for some reason, so Schmooze didn’t do it. The code below seems to be working fine, but is this all going to blow up in my face?
I hope someone knowledgable will let me know if I have a gun aimed at my foot. Here’s what I did to php-asmanager.php:
function Atxfer($channel, $exten, $context, $priority) { return $this->send_request('Atxfer', array('Channel'=>$channel, 'Exten'=>$exten, 'Context'=>$context, 'Priority'=>$priority)); } function CancelAtxfer($channel) { return $this->send_request('CancelAtxfer', array('Channel'=>$channel)); } function PlayDTMF($channel, $digit) { return $this->send_request('PlayDTMF', array('Channel'=>$channel, 'Digit'=>$digit)); }
When I say this is working correctly I mean that I see stuff that looks normal to my non-expert eyes when monitoring AMI transactions in the CLI with “> manager set debug on”
However, I’m sure you have to send the correct channel to Atxfer and CancelAtxfer. When I send the inbound (from-pstn or from-trunk) channel, it seems to bridge all three parties. Being curious, I experimented with PlayDTMF to do the transfers the old reliable way: feature codes on the agent phone. The code below shows how I implemented it. I left in the original code that used Atxfer and CancelAtxfer so someone might tell me what I did wrong there.
$act=$_REQUEST['action']; $ext=$_REQUEST['tgtExt']; $CallData=$_SESSION['CallData']; switch ($act) { case 'Blind': $res=$astman->Redirect($CallData['chan'],'',$ext,'from-queue','1'); break; case 'Attended': $dtmf='*2' . $ext; $digits=str_split($dtmf); $i=0; foreach($digits as $digit) { $i++; // agent channel is the ";2" channel from 'core show channels concise' $out=$astman->PlayDTMF($CallData['AgentChan'],$digit); $res.="$i. sent $digit, got " . implode(':',$out) . ", "; } logit("CA-Atxfer DTMF: $res"); // $res=$astman->Atxfer($CallData['chan'],$ext,'ext-queues','1'); break; case 'Cancel': $dtmf='*5'; $digits=str_split($dtmf); $i=0; foreach($digits as $digit) { $i++; $out=$astman->PlayDTMF($CallData['AgentChan'],$digit); $res.="$i. sent $digit, got " . implode(':',$out) . ", "; } logit("CA-CXL-Atxfer DTMF: $res"); // $res=$astman->CancelAtxfer($CallData['chan']); break; case 'HangUp': // agent channel is the ";2" channel from 'core show channels concise' $res=$astman->Hangup($CallData['AgentChan']); break; default: echo "Invalid Action!"; exit(0); }
The DTMF method is working fine, but I would like to debug the Atxfer method. Anyone have an idea?