-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
45 lines (35 loc) · 1.28 KB
/
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
const app = require('express')()
const bodyParser = require('body-parser')
var http = require('http').Server(app);
var io = require('socket.io')(http);
var port = process.env.PORT || 3000;
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: true }))
// nexmo inbound sms webhook
app
.route('/webhooks/inbound-sms')
.get(handleInboundSms)
.post(handleInboundSms)
function handleInboundSms(request, response) {
const params = Object.assign(request.query, request.body)
console.log(params)
let date_ob = new Date();
let hours = date_ob.getHours();
let minutes = date_ob.getMinutes();
var time=('0' + hours).slice(-2)+':'+('0' + minutes).slice(-2);
var fromNo = (process.env.ANON ? params.From.slice(0,4) + "..."+params.From.slice(-4) : params.From)
io.emit('chat message', '<i>[' + time + '] </i><b>' + fromNo +"</b>: " + params.Body);
response.status(204).send()
}
app.get('/', function(req, res){
res.sendFile(__dirname + '/index.html');
});
app.get('/number', function(req, res) {
res.json({number: (process.env.NUMBER ? process.env.NUMBER : "UNKNOWN")})
})
io.on('connection', function(socket){
console.log('a user connected');
});
http.listen(port, function(){
console.log('listening on *:'+port);
});