forked from twilio/twilio-node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
express.js
36 lines (28 loc) · 894 Bytes
/
express.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
31
32
33
34
35
36
const twilio = require("twilio");
const bodyParser = require("body-parser");
const MessagingResponse = require("twilio").twiml.MessagingResponse;
const authToken = process.env.TWILIO_AUTH_TOKEN;
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(authToken), (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}`);
});