fix: Conversation opening in pending if there's an active bot on the inbox
This commit is contained in:
@@ -14,7 +14,22 @@ class ConversationBuilder
|
||||
end
|
||||
|
||||
def create_new_conversation
|
||||
::Conversation.create!(conversation_params)
|
||||
conversation = ::Conversation.create!(conversation_params)
|
||||
|
||||
# Override status if explicitly provided in params
|
||||
# This is required because the Conversation model's determine_conversation_status callback
|
||||
# automatically sets status to :pending when there's an active bot on the inbox.
|
||||
# However, when users manually create conversations (e.g., via the frontend form),
|
||||
# they should be able to explicitly set the status to :open to bypass bot handling.
|
||||
# We use update_column to avoid triggering callbacks and activity logs since this
|
||||
# is just correcting the status to match the user's explicit intent.
|
||||
if params[:status].present?
|
||||
# rubocop:disable Rails/SkipsModelValidations
|
||||
conversation.update_column(:status, params[:status])
|
||||
# rubocop:enable Rails/SkipsModelValidations
|
||||
end
|
||||
|
||||
conversation
|
||||
end
|
||||
|
||||
def conversation_params
|
||||
|
||||
+1
@@ -134,6 +134,7 @@ export const prepareNewMessagePayload = ({
|
||||
contactId: Number(selectedContact.id),
|
||||
message: { content: message },
|
||||
assigneeId: currentUser.id,
|
||||
status: 'open', // Explicitly set status to open for manually created conversations
|
||||
};
|
||||
|
||||
if (attachedFiles?.length) {
|
||||
|
||||
@@ -80,5 +80,64 @@ describe ConversationBuilder do
|
||||
expect(conversation.id).to eq(existing_conversation.id)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when status is provided in params' do
|
||||
it 'sets the status to the provided value' do
|
||||
conversation = described_class.new(
|
||||
contact_inbox: contact_api_inbox,
|
||||
params: { status: 'open' }
|
||||
).perform
|
||||
|
||||
expect(conversation.status).to eq('open')
|
||||
end
|
||||
|
||||
it 'overrides bot status when status is explicitly provided' do
|
||||
# Create a bot for the inbox
|
||||
create(:agent_bot, account: account)
|
||||
create(:agent_bot_inbox, inbox: api_inbox, account: account)
|
||||
|
||||
conversation = described_class.new(
|
||||
contact_inbox: contact_api_inbox,
|
||||
params: { status: 'open' }
|
||||
).perform
|
||||
|
||||
expect(conversation.status).to eq('open')
|
||||
end
|
||||
|
||||
it 'sets status to resolved when explicitly provided' do
|
||||
conversation = described_class.new(
|
||||
contact_inbox: contact_api_inbox,
|
||||
params: { status: 'resolved' }
|
||||
).perform
|
||||
|
||||
expect(conversation.status).to eq('resolved')
|
||||
end
|
||||
end
|
||||
|
||||
context 'when no status is provided and bot is active' do
|
||||
it 'sets status to pending for bot conversations' do
|
||||
# Create a bot for the inbox
|
||||
create(:agent_bot, account: account)
|
||||
create(:agent_bot_inbox, inbox: api_inbox, account: account)
|
||||
|
||||
conversation = described_class.new(
|
||||
contact_inbox: contact_api_inbox,
|
||||
params: {}
|
||||
).perform
|
||||
|
||||
expect(conversation.status).to eq('pending')
|
||||
end
|
||||
end
|
||||
|
||||
context 'when no status is provided and no bot is active' do
|
||||
it 'uses default status from model' do
|
||||
conversation = described_class.new(
|
||||
contact_inbox: contact_api_inbox,
|
||||
params: {}
|
||||
).perform
|
||||
|
||||
expect(conversation.status).to eq('open')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user