Integrating SMS Messaging with your Rails Application <ul><li>Blythe Dunham </li></ul><ul><li>[email_address] </li></ul><u...
Why SMS? <ul><li>Oldest most reliable means to communicate with mobile users </li></ul><ul><li>Cell phone agnostic </li></...
Popular Applications to Send SMS <ul><li>Standard Email </li></ul><ul><ul><li>yournumber@gatewayaddr  Example:2065551234@t...
Overview: One Way Messaging <ul><li>Mobile Terminated (MT) or Outbound </li></ul>Black Box of Your application &  gateway ...
Overview: Two Way Messaging Black Box of Your application &  gateway & other Mobile Originated (MO) or Inbound  ROCK MO Re...
Simplest approach: SMS as email
Pros and Cons of sending SMS through email <ul><li>The Good </li></ul><ul><li>Free to application (end-user with phone mig...
Pros and Cons of sending SMS through email <ul><li>The Tricky </li></ul><ul><li>User carrier must be known  </li></ul><ul>...
Giant Black Box Explained: SMSCs, SMS Gateways, Service Providers <ul><li>Before exploring the other available SMS options...
SMS Centers (SMSC) SMSC SMSC SMSC
GSM Modem Super App GSM Modem (Cell Phone) SMSC AT Commands
GSM Modem APIs and Applications <ul><li>Kannel in C (open source) supports an API </li></ul><ul><li>RubyGSM - Written by U...
GSM Modem LoDown <ul><li>Advantages </li></ul><ul><li>Cheap </li></ul><ul><li>Can use almost anywhere </li></ul><ul><li>Tw...
Talk directly to all SMS Centers SMSC SMSC SMSC Awesome App
Mission Impossible: Coding for each SMSC <ul><li>Large number of SMS Centers </li></ul><ul><li>Each use different and prop...
SMS Gateway translates SMSC protocols SMSC SMSC SMSC Rockstar App SMS Gateway
SMS Gateways <ul><li>Free Open Source Gateways </li></ul><ul><li>Kannel - written in C supports many SMSCs and also acts a...
Pay the middleman! <ul><li>Charge for sending messages  </li></ul><ul><ul><li>~ 5 cents per message </li></ul></ul><ul><ul...
SMS Gateway: Sending Outbound (MT) <ul><li>Typical approach for Outbound messages is simple: </li></ul><ul><li>Create an a...
Ruby Outbound (MT) message with HTTPS <ul><li>http = Net::HTTP.new(CLICKATELL_BASE_URL,  443 )  </li></ul><ul><li>http.use...
Choosing an API (if you have a choice) <ul><li>HTTP/S (GET & POST) </li></ul><ul><ul><li>By far the easiest to implement <...
SMS Gateway: Two way messaging and MOs <ul><li>Typically enable Outbound messaging </li></ul><ul><li>Obtain or rent a  sho...
Two way messaging: Pull <ul><li>Setup a cron task to pull new messages every few seconds. </li></ul>
Two way messaging: Push <ul><li>Provide a callback URL that service provider invokes for each new message </li></ul>
Do I need a short code? <ul><li>If your awesome app is: </li></ul><ul><li>A giant spam machine </li></ul><ul><li>Implement...
Shared (Rented) Versus Dedicated Short Codes <ul><li>Shared short code   </li></ul><ul><li>shared with others </li></ul><u...
Chewing on a Cactus <ul><li>Choose a short code (selected or random) </li></ul><ul><li>Apply by sending registration data ...
Opt out concerns <ul><li>Handled by most providers </li></ul><ul><li>Implement yourself </li></ul><ul><ul><li>Tracking </l...
Choosing a Service Provider <ul><li>Cost: how many sms messages will you send per month? </li></ul><ul><ul><li>Credit vs. ...
Developer Integration Concerns
Save message information <ul><li>Do you need to save a history or audit trail for reporting? </li></ul><ul><li>Lots of mes...
Inside the SMS ORM: Check out SMS ON RAILS Draft Message Delivery By Date PhoneNumber Number WhiteList? DoNotSend? Outboun...
Outbound Status: Produce and Consume <ul><li>Web action creates an Outbound record with status NOT_PROCESSED </li></ul><ul...
Locking and Delivering: Outbound Status <ul><li>No transactions; no take backs </li></ul><ul><li>When delivering a message...
Bulk Message Delivery  <ul><li>Use batch API call to send multiple phone numbers the same msg </li></ul><ul><li>For huge d...
Bulk Message Delivery Tips <ul><li>Reduce contention for competing servers storing data </li></ul><ul><ul><li>Assign a gro...
Sanitize Phone Numbers <ul><li>PhoneNumber .create!(:number =>  '(206)-555-1212 ' ) </li></ul><ul><li>PhoneNumber .find_by...
Sanitize Phone Numbers <ul><li>Sanitize all phone numbers before search or insert or update </li></ul><ul><li>Store with c...
Outbound Attributes: White List and Opt Out <ul><li>Save safe numbers on a white list and enable checking to </li></ul><ul...
SMS Gateway Service Providers <ul><li>Short List of Providers </li></ul><ul><ul><li>http://www. redoxygen .com </li></ul><...
Useful References <ul><li>General SMS:  http://www. developershome .com/ sms / </li></ul><ul><li>Provider Gateway addresse...
SMS On Rails Engine: SMS in minutes <ul><li>script/plugin install  git :// github .com/ blythedunham / smsonrails </li></u...
Questions? Yo Dawg, I heard you like Rails Apps so I put an SMS Rails App in your Rails App so you can SMS yourself to be ...
Photos <ul><li>Trash can  http://www. flickr .com/photos/ knittingskwerlgurl /396165625/ </li></ul><ul><li>Flowers  http:/...
Upcoming SlideShare
Loading in …5
×

Integrating SMS Messaging with your Rails Application ...

3,771 views

Published on

Published in: Technology, Business
1 Comment
0 Likes
Statistics
Notes
  • Looks like some of your slides are broken, Garry. Informative stuff though, even if a bit out of date. We share more recent data on our slideshare account, feel free to have a look :)
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Be the first to like this

