feat: Introduce last responding agent option to automation assign agent (#12326)

Introduce a `Last Responding Agent` options to assign_agents action in
automations to cover the following use cases.

- Assign conversations to first responding agent : ( automation message
created at , if assignee is nil, assign last responding agent )
- Ensure conversations are not resolved with out an assignee : (
automation conversation resolved at : if assignee is nil, assign last
responding agent )

and potential other cases.

fixes: #1592
This commit is contained in:
Sojan Jose
2026-04-16 18:54:35 +05:30
committed by GitHub
parent 03c10ba147
commit 135be52431
7 changed files with 114 additions and 5 deletions

View File

@@ -70,6 +70,33 @@ describe ActionService do
expect(conversation.reload.assignee).to eq(original_assignee)
end
end
context 'when assigning the last responding agent' do
it 'assigns the last agent who replied publicly' do
note_author = create(:user, account: account, role: :agent)
inbox_member
create(:inbox_member, inbox: conversation.inbox, user: note_author)
create(:message, message_type: :outgoing, account: account,
inbox: conversation.inbox, conversation: conversation, sender: agent)
create(:message, message_type: :outgoing, private: true, account: account,
inbox: conversation.inbox, conversation: conversation, sender: note_author)
action_service.assign_agent(['last_responding_agent'])
expect(conversation.reload.assignee).to eq(agent)
end
it 'does not assign the conversation when there is no public agent reply' do
inbox_member
original_assignee = conversation.assignee
create(:message, message_type: :outgoing, private: true, account: account,
inbox: conversation.inbox, conversation: conversation, sender: agent)
action_service.assign_agent(['last_responding_agent'])
expect(conversation.reload.assignee).to eq(original_assignee)
end
end
end
describe '#assign_team' do

View File

@@ -201,5 +201,21 @@ RSpec.describe AutomationRules::ActionService do
described_class.new(rule, account, conversation).perform
end
end
describe '#perform with assign_agent action' do
before do
create(:inbox_member, inbox: conversation.inbox, user: agent)
rule.actions << { action_name: 'assign_agent', action_params: ['last_responding_agent'] }
end
it 'assigns the conversation to the last responding agent' do
create(:message, message_type: :outgoing, account: account,
inbox: conversation.inbox, conversation: conversation, sender: agent)
described_class.new(rule, account, conversation).perform
expect(conversation.reload.assignee).to eq(agent)
end
end
end
end