fix: Populate meta field for whatsApp shared contacts (#12097)
Fixes https://github.com/chatwoot/chatwoot/issues/11999
This commit is contained in:
@@ -156,11 +156,18 @@ class Whatsapp::IncomingMessageBaseService
|
|||||||
phones = contact[:phones]
|
phones = contact[:phones]
|
||||||
phones = [{ phone: 'Phone number is not available' }] if phones.blank?
|
phones = [{ phone: 'Phone number is not available' }] if phones.blank?
|
||||||
|
|
||||||
|
name_info = contact['name'] || {}
|
||||||
|
contact_meta = {
|
||||||
|
firstName: name_info['first_name'],
|
||||||
|
lastName: name_info['last_name']
|
||||||
|
}.compact
|
||||||
|
|
||||||
phones.each do |phone|
|
phones.each do |phone|
|
||||||
@message.attachments.new(
|
@message.attachments.new(
|
||||||
account_id: @message.account_id,
|
account_id: @message.account_id,
|
||||||
file_type: file_content_type(message_type),
|
file_type: file_content_type(message_type),
|
||||||
fallback_title: phone[:phone].to_s
|
fallback_title: phone[:phone].to_s,
|
||||||
|
meta: contact_meta
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -267,19 +267,16 @@ describe Whatsapp::IncomingMessageService do
|
|||||||
] }] }.with_indifferent_access
|
] }] }.with_indifferent_access
|
||||||
described_class.new(inbox: whatsapp_channel.inbox, params: params).perform
|
described_class.new(inbox: whatsapp_channel.inbox, params: params).perform
|
||||||
expect(Contact.all.first.name).to eq('Kedar')
|
expect(Contact.all.first.name).to eq('Kedar')
|
||||||
|
|
||||||
expect(whatsapp_channel.inbox.conversations.count).not_to eq(0)
|
expect(whatsapp_channel.inbox.conversations.count).not_to eq(0)
|
||||||
|
|
||||||
# Two messages are tested deliberately to ensure multiple contact attachments work.
|
|
||||||
m1 = whatsapp_channel.inbox.messages.first
|
m1 = whatsapp_channel.inbox.messages.first
|
||||||
contact_attachments = m1.attachments.first
|
|
||||||
expect(m1.content).to eq('Apple Inc.')
|
expect(m1.content).to eq('Apple Inc.')
|
||||||
expect(contact_attachments.fallback_title).to eq('+911800')
|
expect(m1.attachments.first.fallback_title).to eq('+911800')
|
||||||
|
expect(m1.attachments.first.meta).to eq({})
|
||||||
|
|
||||||
m2 = whatsapp_channel.inbox.messages.last
|
m2 = whatsapp_channel.inbox.messages.last
|
||||||
contact_attachments = m2.attachments.first
|
|
||||||
expect(m2.content).to eq('Chatwoot')
|
expect(m2.content).to eq('Chatwoot')
|
||||||
expect(contact_attachments.fallback_title).to eq('+1 (415) 341-8386')
|
expect(m2.attachments.first.meta).to eq({ 'firstName' => 'Chatwoot' })
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user