How to Play .wav file after Call answer in Plivo

145 views
Skip to first unread message

Falak Nawaz

unread,
Nov 15, 2011, 2:47:02 AM11/15/11
to Plivo Users
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?

Dhairya Vora

unread,
Nov 15, 2011, 3:53:53 AM11/15/11
to plivo...@googlegroups.com
when the call is accepted by the called person, answerURL is called. for example, if the answerURL="http://mysite.com/file1.php", then file1.php should contain

<?php
require "plivohelper.php";
$r = new Response();
$r->addPlay("/usr/local/freeswitch/recordings/test.wav");
$r->Respond();
?>

If you wish, you can add $r->addRedirect("http://mysite.com/file2.php"); or $r->addHangup(); 

-Dhairya

Falak Nawaz

unread,
Nov 16, 2011, 1:53:42 AM11/16/11
to Plivo Users
Thanks Dhairya. It worked.
Reply all
Reply to author
Forward
0 new messages