No Downloads
Views
Total views
3,771
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
49
Comments
1
Likes
0
Embeds 0
No embeds

No notes for slide
  • AOL requires user to reply and accept
  • Great for emergency messages Good for small number of users or on budget (free)
  • It is possible for an application to interface with all SMSCs by implementing each protocol. This is very time consuming.
  • Instead of using an SMS gateway, GSM Modems (PCMIA card or cell phone itself) can be connected to the computer running the application. GSM Modems use a SIM chip and communicate with SMSCs just like cell phones.
  • There are several open source gateways available. Kannel written in python supports many SMSCs and also acts as a WAP gateway. Since it is cheaper than voice calls and cell phones are readily available a lot of organizations including UNICEF are implementing solutions to send bulk messages for NGOs. Using a GSM modum (cellphone connected to laptop by USB) as a virtual SMSC, RapidSMS was built by Unicef to contact their teams in the fields. Since then it is being used to monitor outbreaks of Hepatitus E, track livestock, and monitor school attendance. Part of RapidSMS uses an open source ruby gem RubyGSM to directly interface with GSM phones.
  • It is possible for an application to interface with all SMSCs by implementing each protocol. This is very time consuming.
  • Most short message service centers (SMSCs) are developed by different companies that use their own communication protocol which is usually proprietary. Don&apos;t attempt to do this unless you are Tom Cruise.
  • Since each protocol is different an SMS Gateway is used to communicate with each SMSC using a unified protocol (example HTTP).
  • An SMS Service Provider acts middleman between mobile network operaters (ex. Verizon) and mobile users Typically lower cost if you buy messages or credit in bulk.
  • An SMS Service Provider acts middleman between mobile network operaters (ex. Verizon) and mobile users Typically lower cost if you buy messages or credit in bulk.
  • Probably send an HTTP message with SOAP or XML
  • If you must use SOAP or XML, its faster (especially on a large scale) to use string substitution instead of running everything through the XML builder.
  • Inbound message cron tasks can consume a huge amount of resources depending on the interval in which data is pulled. Most providers recommend pulling every 10 or 20 seconds.
  • Most providers handle this for you especially if you use a shared short code, but in certain cases you may want to implement yourself. Example, Joe and Veronica send messages to Mary through your system using the same short code. Mary wants to opt out to Joe after their nasty breakup, but, she still wants to SMS with her best friend Veronica. You would have to track opt out to handle this situation. As providers do with shared short codes, the recipient opts out to the sender of the last outbound message to the recipient. Needed certification from each gateway. TMOBILE for example had extra double opt in requirements.
  • Short codes cannot be created very dynamically; takes a few days Some short codes require minimum usage (ex. 500 emails) from the provider
  • Real time messaging
  • Provider support Many providers allow a deliver on date to be specified Most providers have API calls to check status: Implement call asynchronously, check status later Can run a separate cron to update the status of messages
  • Integrating SMS Messaging with your Rails Application ...

    1. 1. Integrating SMS Messaging with your Rails Application <ul><li>Blythe Dunham </li></ul><ul><li>[email_address] </li></ul><ul><li>spongecell .com / snowgiraffe .com </li></ul>
    2. 2. Why SMS? <ul><li>Oldest most reliable means to communicate with mobile users </li></ul><ul><li>Cell phone agnostic </li></ul><ul><li>Everybody is doing it </li></ul><ul><li>Great way to receive emergency messages at the bar </li></ul>SERVER IS DOWN SPARKS ARE UP
    3. 3. Popular Applications to Send SMS <ul><li>Standard Email </li></ul><ul><ul><li>yournumber@gatewayaddr Example:2065551234@txt.att.net </li></ul></ul><ul><ul><li>Find your provider gateway </li></ul></ul><ul><li>Instant Message </li></ul><ul><ul><li>AOL (US only) </li></ul></ul><ul><ul><li>Skype (small fee) </li></ul></ul><ul><li>Other </li></ul><ul><ul><li>Teleflip RIP </li></ul></ul><ul><ul><li>remindblast .com - Send SMS reminders to be awesome or do laundry </li></ul></ul><ul><ul><li>Facebook SMS app </li></ul></ul><ul><ul><li>Cell providers web page (ex. http://www.t-mobile.com ) </li></ul></ul>
    4. 4. Overview: One Way Messaging <ul><li>Mobile Terminated (MT) or Outbound </li></ul>Black Box of Your application & gateway & other Party at A1A Beach front Ave Mobile Terminated (MT)
    5. 5. Overview: Two Way Messaging Black Box of Your application & gateway & other Mobile Originated (MO) or Inbound ROCK MO Respond with &quot;ROCK&quot; for Free party tix MT
    6. 6. Simplest approach: SMS as email
    7. 7. Pros and Cons of sending SMS through email <ul><li>The Good </li></ul><ul><li>Free to application (end-user with phone might pay) </li></ul><ul><li>Easy to integrate. Only email setup required. </li></ul><ul><li>Excellent for use with known numbers </li></ul><ul><ul><li>Emergency Messages with plugins like Exception Notification </li></ul></ul>
    8. 8. Pros and Cons of sending SMS through email <ul><li>The Tricky </li></ul><ul><li>User carrier must be known </li></ul><ul><ul><li>additional user input </li></ul></ul><ul><ul><li>storage considerations </li></ul></ul><ul><li>No delivery confirmation </li></ul><ul><li>Supported by most US but not all cell phone carriers </li></ul><ul><li>No two way messaging </li></ul>
    9. 9. Giant Black Box Explained: SMSCs, SMS Gateways, Service Providers <ul><li>Before exploring the other available SMS options, lets look at how SMS works </li></ul>
    10. 10. SMS Centers (SMSC) SMSC SMSC SMSC
    11. 11. GSM Modem Super App GSM Modem (Cell Phone) SMSC AT Commands
    12. 12. GSM Modem APIs and Applications <ul><li>Kannel in C (open source) supports an API </li></ul><ul><li>RubyGSM - Written by Unicef for RapidSMS to inexpensively send text messages </li></ul>
    13. 13. GSM Modem LoDown <ul><li>Advantages </li></ul><ul><li>Cheap </li></ul><ul><li>Can use almost anywhere </li></ul><ul><li>Two way messaging support </li></ul><ul><li>Disadvantages </li></ul><ul><li>Difficult to setup </li></ul><ul><li>Slow </li></ul><ul><li>Doesn’t scale (only 6 to 10 messages per second) </li></ul><ul><li>Must connect modem to a server </li></ul>
    14. 14. Talk directly to all SMS Centers SMSC SMSC SMSC Awesome App
    15. 15. Mission Impossible: Coding for each SMSC <ul><li>Large number of SMS Centers </li></ul><ul><li>Each use different and proprietary communication protocols </li></ul>Don’t do this unless you are me!
    16. 16. SMS Gateway translates SMSC protocols SMSC SMSC SMSC Rockstar App SMS Gateway
    17. 17. SMS Gateways <ul><li>Free Open Source Gateways </li></ul><ul><li>Kannel - written in C supports many SMSCs and also acts as a WAP gateway </li></ul><ul><li>Must setup/configure on a server yourself </li></ul>
    18. 18. Pay the middleman! <ul><li>Charge for sending messages </li></ul><ul><ul><li>~ 5 cents per message </li></ul></ul><ul><ul><li>Bulk discounts </li></ul></ul><ul><li>Provide convenient APIs </li></ul><ul><li>Most provide two way messaging </li></ul><ul><li>Can help obtain short code </li></ul>
    19. 19. SMS Gateway: Sending Outbound (MT) <ul><li>Typical approach for Outbound messages is simple: </li></ul><ul><li>Create an account </li></ul><ul><li>Buy credits (or messages) </li></ul><ul><li>Start sending messages through the API </li></ul>
    20. 20. Ruby Outbound (MT) message with HTTPS <ul><li>http = Net::HTTP.new(CLICKATELL_BASE_URL, 443 ) </li></ul><ul><li>http.use_ssl = true </li></ul><ul><li>http.enable_post_connection_check = true </li></ul><ul><li>http.start {response = http.request_get(url_string)} </li></ul>
    21. 21. Choosing an API (if you have a choice) <ul><li>HTTP/S (GET & POST) </li></ul><ul><ul><li>By far the easiest to implement </li></ul></ul><ul><ul><li>Great for sending < 10k messages a month </li></ul></ul><ul><li>SMPP </li></ul><ul><ul><li>Best for bulk messages (over 10k per month) </li></ul></ul><ul><ul><li>Leaves Connection open </li></ul></ul><ul><li>STMP - send through mail </li></ul><ul><li>Other options (not so hot) </li></ul><ul><li>FTP - Bulk option for legacy systems </li></ul><ul><li>XML (use HTTP if available) </li></ul><ul><li>SOAP (use HTTP if available) </li></ul><ul><li>Com Object (Seriously? What wah?) </li></ul>
    22. 22. SMS Gateway: Two way messaging and MOs <ul><li>Typically enable Outbound messaging </li></ul><ul><li>Obtain or rent a short code </li></ul><ul><li>Respond to Inbound MOs </li></ul><ul><ul><li>Use a provider campaign management tool ($$$) </li></ul></ul><ul><ul><li>Parse yourself and write some regexp! </li></ul></ul>/^OPT(s*[-_]?s*)OUT|STOP|END|QUIT| UNSUBSCRIBE|EXIT|HALT| FUCK(s*[-_]?s*)OFF|REMOVE|CANCEL)/i
    23. 23. Two way messaging: Pull <ul><li>Setup a cron task to pull new messages every few seconds. </li></ul>
    24. 24. Two way messaging: Push <ul><li>Provide a callback URL that service provider invokes for each new message </li></ul>
    25. 25. Do I need a short code? <ul><li>If your awesome app is: </li></ul><ul><li>A giant spam machine </li></ul><ul><li>Implementing two way messaging </li></ul><ul><li>(Recommended) Sending > 5000 messages per month </li></ul>
    26. 26. Shared (Rented) Versus Dedicated Short Codes <ul><li>Shared short code </li></ul><ul><li>shared with others </li></ul><ul><li>requires keyword like &quot;RUBY&quot; </li></ul><ul><li>Dedicated short code </li></ul><ul><li>all to yourself </li></ul><ul><li>Takes around 2 months to obtain </li></ul><ul><li>$1000 for a selected code or $500 for a random code per month </li></ul>
    27. 27. Chewing on a Cactus <ul><li>Choose a short code (selected or random) </li></ul><ul><li>Apply by sending registration data for 3, 6 or 12 months </li></ul><ul><li>Receive approval email from CSCA </li></ul><ul><li>Pay all up front $500 per month for Random, $1000/mo for Selected </li></ul><ul><li>Apply for approval from each wireless service provider </li></ul><ul><li>Sign a contract with each provider </li></ul><ul><li>Implement and Test each connection with each provider </li></ul>Sms gateway service providers(connection aggregators) will help with this process or you can go directly through the CSCA in the US
    28. 28. Opt out concerns <ul><li>Handled by most providers </li></ul><ul><li>Implement yourself </li></ul><ul><ul><li>Tracking </li></ul></ul><ul><ul><li>Opting out different senders </li></ul></ul>
    29. 29. Choosing a Service Provider <ul><li>Cost: how many sms messages will you send per month? </li></ul><ul><ul><li>Credit vs. sms </li></ul></ul><ul><ul><li>Hidden costs </li></ul></ul><ul><ul><li>Monthly fee </li></ul></ul><ul><li>Coverage: does the provider cover all needed areas? </li></ul><ul><li>Implementation Time: is the API you want to use easy to integrate? </li></ul><ul><li>Opt-out: is it handled? </li></ul><ul><li>Two way messaging: is it supported? Do you need it? </li></ul><ul><li>Help with short code cactus eating experience? </li></ul>
    30. 30. Developer Integration Concerns
    31. 31. Save message information <ul><li>Do you need to save a history or audit trail for reporting? </li></ul><ul><li>Lots of messages to send? </li></ul><ul><li>Can't send in real time (before controller action times out?) </li></ul>
    32. 32. Inside the SMS ORM: Check out SMS ON RAILS Draft Message Delivery By Date PhoneNumber Number WhiteList? DoNotSend? Outbound Status Time Sent Service Provider UID PhoneCarrier Name Email gateway Sender/User Username Password Favorite beer
    33. 33. Outbound Status: Produce and Consume <ul><li>Web action creates an Outbound record with status NOT_PROCESSED </li></ul><ul><li>Cron task processes messages with status NOT_PROCESSED and marks them SUCCESS or FAIL </li></ul>Controller Action Producer Cron/Background Task Consumer NOT_PROCESSED SUCCESS
    34. 34. Locking and Delivering: Outbound Status <ul><li>No transactions; no take backs </li></ul><ul><li>When delivering a message, try locking Outbound ORM object </li></ul>NOT_PROCESSED PROCESSING SUCCESS FAILED
    35. 35. Bulk Message Delivery <ul><li>Use batch API call to send multiple phone numbers the same msg </li></ul><ul><li>For huge deliveries, use SMPP to maintain an open connection </li></ul><ul><li>Set delivery date and send to provider in advance </li></ul><ul><li>Lock multiple records with your database (MySQL FOR UPDATE) </li></ul><ul><li>Use Multiple servers </li></ul>
    36. 36. Bulk Message Delivery Tips <ul><li>Reduce contention for competing servers storing data </li></ul><ul><ul><li>Assign a group of records (ID mod X srvrs) to each server </li></ul></ul><ul><ul><li>(non dedicated servers) put tasks on staggered timers (ex. every 2 min) that execute for a shorter duration(ex. 45 seconds) </li></ul></ul><ul><li>Identify fatal errors and stop the task </li></ul><ul><ul><li>Fatal, stop task: Ex. No response from service provider </li></ul></ul><ul><ul><li>Single message error: Mark failed and continue processing </li></ul></ul><ul><li>Cron to Recover messages in 'PROCESSING' state with updated_at field > duration of consumer task (ex. 10 min) </li></ul><ul><li>Delivery status background task to request delivery information </li></ul><ul><li>Set priority on messages </li></ul>
    37. 37. Sanitize Phone Numbers <ul><li>PhoneNumber .create!(:number => '(206)-555-1212 ' ) </li></ul><ul><li>PhoneNumber .find_by_number( '12065551212' ) == nil </li></ul>Your database without data integrity
    38. 38. Sanitize Phone Numbers <ul><li>Sanitize all phone numbers before search or insert or update </li></ul><ul><li>Store with country code (for USA auto add a 1 for 10 digit numbers not inputted with a + or 0) </li></ul>My database runs on flowers
    39. 39. Outbound Attributes: White List and Opt Out <ul><li>Save safe numbers on a white list and enable checking to </li></ul><ul><li>prevent accidents (test mode) </li></ul><ul><li>restrict access </li></ul><ul><li>Store Opt-Out Information </li></ul><ul><li>Prevent paying for a message to a recipient provider opted out </li></ul><ul><li>Can make a distinction between opt out, opt in, and bounce, abuse </li></ul>smsi
    40. 40. SMS Gateway Service Providers <ul><li>Short List of Providers </li></ul><ul><ul><li>http://www. redoxygen .com </li></ul></ul><ul><ul><li>http://www. redrabbitsms .com/ </li></ul></ul><ul><ul><li>http:// clickatell .com </li></ul></ul><ul><ul><li>http:// quios .com </li></ul></ul><ul><ul><li>http://messagepub.com/ </li></ul></ul><ul><ul><li>http://www.openmarMeket.com/products-and-services/message-and-content-delivery.html </li></ul></ul><ul><ul><li>http://www.mobilemarketing.net </li></ul></ul><ul><ul><li>http://www.textmarks.com/ </li></ul></ul><ul><ul><li>http://www.mozes.com/ </li></ul></ul><ul><li>Long list and comparison table of providers: </li></ul><ul><li> http://www. developershome .com/ sms / smsGatewayProvComp .asp </li></ul>
    41. 41. Useful References <ul><li>General SMS: http://www. developershome .com/ sms / </li></ul><ul><li>Provider Gateway addresses: http://en. wikipedia .org/ wiki /SMS_gateway </li></ul><ul><li>Sms On Rails Engine: http:// github .com/ blythedunham / smsonrails </li></ul><ul><li>Clickatell Gem: http://clickatell.rubyforge.org/ </li></ul><ul><li>Exception Notification Plugin: </li></ul><ul><li> http:// github .com/rails/exception_notification/tree/master </li></ul><ul><li>Kannel: http://www. kannel .org/ </li></ul><ul><li>RapidSms http://mobileactive.org/tagging/rapid-sms </li></ul><ul><li>RubyGSM http://mobilehacking.org/index.php/ RubyGSM </li></ul><ul><li>More Mobile Tools: http://mobilehacking.org/index.php/Main_Page </li></ul><ul><li>Common Short Code Admin(CSCA) http://www. usshortcodes .com/ </li></ul>
    42. 42. SMS On Rails Engine: SMS in minutes <ul><li>script/plugin install git :// github .com/ blythedunham / smsonrails </li></ul>Demo <ul><li>Support for: </li></ul><ul><li>Email Gateway Integration with phone carrier email domains </li></ul><ul><li>Clickatell HTTPS Integration </li></ul><ul><li>ORM/DB tables and migrations to store messages </li></ul><ul><li>RESTful admin views to show message history </li></ul><ul><li>Safe Locking and delivery </li></ul><ul><li>Safely store phone numbers </li></ul><ul><li>Dynamic parameter substitution </li></ul><ul><li>Not included: (yet) </li></ul><ul><li>Crons tasks or bulk message delivery </li></ul><ul><li>Stale message recovery </li></ul><ul><li>Pretty UI with rounded corners customized to your application </li></ul><ul><li>Inbound Message support </li></ul><ul><li>Please log tickets on github! </li></ul>
    43. 43. Questions? Yo Dawg, I heard you like Rails Apps so I put an SMS Rails App in your Rails App so you can SMS yourself to be awesome
    44. 44. Photos <ul><li>Trash can http://www. flickr .com/photos/ knittingskwerlgurl /396165625/ </li></ul><ul><li>Flowers http://www. flickr .com/photos/ blondepowers /2722511769/ </li></ul><ul><li>Timepiece: http://www. flickr .com/photos/ lebron /223223725/ </li></ul><ul><li>Bear http://www. flickr .com/photos/ guenterleitenbauer /697065143/ </li></ul><ul><li>Email http://www. flickr .com/photos/ charuca /2448685976/ </li></ul><ul><li>Golden gate: http://www.flickr.com/photos/h2orange/63606734/ </li></ul><ul><li>Beetles: http://www.flickr.com/photos/lhtang2006/3490285407/ </li></ul><ul><li>Computer Cat: http://www.flickr.com/photos/sammrowe/3491788169/ </li></ul><ul><li>Giant: http://www.flickr.com/photos/andreatallone/2841979961/ </li></ul>

    ×