Skip to content

Instantly share code, notes, and snippets.

@victorpaulo
Created August 26, 2019 13:58
Show Gist options
  • Save victorpaulo/0d8ee9c97e1ee1e040bf8e3a219b6d64 to your computer and use it in GitHub Desktop.
Save victorpaulo/0d8ee9c97e1ee1e040bf8e3a219b6d64 to your computer and use it in GitHub Desktop.
Twilio WhatsApp sender
'use strict';
const express = require('express');
const bodyParser = require('body-parser');
require('dotenv').config();
const clientTwilio = require('twilio')(process.env.accountSid, process.env.authToken);
// Constants
const port = process.env.PORT || 8080;
// App
const app = express();
app.use(bodyParser.urlencoded({
extended: true
}));
app.use(bodyParser.json());
app.post('/', function (req, res) {
console.log("echo post");
clientTwilio.messages
.create({
body: req.body.Body,
from: 'whatsapp:+14.......6',
to: req.body.From,
})
.then(message => console.log(message.sid))
.done();
});
var server = app.listen(port, function () {
console.log('Server running at http://127.0.0.1:' + port + '/');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment