Commit 2be1f1f4e4ccb5256c5e72162e6b05781667cac7
1 parent
b7e1d743ff
Exists in
master
Ignored expired message
Showing 2 changed files with 16 additions and 1 deletions Side-by-side Diff
lib/smstools-handler/received.js
1 | 1 | const fs = require('fs'); |
2 | +const moment = require('moment'); | |
2 | 3 | const logger = require('komodo-sdk/logger'); |
3 | 4 | |
4 | 5 | const config = require('komodo-sdk/config'); |
... | ... | @@ -29,14 +30,27 @@ module.exports = async (msgFilename) => { |
29 | 30 | const imsi = parsedMsg.headers.get('imsi'); |
30 | 31 | const { text } = parsedMsg; |
31 | 32 | |
33 | + const sentRaw = parsedMsg.headers.get('sent'); | |
34 | + const sent = sentRaw && moment(sentRaw, 'YY-MM-DD HH:mm:ss'); | |
35 | + | |
32 | 36 | logger.info('Message parsed', { |
33 | - from, imsi, text, | |
37 | + from, imsi, text, sent, | |
34 | 38 | }); |
35 | 39 | |
36 | 40 | if (!from || !imsi || !text) { |
37 | 41 | return; |
38 | 42 | } |
39 | 43 | |
44 | + if (sent) { | |
45 | + const messageAgeMs = new Date() - sent; | |
46 | + if (messageAgeMs > 5 * 60 * 1000) { | |
47 | + logger.info('Ignore expired message', { | |
48 | + imsi, from, text, sent, messageAgeMs, | |
49 | + }); | |
50 | + return; | |
51 | + } | |
52 | + } | |
53 | + | |
40 | 54 | const doNotForwardToCore = (from.search(/(\+)*62/) !== 0) || (from.length <= 8); |
41 | 55 | |
42 | 56 | messagingClient.onIncomingMessage({ |
test/mailparser-wrapper.js
... | ... | @@ -27,6 +27,7 @@ Length: 20 |
27 | 27 | obj.headers.get('subject').should.equal('USB7'); |
28 | 28 | obj.headers.get('modem').should.equal('USB7'); |
29 | 29 | obj.headers.get('imsi').should.equal('510014032469304', 'imsi'); |
30 | + obj.headers.get('sent').should.equal('19-11-28 20:24:56'); | |
30 | 31 | |
31 | 32 | obj.text.should.equal('25.082178898202.1234'); |
32 | 33 | }); |