10
10
. get ( handleInboundSms )
11
11
. post ( handleInboundSms ) ;
12
12
13
- let concat_sms = [ ] ; // Array of message objects
13
+ const concat_sms = [ ] ; // Array of message objects
14
14
15
- function handleInboundSms ( request , response ) {
15
+ const handleInboundSms = ( request , response ) => {
16
16
const params = Object . assign ( request . query , request . body ) ;
17
-
18
- if ( params [ 'concat' ] === 'true' ) {
17
+ console . dir ( params )
18
+ if ( params [ 'concat' ] == 'true' ) {
19
19
/* This is a concatenated message. Add it to an array
20
20
so that we can process it later. */
21
21
concat_sms . push ( {
@@ -27,9 +27,7 @@ function handleInboundSms(request, response) {
27
27
28
28
/* Do we have all the message parts yet? They might
29
29
not arrive consecutively. */
30
- let parts_for_ref = concat_sms . filter ( function ( part ) {
31
- return part . ref == params [ 'concat-ref' ] ;
32
- } ) ;
30
+ const parts_for_ref = concat_sms . filter ( part => part . ref == params [ 'concat-ref' ] ) ;
33
31
34
32
// Is this the last message part for this reference?
35
33
if ( parts_for_ref . length == params [ 'concat-total' ] ) {
@@ -45,31 +43,24 @@ function handleInboundSms(request, response) {
45
43
response . status ( 204 ) . send ( ) ;
46
44
}
47
45
48
- function processConcatSms ( all_parts ) {
49
-
50
- // Order all the message parts
51
- all_parts . sort ( function ( a , b ) {
52
- if ( Number ( a . part ) < Number ( b . part ) ) {
53
- return - 1 ;
54
- } else {
55
- return 1 ;
56
- }
57
- } )
46
+ const processConcatSms = ( all_parts ) => {
58
47
59
- let concat_message = '' ;
48
+ // Sort the message parts
49
+ all_parts . sort ( ( a , b ) => a . part - b . part ) ;
60
50
61
51
// Reassemble the message from the parts
52
+ let concat_message = '' ;
62
53
for ( i = 0 ; i < all_parts . length ; i ++ ) {
63
54
concat_message += all_parts [ i ] . message ;
64
55
}
65
56
66
57
displaySms ( all_parts [ 0 ] . from , concat_message ) ;
67
58
}
68
59
69
- function displaySms ( msisdn , text ) {
60
+ const displaySms = ( msisdn , text ) => {
70
61
console . log ( 'FROM: ' + msisdn ) ;
71
62
console . log ( 'MESSAGE: ' + text ) ;
72
63
console . log ( '---' ) ;
73
64
}
74
65
75
- app . listen ( process . env . PORT ) ;
66
+ app . listen ( process . env . PORT ) ;
0 commit comments