fix: Email collect overriding existing contact name (#7355)

Currently, if Enable email collect box is enabled, and the user starting the chat already has an account with the same email, it will override the current account with {name} from the email name@email.com , this fixes it.

Co-authored-by: Sojan <sojan@pepalo.com>
This commit is contained in:
Luis
2023-06-22 07:39:12 -06:00
committed by GitHub
parent 82e5fc413e
commit 533f9f7fe4
2 changed files with 4 additions and 2 deletions

View File

@@ -17,7 +17,8 @@ class Api::V1::Widget::MessagesController < Api::V1::Widget::BaseController
@message.update!(submitted_email: contact_email)
ContactIdentifyAction.new(
contact: @contact,
params: { email: contact_email, name: contact_name }
params: { email: contact_email, name: contact_name },
retain_original_contact_name: true
).perform
else
@message.update!(message_update_params[:message])

View File

@@ -159,7 +159,7 @@ RSpec.describe '/api/v1/widget/messages', type: :request do
it 'updates message in conversation and deletes the current contact' do
message = create(:message, account: account, content_type: 'input_email', inbox: web_widget.inbox, conversation: conversation)
email = Faker::Internet.email
create(:contact, account: account, email: email)
existing_contact = create(:contact, account: account, email: email, name: 'John Doe')
contact_params = { email: email }
put api_v1_widget_message_url(message.id),
params: { website_token: web_widget.website_token, contact: contact_params },
@@ -168,6 +168,7 @@ RSpec.describe '/api/v1/widget/messages', type: :request do
expect(response).to have_http_status(:success)
message.reload
expect(existing_contact.reload.name).to eq('John Doe')
expect { contact.reload }.to raise_error(ActiveRecord::RecordNotFound)
end