fix: ensure contact name defaults to phone number when pushName is absent (#94)

This commit is contained in:
Gabriel Jablonski 2025-08-11 23:10:31 -03:00 committed by GitHub
parent 8c851c9197
commit 587623a09f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 1 deletions

View File

@ -128,7 +128,7 @@ module Whatsapp::BaileysHandlers::Helpers # rubocop:disable Metrics/ModuleLength
def contact_name
# NOTE: `verifiedBizName` is only available for business accounts and has a higher priority than `pushName`.
name = @raw_message[:verifiedBizName].presence || @raw_message[:pushName]
return name if self_message? || incoming?
return name if name.presence && (self_message? || incoming?)
phone_number_from_jid
end

View File

@ -344,6 +344,16 @@ describe Whatsapp::IncomingMessageBaileysService do
expect(conversation.contact.name).to eq('5511912345678')
end
it 'creates contact with phone number as name on incoming message if pushName is not present' do
raw_message[:pushName] = nil
create(:account_user, account: inbox.account)
described_class.new(inbox: inbox, params: params).perform
conversation = inbox.conversations.last
expect(conversation.contact.name).to eq('5511912345678')
end
it 'creates a message on an existing conversation' do
contact = create(:contact, account: inbox.account, name: 'John Doe')
contact_inbox = create(:contact_inbox, inbox: inbox, contact: contact, source_id: '5511912345678')