-
Notifications
You must be signed in to change notification settings - Fork 0
/
index_0.js
38 lines (26 loc) · 972 Bytes
/
index_0.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
37
const express = require("express");
const app = express();
const server = require("http").createServer(app);
require("dotenv").config();
app.use(express.urlencoded({
extended: true
}));
// Home da página
app.get("/", (req, res) => res.send("Olá mundo!"));
// Receber chamada telefônica
app.post("/", (req, res) => {
console.log(`Nova chamada de ${req.body.FromCity}/${req.body.FromState} do número ${escondeNumero(req.body.From)}`, );
res.set("Content-Type", "text/xml");
res.send(`
<Response>
<Say voice="alice" language="pt-BR">A Tuílio quer dar boas vindas para você no Tê Dê Cê.</Say>
<Play>http://demo.twilio.com/docs/classic.mp3</Play>
</Response>
`);
});
console.log("Escutando na porta 8080");
server.listen(8080);
function escondeNumero(number) {
// +5511999991234 => +55119****1234
return number.substr(0, number.length - 8) + '****-' + number.substr(number.length - 4 )
}