feat: Add WhatsApp profile for contact name resolution (#12123)

Fixes https://linear.app/chatwoot/issue/CW-4397/whatsapp-contacts-name-update-after-responsd-to-template
This commit is contained in:
Muhsin Keloth
2025-08-12 14:20:52 +05:30
committed by GitHub
parent b4f758f644
commit fdcfed2cd7
2 changed files with 115 additions and 0 deletions

View File

@@ -92,6 +92,9 @@ class Whatsapp::IncomingMessageBaseService
@contact_inbox = contact_inbox
@contact = contact_inbox.contact
# Update existing contact name if ProfileName is available and current name is just phone number
update_contact_with_profile_name(contact_params)
end
def set_conversation
@@ -171,4 +174,21 @@ class Whatsapp::IncomingMessageBaseService
)
end
end
def update_contact_with_profile_name(contact_params)
profile_name = contact_params.dig(:profile, :name)
return if profile_name.blank?
return if @contact.name == profile_name
# Only update if current name exactly matches the phone number or formatted phone number
return unless contact_name_matches_phone_number?
@contact.update!(name: profile_name)
end
def contact_name_matches_phone_number?
phone_number = "+#{@processed_params[:messages].first[:from]}"
formatted_phone_number = TelephoneNumber.parse(phone_number).international_number
@contact.name == phone_number || @contact.name == formatted_phone_number
end
end