Add SMS to your Web App (with 4 lines of code)

9938079733_14d672c805_z

Hi there, my name is Jarod Reyes and I’m the Technical Content Producer at Twilio. In this post I’d like to quickly show you how easy it is to add SMS to your web app then give you a more in-depth look at how Twilio works as well as some more robust use-cases for SMS.

This post was inspired by a conversation I had with a friend shortly after joining Twilio. We were talking about API’s when he nonchalantly explained that he himself used Twilio to send SMS notifications from his web app. As proof he then turned his laptop around to face me and pointed to the “four lines of code [he] added” to enable SMS.

Certainly it is not always that simple. Some of our biggest customers have built entire businesses around the Twilio Platform, but everyone has to start somewhere and in my opinion these four lines of code are the place to start.

So without further adieu, I present the four lines needed to send an SMS from your web app:

Or how about Ruby:

To see more awesome examples including node.js, python, C# or java visit the Twilio docs.

So now that we’ve gotten that out of the way, let’s quickly discuss how Twilio accomplishes this task.

How Twilio Works

Outbound Messages
When you send an SMS/MMS from your web app using Twilio it works like this:

sms-1-way
As you can see sending an SMS is pretty straight forward, in fact all of this interaction is triggered with just those four lines I showed you above. But what if you want that user to be able to respond to your outgoing message? Well then your Twilio Phone Number needs some extra instructions, specifically what to do when it receives an incoming SMS.

Inbound Messages
When an SMS is received by your Twilio Number it looks something like this:

sms-2-way

Now that we’ve looked at how Twilio interacts with your web application at a high level, it’s time to put our gloves on and dig in. We’ll start by doing some basic setup.

Setup: Get your free Twilio number and install a helper library

Sign up at Twilio to get your free Twilio number. Once you sign up click on Numbers to see your number.

manage-numbers
If you plan on receiving SMS messages with your web app you will also need somewhere to host your TwiML instructions. There are lots of web hosting services that will host your application for free or cheaply including Heroku and Googles AppEngine.

Installing the Helper Library

Twilio helper libraries give you the ability to interact with the Twilio REST API in the language of your choice. Installing the libraries is usually quite straightforward. For example, to install the Ruby helper library you could just install the gem like so:

Here are some of officially supported Twilio helper libraries:
Click to get installation instructions and further documentation

To view all of the available helper libraries visit the Twilio docs.

Once you’ve installed the helper library of your choice it’s time to use the REST API to send and receive SMS Messages.

Next Step: Read the docs

If you’ve worked with APIs in the past you might just want to dive in to the API docs. The Twilio REST API documentation is fully stocked with examples to help you dive in. However if you’re like me and you prefer a more tutorial approach check out the Twilio Quickstart, which will walk you through sending and receiving your first SMS.

API Reference:

Quickstart: Sending and Receiving an SMS (uses PHP)

Congratulations, now you’re able to add SMS capabilities to any of your web apps in minutes.

Once you’ve grasped these basic concepts consider upping the ante and adding even more sweetness to your application. Here are some popular ideas:

