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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user