Created
November 22, 2019 15:59
-
-
Save bdm1981/76f80e3f11acaf8f5b1fb5d894a718f8 to your computer and use it in GitHub Desktop.
Sendgrid email to twilio SMS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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