Well I hope this taste of the Twilio API has left you excited to learn even more. Many of my colleagues have written awesome tutorials on using SMS for even cooler purposes. Here are a few of my favorites. Happy hacking.

  • Nilima

    Newly constructed building houses for rent in HSR Layout with cover parking.

    rent: 23000, Deposit: 10 months negotiable.

    Note: Broker charges One month rent.

    for more contact below details

    Thanks & Regards

    BG Enterprises

    Birendra B

    Mob: 7259679626

    What’sapp: 9206534065

    Details

    Type For rent
    Num. Rooms 2
    Num. Bathrooms 1
    Status New construction
    Square Meters 1200
    Square Meters (total) 12001
    Num. Floors 0
    Floor Number 2
    Other characteristics

    Elevator,Terrace,Parking,Furnished,New

    For buy property,flats in Bangalore, click here
    [Url=https://rackonshomes.cu.cc/houses-apartments-for-rent/2bhk-house-for-rent-in-hsr-layout-with-parking_i6503]https://rackonshomes.cu.cc/houses-apartments-for-rent/2bhk-house-for-rent-in-hsr-layout-with-parking_i6503[URL]

  • Nilima

    Rackons.com is a free local classifieds website & online classifieds platform where you can post free advertisements related a business, product, items and service offered in India!!!. Rackons.com, launched in 2015, a place where people can connect with each other to buy/sell/find goods and services. We have 9 Categories & Approx 150 sub-categories including Electronics, Real estate, vehicles, jobs, community, personals,Entertainment etc Rackons.com provides many new features for sellers to grow their business fast & promote their service in all over world..Rackons.com works for both sellers as well as buyers. so Everyone can use our free as well as premium service. Sellers can sell anything, Buyers can buy anything from Rackons.com
    New features :
    SEND PM Option : Buyers can send message privately to sellers related to their products or purchase. This is only best features for sellers & buyers both where they can meet to each other & discuss about products, service.

    Add Money to wallet : This option is only provide by Rackons.com classified site, No Other company provide this features for sellers. Through this features, sellers can add some money in their Rackons account wallet, & they can use that money to promote their business by premium ad or premium banner or many ways. And they will get Extra money also i.e. If they pay 500/- then they will get 20% extra mean 600/- will be credit in their wallet. click here to get extra money : http://rackons.com/rackonswallet-p259

    Promo Code : This also best option for small & medium business sellers, If they dont want to invest money to purchase premium ad then they can use promo code then they will get some amount in their wallet & can use that money in premium ads Its also best & free service for sellers. They can use free premium ads service without pay any fees.

    Live chat Support : Rackons.com company also provide live chat support for both sellers as well as buyers, if they want any type of service & they are unable to find or post any type of problems then our live chat support team will help you both. Its very easy & fast service.

    Social Sharing : Rackons.com also provide social sharing option for sellers, Rackons.com will share all premium ads on all social media like facebook, twiiter, Google+, linkedin. pinterest, etc Through this sharing, buyers can see their ads & can contact them through this sharing. So this is very useful for both sellers as well as buyers.

    Mobile recharge : This is premium service. When sellers will buy premium ad then they can get Free Mobile recharge, they can see pricing of premium ad & mobile recharge system while publish an ad on site http://rakcons.com/item/new

    Many More features for sellers & buyers…So Rackons.com is India’s as well as all over world best classified company, No Other company will provide your thats all features.. Its Totally Free service..

    If you want more business with rackons.com then you need to pay..You can also join with Rackons.com & can earn money..Note: Investors can also invest money in Rackons.com Its very big brand company..

  • Asif Alvi

    Hello Twilio
    I want to recieve message form my twilio number at my dashboard which are live and also want to send the messages from my dashboard. I made my dashboard for the purpose of receiving and sending messages from my twilio number. Please give some suggestion for that i can do these things in my dashboard. I want to use Twilio library in PHP language.
    Thanking you

    • dprothero

      Definitely check out our PHP quick start here: bit.ly/1Xxo09Y

      • Asif Alvi

        Thanks a lot sir,
        one more thing i wanna do. I have two twilio number , if i select the one number of them, then the messages related to that number should be appear and when i select another number then their messages should be appear. Please tell me how to do it and how can i implement in my dashboard.
        Thanks once again,

        • dprothero

          You can retrieve messages using the Messages list resource: https://www.twilio.com/docs/api/rest/message#list

          You can pass a From=[your number] for one request to get all the messages from a particular phone number and then make a second request with To=[your number] to get the inbound messages.

          The other option would be to make a single request without a filter and then filter them in your own PHP code.

          • Asif Alvi

            sir can u make codes for this ?

  • Sarika

    Useful information.
    Thanks, Sarika