Skip to content

Instantly share code, notes, and snippets.

@po5i
Forked from caseysoftware/targetted-delete.php
Last active April 9, 2018 22:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save po5i/2da778a0e32134fd110f88486471ec0e to your computer and use it in GitHub Desktop.
Save po5i/2da778a0e32134fd110f88486471ec0e to your computer and use it in GitHub Desktop.
This is a simple script using the Twilio PHP Helper library to retrieve Calls within a certain date range and the delete their associated recordings if they're particularly short.
<?php
// Get the PHP helper library from https://twilio.com/docs/libraries/php
require_once '/path/to/vendor/autoload.php';
use Twilio\Rest\Client;
// Your Account Sid and Auth Token from twilio.com/console
$sid = "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
$token = "your_auth_token";
$toNumber = "{fill this in with your number}";
$twilio = new Client($sid, $token);
$calls = $client->calls->read(
array("to" => $toNumber, "startTimeBefore" => "2011-11-10")
);
foreach ($calls as $call) {
if ($call->duration < 20) {
echo "Call: " . $call->sid . " -- " . $call->start_time . "\n";
$recordings = $call->recordings;
foreach($recordings as $recording) {
echo "Deleting: " . $recording->sid . "\n";
$client->recordings($recording->sid)->delete();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment