feat: Integrate Twilio WhatsApp ProfileName for contact name resolution (#12122)

- Update existing contacts retroactively when ProfileName is available
- Only update contacts whose names exactly match their phone numbers
This commit is contained in:
Muhsin Keloth
2025-08-07 12:53:39 +05:30
committed by GitHub
parent ca13664ef9
commit f984d745e7
3 changed files with 94 additions and 1 deletions

View File

@@ -30,7 +30,8 @@ class Twilio::CallbackController < ApplicationController
:NumMedia,
:Latitude,
:Longitude,
:MessageType
:MessageType,
:ProfileName
)
end
end

View File

@@ -61,6 +61,9 @@ class Twilio::IncomingMessageService
@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_name_if_needed
end
def conversation_params
@@ -173,4 +176,18 @@ class Twilio::IncomingMessageService
coordinates_long: params[:Longitude].to_f
)
end
def update_contact_name_if_needed
return if params[:ProfileName].blank?
return if @contact.name == params[:ProfileName]
# Only update if current name exactly matches the phone number or formatted phone number
return unless contact_name_matches_phone_number?
@contact.update!(name: params[:ProfileName])
end
def contact_name_matches_phone_number?
@contact.name == phone_number || @contact.name == formatted_phone_number
end
end