Commit 6abb33e39cacc42d658b089116d7970e302382d2
1 parent
1697d0840e
Exists in
master
Incoming SMS from with +
Showing 3 changed files with 14 additions and 2 deletions Side-by-side Diff
lib/report-sender.js
... | ... | @@ -14,12 +14,23 @@ function incomingSMS(message) { |
14 | 14 | throw e; |
15 | 15 | } |
16 | 16 | |
17 | + if (!message.metadata.from) { | |
18 | + const e = new Error('Missing metadata.from on incoming sms'); | |
19 | + e.smsObj = message; | |
20 | + throw e; | |
21 | + } | |
22 | + | |
17 | 23 | if (!message.message) { |
18 | 24 | const e = new Error('Missing message on incoming sms'); |
19 | 25 | e.smsObj = message; |
20 | 26 | throw e; |
21 | 27 | } |
22 | 28 | |
29 | + if (message.metadata.from.indexOf('+') !== 0) { | |
30 | + logger.verbose('Do not send report on incoming message when sender does not start with "+".', { from: message.metadata.from, msg: message.message }); | |
31 | + return; | |
32 | + } | |
33 | + | |
23 | 34 | const requestOptions = { |
24 | 35 | url: config.report_url.incoming_sms, |
25 | 36 | qs: { |
lib/sms.js
... | ... | @@ -22,7 +22,8 @@ function extract(raw) { |
22 | 22 | |
23 | 23 | [result.metadata.raw] = lines; |
24 | 24 | result.metadata.status = typeof metadata[0] === 'string' ? metadata[0].replace(/^.+: /, '') : ''; |
25 | - result.metadata.from = typeof metadata[1] === 'string' ? metadata[1].replace(/^\+/, '') : ''; | |
25 | + // result.metadata.from = typeof metadata[1] === 'string' ? metadata[1].replace(/^\+/, '') : ''; | |
26 | + result.metadata.from = metadata[1]; | |
26 | 27 | |
27 | 28 | const tsFromRaw = `${metadata[3]} ${(metadata[4] || '').replace(/\+\d+/, '')}`; |
28 | 29 | result.metadata.ts = moment(tsFromRaw, 'YY/MM/DD HH:mm:ss').format('YYYY-MM-DD HH:mm:ss'); |
test/sms.js
... | ... | @@ -17,7 +17,7 @@ describe('#sms', () => { |
17 | 17 | |
18 | 18 | it('should return correct metadata', () => { |
19 | 19 | messageParsed.metadata.status.should.equal('REC UNREAD'); |
20 | - messageParsed.metadata.from.should.equal('6282210008543'); | |
20 | + messageParsed.metadata.from.should.equal('+6282210008543'); | |
21 | 21 | messageParsed.metadata.ts.should.equal('2019-07-26 13:21:16'); |
22 | 22 | }); |
23 | 23 |