How To Integrate Clickatell In Rails Application

When it comes to sending an SMS using Ruby on Rails, there are two approaches you can take. The first – and more complicated – is to use your own hardware and something like the ruby-sms library to communicate with the hardware. This set-up is time consuming, a pain to maintain and probably not very scalable.

The second option is to take the much easier route and use an existing SMS gateway service. There are many SMS gateways out there that offer APIs (ranging from HTTP/FTP based to email and COM-based); one such provider is Clickatell sms service, who are one of the bigger providers out there with a range of services.

Clickatell is a privately held mobile communications company founded in 2000 and headquartered in Redwood City, CA, with offices in Cape Town and Johannesburg, South Africa and Laos, Nigeria.

Clickatell delivers short message service (SMS) messages through its Clickatell Gateway to mobile phone users through more than 800 networks in more than 220 countries and territories, with the potential to reach five billion mobile phone users, or more than 70 percent of the world’s population.

1. Rails Clickatell Integration : 

<i> For integration of the clickatell API in any rails application,we need to get api-id,username and password from clickatell website.This will be needed to authentication.

2. Signing Up At Clickatell :

<i> First we need to sign up on www.clickatell.com and after activating the account check for central api among other available API’s.

<ii> After selecting the http api(central api),fill in other details and settings and note down the api id.This id along with username and password will be used to to send sms to networks.

3. Usage In Rails Appication :

<i> Install the gem :

sudo gem install clickatell

<ii> After installing the gem,checkout from terminal as :

sms –help –>this gives all the options that can be used and also shows that gem is installed properly.

e.g-From terminal:-

sms –help

Usage: sms [options] recipient(s) message

Recipients can be a comma-separated list, up to 100 max.

Specific options :

-u, –username USERNAME Specify the clickatell username (overrides ~/.clickatell setting)

-p, –password PASSWORD Specify the clickatell password (overrides ~/.clickatell setting)

-k, –apikey API_KEY Specify the clickatell API key (overrides ~/.clickatell setting)

-f, –from NAME_OR_NUMBER Specify the name or number that the SMS will appear from

-b, –show-balance Shows the total number of credits remaining on your account

-s, –status MESSAGE_ID Displays the status of the specified message.

-S, –secure Sends request using HTTPS

-d, –debug

-h, –help Show this message

4. Sending An Sms From Terminal :

<i> For sending sms from the rails application, go to that application folder from terminal. <ii> Use the command :

sms -u username -p password -k 3369665 +91[phone number] ‘message to send’ Sending ‘hiiiiiiiii’ to <phone number>… Message sent successfully (message id: 1619575838a1dfcecce8e530174b4d14). <iii> With the message id, message delivery status can also be checked : $ sms -s 1619575838a1dfcecce8e530174b4d14 -u <username> -p <password> -k 3369665 Getting status of message #1619575838a1dfcecce8e530174b4d14. Status: (#7). –>Status: (#7) shows the status of the message.Status codes and there respective meaning can be checked out from clickatell’s official http api guide. <iv> Credit balance can also be checked from terminal as follows : $ sms -u <username> -p <password> -k 3369665 –show-balance

Retrieving account balance…

You have 4.6 credits remaining.

note:-Many other options are there and are described in the HTTP API documentation.

<v> Sending sms from the rails view page or any form requires little more of coding :

There is a very good example of how to do this here :

https://github.com/lukeredpath/clickatell.git

RailsCarma has been implementing Ruby on Rails from its nascent stages for development, training, deploying and contributing back to the Rails Community. Through trusted technical expertise and consummate customer service combined to deliver a delightful experience for clients, RailsCarma provide end to end Ruby on Rails consulting, architecture, building, management and extension to companies around the globe. Contact Us to know more.

Read more :

Get in touch with us.

Subscribe For Latest Updates

Related Posts

Leave a Comment

Your email address will not be published. Required fields are marked *

en_USEnglish