Hi, a very good afternoon to all of you !!!
how can we originate outbound call by php AMI ,play voice file and store the DTMF enter by caller(call receiver) by using php AMI or by dialplan and if possible then shared the document and if you have any other idea then also shared ,b’coz i have tried so many time but didn’t get any success. I am using below mention code but i am not understanding the what should be added to do my task i.e how can i got dtmf on outgoing call ?
my testing code is given below
<?php
$port = 5038;
$username = "asterisk";
$context = "12345";
$socket = stream_socket_client("tcp://localhost:5038");
if($socket)
{
echo "Connected to socket, sending authentication request.\n";
// Prepare authentication request
$authenticationRequest = "Action: Login\r\n";
$authenticationRequest .= "Username: asterisk\r\n";
$authenticationRequest .= "Secret: 12345\r\n";
$authenticationRequest .= "Events: on\r\n\r\n";
// Send authentication request
$authenticate = stream_socket_sendto($socket, $authenticationRequest);
if($authenticate > 0)
{
// Wait for server response
usleep(200000);
// Read server response
$authenticateResponse = fread($socket, 4096);
// Check if authentication was successful
if(strpos($authenticateResponse, 'Success') !== false)
{
echo "Authenticated to Asterisk Manager Inteface. Initiating call.\n";
$originateRequest = "Action: Originate\r\n";
$originateRequest .= "Channel: SIP/tatasip/${Exten}r\n";
$originateRequest .= "Callerid: 7582963145\r\n";
$originateRequest .= "Application: Playback\r\n";
$originateRequest .= "Data: /usr/file\r\n";
$originateRequest .= "Context: amitest\r\n";
$originateRequest .= "Exten: 91111\r\n";
fputs($socket, "Account:23456\r\n" );
$originateRequest .= "Priority: 2\r\n";
$originateRequest .= "ActionID: 123\r\n";
$originateRequest .= "Async: yes\r\n\r\n";
$originate = stream_socket_sendto($socket, $originateRequest);
}
// Send originate request
// $originate = stream_socket_sendto($socket, $originateRequest);
if($originate > 0)
{
// Wait for server response
usleep(1000);
while(true) {
// Read server response
$originateResponse = fread($socket, 4096);
echo $originateResponse . "\n";
}
$responce=fgets($socket,4096);
echo $responce."\n";
// Check if originate was successful
if(strpos($originateResponse, 'Success') !== false)
{
echo "Call initiated, dialing.\n";
} else {
echo "Could not initiate call.\n";
}
} else {
echo "Could not write call initiation request to socket.\n";
}
} else {
echo "Could not authenticate to Asterisk Manager Interface.\n";
}
} else {
echo "Could not write authentication request to socket.\n";
}
//else {
echo "Unable to connect to socket.";
//}
echo $originateResponse;
?>
tttt.txt (2.9 KB)