-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
30 lines (24 loc) · 959 Bytes
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
const http = require('http');
const express = require('express');
const MessagingResponse = require('twilio').twiml.MessagingResponse;
const bodyParser = require('body-parser');
const responder = require('./responder/responder');
const app = express();
app.use(bodyParser.urlencoded({ extended: false }));
app.post('/', async (req, res) => {
const twiml = new MessagingResponse();
if (req.body.Body != null) { //Check if response is not null, if it isn't then we delegate to the handler
var number = req.body.From;
let msg = await responder.buidReply(req.body.From, req.body.Body);
twiml.message(msg);
} else {
twiml.message(
'Sorry something went wrong, please try again later'
);
}
res.writeHead(200, { 'Content-Type': 'text/xml' });
res.end(twiml.toString());
});
http.createServer(app).listen(process.env.PORT || 8080, () => {
console.log('Listen on defualt port');
});