If two operations are inside the same file, you can simply wrap the Twilio call in a function and call it from Firebase , for example, like this ...
function sendSMS(dest, msg) { client.messages.create({ to: dest, from: "+14352058756", body: msg }, function(err, message) { console.log(message.sid); }); } ref.limitToFirst(1).on('child_added', function(snapshot) { var userDetails = snapshot.val(); var mobileNumber = userDetails.mobileNumber; sendSMS(mobileNumber, "Hey There! Good luck on the bar exam!"); });
If the Twilio operation is in another file, you can export it and require that you use Firebase
//twiliofile.js module.exports.sendSMS = function(dest, msg) { client.messages.create({ to: dest, from: "+14352058756", body: msg }, function(err, message) { console.log(message.sid); }); }
-
//firebasefile.js var sms = require('./twiliofile.js'); ref.limitToFirst(1).on('child_added', function(snapshot) { var userDetails = snapshot.val(); var mobileNumber = userDetails.mobileNumber; sms.sendSMS(mobileNumber, "Hey There! Good luck on the bar exam!"); });
source share