first almost-working acceptance of V2 JSON message

Denver Gingerich created

Thanks to 4607bb5 we now had params moved out of the way (since we
can't re-assign to this special variable) so we could now just simply
assign the JSON block to the new params variable (jparams).  Since the
Bandwidth V2 API differs a bit from the V1 API (on which this file is
based), we had to comment out some parameters for now, and change
'messageId' to 'id', but other than that the parameters at least
exist in V2.

However, this still doesn't cause the message to flow completely
through the SGX, since we haven't fixed the 'to' parameter, which is
now an array in V2, and so we now get something like:

'jid_key (catapult_jid-["+14165551212"]) DNE; BW API misconfigured?'

But this is way better than crashing the SGX, which is what we got
when passing in V2 messages before this fix.

So we're well on the road to getting V2 messages all the way through
the SGX and probably just need a couple minor fixes now.  Yay!

Change summary

sgx-bwmsgsv2.rb | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)

Detailed changes

sgx-bwmsgsv2.rb 🔗

@@ -785,7 +785,8 @@ class WebhookHandler < Goliath::API
 
 		puts 'ENV: ' + env.reject{ |k| k == 'params' }.to_s
 
-		jparams = params
+		# TODO: process each message in list, not just first one
+		jparams = params['_json'][0]['message']
 
 		users_num = ''
 		others_num = ''
@@ -801,11 +802,11 @@ class WebhookHandler < Goliath::API
 			return [200, {}, "OK"]
 		end
 
-		puts 'BODY - messageId: ' + jparams['messageId'] +
-			', eventType: ' + jparams['eventType'] +
-			', time: ' + jparams['time'] +
+		puts 'BODY - messageId: ' + jparams['id'] +
+			#', eventType: ' + jparams['eventType'] +
+			#', time: ' + jparams['time'] +
 			', direction: ' + jparams['direction'] +
-			', state: ' + jparams['state'] +
+			#', state: ' + jparams['state'] +
 			', deliveryState: ' + (jparams['deliveryState'] ?
 				jparams['deliveryState'] : 'NONE') +
 			', deliveryCode: ' + (jparams['deliveryCode'] ?