Skip to content

Instantly share code, notes, and snippets.

@JacobKnaack
Created June 14, 2019 08:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JacobKnaack/2ca07e30952acd0200594f795c5efa85 to your computer and use it in GitHub Desktop.
Save JacobKnaack/2ca07e30952acd0200594f795c5efa85 to your computer and use it in GitHub Desktop.
Cosmic Messenger Twiliio Notifications middleware
var twilioClient = require('./twilioClient');
const admins = require('./config').adminNumbers;
function formatMessage(user, messageText) {
return `Message from ${user}: ${messageText}`;
};
exports.notifyOnMessage = function (req, res, next) {
if (req.session) {
const { title, content } = req.body;
admins.forEach(function (admin) {
var messageToSend = formatMessage(title, content);
twilioClient.sendSms(admin.phoneNumber, messageToSend);
});
}
next();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment