chore: Add event for conversations transferred to Bot (#2167)
* chore: Event for conversation transferred to Bot Co-authored-by: Muhsin Keloth <muhsinkeramam@gmail.com> Co-authored-by: Nithin David <webofnithin@gmail.com>
This commit is contained in:
@@ -10,8 +10,7 @@ class ActionCableConnector extends BaseActionCableConnector {
|
||||
'message.created': this.onMessageCreated,
|
||||
'message.updated': this.onMessageUpdated,
|
||||
'conversation.created': this.onConversationCreated,
|
||||
'conversation.opened': this.onStatusChange,
|
||||
'conversation.resolved': this.onStatusChange,
|
||||
'conversation.status_changed': this.onStatusChange,
|
||||
'user:logout': this.onLogout,
|
||||
'page:reload': this.onReload,
|
||||
'assignee.changed': this.onAssigneeChanged,
|
||||
|
||||
@@ -8,8 +8,7 @@ class ActionCableConnector extends BaseActionCableConnector {
|
||||
'message.updated': this.onMessageUpdated,
|
||||
'conversation.typing_on': this.onTypingOn,
|
||||
'conversation.typing_off': this.onTypingOff,
|
||||
'conversation.resolved': this.onStatusChange,
|
||||
'conversation.opened': this.onStatusChange,
|
||||
'conversation.status_changed': this.onStatusChange,
|
||||
'presence.update': this.onPresenceUpdate,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -32,25 +32,11 @@ class ActionCableListener < BaseListener
|
||||
broadcast(account, tokens, MESSAGE_UPDATED, message.push_event_data)
|
||||
end
|
||||
|
||||
def conversation_resolved(event)
|
||||
def conversation_status_changed(event)
|
||||
conversation, account = extract_conversation_and_account(event)
|
||||
tokens = user_tokens(account, conversation.inbox.members) + [conversation.contact&.pubsub_token]
|
||||
|
||||
broadcast(account, tokens, CONVERSATION_RESOLVED, conversation.push_event_data)
|
||||
end
|
||||
|
||||
def conversation_opened(event)
|
||||
conversation, account = extract_conversation_and_account(event)
|
||||
tokens = user_tokens(account, conversation.inbox.members) + [conversation.contact&.pubsub_token]
|
||||
|
||||
broadcast(account, tokens, CONVERSATION_OPENED, conversation.push_event_data)
|
||||
end
|
||||
|
||||
def conversation_lock_toggle(event)
|
||||
conversation, account = extract_conversation_and_account(event)
|
||||
tokens = user_tokens(account, conversation.inbox.members)
|
||||
|
||||
broadcast(account, tokens, CONVERSATION_LOCK_TOGGLE, conversation.lock_event_data)
|
||||
broadcast(account, tokens, CONVERSATION_STATUS_CHANGED, conversation.push_event_data)
|
||||
end
|
||||
|
||||
def conversation_typing_on(event)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
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]
|
||||
inbox = conversation.inbox
|
||||
@@ -6,6 +7,7 @@ class WebhookListener < BaseListener
|
||||
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]
|
||||
inbox = conversation.inbox
|
||||
@@ -13,6 +15,13 @@ class WebhookListener < BaseListener
|
||||
deliver_webhook_payloads(payload, inbox)
|
||||
end
|
||||
|
||||
def conversation_status_changed(event)
|
||||
conversation = extract_conversation_and_account(event)[0]
|
||||
inbox = conversation.inbox
|
||||
payload = conversation.webhook_data.merge(event: __method__.to_s)
|
||||
deliver_webhook_payloads(payload, inbox)
|
||||
end
|
||||
|
||||
def message_created(event)
|
||||
message = extract_message_and_account(event)[0]
|
||||
inbox = message.inbox
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
# contact_last_seen_at :datetime
|
||||
# identifier :string
|
||||
# last_activity_at :datetime not null
|
||||
# locked :boolean default(FALSE)
|
||||
# status :integer default("open"), not null
|
||||
# uuid :uuid not null
|
||||
# created_at :datetime not null
|
||||
@@ -104,14 +103,6 @@ class Conversation < ApplicationRecord
|
||||
Redis::Alfred.get(mute_key).present?
|
||||
end
|
||||
|
||||
def lock!
|
||||
update!(locked: true)
|
||||
end
|
||||
|
||||
def unlock!
|
||||
update!(locked: false)
|
||||
end
|
||||
|
||||
def unread_messages
|
||||
messages.unread_since(agent_last_seen_at)
|
||||
end
|
||||
@@ -187,8 +178,8 @@ class Conversation < ApplicationRecord
|
||||
{
|
||||
CONVERSATION_OPENED => -> { saved_change_to_status? && open? },
|
||||
CONVERSATION_RESOLVED => -> { saved_change_to_status? && resolved? },
|
||||
CONVERSATION_STATUS_CHANGED => -> { saved_change_to_status? },
|
||||
CONVERSATION_READ => -> { saved_change_to_contact_last_seen_at? },
|
||||
CONVERSATION_LOCK_TOGGLE => -> { saved_change_to_locked? },
|
||||
CONVERSATION_CONTACT_CHANGED => -> { saved_change_to_contact_id? }
|
||||
}.each do |event, condition|
|
||||
condition.call && dispatcher_dispatch(event)
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
class Conversations::EventDataPresenter < SimpleDelegator
|
||||
def lock_data
|
||||
{ id: display_id, locked: locked? }
|
||||
end
|
||||
|
||||
def push_data
|
||||
{
|
||||
additional_attributes: additional_attributes,
|
||||
|
||||
Reference in New Issue
Block a user