-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
51 lines (40 loc) · 1.11 KB
/
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
39
40
41
42
43
44
45
46
47
48
49
require('dotenv').config();
const app = require('express')();
const bodyParser = require('body-parser');
app.set('port', (process.env.PORT || 5000);
app.use(bodyParser.json());
const NEXMO_API_KEY = process.env.NEXMO_API_KEY;
const NEXMO_API_SECRET = process.env.NEXMO_API_SECRET;
const WEBHOOK_URL = process.env.WEBHOOK_URL;
const Nexmo = require('nexmo');
const nexmo = new Nexmo({
apiKey: NEXMO_API_KEY,
apiSecret: NEXMO_API_SECRET
});
/**
* Make the request
*/
app.get('/insight/:number', function(request, response) {
console.log("Getting information for " + request.params.number);
nexmo.numberInsight.get({
level: 'advancedAsync',
number: request.params.number,
callback: WEBHOOK_URL
}, function (error, result) {
if (error) {
console.error(error);
} else {
console.log(result);
}
});
});
/**
* Callback for the webhook
*/
app.post('/webhooks/insight', function (request, response) {
console.dir(request.body);
response.status(204).send();
});
app.listen(app.get('port'), function() {
console.log('Listening on port', app.get('port'));
});