diff --git a/app/controllers/api/v1/accounts/conversations/messages_controller.rb b/app/controllers/api/v1/accounts/conversations/messages_controller.rb index 7e7d63e98..82b787b90 100644 --- a/app/controllers/api/v1/accounts/conversations/messages_controller.rb +++ b/app/controllers/api/v1/accounts/conversations/messages_controller.rb @@ -74,7 +74,7 @@ class Api::V1::Accounts::Conversations::MessagesController < Api::V1::Accounts:: end def ensure_agent_bot_takeover - return unless Current.user && @conversation.assignee_agent_bot_id.present? + return unless Current.user.is_a?(User) && @conversation.assignee_agent_bot_id.present? return if private_message? || incoming_message? render json: { error: 'Conversation is assigned to an Agent Bot. Take over the conversation before replying.' }, status: :unprocessable_entity diff --git a/app/javascript/dashboard/components/widgets/conversation/ReplyBoxBanner.vue b/app/javascript/dashboard/components/widgets/conversation/ReplyBoxBanner.vue index 56e08bb0c..f3a8b812c 100644 --- a/app/javascript/dashboard/components/widgets/conversation/ReplyBoxBanner.vue +++ b/app/javascript/dashboard/components/widgets/conversation/ReplyBoxBanner.vue @@ -42,9 +42,8 @@ const assignedAgent = computed({ }, }); -const isUserTyping = computed( - () => props.message !== '' && !props.isOnPrivateNote -); +const hasMessage = computed(() => props.message !== ''); +const isUserTyping = computed(() => hasMessage.value && !props.isOnPrivateNote); const isUnassigned = computed(() => !assignedAgent.value); const isAssignedToOtherAgent = computed( () => assignedAgent.value?.id !== currentUser.value?.id @@ -58,7 +57,7 @@ const showSelfAssignBanner = computed(() => { const showBotHandoffBanner = computed(() => { return ( - isUserTyping.value && currentChat.value?.meta?.assignee_type === 'AgentBot' + hasMessage.value && currentChat.value?.meta?.assignee_type === 'AgentBot' ); }); diff --git a/spec/controllers/api/v1/accounts/conversations/messages_controller_spec.rb b/spec/controllers/api/v1/accounts/conversations/messages_controller_spec.rb index 8dd7746b1..31f75f700 100644 --- a/spec/controllers/api/v1/accounts/conversations/messages_controller_spec.rb +++ b/spec/controllers/api/v1/accounts/conversations/messages_controller_spec.rb @@ -136,7 +136,7 @@ RSpec.describe 'Conversation Messages API', type: :request do end context 'when it is an authenticated agent bot' do - let!(:agent_bot) { create(:agent_bot) } + let!(:agent_bot) { create(:agent_bot, account: account) } it 'creates a new outgoing message' do create(:agent_bot_inbox, inbox: inbox, agent_bot: agent_bot) @@ -152,6 +152,21 @@ RSpec.describe 'Conversation Messages API', type: :request do expect(conversation.messages.first.content).to eq(params[:content]) end + it 'creates a new outgoing message when the agent bot owns the conversation' do + create(:agent_bot_inbox, inbox: inbox, agent_bot: agent_bot) + conversation.update!(assignee_agent_bot: agent_bot) + params = { content: 'test-message' } + + post api_v1_account_conversation_messages_url(account_id: account.id, conversation_id: conversation.display_id), + params: params, + headers: { api_access_token: agent_bot.access_token.token }, + as: :json + + expect(response).to have_http_status(:success) + expect(conversation.messages.count).to eq(1) + expect(conversation.messages.first.content).to eq(params[:content]) + end + it 'creates a new outgoing input select message' do create(:agent_bot_inbox, inbox: inbox, agent_bot: agent_bot) select_item1 = build(:bot_message_select)