Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion demo/_credentialsSample.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@
"extension": "",
"password": "",
"fromPhoneNumber": "16501112222",
"toPhoneNumber": "14151112222"
"toPhoneNumber": "14151112222",
"dateFrom": "2015-10-20",
"dateTo": "2015-10-24"
}
62 changes: 57 additions & 5 deletions demo/callRecording.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,32 +23,84 @@

$callLogRecords = $platform->get('/account/~/extension/~/call-log', array(
'type' => 'Voice',
'withRecording' => 'True'))
'withRecording' => 'True',
'dateFrom' => $credentials['dateFrom'],
'dateTo' => $credentials['dateTo']))
->json()->records;

foreach ($callLogRecords as $callLogRecord) {
// Create a CSV file to log the records

$status = "Success";
$dir = $credentials['dateFrom'];
$fname = "recordings_${dir}.csv";
$fdir = "/DownloadRecordings/Recordings/${dir}";

// check if the directory exists
// mkdir('/AllianceRecordings/Recordings/${dir}', 0700);

if (is_dir($fdir) === false)
{
mkdir($fdir, 0777, true);
// mkdir("/AllianceRecordings/JSON/${dir}", 0755, true);
}

$file = fopen($fname,'w');
$fileHeaders = array("RecordingID","ContentURI","Filename","DownloadStatus");
fputcsv($file, $fileHeaders);
$fileContents = array();




$timePerRecording = 6;

foreach ($callLogRecords as $i => $callLogRecord) {

$id = $callLogRecord->recording->id;

print "Downloading Call Log Record ${id}" . PHP_EOL;

$uri = $callLogRecord->recording->contentUri;

print "The contentURI is : ${uri}";

print "Retrieving ${uri}" . PHP_EOL;

$apiResponse = $platform->get($callLogRecord->recording->contentUri);

$ext = ($apiResponse->response()->getHeader('Content-Type')[0] == 'audio/mpeg')
? 'mp3' : 'wav';

file_put_contents("recording_${id}.${ext}", $apiResponse->raw());
$start = microtime(true);

file_put_contents("${fdir}/recording_${id}.${ext}", $apiResponse->raw());

$filename = "recording_${id}.${ext}";

if(filesize("${fdir}/recording_${id}.${ext}") == 0) {
$status = "failure";
}

print "Wrote Recording for Call Log Record ${id}" . PHP_EOL;

file_put_contents("recording_${id}.json", json_encode($callLogRecord));
file_put_contents("${fdir}/recording_${id}.json", json_encode($callLogRecord));

print "Wrote Metadata for Call Log Record ${id}" . PHP_EOL;

}
$end=microtime(true);

// Check if the recording completed wihtin 6 seconds.
$time = ($end*1000 - $start * 1000);
if($time < $timePerRecording) {
sleep($timePerRecording-$time);
}


$fileContents = array($id, $uri, $filename, $status);
fputcsv($file, $fileContents);

}

fclose($file);

?>