diff --git a/sgx-bwmsgsv2.rb b/sgx-bwmsgsv2.rb index fb2c8a8d783bd0dadd8c4fe690d4550ba7c5d127..f74c817072dce114ac1562fd787f91bc4ef272cd 100755 --- a/sgx-bwmsgsv2.rb +++ b/sgx-bwmsgsv2.rb @@ -300,7 +300,7 @@ module SGXbwmsgsv2 LOG.debug("Proxied media URL", url: media_url) end - msg = m ? m.copy : Blather::Stanza::Message.new(to, "") + msg = m ? m.copy : Blather::Stanza::Message.new(to) msg.from = from msg.subject = subject if subject @@ -850,13 +850,11 @@ module SGXbwmsgsv2 }.catch_only(BandwidthError) { |e| EMPromise.reject(case e.code when 401 - # TODO: add text re bad credentials - [:auth, 'not-authorized'] + [:auth, 'not-authorized', e.to_s] when 404 - # TODO: add text re number not found or disabled - [:cancel, 'item-not-found'] + [:cancel, 'item-not-found', e.to_s] else - [:modify, 'not-acceptable'] + [:modify, 'not-acceptable', e.to_s] end) } end @@ -1213,6 +1211,10 @@ class WebhookHandler < Goliath::API end return [200, {}, "OK"] + + if !text || text.empty? || (jparams['to'].length > 1 && media_urls.any?) + return [200, {}, "OK"] + end end else text = "unknown type (#{type})" \ @@ -1309,8 +1311,10 @@ class WebhookHandler < Goliath::API # if message-failed, we already set msg.from # moreover, we said `msg = msg.as_error`, and StanzaError - msg.from = others_num + '@' + ARGV[0] if msg.respond_to?(:from=) - SGXbwmsgsv2.write(msg) + if msg + msg.from = others_num + '@' + ARGV[0] if msg.respond_to?(:from=) + SGXbwmsgsv2.write(msg) + end # Emit event to messages stream case [jparams['direction'], type]