feat: APIs to assign agents_bots as assignee in conversations (#12836)
## Summary - add an assignee_agent_bot_id column as an initital step to prototype this before fully switching to polymorphic assignee - update assignment APIs and conversation list / show endpoints to reflect assignee as agent bot - ensure webhook payloads contains agent bot assignee [Codex Task](https://chatgpt.com/codex/tasks/task_e_6912833377e48326b6641b9eee32d50f) --------- Co-authored-by: Pranav <pranav@chatwoot.com>
This commit is contained in:
43
app/services/conversations/assignment_service.rb
Normal file
43
app/services/conversations/assignment_service.rb
Normal file
@@ -0,0 +1,43 @@
|
||||
class Conversations::AssignmentService
|
||||
def initialize(conversation:, assignee_id:, assignee_type: nil)
|
||||
@conversation = conversation
|
||||
@assignee_id = assignee_id
|
||||
@assignee_type = assignee_type
|
||||
end
|
||||
|
||||
def perform
|
||||
agent_bot_assignment? ? assign_agent_bot : assign_agent
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
attr_reader :conversation, :assignee_id, :assignee_type
|
||||
|
||||
def assign_agent
|
||||
conversation.assignee = assignee
|
||||
conversation.assignee_agent_bot = nil
|
||||
conversation.save!
|
||||
assignee
|
||||
end
|
||||
|
||||
def assign_agent_bot
|
||||
return unless agent_bot
|
||||
|
||||
conversation.assignee = nil
|
||||
conversation.assignee_agent_bot = agent_bot
|
||||
conversation.save!
|
||||
agent_bot
|
||||
end
|
||||
|
||||
def assignee
|
||||
@assignee ||= conversation.account.users.find_by(id: assignee_id)
|
||||
end
|
||||
|
||||
def agent_bot
|
||||
@agent_bot ||= AgentBot.accessible_to(conversation.account).find_by(id: assignee_id)
|
||||
end
|
||||
|
||||
def agent_bot_assignment?
|
||||
assignee_type.to_s == 'AgentBot'
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user