Hello Team,
I have written AMI Originate code in PHP, Everything is working fine except one thing Call Status response in PHP Code.
Let me brief you the requirement, When I hit AMI code in the browser it make outbound call to the user phone, if user cancel / accept the incoming call then browser show call status either NO ANSWER/ ANSWERED.
Below is My Code :
<?php
if (true){
$asterisk_ip = 'localhost';
$calling_number = $_REQUEST['calling_number'];
$user = 'USER';
$pass = 'PASSWORD';
$channel = '@outbound';
$called_exten = 'XXXXXXX';
$id = $_REQUEST['id'];
if ( ! empty( $calling_number ) ){
$timeout = 10;
$socket = fsockopen($asterisk_ip,"5038", $errno, $errstr, $timeout);
fputs($socket, "Action: Login\r\n");
fputs($socket, "UserName: $user\r\n");
fputs($socket, "Secret: $pass\r\n\r\n");
fputs($socket, "Action: Originate\r\n" );
fputs($socket, "Channel: Local/$calling_number@outbound-ami-status/n\r\n" );
fputs($socket, "Exten: $calling_number\r\n" );
fputs($socket, "Context: outbound\r\n" );
fputs($socket, "Priority: 1\r\n" );
fputs($socket, "Callerid: XXXXXXX\r\n" );
fputs($socket, "WaitTime: 5\r\n" );
fputs($socket, "Variable: web_lead_id=$id\r\n");
fputs($socket, "Async: true\r\n" );
fputs($socket, "Action: logoff\r\n\r\n" );
$i=0;
while($i<5){
if(!feof($socket)){
$wrets .= fread($socket, 128);
}
$i++;
}
fclose($socket);
} else{
echo "Unable to determine number from (" . $_REQUEST['calling_number'] . ")\r\n";
}
} else{
echo "Please Enter Correct Customer Mobile Number";
}
?>
Please help on this if something I missed to add here in the code please advice.
I believe we need to do some changes in this code only
$i=0;
while($i<5){
if(!feof($socket)){
$wrets .= fread($socket, 128);
}
$i++;
}
Awaiting for your response.