Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Integrate twilio with rails

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 369
    Comment on it

    Twilio is a cloud-based service that allows software developers to programmatically make and receive phone calls and send and receive text messages using Twilio's cloud APIs. So once developer integrates their application with Twilio, their application can make phone calls and can send text messages.
    In order to use Twilio's APIs, A first thing we need to do is sign-up for a free Twilio account at http://twilio.com/try-twilio.After sign-up Twilio will ask you to either send you a text message or give you a quick call to verify that you’re a real person.
    You will get either a text message or a phone call with a verification code. Enter that verification code and you can proceed for getting a phone number.Twilio will assign you a random phone number.
    On your Dashboard you will get the API Credentials(AccountSid and Auth Token).To use the Twilio API you will need AccountSid and Auth Token.

    Now let's integrate Twilio to rails application. Ruby provides twilio-ruby gem for communicating with Twilio API.
    To install the gem, add Twilio-ruby to gemfile and run bundle install.

    gem 'twilio-ruby'

    To Send a text message using Twilio, we have created a controller twilio_controller.rb in the app/controllers directory
     

    class TwilioController < ApplicationController
    
     def send_text_message
        twilio_sid = "ACxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
        twilio_token = "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy"
        twilio_phone_number = "twilio number"
        to_number = "Your phone number"
        @client = Twilio::REST::Client.new twilio_sid, twilio_token
    
        @client.messages.create(
          :from => twilio_phone_number,
          :to => to_number,
          :body => "Welcome to Twilio, This messaege is a testing message"
        )
      end
    
    end


     
    Inside the controller, we have created an action send_text_message that will send a text message from Twilio's number to your number.
    After this we need to edit config/routes.rb and write a URL path to our controller and action:

    post 'twilio/send_text_message' => 'twilio#send_text_message'
    
    

    To test Twilio, open up your web browser and go to http://localhost:3000/twilio/send_text_message, You will get a message "Welcome to Twilio, This message is a testing message" from Twilio number to your number.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: