forked from twilio/twilio-node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexpress.js
More file actions
32 lines (25 loc) · 835 Bytes
/
Copy pathexpress.js
File metadata and controls
32 lines (25 loc) · 835 Bytes
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
31
32
const twilio = require('twilio');
const bodyParser = require('body-parser');
const MessagingResponse = require('twilio').twiml.MessagingResponse;
const express = require('express')
const app = express()
const port = 3000
app.use(bodyParser.json({
verify: (req, res, buf) => {
req.rawBody = buf
}
}))
app.get('/', (req, res) => {
res.send('Hello World!')
})
app.post('/message', twilio.webhook(), (req, res) => {
// Twilio Messaging URL - receives incoming messages from Twilio
const response = new MessagingResponse();
response.message(`Your text to me was ${req.body.Body}.
Webhooks are neat :)`);
res.set('Content-Type', 'text/xml');
res.send(response.toString());
});
app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`)
})