on-received.js
2.15 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
73
74
75
76
77
78
79
80
81
const DEFAULT_MAX_MESSAGE_AGE_IN_SECS = 300;
const moment = require('moment');
const config = require('komodo-sdk/config');
const logger = require('tektrans-logger');
const messagingCenter = require('komodo-center-messaging-client-lib');
const modems = require('../../modems');
const blacklistMsgPatterns = [
/^TRANSAKSI KE NOMOR/,
/^Kesalahan autentikasi/,
/^Saldo anda/,
/^Perintah salah/,
];
const maxMessageAgeInSeconds = config.max_message_age_in_secs
|| DEFAULT_MAX_MESSAGE_AGE_IN_SECS;
module.exports = (req, res) => {
res.end('OK');
const {
msg, msisdn, smsc, ts,
} = req.query;
if (!(msg || '').trim()) {
logger.verbose('ON-RECEIVED B09186E3: Skip empty message', {
qs: req.query,
});
return;
}
const msgUpperCased = (msg || '').trim().toUpperCase();
if (
(msisdn.search(/\+*62/) === 0)
&& blacklistMsgPatterns.find((pattern) => msgUpperCased.search(pattern) >= 0)
) {
logger.verbose('ON-RECEIVED 5486D373: Skip invalid message', {
msg,
msisdn,
qs: req.query,
});
return;
}
const sentTime = moment(ts, 'YYYY-MM-DD HH:mm:ss');
const messageAgeInSeconds = Math.round(Number(new Date() - sentTime) / 1000);
if (messageAgeInSeconds > maxMessageAgeInSeconds) {
logger.warn('ON-RECEIVED 2247F406: Got expired message from EVO-CP', {
qs: req.query,
messageAgeInSeconds,
maxMessageAgeInSeconds,
});
return;
}
logger.info('ON-RECEIVED D3747E3C: Got message from EVO-CP', {
messageAgeInSeconds,
qs: req.query,
});
const modem = modems.modemsDictionary[smsc] || {};
const doNotForwardToCore = (msisdn.search(/(\+)*62/) !== 0) || (msisdn.length <= 8);
messagingCenter.onIncomingMessage({
me: modem.imsi || smsc,
partner: `${msisdn}${config.number_suffix || ''}`,
partner_raw: msisdn,
msg,
origin_label: modem.imsi || smsc,
origin_transport: 'SMS',
origin_partner: msisdn,
do_not_forward_to_core: doNotForwardToCore,
});
};