Skip to content

Instantly share code, notes, and snippets.

@tristanjahier
Last active May 7, 2019 05:26
Show Gist options
  • Save tristanjahier/e46088d019e1e15e1443 to your computer and use it in GitHub Desktop.
Save tristanjahier/e46088d019e1e15e1443 to your computer and use it in GitHub Desktop.
A script to mass delete Twilio recordings using the Node.js helper library

Twilio recordings mass delete script

This is a Node.js script, written in CoffeeScript. Of course you'll need Node.js and NPM. Additionally, it requires the Coffee Script compiler/interpreter and the Twilio package.

npm install -g coffee-script
npm install twilio

Once everything is ready, you can run the script like that:

coffee twilio-recordings-mass-delete.coffee

If it does not work, compile to JavaScript and run it with Node:

coffee -c twilio-recordings-mass-delete.coffee
node twilio-recordings-mass-delete.js
require 'twilio/lib'
# ----------------------------------------------------------------
# Script requirements & configuration (fill in the blanks)
config =
accountSID: '<FillMe>'
authToken: '<FillMe>'
options: # custom options to filter the recordings
pageSize: 100
# https://www.twilio.com/docs/api/rest/recording#list-get-filters
"dateCreated<": "2015-02-01"
# ----------------------------------------------------------------
client = require('twilio')(config.accountSID, config.authToken)
readyToWork = true
jobIsDone = false
totalNumDestroyed = 0
unleashWrathOnRecordings = ->
# Retrieve a list of 'pageSize' recordings
client.recordings.list config.options, (err, data) ->
numToDestroy = data.recordings.length
numDestroyed = 0
# Check if the end is reached
if numToDestroy == 0
jobIsDone = true
return
if numToDestroy < config.options.pageSize
jobIsDone = true
# For each recording, send an API request to destroy it
data.recordings.forEach (recording) ->
client.recordings(recording.sid).delete (err, data) ->
if err
console.error "\x1b[31mError: #{err.status}\x1b[39m"
else
console.log "\x1b[31m✘\x1b[39m #{recording.sid}"
numDestroyed++
totalNumDestroyed++
if numDestroyed >= numToDestroy
readyToWork = true
burstCount = 0
loopID = setInterval(->
if jobIsDone
clearInterval(loopID)
console.log "\x1b[42m\x1b[37m \\o/ Done! \\o/ \x1b[39m\x1b[49m\n\
\x1b[42m\x1b[37m Hey I've just destroyed #{totalNumDestroyed} recordings forever! \x1b[39m\x1b[49m\n\
\x1b[42m\x1b[37m I killed them. They cried in the process. :) \x1b[39m\x1b[49m"
return
if readyToWork
burstCount++
console.log "\x1b[36m==> Burst n°#{burstCount}\x1b[39m"
unleashWrathOnRecordings()
readyToWork = false
, 2000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment