File tree Expand file tree Collapse file tree 2 files changed +22
-0
lines changed
Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ def conversation_status_changed(event)
33 conversation = extract_conversation_and_account ( event ) [ 0 ]
44 changed_attributes = extract_changed_attributes ( event )
55 inbox = conversation . inbox
6+
67 payload = conversation . webhook_data . merge ( event : __method__ . to_s , changed_attributes : changed_attributes )
78 deliver_webhook_payloads ( payload , inbox )
89 end
@@ -88,6 +89,7 @@ def inbox_updated(event)
8889 def deliver_account_webhooks ( payload , account )
8990 account . webhooks . account_type . each do |webhook |
9091 next unless webhook . subscriptions . include? ( payload [ :event ] )
92+ next if payload [ :inbox ] . present? && ( webhook . inbox_id . present? && webhook . inbox_id != payload [ :inbox ] [ :id ] )
9193
9294 WebhookJob . perform_later ( webhook . url , payload )
9395 end
Original file line number Diff line number Diff line change 7575 listener . message_created ( api_event )
7676 end
7777 end
78+
79+ context 'when webhook has an inbox and it matches the event inbox' do
80+ it 'receives the event' do
81+ webhook = create ( :webhook , account : account , inbox : inbox )
82+ expect ( WebhookJob ) . to receive ( :perform_later )
83+ . with ( webhook . url , message . webhook_data . merge ( event : 'message_created' ) ) . once
84+
85+ listener . message_created ( message_created_event )
86+ end
87+ end
88+
89+ context 'when webhook has an inbox and it does not match the event inbox' do
90+ it 'does not receive the event' do
91+ another_inbox = create ( :inbox , account : account )
92+ create ( :webhook , account : account , inbox : another_inbox )
93+
94+ expect ( WebhookJob ) . not_to receive ( :perform_later )
95+ listener . message_created ( message_created_event )
96+ end
97+ end
7898 end
7999
80100 describe '#conversation_created' do
You can’t perform that action at this time.
0 commit comments