Skip to content

Instantly share code, notes, and snippets.

@armandocanals
Created April 24, 2011 23:06
Show Gist options
  • Save armandocanals/939961 to your computer and use it in GitHub Desktop.
Save armandocanals/939961 to your computer and use it in GitHub Desktop.
SMS Blast using Twilio
require 'rubygems'
require 'open-uri'
require 'csv'
require 'rest_client'
csv = open("path/to/file.csv") # I choose csv, you can choose whatever file you want to loop through
arr = []
CSV.parse(csv) do |row|
cell_num = row[2] #row for cell number
home_num = row[3] #row for home_num
arr << cell_num if cell_num #only push cell_num to array if it exists
arr << home_num if home_num #only push home_num to array if it exists
end
def send_msg(num)
msg = "HELLO EVERYONE"
sleep 1 # Give 1 sec between api requests.
begin
# RestClient.post 'https://{TwilioSID}:{TwilioAuthToken}@api.twilio.com/2010-04-01/Accounts/{TwilioSID}/SMS/Messages', { :From => "+1415*******", :To => num, :Body => msg}
rescue
end
end
arr.each {|x| send_msg "+1#{x.gsub(/\-|\(|\)|/,'').gsub(' ','')}"} #regex used to clean numbers for the twilio api. This is specific to my csv.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment