feat: Add the ability to receive contact(vCard) on a WhatsApp inbox (#6330)
Co-authored-by: Pranav Raj S <pranav@chatwoot.com>
This commit is contained in:
@@ -23,7 +23,7 @@ describe Whatsapp::IncomingMessageService do
|
||||
expect(whatsapp_channel.inbox.messages.first.content).to eq('Test')
|
||||
end
|
||||
|
||||
it 'appends to last conversation when if conversation already exisits' do
|
||||
it 'appends to last conversation when if conversation already exists' do
|
||||
contact_inbox = create(:contact_inbox, inbox: whatsapp_channel.inbox, source_id: params[:messages].first[:from])
|
||||
2.times.each { create(:conversation, inbox: whatsapp_channel.inbox, contact_inbox: contact_inbox) }
|
||||
last_conversation = create(:conversation, inbox: whatsapp_channel.inbox, contact_inbox: contact_inbox)
|
||||
@@ -213,5 +213,38 @@ describe Whatsapp::IncomingMessageService do
|
||||
expect(location_attachment.external_url).to eq('http://location_url.test')
|
||||
end
|
||||
end
|
||||
|
||||
context 'when valid contact message params' do
|
||||
it 'creates appropriate message and attachments' do
|
||||
params = { 'contacts' => [{ 'profile' => { 'name' => 'Kedar' }, 'wa_id' => '919746334593' }],
|
||||
'messages' => [{ 'from' => '919446284490',
|
||||
'id' => 'wamid.SDFADSf23sfasdafasdfa',
|
||||
'timestamp' => '1675823265',
|
||||
'type' => 'contacts',
|
||||
'contacts' => [
|
||||
{
|
||||
'name' => { 'formatted_name' => 'Apple Inc.' },
|
||||
'phones' => [{ 'phone' => '+911800', 'type' => 'MAIN' }]
|
||||
},
|
||||
{ 'name' => { 'first_name' => 'Chatwoot', 'formatted_name' => 'Chatwoot' },
|
||||
'phones' => [{ 'phone' => '+1 (415) 341-8386' }] }
|
||||
] }] }.with_indifferent_access
|
||||
described_class.new(inbox: whatsapp_channel.inbox, params: params).perform
|
||||
expect(Contact.all.first.name).to eq('Kedar')
|
||||
|
||||
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
|
||||
contact_attachments = m1.attachments.first
|
||||
expect(m1.content).to eq('Apple Inc.')
|
||||
expect(contact_attachments.fallback_title).to eq('+911800')
|
||||
|
||||
m2 = whatsapp_channel.inbox.messages.last
|
||||
contact_attachments = m2.attachments.first
|
||||
expect(m2.content).to eq('Chatwoot')
|
||||
expect(contact_attachments.fallback_title).to eq('+1 (415) 341-8386')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user