Skip to content

Instantly share code, notes, and snippets.

@bdm1981
Created November 22, 2019 15:59
Show Gist options
  • Save bdm1981/76f80e3f11acaf8f5b1fb5d894a718f8 to your computer and use it in GitHub Desktop.
Save bdm1981/76f80e3f11acaf8f5b1fb5d894a718f8 to your computer and use it in GitHub Desktop.
Sendgrid email to twilio SMS
const express = require("express");
const bodyParser = require("body-parser");
const multer = require("multer");
const upload = multer();
const app = express();
require("dotenv").config();
const client = require("twilio")(
process.env.ACCOUNT_SID,
process.env.AUTH_TOKEN
);
app.post("/parse", upload.none(), (req, res) => {
console.log(req.body);
let regexp = /(^.\d+[^@])/g;
let toNumber = req.body.to.match(regexp)[0];
let message = `Subject: ${req.body.subject}\nMessage: ${req.body.text}`;
client.messages
.create({ from: "+1XXXXXXXXXX", body: message, to: toNumber })
.then(() => res.sendStatus(200));
});
app.listen(3010, function() {
console.log("Example app listening on port 3010!");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment