Building SMS marketing application with Twilio

Twilio provides infrastructure APIs for businesses to build scalable, reliable voice and text messaging applications. Using Twilio you can:
·      Make and receive phone calls - build applications that use the phone network to interact with people on landlines and cell phones all over the world. In just a few lines of code, you'll have phones ringing
·      Send and receive text messages - Build applications that interact via text messages. Get up and running in minutes with a simple, phone-number based API or apply for your very own short code today
·      Add voice client to web sites – an audio pipes that turn every application into a phone. Connect your users across web browsers, mobile phones, tablets, and even traditional phones

Whether you are building voice or text application, Twilio API data flow is quite simple:

1.      A User calls or sends an SMS to your Twilio phone number
2.     Twilio receives the call or SMS and makes a request to your application
3.     Your app receives that request information and sends XML back to Twilio
4.     Twilio executes those instructions and interacts with the user
Twilio provided many implementations to theirs API including JAVA, PHP, RUBY, NodeJS and more. Following is a simple example for text (SMS) marketing application using JAVA client to Twilio.
Lets assume your business maintains a client base for marketing promotions. Once a week we would like to send text message to all clients stating the upcoming promotion.
First we authentication our self to Twilio using API key and authentication token
String accountId = “xxxxxxxx”; //your account api key
String authToken = “xxxxxxxxxx”; //your auth token

final TwilioRestClient client = new TwilioRestClient(accountId, authToken);
final Account mainAccount = client.getAccount();
if (mainAccount == null) {
logger.error("Authentication failed. Main account is ampty.");
	return false;


Second lets assume you have loaded all you clients phone number into a map. We will iterate over the map and send our promotion text message to all clients


Map<String, String> clients; //Map<phone number, client name>
Final SmsFactory smsFactory = mainAccount.getSmsFactory();
if (smsFactory == null) {
logger.error("Authentication failed. Sms factory empty.");
	return false;

String from = “xxxxx”;  //our Twilio phone number
String promotion = “Best deal ever”;  //our promotion text

final Map<String, String> smsParams = new HashMap<String, String>(); //params for the sms object

for (String number : clients.keySet()) {
	String clientName = clients.get(number);
	String message = “Hello “ + clientName + promotion;

smsParams.put("From", from);
	smsParams.put("To", number);
	smsParams.put("Body", message);

	try {
		Sms sms = smsFactory.create(smsParams);
	catch (TwilioRestException e) {



That it. Simple.

This is only a simple example. You can do many things using this API in regards to SMS such as group chatting, password verifications, reminders, text manipulations and more.


Thank you for your interest!

We will contact you as soon as possible.

Want to Know More?

Oops, something went wrong
Please try again or contact us by email at
Thank you for your interest!

We will contact you as soon as possible.

Let's talk

Oops, something went wrong
Please try again or contact us by email at