Using Twilio to send SMS with Cloud Code

Step 1: Create Twilio Account

Go to https://www.twilio.com and create a Account

If the thing goes well, there are a simple tutorial to let you send SMS to your phone. After that you will receive your first Phone Number for your Twilio Account.

If you can not find your phone number, go to # phone Number (you may use it at the cloud code when testing.)screen-shot-2016-09-22-at-5-44-12-pm

Step 2: Get Account SID and Auth Token

Go to Home -> Dashboard

screen-shot-2016-09-22-at-5-42-51-pm

Copy your SID and Auth Token for Cloud Code.

Step 3: Implement Cloud Code

Parse.Cloud.define("SendSMS",function(request,response){
 //require the Twilio module and create a REST client
 var client = require('twilio')('AccountSID','AuthToken');
 //Send an SMS text message
 client.sendMessage({
 // you can use request.params to pass the number you want to send
 to:'+target test Phone number', // Any number Twilio can deliver to
 from: '+Your first Phone number', // A number you bought from Twilio and can use for outbound communication
 body: 'SMS From Cloud Code.' // body of the SMS message

 }, {
 function(error, responseData) {
   if (error) {
      // console.log(error);
      response.error(error);
   } else {
      // console.log(responseData);
      response.success(responseData); 
   }
 }
}
); 
});

Step 4: Test

screenshot_2016-09-22-18-01-04_com-android-mms