Last active
August 29, 2015 14:23
-
-
Save lippytak/1409552ce161b7fc6a59 to your computer and use it in GitHub Desktop.
Destroy all media from a Twilio phone number
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'twilio-ruby' | |
require 'pry' | |
# This deletes all of the media (not message content) from all messages to a Twilio phone # | |
# Need 3 env vars set: TWILIO_SID, TWILIO_AUTH, and TWILIO_NUMBER | |
def process_multipage_list(list, return_array) | |
list.each do |item| | |
return_array << item | |
end | |
if list.next_page != [] | |
process_multipage_list(list.next_page, return_array) | |
else | |
return return_array | |
end | |
end | |
client = Twilio::REST::Client.new(ENV['TWILIO_SID'], ENV['TWILIO_AUTH']) | |
all_messages = process_multipage_list(client.account.messages.list({:to => ENV['TWILIO_NUMBER']}), Array.new) | |
all_messages.each do |msg| | |
begin | |
puts "media found: #{msg.media.total} (#{msg.sid})" | |
msg.media.list.each do |media| | |
puts " deleting media #{media}" | |
media.delete | |
end | |
rescue Twilio::REST::RequestError => e | |
puts "--" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment