Skip to content
Create a gist now

Instantly share code, notes, and snippets.

Embed URL


Subversion checkout URL

You can clone with
Download ZIP
Need to be notified of something immediately via telephone? Twilio/AWS/Ruby mashup to do just that
require 'twilio-ruby'
require 'aws'
# Creates a phone call using the Twilio and AWS SDK's that uses text-to-speech to play a message
# Expected to be called from the command line with the respective arguments
# Creates an XML document that is uploaded to S3. This XML document tells Twilio what to do once the call is connected
# pass your Twilio creds via environmental variables
twilio_sid = ENV['TWILIO_SID']
twilio_token = ENV['TWILIO_TOKEN']
# pass your AWS information via environemental variables
aws_key_id = ENV['AWS_KEY_ID']
aws_secret_access_key = ENV['AWS_SECRET_ACCESS_KEY']
aws_bucket = ENV['AWS_BUCKET'] # this bucket should already exist
# you might set the lifecycle on this bucket to delete files after a day or so
recipient = ARGV[0] #+15555551234
sender = ARGV[1] #+15555551234
message = ARGV[2] #"THIS IS MY MESSAGE"
# create the TwiML
response = do |r|
r.Say message, voice: 'woman', loop: 0
# upload the TwiML to S3
filename = + '.xml'
s3 = aws_key_id, secret_access_key: aws_secret_access_key)
bucket = s3.buckets[aws_bucket]
file = bucket.objects[filename].write(response.text, content_type: 'application/xml')
# create a URL for the file that Twilio can access
url = file.url_for(:read, expires: 300, secure: false).to_s
# initiate the call passing the url of the XML document
client = twilio_sid, twilio_token
client.account.calls.create(url: url, to: recipient, from: sender, method: "GET", if_machine: 'Continue')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.