Configure Twilio In rails 3


Now you can make voice call and can send text message using Twilio api in rails 3. Follow the below steps for setting up Twilio in your Rails application.

1) First create a new rails application using rails new twilio_app.

2) Add the gem "twilio-ruby" in your gem file and run the bundle command.

3) Go to http://www.twilio.com/ and create a free new account. After creating the account just go to the https://www.twilio.com/user/account  and get the ACCOUNT SID and AUTH TOKEN from there .

4)Now for sending sms put the code inside your controller.


   account_sid = ACCOUNT SID
   auth_token = AUTH TOKEN
   @client = Twilio::REST::Client.new account_sid, auth_token

   message = @client.account.sms.messages.create(:body => "Hey Jhon !",
             :to => "+14159352345",
             :from => "+14158141829")
   puts message.sid

for trial account to  number must be registered inside twilio . You can upgrade your account for mass production use. to number must contain a valid phone number with include a '+' and the country code like +91.
For the from number you can use your twilio number or short codes purchased from Twilio .

5) For phone call facility you need to change your code little bit like.
     @call = @client.account.calls.create( :from => '+14159341234',
                  :to => '+18004567890', :url => 'http://example.com/call-handler'
                 )

- There are other options provided by Twilio and for more information you can check "twilio-ruby" gem documentation.

Comments

Popular posts from this blog

Insert Bulk data using active record import

Swap primary keys between two records in the same table in Postgres

How to add a bootstrap table with fixed header and scrollable body