Ahoy hoy Twilio!

What is Twilio?

An API that allows your apps to integrate SMS, MMS, video, two-way authentication and all the functionality of the mobile phone. Twilio is used by many companies to connect with their users and customers through voice and video and build applications that allow them to use their phone to stay connected.

Can I use Twilio with NodeJS?

YES!

The Setup

  1. Sign up for a Twilio account.
  2. Configure a new Twilio phone number. This is the phone number from where messages will be sent from.
  3. For the purposes of getting started, we’ll use our own personal mobile number with Twilio to test our SMS application.
  4. Install Twilio, node, and express using npm install
  5. Open Sublime Text and open a new .js file. I named mine ahoy.js

The Require Statements

Require statements in our ahoy.js file
Require statements in our ahoy.js file

var twilio will allow our application to use the Twilio library

var key contains the ACCOUNT_SID and ACCOUNT_TOKEN. For security purposes, I placed my ACCOUNT_SID, ACCOUNT_TOKEN, and Twilio phone number in a separate file so that they are not visible in my application.

var TWILIO_ACCOUNT_SID is the way the application will be verified with Twilio

var AUTH_TOKEN is the token that verifies our identify with Twilio

var number is the Twilio phone number we set up in Step 2

var client is the how we we marry the Twilio library, account_SID and token to make requests.

The Client Request Using the Twilio API

This will send our message to the phone number indicated in the "to" field.
This will send our message to the phone number indicated in the “to” field.

As stated above, I save my Twilio number as a variable that points to a file path where the actual number is located. I then placed this file in my .gitignore file.

The body can be changed to any message you wish.

The Success/Error Message

For those that work in nodeJS, looks familiar right?
For those that work in nodeJS, looks familiar right?

If there is no error, we’ll see the message unique ID or message_sid and the date it was created in our terminal.

Running the Application

Type the following command into your terminal:

Screen Shot 2015-09-07 at 2.02.16 PM

You should receive a message in the terminal that looks like this:

Success!
Success!

Here is what it looks like when it arrives on our phone.

Photo on 9-7-15 at 2.10 PM

Here’s the link to the complete code on Github. Feel free to fork it and contribute

One thought on “Ahoy hoy Twilio!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s