## 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>
46 lines
1.1 KiB
Ruby
46 lines
1.1 KiB
Ruby
class Api::V1::Accounts::Conversations::AssignmentsController < Api::V1::Accounts::Conversations::BaseController
|
|
# assigns agent/team to a conversation
|
|
def create
|
|
if params.key?(:assignee_id) || agent_bot_assignment?
|
|
set_agent
|
|
elsif params.key?(:team_id)
|
|
set_team
|
|
else
|
|
render json: nil
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
def set_agent
|
|
resource = Conversations::AssignmentService.new(
|
|
conversation: @conversation,
|
|
assignee_id: params[:assignee_id],
|
|
assignee_type: params[:assignee_type]
|
|
).perform
|
|
|
|
render_agent(resource)
|
|
end
|
|
|
|
def render_agent(resource)
|
|
case resource
|
|
when User
|
|
render partial: 'api/v1/models/agent', formats: [:json], locals: { resource: resource }
|
|
when AgentBot
|
|
render partial: 'api/v1/models/agent_bot_slim', formats: [:json], locals: { resource: resource }
|
|
else
|
|
render json: nil
|
|
end
|
|
end
|
|
|
|
def set_team
|
|
@team = Current.account.teams.find_by(id: params[:team_id])
|
|
@conversation.update!(team: @team)
|
|
render json: @team
|
|
end
|
|
|
|
def agent_bot_assignment?
|
|
params[:assignee_type].to_s == 'AgentBot'
|
|
end
|
|
end
|