From b277759370ce0e8bdc569f0b0fe89f9b9696bb04 Mon Sep 17 00:00:00 2001 From: Denver Gingerich Date: Fri, 24 Apr 2020 21:10:38 +0000 Subject: [PATCH] first working message delivery receipts; tiny hack 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. --- sgx-bwmsgsv2.rb | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/sgx-bwmsgsv2.rb b/sgx-bwmsgsv2.rb index 8f48652bb8151e3e2d87f493187d65ba0c4639f7..1aba0c99c2f24fb10fc3b17520f7812ee367bd3a 100755 --- a/sgx-bwmsgsv2.rb +++ b/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