fix: ensure contact name defaults to phone number when pushName is absent (#94)
This commit is contained in:
parent
8c851c9197
commit
587623a09f
@ -128,7 +128,7 @@ module Whatsapp::BaileysHandlers::Helpers # rubocop:disable Metrics/ModuleLength
|
|||||||
def contact_name
|
def contact_name
|
||||||
# NOTE: `verifiedBizName` is only available for business accounts and has a higher priority than `pushName`.
|
# NOTE: `verifiedBizName` is only available for business accounts and has a higher priority than `pushName`.
|
||||||
name = @raw_message[:verifiedBizName].presence || @raw_message[: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
|
phone_number_from_jid
|
||||||
end
|
end
|
||||||
|
|||||||
@ -344,6 +344,16 @@ describe Whatsapp::IncomingMessageBaileysService do
|
|||||||
expect(conversation.contact.name).to eq('5511912345678')
|
expect(conversation.contact.name).to eq('5511912345678')
|
||||||
end
|
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
|
it 'creates a message on an existing conversation' do
|
||||||
contact = create(:contact, account: inbox.account, name: 'John Doe')
|
contact = create(:contact, account: inbox.account, name: 'John Doe')
|
||||||
contact_inbox = create(:contact_inbox, inbox: inbox, contact: contact, source_id: '5511912345678')
|
contact_inbox = create(:contact_inbox, inbox: inbox, contact: contact, source_id: '5511912345678')
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user