first working message delivery receipts; tiny hack

Denver Gingerich created

Delivery receipts (at least for single-recipient messages) now work
correctly with the V2 API.  This was mostly simple changes (just
needed to change the deliveryState == 'delivered' check to instead be
type == 'message-delivered'), but did require a bit of a hack because
of the way we decided to determine the source and destination numbers
in d2e2d92 - there's probably a cleaner way, but we'll just go forward
with this quick fix for now, and do a better job of it later (which
may be needed anyway once we do (likely required) additional work for
multi-recipient message delivery receipts.

Change summary

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

Detailed changes

sgx-bwmsgsv2.rb 🔗

@@ -937,8 +937,9 @@ class WebhookHandler < Goliath::API
 			id = WEBrick::HTTPUtils.unescape(tag_parts[0])
 			resourcepart = WEBrick::HTTPUtils.unescape(tag_parts[1])
 
-			case jparams['deliveryState']
+			case type
 			when 'not-delivered'
+				# TODO: update above label
 				# create a bare message like the one user sent
 				msg = Blather::Stanza::Message.new(
 					others_num + '@' + ARGV[0])
@@ -951,7 +952,7 @@ class WebhookHandler < Goliath::API
 					'recipient-unavailable',
 					:wait
 				).to_node
-			when 'delivered'
+			when 'message-delivered'
 				msg = ReceiptMessage.new(bare_jid)
 
 				# TODO: put in member/instance variable
@@ -965,14 +966,18 @@ class WebhookHandler < Goliath::API
 				rcvd['xmlns'] = 'urn:xmpp:receipts'
 				rcvd['id'] = id
 				msg.add_child(rcvd)
+
+				# TODO: make prettier: this should be done above
+				others_num = params['_json'][0]['to']
 			when 'waiting'
+				# TODO: update above label
 				# can't really do anything with it; nice to know
 				puts "message with id #{id} waiting"
 				return [200, {}, "OK"]
 			else
 				# TODO: notify somehow of unknown state receivd?
 				puts "message with id #{id} has "\
-					"othr state #{jparams['deliveryState']}"
+					"other type #{type}"
 				return [200, {}, "OK"]
 			end