-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
51 lines (33 loc) · 939 Bytes
/
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
48
49
50
51
const express = require('express');
const logger = require('morgan');
const port = process.env.PORT || 3030;
const app = express();
app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.get('/', (req, res) => {
res.send("USSD with js");
})
app.post('/', (req, res) => {
let { sessionId, serviceCode, phoneNumber, text } = req.body;
if (text == '') {
let response = `CON Get free unlimited internet for a week
1.YES
2.NO`
res.send(response);
}
else if (text == '1') {
let response = `END Kijana pambana hamna cha bure`
res.send(response);
}
else if (text == '2') {
let response = `END Good, you are on the right path`
res.send(response);
}
else {
res.status(400).send('bad request');
}
})
app.listen(port, () => {
console.log(`Listening to port ${port}`)
})