Compare commits
5
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e944dd20c7 | ||
|
|
2f4a5a12c5 | ||
|
|
9ce2376321 | ||
|
|
a98d26fafa | ||
|
|
10b9da14ef |
@@ -14,7 +14,22 @@ class ConversationBuilder
|
|||||||
end
|
end
|
||||||
|
|
||||||
def create_new_conversation
|
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
|
end
|
||||||
|
|
||||||
def conversation_params
|
def conversation_params
|
||||||
|
|||||||
+1
@@ -136,6 +136,7 @@ export const prepareNewMessagePayload = ({
|
|||||||
contactId: Number(selectedContact.id),
|
contactId: Number(selectedContact.id),
|
||||||
message: { content: message },
|
message: { content: message },
|
||||||
assigneeId: currentUser.id,
|
assigneeId: currentUser.id,
|
||||||
|
status: 'open', // Explicitly set status to open for manually created conversations
|
||||||
};
|
};
|
||||||
|
|
||||||
if (attachedFiles?.length) {
|
if (attachedFiles?.length) {
|
||||||
|
|||||||
+1
@@ -287,6 +287,7 @@ describe('composeConversationHelper', () => {
|
|||||||
contactId: 2,
|
contactId: 2,
|
||||||
message: { content: 'Hello' },
|
message: { content: 'Hello' },
|
||||||
assigneeId: 3,
|
assigneeId: 3,
|
||||||
|
status: 'open',
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -80,5 +80,64 @@ describe ConversationBuilder do
|
|||||||
expect(conversation.id).to eq(existing_conversation.id)
|
expect(conversation.id).to eq(existing_conversation.id)
|
||||||
end
|
end
|
||||||
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
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user