diff --git a/sgx-bwmsgsv2.rb b/sgx-bwmsgsv2.rb index 9ad0a73ed8a812f746bba6a05a7da8cb77128316..f35616b8353e689b34c4403694f64cbfd031ec5c 100755 --- a/sgx-bwmsgsv2.rb +++ b/sgx-bwmsgsv2.rb @@ -1135,6 +1135,22 @@ class WebhookHandler < Goliath::API # TODO: remove this hack if jparams['to'].length > 1 + case type + when 'message-failed' + MessageEvent::Failed.new( + timestamp: jparams['time'], + stanza_id: id, + bandwidth_id: jparams['id'], + error_code: jparams['errorCode'].to_s, + error_description: jparams['description'].to_s + ).emit(REDIS) + when 'message-delivered' + MessageEvent::Delivered.new( + timestamp: jparams['time'], + stanza_id: id, + bandwidth_id: jparams['id'] + ).emit(REDIS) + end puts "WARN! group no rcpt: #{users_num}" return [200, {}, "OK"] end diff --git a/test/property/test_webhook_handler.rb b/test/property/test_webhook_handler.rb index 828086e0b6305d1014f3acc8277c545b28dbde92..a88993e7264823cfd7f594b0cb455115ff9c86ce 100644 --- a/test/property/test_webhook_handler.rb +++ b/test/property/test_webhook_handler.rb @@ -181,4 +181,32 @@ class WebhookPropertyTest < Minitest::Test } end em :test_unknown_direction_returns_400_missing_params_when_message_failed + + def test_delivered_emits_correct_stream_event + property_of { + Webhook + .new(REDIS) + .type { "message-delivered" } + .generate + }.check { |metadata, example| + invoke_webhook(example) + + entries = REDIS.stream_entries("messages").sync + assert_equal 1, entries.length + + fields = entries.first[:fields] + expected_keys = %w[ + event source timestamp stanza_id bandwidth_id + ].sort + assert_equal expected_keys, fields.keys.sort + + assert_equal "delivered", fields["event"] + assert_equal "bwmsgsv2", fields["source"] + + assert_equal metadata["stanza_id"], fields["stanza_id"] + assert_equal example["message"]["id"], fields["bandwidth_id"] + assert_equal example["message"]["time"], fields["timestamp"] + } + end + em :test_delivered_emits_correct_stream_event end