Chore: Add a real-time event for contact resolution/update (#696)
* Chore: Add a real-time event for contact resolution/update * Chore: Ensure Events are sent to administrators Addresses: #419
This commit is contained in:
@@ -38,9 +38,12 @@ class Account < ApplicationRecord
|
||||
after_create :notify_creation
|
||||
after_destroy :notify_deletion
|
||||
|
||||
def channel
|
||||
# This should be unique for account
|
||||
'test_channel'
|
||||
def agents
|
||||
users.where(account_users: { role: :agent })
|
||||
end
|
||||
|
||||
def administrators
|
||||
users.where(account_users: { role: :administrator })
|
||||
end
|
||||
|
||||
def all_conversation_tags
|
||||
|
||||
@@ -25,6 +25,8 @@ class Contact < ApplicationRecord
|
||||
include Pubsubable
|
||||
include Avatarable
|
||||
include AvailabilityStatusable
|
||||
include Events::Types
|
||||
|
||||
validates :account_id, presence: true
|
||||
validates :email, allow_blank: true, uniqueness: { scope: [:account_id], case_sensitive: false }
|
||||
validates :identifier, allow_blank: true, uniqueness: { scope: [:account_id] }
|
||||
@@ -36,6 +38,8 @@ class Contact < ApplicationRecord
|
||||
has_many :messages, dependent: :destroy
|
||||
|
||||
before_validation :downcase_email
|
||||
after_create :dispatch_create_event
|
||||
after_update :dispatch_update_event
|
||||
|
||||
def get_source_id(inbox_id)
|
||||
contact_inboxes.find_by!(inbox_id: inbox_id).source_id
|
||||
@@ -53,11 +57,22 @@ class Contact < ApplicationRecord
|
||||
def webhook_data
|
||||
{
|
||||
id: id,
|
||||
name: name
|
||||
name: name,
|
||||
avatar: avatar_url
|
||||
}
|
||||
end
|
||||
|
||||
def downcase_email
|
||||
email.downcase! if email.present?
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def dispatch_create_event
|
||||
Rails.configuration.dispatcher.dispatch(CONTACT_CREATED, Time.zone.now, contact: self)
|
||||
end
|
||||
|
||||
def dispatch_update_event
|
||||
Rails.configuration.dispatcher.dispatch(CONTACT_UPDATED, Time.zone.now, contact: self)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user