add support for message delivery failure notifying

Denver Gingerich created

This is similar to the support for message delivery receipts
themselves, so it's actually just as simple as checking for the
correct 'type', and the importing the two hacks that we already have
for message delivery receipts, namely those in b277759 and d49bf12 -
we probably want to move them into a common area eventually, but this
is fine for now, and definitely works in our tests just now.

Change summary

sgx-bwmsgsv2.rb | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)

Detailed changes

sgx-bwmsgsv2.rb 🔗

@@ -939,20 +939,28 @@ class WebhookHandler < Goliath::API
 			resourcepart = WEBrick::HTTPUtils.unescape(tag_parts[1])
 
 			case type
-			when 'not-delivered'
-				# TODO: update above label
+			when 'message-failed'
 				# create a bare message like the one user sent
 				msg = Blather::Stanza::Message.new(
 					others_num + '@' + ARGV[0])
 				msg.from = bare_jid + '/' + resourcepart
 				msg['id'] = id
 
+				# TODO: remove this hack
+				if jparams['to'].length > 1
+					puts "WARN! group no rcpt: #{users_num}"
+					return [200, {}, "OK"]
+				end
+
 				# create an error reply to the bare message
 				msg = Blather::StanzaError.new(
 					msg,
 					'recipient-unavailable',
 					:wait
 				).to_node
+
+				# TODO: make prettier: this should be done above
+				others_num = params['_json'][0]['to']
 			when 'message-delivered'
 				# TODO: remove this hack
 				if jparams['to'].length > 1