mirror of
https://github.com/lingble/chatwoot.git
synced 2025-12-15 18:27:14 +00:00
chore: Adds API for agent bot avatar upload (#8533)
Adds API for agent bot avatar upload - accounts/agent_bot - platform/agent_bot
This commit is contained in:
@@ -10,11 +10,18 @@ class Api::V1::Accounts::AgentBotsController < Api::V1::Accounts::BaseController
|
||||
def show; end
|
||||
|
||||
def create
|
||||
@agent_bot = Current.account.agent_bots.create!(permitted_params)
|
||||
@agent_bot = Current.account.agent_bots.create!(permitted_params.except(:avatar_url))
|
||||
process_avatar_from_url
|
||||
end
|
||||
|
||||
def update
|
||||
@agent_bot.update!(permitted_params)
|
||||
@agent_bot.update!(permitted_params.except(:avatar_url))
|
||||
process_avatar_from_url
|
||||
end
|
||||
|
||||
def avatar
|
||||
@agent_bot.avatar.purge if @agent_bot.avatar.attached?
|
||||
@agent_bot
|
||||
end
|
||||
|
||||
def destroy
|
||||
@@ -30,6 +37,10 @@ class Api::V1::Accounts::AgentBotsController < Api::V1::Accounts::BaseController
|
||||
end
|
||||
|
||||
def permitted_params
|
||||
params.permit(:name, :description, :outgoing_url, :bot_type, bot_config: [:csml_content])
|
||||
params.permit(:name, :description, :outgoing_url, :avatar, :avatar_url, :bot_type, bot_config: [:csml_content])
|
||||
end
|
||||
|
||||
def process_avatar_from_url
|
||||
::Avatar::AvatarFromUrlJob.perform_later(@agent_bot, params[:avatar_url]) if params[:avatar_url].present?
|
||||
end
|
||||
end
|
||||
|
||||
@@ -83,14 +83,14 @@ class Api::V1::Accounts::ContactsController < Api::V1::Accounts::BaseController
|
||||
@contact = Current.account.contacts.new(permitted_params.except(:avatar_url))
|
||||
@contact.save!
|
||||
@contact_inbox = build_contact_inbox
|
||||
process_avatar
|
||||
process_avatar_from_url
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
@contact.assign_attributes(contact_update_params)
|
||||
@contact.save!
|
||||
process_avatar if permitted_params[:avatar].present? || permitted_params[:avatar_url].present?
|
||||
process_avatar_from_url
|
||||
end
|
||||
|
||||
def destroy
|
||||
@@ -174,7 +174,7 @@ class Api::V1::Accounts::ContactsController < Api::V1::Accounts::BaseController
|
||||
@contact = Current.account.contacts.includes(contact_inboxes: [:inbox]).find(params[:id])
|
||||
end
|
||||
|
||||
def process_avatar
|
||||
def process_avatar_from_url
|
||||
::Avatar::AvatarFromUrlJob.perform_later(@contact, params[:avatar_url]) if params[:avatar_url].present?
|
||||
end
|
||||
|
||||
|
||||
@@ -9,13 +9,15 @@ class Platform::Api::V1::AgentBotsController < PlatformController
|
||||
def show; end
|
||||
|
||||
def create
|
||||
@resource = AgentBot.new(agent_bot_params)
|
||||
@resource = AgentBot.new(agent_bot_params.except(:avatar_url))
|
||||
@resource.save!
|
||||
process_avatar_from_url
|
||||
@platform_app.platform_app_permissibles.find_or_create_by(permissible: @resource)
|
||||
end
|
||||
|
||||
def update
|
||||
@resource.update!(agent_bot_params)
|
||||
@resource.update!(agent_bot_params.except(:avatar_url))
|
||||
process_avatar_from_url
|
||||
end
|
||||
|
||||
def destroy
|
||||
@@ -23,6 +25,11 @@ class Platform::Api::V1::AgentBotsController < PlatformController
|
||||
head :ok
|
||||
end
|
||||
|
||||
def avatar
|
||||
@resource.avatar.purge if @resource.avatar.attached?
|
||||
@resource
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_resource
|
||||
@@ -30,6 +37,10 @@ class Platform::Api::V1::AgentBotsController < PlatformController
|
||||
end
|
||||
|
||||
def agent_bot_params
|
||||
params.permit(:name, :description, :account_id, :outgoing_url)
|
||||
params.permit(:name, :description, :account_id, :outgoing_url, :avatar, :avatar_url)
|
||||
end
|
||||
|
||||
def process_avatar_from_url
|
||||
::Avatar::AvatarFromUrlJob.perform_later(@resource, params[:avatar_url]) if params[:avatar_url].present?
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user