Skip to content

Instantly share code, notes, and snippets.

@mrlynn
Created September 20, 2018 17:26
Show Gist options
  • Save mrlynn/edde6583363e9dbac63ad7d3d3f17518 to your computer and use it in GitHub Desktop.
Save mrlynn/edde6583363e9dbac63ad7d3d3f17518 to your computer and use it in GitHub Desktop.
Send an SMS Text Message with MongoDB Stitch
exports = function(message) {
const mongodb = context.services.get("mongodb-atlas");
const coll = mongodb.db("db").collection("users");
const twilio = context.services.get("my-twilio-service");
const yourTwilioNumber = context.values.get("twilioNumber");
coll.find().toArray().then(users => {
users.forEach(user => twilio.send({
to: user.phone,
from: yourTwilioNumber,
body: message
})
);
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment