diff --git a/app/controllers/api/v1/accounts/agent_bots_controller.rb b/app/controllers/api/v1/accounts/agent_bots_controller.rb new file mode 100644 index 000000000..7348ef255 --- /dev/null +++ b/app/controllers/api/v1/accounts/agent_bots_controller.rb @@ -0,0 +1,35 @@ +class Api::V1::Accounts::AgentBotsController < Api::V1::Accounts::BaseController + before_action :current_account + before_action :check_authorization + before_action :agent_bot, except: [:index, :create] + + def index + @agent_bots = AgentBot.where(account_id: [nil, Current.account.id]) + end + + def show; end + + def create + @agent_bot = Current.account.agent_bots.create!(permitted_params) + end + + def update + @agent_bot.update!(permitted_params) + end + + def destroy + @agent_bot.destroy + head :ok + end + + private + + def agent_bot + @agent_bot = AgentBot.where(account_id: [nil, Current.account.id]).find(params[:id]) if params[:action] == 'show' + @agent_bot ||= Current.account.agent_bots.find(params[:id]) + end + + def permitted_params + params.permit(:name, :description, :outgoing_url) + end +end diff --git a/app/controllers/api/v1/accounts/inboxes_controller.rb b/app/controllers/api/v1/accounts/inboxes_controller.rb index 014e213d4..8a5f5b9b9 100644 --- a/app/controllers/api/v1/accounts/inboxes_controller.rb +++ b/app/controllers/api/v1/accounts/inboxes_controller.rb @@ -38,6 +38,10 @@ class Api::V1::Accounts::InboxesController < Api::V1::Accounts::BaseController update_channel_feature_flags end + def agent_bot + @agent_bot = @inbox.agent_bot + end + def set_agent_bot if @agent_bot agent_bot_inbox = @inbox.agent_bot_inbox || AgentBotInbox.new(inbox: @inbox) diff --git a/app/controllers/api/v1/agent_bots_controller.rb b/app/controllers/api/v1/agent_bots_controller.rb deleted file mode 100644 index a82f71bb9..000000000 --- a/app/controllers/api/v1/agent_bots_controller.rb +++ /dev/null @@ -1,7 +0,0 @@ -class Api::V1::AgentBotsController < Api::BaseController - skip_before_action :authenticate_user! - - def index - render json: AgentBot.all - end -end diff --git a/app/controllers/platform/api/v1/agent_bots_controller.rb b/app/controllers/platform/api/v1/agent_bots_controller.rb new file mode 100644 index 000000000..0c79e118d --- /dev/null +++ b/app/controllers/platform/api/v1/agent_bots_controller.rb @@ -0,0 +1,35 @@ +class Platform::Api::V1::AgentBotsController < PlatformController + before_action :set_resource, except: [:index, :create] + before_action :validate_platform_app_permissible, except: [:index, :create] + + def index + @resources = @platform_app.platform_app_permissibles.where(permissible_type: 'AgentBot').all + end + + def create + @resource = AgentBot.new(agent_bot_params) + @resource.save! + @platform_app.platform_app_permissibles.find_or_create_by(permissible: @resource) + end + + def show; end + + def update + @resource.update!(agent_bot_params) + end + + def destroy + @resource.destroy! + head :ok + end + + private + + def set_resource + @resource = AgentBot.find(params[:id]) + end + + def agent_bot_params + params.permit(:name, :description, :account_id, :outgoing_url) + end +end diff --git a/app/dashboards/agent_bot_dashboard.rb b/app/dashboards/agent_bot_dashboard.rb index ca6ca7ad1..87605135d 100644 --- a/app/dashboards/agent_bot_dashboard.rb +++ b/app/dashboards/agent_bot_dashboard.rb @@ -15,8 +15,7 @@ class AgentBotDashboard < Administrate::BaseDashboard description: Field::String, outgoing_url: Field::String, created_at: Field::DateTime, - updated_at: Field::DateTime, - hide_input_for_bot_conversations: Field::Boolean + updated_at: Field::DateTime }.freeze # COLLECTION_ATTRIBUTES @@ -39,7 +38,6 @@ class AgentBotDashboard < Administrate::BaseDashboard name description outgoing_url - hide_input_for_bot_conversations ].freeze # FORM_ATTRIBUTES @@ -49,7 +47,6 @@ class AgentBotDashboard < Administrate::BaseDashboard name description outgoing_url - hide_input_for_bot_conversations ].freeze # COLLECTION_FILTERS diff --git a/app/javascript/widget/mixins/configMixin.js b/app/javascript/widget/mixins/configMixin.js index df26add3b..c70d9ca57 100644 --- a/app/javascript/widget/mixins/configMixin.js +++ b/app/javascript/widget/mixins/configMixin.js @@ -1,8 +1,5 @@ export default { computed: { - hideInputForBotConversations() { - return window.chatwootWebChannel.hideInputForBotConversations; - }, useInboxAvatarForBot() { return window.chatwootWidgetDefaults.useInboxAvatarForBot; }, diff --git a/app/javascript/widget/mixins/specs/configMixin.spec.js b/app/javascript/widget/mixins/specs/configMixin.spec.js index 014a7930a..663cf695d 100644 --- a/app/javascript/widget/mixins/specs/configMixin.spec.js +++ b/app/javascript/widget/mixins/specs/configMixin.spec.js @@ -3,7 +3,6 @@ import configMixin from '../configMixin'; import Vue from 'vue'; global.chatwootWebChannel = { - hideInputForBotConversations: true, avatarUrl: 'https://test.url', hasAConnectedAgentBot: 'AgentBot', enabledFeatures: ['emoji_picker', 'attachments'], @@ -25,12 +24,10 @@ describe('configMixin', () => { const wrapper = createWrapper(vm); expect(wrapper.vm.hasEmojiPickerEnabled).toBe(true); expect(wrapper.vm.hasAttachmentsEnabled).toBe(true); - expect(wrapper.vm.hideInputForBotConversations).toBe(true); expect(wrapper.vm.hasAConnectedAgentBot).toBe(true); expect(wrapper.vm.useInboxAvatarForBot).toBe(true); expect(wrapper.vm.inboxAvatarUrl).toBe('https://test.url'); expect(wrapper.vm.channelConfig).toEqual({ - hideInputForBotConversations: true, avatarUrl: 'https://test.url', hasAConnectedAgentBot: 'AgentBot', enabledFeatures: ['emoji_picker', 'attachments'], diff --git a/app/javascript/widget/views/Home.vue b/app/javascript/widget/views/Home.vue index 3d77f33b5..a86c29a28 100755 --- a/app/javascript/widget/views/Home.vue +++ b/app/javascript/widget/views/Home.vue @@ -62,10 +62,7 @@ leave-class="opacity-100 transform translate-y-0" leave-to-class="opacity-0 transform " > -