-
-
Save goliatone/6394498 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 'rubygems' | |
require 'aws-sdk' | |
require 'twilio-ruby' | |
account_sid = ENV['twilio_account_sid'] | |
auth_token = ENV['twilio_auth_token'] | |
client = Twilio::REST::Client.new account_sid, auth_token | |
from = ENV['twilo_from_number'] | |
sqs = AWS::SQS.new( :access_key_id => ENV['aws_access_key'], :secret_access_key => ENV['aws_secret_key']) | |
q = sqs.queues.named(ENV['sqs_queue_name']) | |
sent_to = [] | |
puts "Listening for messages..." | |
q.poll do |msg| | |
puts "Got message: #{msg.body}" | |
msg_parts = msg.body.split(':') | |
number = msg_parts[0] | |
name = msg_parts[1] | |
if number =~ /\+\d{7,}/ | |
if !sent_to.include? number | |
sent_to.push number | |
client.account.sms.messages.create( | |
:from => from, | |
:to => number, | |
:body => "Congratulations #{name}, you have deployed an application to the cloud!" | |
) | |
puts "\tSending message to #{number}" | |
else | |
puts "\tNot sending to #{number} as it has already been sent to." | |
end | |
else | |
puts "\tNot a number: #{number}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment