I’m using AMI from my web portal to my freepbx server. It works. The script below connects to the AMI server, makes a call to my cell ($MyCell) and then proceeds to call the $TargetCell to connect my cell and the target cell together in a call. Works fine.
The issue is CallerID ($CompanyName, $CompanyDID). When the AMI calls $MyCell (my cell), it shows the caller ID I’m providing ($CompanyName, $CompanyDID). But when it calls the $TargetCell, it shows $CompanyName (the name part of callerid) as expected, but gives it my cell number instead of $CompanyDID… thus not masking my number and not making it look like they were called from the office as intended (despite of course using the AMI server which is the host of said line).
I can’t seem to figure out WHY.
-
I’m using VOIP Innovations for my trucks, VI Support says they don’t do any re-writes or changes the outbound call… so they don’t feel they are manipulating said change (true? not sure). But when you think about it, VI doesn’t host my cell number either so forcing it to be my cell number as outbound on the second part of the call doesn’t make total sense either.
-
Yes, the number DID I’m using as CallerID are both hosted at VI and on that server - so it’s not a trick or unregistered issue.
Any help would be great. Here’s my code.
(I’m masking the variables, which I already have loaded… and this is the processing form php file that I"m posting. Again, works fine. It’s just all about figuring out the CallerID re-write or whatever issue on the second leg of the call.)
$TargetCell = $_POST['phoneNumber'];
$MyCell = [HIDING IT HERE, IT's A 10-digit DID]
include '../../functions/ami.conf'; // This loads in my AMI creds
// Establish a connection to AMI
$socket = fsockopen($host, $port, $errno, $errstr, 30);
if (!$socket) {
die("Could not connect to AMI: $errstr ($errno)\n");
}
// Helper function to read response
function readResponse($socket) {
$response = '';
while (($line = fgets($socket, 4096)) !== false) {
$response .= $line;
if (trim($line) === '') {
break;
}
}
return $response;
}
// Login to AMI
fputs($socket, "Action: Login\r\n");
fputs($socket, "Username: $username\r\n");
fputs($socket, "Secret: $password\r\n\r\n");
// Read the login response
$loginResponse = readResponse($socket);
//echo "Login Response:\n$loginResponse\n";
if (strpos($loginResponse, 'Success') === false) {
die("Failed to log in to AMI: $loginResponse\n");
}
// Originate the call to your cell phone first
fputs($socket, "Action: Originate\r\n");
fputs($socket, "Channel: Local/$MyCell@from-internal\r\n"); // Call to your phone
fputs($socket, "Exten: $TargetCell\r\n"); // Number to connect to after you pick up
fputs($socket, "Context: from-internal\r\n");
fputs($socket, "Priority: 1\r\n");
// Ensure that the CallerID is set for both legs of the call
fputs($socket, "CallerID: \"$CompanyName\" <$CompanyDID>\r\n"); // Use $CompanyDID for both calls
// Set a timeout
fputs($socket, "Timeout: 30000\r\n"); // 30 seconds timeout
fputs($socket, "Async: true\r\n\r\n");
// Log out from AMI
fputs($socket, "Action: Logoff\r\n\r\n");
// Close the connection
fclose($socket);