Skip to content

Instantly share code, notes, and snippets.

@TalhaAwan
Created August 3, 2017 19:47
Show Gist options
  • Save TalhaAwan/9c3a597e99f7a46d1a0e53b80154fd4d to your computer and use it in GitHub Desktop.
Save TalhaAwan/9c3a597e99f7a46d1a0e53b80154fd4d to your computer and use it in GitHub Desktop.
Node/Express endpoint to send sms to multiple users
const Router = require('express').Router;
const router = new Router();
const client = require('twilio')('xxxxxxx', 'xxxxx');
router.post('/send-sms', function(req, res){
var users = req.body.users
var smsBody = req.body.smsBody;
async.each(users, function(user, callback) {
client.sendMessage({
to: user.cellNum,
from: '+15005550006',
body: smsBody
}, function(err) {
if (!err) {
return callback();
}
else{
return callback(err);
}
});
}, function(err){
if(err){
res.status(500).json({
msg: err.message
});
}
else{
res.json({
msg: "Message sent to all users successfully"
});
}
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment