fix: handle senderPn for LID JID type messages (#85)
* fix: handle phone number from LID JID type * test! * fix: correct condition for jid_type in handle_message method
This commit is contained in:
parent
138e4d3c01
commit
6f6e798700
@ -116,9 +116,13 @@ module Whatsapp::BaileysHandlers::Helpers # rubocop:disable Metrics/ModuleLength
|
||||
end
|
||||
|
||||
def phone_number_from_jid
|
||||
reference_field = jid_type == 'lid' ? :senderPn : :remoteJid
|
||||
jid = @raw_message[:key][reference_field]
|
||||
return unless jid
|
||||
|
||||
# NOTE: jid shape is `<user>_<agent>:<device>@<server>`
|
||||
# https://github.com/WhiskeySockets/Baileys/blob/v6.7.16/src/WABinary/jid-utils.ts#L19
|
||||
@raw_message[:key][:remoteJid].split('@').first.split(':').first.split('_').first
|
||||
jid.split('@').first.split(':').first.split('_').first
|
||||
end
|
||||
|
||||
def contact_name
|
||||
|
||||
@ -20,8 +20,9 @@ module Whatsapp::BaileysHandlers::MessagesUpsert
|
||||
end
|
||||
end
|
||||
|
||||
def handle_message
|
||||
return if jid_type != 'user'
|
||||
def handle_message # rubocop:disable Metrics/CyclomaticComplexity
|
||||
return unless %w[lid user].include?(jid_type)
|
||||
return if jid_type == 'lid' && !phone_number_from_jid
|
||||
return if ignore_message?
|
||||
return if find_message_by_source_id(raw_message_id) || message_under_process?
|
||||
|
||||
|
||||
@ -690,6 +690,29 @@ describe Whatsapp::IncomingMessageBaileysService do
|
||||
expect(second_message.content).to eq('Hello from another user')
|
||||
end
|
||||
end
|
||||
|
||||
context 'when jid type is lid' do
|
||||
it 'processes the message with phone number from lid jid type' do
|
||||
raw_message[:key][:remoteJid] = '12345678@lid'
|
||||
raw_message[:key][:senderPn] = '5511912345678@s.whatsapp.net'
|
||||
|
||||
described_class.new(inbox: inbox, params: params).perform
|
||||
|
||||
conversation = inbox.conversations.last
|
||||
message = conversation.messages.last
|
||||
|
||||
expect(message).to be_present
|
||||
expect(conversation.contact.phone_number).to eq('+5511912345678')
|
||||
end
|
||||
end
|
||||
|
||||
it 'skips message if senderPn is not present' do
|
||||
raw_message[:key][:remoteJid] = '12345678@lid'
|
||||
|
||||
described_class.new(inbox: inbox, params: params).perform
|
||||
|
||||
expect(inbox.conversations).to be_empty
|
||||
end
|
||||
end
|
||||
|
||||
context 'when processing messages.update event' do
|
||||
|
||||
Loading…
Reference in New Issue
Block a user