-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
38 lines (32 loc) · 975 Bytes
/
index.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
const PORT = process.env.PORT || 8080,
CLOCKWORK_SMS_KEY = '08a14c0a82174c63451b296ade317da3764014fe';
var clockwork = require('clockwork'),
sms = clockwork({key: CLOCKWORK_SMS_KEY}),
express = require('express'),
bodyParser = require('body-parser'),
app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.get('/', function(req, res) {
res.send('Whoo! This is it in dbms2final!');
})
app.post('/send', function(req, mainRes) {
var receiver = req.body.number;
var message = req.body.message;
sms.sendSms({
To: receiver,
Content: message
}, function(err, res) {
if (err) {
console.log(`Oops! ${err}`);
mainRes.send(`Oops! ${err}`);
} else {
console.log('Sent successfully \n', res.responses[0]);
mainRes.send(`The message was successfully sent to ${receiver} \n with the message of ${message}`);
}
}
);
});
app.listen(PORT, function() {
console.log(`Listening on ${PORT}`);
});