-
Notifications
You must be signed in to change notification settings - Fork 11
/
server.js
48 lines (37 loc) · 1.13 KB
/
server.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
46
47
require('dotenv').config();
const express = require('express');
const bodyParser = require('body-parser');
const SmsProxy = require('./SmsProxy');
const app = express();
app.set('port', (process.env.PORT || 3000));
app.use(bodyParser.urlencoded({ extended: false }));
app.listen(app.get('port'), function () {
console.log('SMS Proxy App listening on port', app.get('port'));
});
const smsProxy = new SmsProxy();
app.get('/', (req, res) => {
res.send('Hello world');
})
// Handle and route incoming SMS to virtual numbers
app.get('/webhooks/inbound-sms', (req, res) => {
const from = req.query.msisdn;
const to = req.query.to;
const text = req.query.text;
// Route virtual number to real number
smsProxy.proxySms(from, text);
res.sendStatus(204);
});
// Start a chat
app.post('/chat', (req, res) => {
const userANumber = req.body.userANumber;
const userBNumber = req.body.userBNumber;
smsProxy.createChat(userANumber, userBNumber, (err, result) => {
if (err) {
res.status(500).json(err);
}
else {
res.json(result);
}
});
res.send('OK');
});