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

@@ -43,10 +43,10 @@ class ActionService
def assign_agent(agent_ids = [])
return @conversation.update!(assignee_id: nil) if agent_ids[0] == 'nil'
agent_ids = [last_responding_agent_id] if agent_ids[0] == 'last_responding_agent'
return unless agent_belongs_to_inbox?(agent_ids)
@agent = @account.users.find_by(id: agent_ids)
return unless @agent.present? && @agent.confirmed?
@conversation.update!(assignee_id: @agent.id)
@@ -95,6 +95,10 @@ class ActionService
private
def last_responding_agent_id
@conversation.messages.outgoing.where(sender_type: 'User', private: false).last&.sender_id
end
def agent_belongs_to_inbox?(agent_ids)
member_ids = @conversation.inbox.members.pluck(:user_id)
assignable_agent_ids = member_ids + @account.administrators.ids