Skip to content

Instantly share code, notes, and snippets.

Last active Jan 4, 2016
What would you like to do?
Basic script of the Twilio Live Demo to introduce Twilio's API
#Add Ruby Library
require "twilio-ruby"
#Connect to my account
@client = 'AccountSid', 'AuthToken'
#Assiging that object so it easier to access my Account
@account = @client.account
#Get a list of all available US phone numbers
@account.available_phone_numbers.get('US').local.list({:area_code => '415'})
#Will assign n to the first number of that list
n = _[0]
#Let's purchase that phone number
@account.incoming_phone_numbers.create(:phone_number =>n.phone_number)
#Assign the phone number you just bought to variable 'my_number'
my_number = _
#Configuring Twilio phone number to a Voice application
my_number.update({:voice_url => ''})
#Or Configure to SMS application
my_number.update({:sms_url => ''})
#Display phone number for people to call
#Ask audience to call or text
#Here's a list of all the people who have called my number
@account.calls.list({:to => my_number.phone_number}).each do |x|
puts x.from
#Send SMS messages to all callers
@account.calls.list({:to => my_number.phone_number}).each do |x|
@account.sms.messages.create(:from => my_number.phone_number, :to =>x.from, :body => 'Thanks!')
#SMS Body
Thanks for watching the Twilio demo!
#Variation: Can also call all incoming callers and place them in a conference room to make those phones ring.
@account.calls.list({:to =>my_number.phone_number}).each do |x|
@account.calls.create({:from=>my_number.phone_number, :to=>x.from, :url => ''})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment