Need to quickly send a lots of SMS messages? Us too.
Since development is very active, add this to your Gemfile:
gem "em-twilio", :git => "git://github.com/groupme/em-twilio.git"
require 'eventmachine'
require 'em-twilio'
EM::Twilio.authenticate(YOUR_ACCOUNT_SID, YOUR_TOKEN)
EM.run do
to = "+12135550000"
from = "+13105550000"
body = "Hello World"
EM::Twilio.send_sms(to, from, body)
EM.stop
end
The library will split a given body into chunks of 160 characters as best it can.
If you do not want to split message, you must split it yourself!
You can register callbacks to process the Twilio SID or exceptions:
EM::Twilio.send_sms(to, from, body) do |response|
if response.success?
puts response.sid
else
puts "timeout!" if response.error.kind_of?(EM::Twilio::TimeoutError)
end
end
Here's a list of possible exceptions. See em-twilio.rb
for more.
EM::Twilio::Error < StandardError
EM::Twilio::RequestError < EM::Twilio::Error
EM::Twilio::UnauthorizedError < EM::Twilio::Error
EM::Twilio::ServerError < EM::Twilio::Error
EM::Twilio::ServiceUnavailableError < EM::Twilio::Error
EM::Twilio::MissingCredentialsError < EM::Twilio::Error
EM::Twilio::NetworkError < EM::Twilio::Error
EM::Twilio::TimeoutError < EM::Twilio::NetworkError
See LICENSE for details