Skip to content

Instantly share code, notes, and snippets.

@kwhinnery
Created May 14, 2020
Embed
What would you like to do?
const http = require('http');
const express = require('express');
const bodyParser = require('body-parser');
const MessagingResponse = require('twilio').twiml.MessagingResponse;
const app = express();
app.use(bodyParser.urlencoded({ extended: false });
app.post('/sms', (req, res) => {
const twiml = new MessagingResponse();
// Here is the from number and message body
console.log(req.body.From);
console.log(req.body.Body);
const message = twiml.message();
message.body('The Robots are coming! Head for the hills!');
message.media('https://farm8.staticflickr.com/7090/6941316406_80b4d6d50e_z_d.jpg');
res.writeHead(200, {'Content-Type': 'text/xml'});
res.end(twiml.toString());
});
http.createServer(app).listen(1337, () => {
console.log('Express server listening on port 1337');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment