SMS Gateway
Send a Message
Post to /messages with the following parameters
- key—your gateway key
- recipient—phone number
- message
- hash—a hexdigest of your password and the message.
- Example:
Digest::MD5.hexdigest('supersecretpassword' + @message)
- Example:
Tatango Gateway returns the following HTTP status codes:
Successful
- 200 OK —Your Message has been sent
- 202 Accepted —Your message has been accepted for delivery and the mobile phone number has been invited to opt-in. Message will be sent if they opt in.
Client Errors
- 400 Bad Request —Invalid Phone Number
- 401 Unauthorized —Check your id and hash
- 403 Forbidden —This Phone Number has been blocked, do not send again
- 409 Conflict —Mobile invitation pending, message not sent (try again later). NOTE: in the future, you will be able to query invitation status
Server Errors
- 500 Internal Server Error
- 501 Not Implemented
- 503 Service Unavailable —when the queue is down
MO’s
You specify the URL to which these will be POSTed in your provider control panel. MO’s are routed based upon both keywords and recent messages. If a message starts with the keyword that you specify in the provider control panel, it will be routed to you. Also, if a message
Mobile-originated messages will be POSTed in the following simple XML format:1 2 <?xml version="1.0"?> 3 <message> 4 <sender>PHONE_NUMBER</sender> 5 <content><![CDATA[MESSAGE_BODY]]></content> 6 </message>
Examples
Here are a few simple examples. Handling errors is left as an exercise to the reader.
TatangoSMS rubygem
We are currently developing a rubygem to make sending and receiving messages with the Tatango SMS Gateway even easier. The gem is in its preliminary stages, but if you have rubygems installed, you can install it with this command: gem install tatango-sms. This example shows receiving a message as well as sending a message. It simply sends back what the user sent, only reversed.
We also have Rdoc for the tatango-sms gem.
1 require 'rubygems' 2 require 'tatango_sms' 3 4 # setup a mobile terminated object with our Tatango SMS Gateway key and password 5 mt = TatangoSMS::MT.new('key', 'password') 6 7 # run a server on port 3333 to accept incoming messages from Tatango 8 server = TatangoSMS:MO.server('0.0.0.0', '3333') 9 TatangoSMS::MO.receive(server, '/') do |phone_number, content| 10 # send the reversed message back 11 mt.send(phone_number, content.reverse) 12 end 13 14 server.run.join
Ruby
1 2 # ruby send_message 9998887777 here is a message 3 4 require 'digest/md5' 5 require 'net/http' 6 require 'uri' 7 8 config = {:url=>'http://gateway.tatango.com/messages', :key=>'your key', :password=>'your password'} 9 10 phone_number = ARGV.shift 11 message = ARGV.join ' ' 12 13 result = Net::HTTP.post_form( 14 URI.parse(config[:url]), { 15 'key' => config[:key], 16 'recipient' => phone_number, 17 'message' => message, 18 'hash' => Digest::MD5.hexdigest(config[:password] + message) 19 } 20 ) 21 22 p result
PHP
1 2 <? 3 $url = 'http://gateway.tatango.com/messages'; 4 $key = 'your key'; 5 $password = 'your password'; 6 $phone_number = '9998887777'; 7 8 $message = 'here is a message'; 9 $encoded_message = urlencode($message); 10 $hash = md5($password . $message); 11 12 $curl_session = curl_init($url); 13 curl_setopt($curl_session, CURLOPT_POST, 1); 14 curl_setopt($curl_session, CURLOPT_POSTFIELDS, 15 "key=$key&recipient=$phone_number&message=$encoded_message&hash=$hash"); 16 curl_exec($curl_session); 17 curl_close($curl_session); 18 ?>

