Skip to content

Instantly share code, notes, and snippets.

@kwhinnery
Created May 14, 2020 19:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kwhinnery/9e9cad3f2899f6212f4babd21747e23d to your computer and use it in GitHub Desktop.
Save kwhinnery/9e9cad3f2899f6212f4babd21747e23d to your computer and use it in GitHub Desktop.
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