From 6abd6539b370856a6bb2d6dab69588359de88947 Mon Sep 17 00:00:00 2001 From: Denver Gingerich Date: Wed, 22 Apr 2020 00:47:54 +0000 Subject: [PATCH] first almost-working acceptance of V2 JSON message 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! --- sgx-bwmsgsv2.rb | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/sgx-bwmsgsv2.rb b/sgx-bwmsgsv2.rb index f275fe41f095b14862e9d843aab91f144ab0633d..d26c798fe99ebf8b6bcdf60e6ea49cd9e573a8fc 100755 --- a/sgx-bwmsgsv2.rb +++ b/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'] ?