Permalink
Cannot retrieve contributors at this time
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
29 lines (26 sloc)
1005 Bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var twilio = require('twilio'), | |
| cloudConfig = require('cloud/cloudConfig'); | |
| //Initialize the Twilio cloud module | |
| twilio.initialize(cloudConfig.accountSid, cloudConfig.authToken); | |
| //Define a cloud function to send an SMS | |
| Parse.Cloud.define('sendLink', function(request, response) { | |
| //format phone number | |
| var n = request.params.phoneNumber.replace(/[^\d.]/g, ''); | |
| if (request.params.phoneNumber.indexOf('+') === 0) { | |
| n = '+'+n; | |
| } | |
| twilio.sendSMS({ | |
| From: cloudConfig.from, //a twilio number you control | |
| To: n, | |
| Body: cloudConfig.message + cloudConfig.downloadLink | |
| }, { | |
| success: function(httpResponse) { | |
| console.log(httpResponse); | |
| response.success('Link is on the way to your phone!'); | |
| }, | |
| error: function(httpResponse) { | |
| console.error(httpResponse); | |
| response.error('There was a problem sending the link - please check your phone number and try again.'); | |
| } | |
| }); | |
| }); |