Twilio Test Application in Node js

First things first – if you have not yet installed Node.js on your system, you can download an installer for your platform from nodejs.org

Next, install the Twilio module using npm, in the same directory as “Twilio.js”

[sudo] npm install twilio
var twilio = require('twilio');
var client = new twilio.RestClient('TWILIO_ACCOUNT_SID', 'TWILIO_AUTH_TOKEN');
 
// REST client will handle authentication and response serialzation for you.
client.sms.messages.create({
 to:'+16512223344',
 from:'TWILIO_NUMBER',
 body:'Hello World'
}, function(error, message) {
 if (!error) {
 // information about the text messsage you just sent:
 console.log('Success! The SID for this SMS message is:');
 console.log(message.sid);
 
 console.log('Message sent on:');
 console.log(message.dateCreated);
 } else {
 console.log('Oops!This number is invalid.');
 }
});

To run this code, return to the terminal and run

node Twilio.js

 

Advertisements

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