Hello,
I am developing a PHP application that uses plivo to call some numbers
and when call is received by the recipient, a recorded message will be
played.
I have been successful in making calls to my provided numbers through
plivo, but I am unable to figure out how to play a recorded message
when call is received.
Following is my PHP code:
$client = new PlivoRestClient($REST_API_URL, $AccountSid, $AuthToken,
$ApiVersion);
$extra_dial_string =
"bridge_early_media=true,hangup_after_bridge=true";
# Initiate a new outbound call to user/1000 using a HTTP POST
$call_params = array(
'Delimiter' => '>', # Delimter for the bulk list
'From'=> '919191919191', # Caller Id
'To' => '1000>1001', # User Numbers to Call separated by
delimeter
'Gateways' => "user/>user/", # Gateway string for each number
separated by delimeter
'GatewayCodecs' => "'PCMA,PCMU'>'PCMA,PCMU'", # Codec string
as needed by FS for each gateway separated by delimeter
'GatewayTimeouts' => "60>30", # Seconds to timeout in string
for each gateway separated by delimeter
'GatewayRetries' => "2>1", # Retry String for Gateways
separated by delimeter, on how many times each gateway should be
retried
'ExtraDialString' => $extra_dial_string,
'AnswerUrl' => "
http://192.168.100.62:5000/answered/",
'HangupUrl' => "
http://192.168.100.62:5000/hangup/",
'RingUrl' => "
http://127.0.0.1:5000/ringing/",
);
try {
// Initiate various calls
$response = $client->bulk_call($call_params);
print_r($response);
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
exit(0);
}
// check response for success or error
if($response->IsError) {
echo "Error starting phone calls: {$response->ErrorMessage}
\n";
} else {
//echo "Started calls: {$response->Response->RequestUUID[0]}
\n";
//test if call has been received on this answerURL
//
http://192.168.100.62:5000/answered/
// HOW to TEST?
if( test that call is answered ) {
$play_params = array(
'CallUUID' => "{$response->Response->RequestUUID[0]}",
'Sounds' => "/usr/local/freeswitch/recordings/test.wav",
);
$response2 = $client->play($play_params);
print_r($response2);
}
}
Kindly tell me if I am doing this right way?