Twilio SMS Messaging — Axway Titanium Cross-Platform Library

I have integrated Twilio SMS Messaging for various clients over the past few years and decided it was time to wrap this up into my own library to ease portability.

For this library — I took a very simplistic approach. Just added SMS Messaging and no SDK’s or additional libraries; just a basic common.js module.

Setup Twilio Account and API Key

  1. Create a free Twilio Account at https://www.twilio.com/
  2. Create an API Key at https://www.twilio.com/console/video/dev-tools/api-keys
Make note of your API Secret. After you complete the setup the API Key can no longer be retrieved.

Download Library

Copy the /lib/ti.twilio.js file into your Axway Titanium Project under /app/lib/

https://github.com/adamtarmstrong/ti.twilio


Add Module and Initialize

  • AccountSID, APISID, & APISecret = All {strings} from your Twilio Account
  • timeout = {integer} to define API timeout in milliseconds
  • FROM_PhoneNumber = {string} in E.164 format of phone # to send message FROM (ie. +15005550006')
NOTE: FROM_PhoneNumber passed in must match the API Key Environment (more details in github repo)
var twilioClient = require('ti.twilio');
twilioClient.init('AccountSID', 'APISID', 'APISecret', 'FROM_PhoneNumber', timeout);

Send SMS Message

  • Message = {string} message to send to user
  • TO_PhoneNumber = {string} in E.164 format of client phone # to send message TO (ie. +146921439389')
  • successCallback = {function} to execute upon success
  • failureCallback = {function} to execute upon failure
twilioClient.sendSMS(Message, TO_PhoneNumber, successCallback, failureCallback);

That’s it!


This is just a basic SMS Message and I plan to expand the methods over time. Code contributions are greatly appreciated!