Send Text Messages From Rails with SMS Fu 16

Posted by brendan
on Thursday, February 28
This plugin has been sitting dormant for a while and I haven't had a chance to really write about it since I've been so busy lately. Basically what this is, is just a quick Rails plugin that allows you to send an SMS from your application. This does not require any kind of "gateway" or third-party service to get the job done. The plugin takes in a phone number, the carrier, and a message. From this information, it will format an e-mail correctly that will actually end up being sent to that phone in the form of a text message. How easy is it to use? Very.

You can grab the latest from GitHub.
git clone git://github.com/brendanlim/sms-fu.git vendor/plugins/sms_fu

Supported Carriers: Sorry, International carriers aren't supported at the moment. Alltel, Ameritech, AT&T, BellSouth Mobility, BlueSkyFrog, Boost Mobile, Cellular South, Fido, Metro PCS, PSC Wireless, Qwest, Southern Link, Sprint, Suncom, T-Mobile (US/UK/Germany), Virgin Mobile, Verizon Wireless, Vodafone (UK,Italy,Japan).

Add this one include line to one of your controllers.
      class ExampleController < ApplicationController
        include SMSFu
      end
After this, just edit /config/sms_fu.yml with your custom reply-to address.

The three required parameters are the phone number, carrier, and the message itself. You can find the correct carrier codes in sms_fu.yml.

      deliver_sms("5558675309","AT&T","your message here")

You can set the maximum length of the SMS message, which is not set by default. Most phones can only accept 128 characters, and each phone can handle these messages differently. To set the limit, just pass it in as an option when delivering an SMS.

      deliver_sms("5558675309","AT&T","your message here", :limit => 200)

If you want to roll your own mailer and just want to use SMS Fu to retrieve the formatted address of the recipient, you can do so by doing the following below.
      get_sms_address("5558675309","AT&T")

Hope you all enjoy, and please send me some feedback on any new features you'd like added.

Comments

Leave a response

  1. Eric AndersonMarch 21, 2008 @ 03:51 PM
    This looks great! I don't know much about SMS but this plugin makes me not have to. :) I wonder if it would be worth the effort to turn into a ActionMailer type setup so the message contents are described in templates. Probably not worth it since the messages are usually so small. Not knowing anything about sms, what is the address of the recipient?
  2. ronald mcpoopMarch 21, 2008 @ 08:55 PM
    i'm not sure i see the utility if i have to enter the carrier as well as the phone number. can anyone recommend ways to figure that out given only the phone number?
  3. ronald mcpoopMarch 22, 2008 @ 03:12 AM
    ronald mcpoop: I think the reason it needs the carrier is because it has to know how to format the email address. I guess you could just try them all and one will get through, but that would be kinda spammy.
  4. VinceMarch 23, 2008 @ 04:01 AM
    Hi, The email for Aliant (Division from Bell Canada) would be number@txt.aliant.net I'm not sure what it is for Bell if there's one more general
  5. Brendan G. LimMarch 23, 2008 @ 04:35 AM
    Vince, thanks! I'll add that in soon.
  6. StephenMarch 23, 2008 @ 02:23 PM
    You can detect the carrier based on the first 6 digits of the number: http://www.telcodata.us/telcodata/telco $5 for the CSV, or you could write something to query the site (probably not cost-effective).
  7. Brendan G. LimMarch 23, 2008 @ 09:58 PM
    Stephen, very cool. Thanks so much for that info.
  8. Cody MaggardMarch 24, 2008 @ 02:23 PM
    @Stephen: I don't think that would take into account number portability, unfortunately. What if I were to take my number in the Sprint block to AT&T? Suddenly there's a whole bunch of bounced emails. It'd probably be most useful as a "this is our best guess as to your carrier" default option.
  9. Brendan G. LimMarch 24, 2008 @ 02:50 PM
    Cody, good point. The best solution, in this case at the moment, would be to just ask the user for both their number and carrier.
  10. chrisMarch 27, 2008 @ 02:43 AM
    Teleflip is a free and easy to use service that allows you to send SMS messages (or text messages) to anyone in North America, that means no European support! The service is simple to use. All you need to do is send an e-mail to 10digitnumber@teleflip.com and the message is automatically sent to the number. Teleflip determines the carrier for you, just send an e-mail to: "2025556900@teleflip.com" with some message: "Hey, what's up?"
  11. Adam C. BairMarch 29, 2008 @ 06:05 AM
    This was mentioned in the Rails Envy Podcast! Congrats Brendan :) http://railsenvy.com/2008/3/26/rails-envy-podcast-episode-024-03-26-2008
  12. Brendan G. LimMarch 29, 2008 @ 03:31 PM
    Thanks so much Adam! :)
  13. jeff judgeMarch 30, 2008 @ 07:16 PM
    nice work brendan, this will definitely be a helpful plugin for a lot of people. @stephen telcodata.us isn't a viable solution since it doesn't take number portability into account. just think of all the people who have recently switched to at&t. i've been using tmobile for over three years (switched from verizon) and it shows my number still registered as verizon. my company, http://interactivemediums.com, does a bunch of work with short codes and in the us and supports sms applications for customers like orbitz and sprint. we've built a solid messaging platform and we're getting ready to release a two-way sms via short code api. i'd love to get some input on what people would like to see in an api from a functionality and cost standpoint. my email is jeff@interactivemediums.com, and i'll follow this thread if there are any comments. thanks a lot.
  14. James DanielsMarch 31, 2008 @ 04:15 AM
    Livejournal has a nice list of providers and emails going http://www.livejournal.com/tools/textmessage.bml?mode=details Cheers!
  15. Kit PlummerMarch 31, 2008 @ 06:47 PM
    It'd be pretty cool to see this packaged as a gem, rather than a Rails plugin. Not complaining...just making a statement. I'd love to be able to integrate this capability in to my non-Rails Ruby apps. Cool stuff dude.
  16. johnApril 01, 2008 @ 06:31 AM
    Regarding Chris's comment about teleflip: I don't know if it still works, but at one time you could turn on "return receipt" in your outgoing e-mail client (if your cllient supports it) send your msg to teleflip, and then you would get, in the return message, the carrier to which the SMS was delivered. This would be another way to eliminate the need for the end-user to specify the carrier.
  17. jakeApril 02, 2008 @ 05:18 AM
    this is excellent! Could a 3rd part sms provider be integrated to increase coverage?
  18. shea butterApril 12, 2008 @ 11:31 AM
    Great tutorial. I sure would use it. Thanks Brenden Lim
Comment