Created
May 14, 2020 19:27
-
-
Save kwhinnery/9e9cad3f2899f6212f4babd21747e23d to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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