sms-response

node v12.22.12
version: 6.0.0
endpointsharetweet
const http = require('http'); var tonicExpress = require("@runkit/runkit/express-endpoint/1.0.0"); // Just provide the exports object to the tonicExpress helper var app = tonicExpress(module.exports); const MessagingResponse = require('twilio').twiml.MessagingResponse; const bodyParser = require('body-parser'); //const app = express(); app.use(bodyParser.urlencoded({ extended: false })); //app.get("/:name", (req, res) => res.send(`hey ${req.params.name}`)) app.post('/', (req, res) => { const twiml = new MessagingResponse(); if (req.body.Body == 'hello') { twiml.message('Hi!'); } else if (req.body.Body == 'bye') { twiml.message('Goodbye'); } else { twiml.message( 'No Body param match, Twilio sends this in the request to your server.' ); } res.writeHead(200, { 'Content-Type': 'text/xml' }); res.end(twiml.toString()); }); http.createServer(app).listen(1337, () => { console.log('Express server listening on port 1337'); });
Loading…

no comments

    sign in to comment