chore: Webhook event data improvements (#4317)
This commit is contained in:
@@ -22,4 +22,12 @@ class BaseListener
|
||||
contact = event.data[:contact]
|
||||
[contact, contact.account]
|
||||
end
|
||||
|
||||
def extract_changed_attributes(event)
|
||||
changed_attributes = event.data[:changed_attributes]
|
||||
|
||||
return if changed_attributes.blank?
|
||||
|
||||
changed_attributes.map { |k, v| { k => { previous_value: v[0], current_value: v[1] } } }
|
||||
end
|
||||
end
|
||||
|
||||
@@ -2,23 +2,34 @@ class WebhookListener < BaseListener
|
||||
# FIXME: deprecate the opened and resolved events in future in favor of status changed event.
|
||||
def conversation_resolved(event)
|
||||
conversation = extract_conversation_and_account(event)[0]
|
||||
changed_attributes = extract_changed_attributes(event)
|
||||
inbox = conversation.inbox
|
||||
payload = conversation.webhook_data.merge(event: __method__.to_s)
|
||||
payload = conversation.webhook_data.merge(event: __method__.to_s, changed_attributes: changed_attributes)
|
||||
deliver_webhook_payloads(payload, inbox)
|
||||
end
|
||||
|
||||
# FIXME: deprecate the opened and resolved events in future in favor of status changed event.
|
||||
def conversation_opened(event)
|
||||
conversation = extract_conversation_and_account(event)[0]
|
||||
changed_attributes = extract_changed_attributes(event)
|
||||
inbox = conversation.inbox
|
||||
payload = conversation.webhook_data.merge(event: __method__.to_s)
|
||||
payload = conversation.webhook_data.merge(event: __method__.to_s, changed_attributes: changed_attributes)
|
||||
deliver_webhook_payloads(payload, inbox)
|
||||
end
|
||||
|
||||
def conversation_status_changed(event)
|
||||
conversation = extract_conversation_and_account(event)[0]
|
||||
changed_attributes = extract_changed_attributes(event)
|
||||
inbox = conversation.inbox
|
||||
payload = conversation.webhook_data.merge(event: __method__.to_s)
|
||||
payload = conversation.webhook_data.merge(event: __method__.to_s, changed_attributes: changed_attributes)
|
||||
deliver_webhook_payloads(payload, inbox)
|
||||
end
|
||||
|
||||
def conversation_updated(event)
|
||||
conversation = extract_conversation_and_account(event)[0]
|
||||
changed_attributes = extract_changed_attributes(event)
|
||||
inbox = conversation.inbox
|
||||
payload = conversation.webhook_data.merge(event: __method__.to_s, changed_attributes: changed_attributes)
|
||||
deliver_webhook_payloads(payload, inbox)
|
||||
end
|
||||
|
||||
|
||||
@@ -188,7 +188,7 @@ class Conversation < ApplicationRecord
|
||||
return unless previous_changes.keys.present? && (previous_changes.keys & %w[team_id assignee_id status snoozed_until
|
||||
custom_attributes]).present?
|
||||
|
||||
dispatcher_dispatch(CONVERSATION_UPDATED)
|
||||
dispatcher_dispatch(CONVERSATION_UPDATED, previous_changes)
|
||||
end
|
||||
|
||||
def self_assign?(assignee_id)
|
||||
@@ -207,14 +207,15 @@ class Conversation < ApplicationRecord
|
||||
CONVERSATION_READ => -> { saved_change_to_contact_last_seen_at? },
|
||||
CONVERSATION_CONTACT_CHANGED => -> { saved_change_to_contact_id? }
|
||||
}.each do |event, condition|
|
||||
condition.call && dispatcher_dispatch(event)
|
||||
condition.call && dispatcher_dispatch(event, status_change)
|
||||
end
|
||||
end
|
||||
|
||||
def dispatcher_dispatch(event_name)
|
||||
def dispatcher_dispatch(event_name, changed_attributes = nil)
|
||||
return if Current.executed_by.present? && Current.executed_by.instance_of?(AutomationRule)
|
||||
|
||||
Rails.configuration.dispatcher.dispatch(event_name, Time.zone.now, conversation: self, notifiable_assignee_change: notifiable_assignee_change?)
|
||||
Rails.configuration.dispatcher.dispatch(event_name, Time.zone.now, conversation: self, notifiable_assignee_change: notifiable_assignee_change?,
|
||||
changed_attributes: changed_attributes)
|
||||
end
|
||||
|
||||
def conversation_status_changed_to_open?
|
||||
|
||||
Reference in New Issue
Block a user