fix: open bot handled conversations on human assignment
This commit is contained in:
@@ -3,7 +3,7 @@ module AssignmentHandler
|
||||
include Events::Types
|
||||
|
||||
included do
|
||||
before_save :ensure_assignee_is_from_team
|
||||
before_validation :ensure_assignee_is_from_team
|
||||
after_commit :notify_assignment_change, :process_assignment_changes
|
||||
end
|
||||
|
||||
@@ -14,10 +14,6 @@ module AssignmentHandler
|
||||
|
||||
validate_current_assignee_team
|
||||
self.assignee ||= find_assignee_from_team
|
||||
return if assignee_id.blank?
|
||||
|
||||
self.status = :open if assignee_agent_bot_id.present? && pending?
|
||||
self.assignee_agent_bot = nil
|
||||
end
|
||||
|
||||
def validate_current_assignee_team
|
||||
|
||||
@@ -274,6 +274,7 @@ class Conversation < ApplicationRecord
|
||||
def reset_agent_bot_when_assignee_present
|
||||
return if assignee_id.blank?
|
||||
|
||||
self.status = :open if assignee_agent_bot_id.present? && pending?
|
||||
self.assignee_agent_bot_id = nil
|
||||
end
|
||||
|
||||
|
||||
@@ -14,9 +14,8 @@ class Conversations::AssignmentService
|
||||
attr_reader :conversation, :assignee_id, :assignee_type
|
||||
|
||||
def assign_agent
|
||||
conversation.status = :open if assignee && conversation.assignee_agent_bot_id.present? && conversation.pending?
|
||||
conversation.assignee = assignee
|
||||
conversation.assignee_agent_bot = nil
|
||||
conversation.assignee_agent_bot = nil if assignee.blank?
|
||||
conversation.save!
|
||||
assignee
|
||||
end
|
||||
|
||||
@@ -57,6 +57,18 @@ describe ActionService do
|
||||
action_service.assign_agent([agent.id])
|
||||
expect(conversation.reload.assignee).to eq(agent)
|
||||
end
|
||||
|
||||
it 'opens bot-owned pending conversations when assigning the agent' do
|
||||
inbox_member
|
||||
conversation.update!(assignee: nil, assignee_agent_bot: create(:agent_bot, account: account), status: :pending)
|
||||
|
||||
action_service.assign_agent([agent.id])
|
||||
|
||||
conversation.reload
|
||||
expect(conversation.assignee).to eq(agent)
|
||||
expect(conversation.assignee_agent_bot).to be_nil
|
||||
expect(conversation.status).to eq('open')
|
||||
end
|
||||
end
|
||||
|
||||
context 'when agent is unconfirmed' do
|
||||
|
||||
Reference in New Issue
Block a user