report-sender.js
2.26 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/**
* Report sender
* @module report-sender
* @deprecated
*/
const request = require('request');
const config = require('komodo-sdk/config');
const logger = require('komodo-sdk/logger');
logger.warn(`'${path.basename(__filename, '.js')}' is DEPRECATED, please use 'report-sender2'!`);
// eslint-disable-next-line no-console
console.trace(`'${path.basename(__filename, '.js')}' is DEPRECATED, please use 'report-sender2'!`);
function incomingSMS(message, modemInfo) {
if (!message || !config || !config.report_url || !config.report_url.incoming_sms) return;
if (!message.metadata) {
const e = new Error('Missing metadata on incoming sms');
e.smsObj = message;
throw e;
}
if (!message.metadata.from) {
const e = new Error('Missing metadata.from on incoming sms');
e.smsObj = message;
throw e;
}
if (!message.message) {
const e = new Error('Missing message on incoming sms');
e.smsObj = message;
throw e;
}
const requestOptions = {
url: config.report_url.incoming_sms,
qs: {
ts: message.metadata.ts,
status: message.metadata.status,
number: message.metadata.from,
msg: message.message,
modem: config.name,
modem_imsi: modemInfo.imsi,
modem_msisdn: modemInfo.msisdn,
modem_device: config.modem.device,
modem_network_id: modemInfo.networkId,
modem_network_name: modemInfo.networkName,
modem_signal_strength: modemInfo.signalStrength,
uptime: Math.floor(process.uptime()),
report_port: config.http_command_server.listen_port,
report_apikey: config.http_command_server.apikey,
report_path_sms: '/sms',
},
};
logger.info('Sending report via HTTP', requestOptions);
request(requestOptions, (err, res, body) => {
if (err) {
logger.warn(`Error sending report via HTTP. ${err.toString()}`);
return;
}
if (res.statusCode !== 200) {
logger.warn(`Error sending report via HTTP. Server respond with HTTP status code ${res.statusCode}`, { http_status_code: res.statusCode, body });
}
});
}
exports.incomingSMS = incomingSMS;