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:
@@ -95,33 +95,6 @@ RSpec.describe Webhooks::WhatsappEventsJob, type: :job do
|
||||
end.not_to change(Message, :count)
|
||||
end
|
||||
|
||||
it 'Ignore contacts type message and stop raising error' do
|
||||
other_channel = create(:channel_whatsapp, phone_number: '+1987654', provider: 'whatsapp_cloud', sync_templates: false,
|
||||
validate_provider_config: false)
|
||||
wb_params = {
|
||||
phone_number: channel.phone_number,
|
||||
object: 'whatsapp_business_account',
|
||||
entry: [{
|
||||
changes: [{
|
||||
value: {
|
||||
contacts: [{ profile: { name: 'Test Test' }, wa_id: '1111981136571' }],
|
||||
messages: [{ from: '1111981136571',
|
||||
contacts: [{ phones: [{ phone: '+1987654' }], name: { first_name: 'contact name' } }],
|
||||
timestamp: '1664799904',
|
||||
type: 'contacts' }],
|
||||
metadata: {
|
||||
phone_number_id: other_channel.provider_config['phone_number_id'],
|
||||
display_phone_number: other_channel.phone_number.delete('+')
|
||||
}
|
||||
}
|
||||
}]
|
||||
}]
|
||||
}.with_indifferent_access
|
||||
expect do
|
||||
Whatsapp::IncomingMessageWhatsappCloudService.new(inbox: other_channel.inbox, params: wb_params).perform
|
||||
end.not_to change(Message, :count)
|
||||
end
|
||||
|
||||
it 'will not enque Whatsapp::IncomingMessageWhatsappCloudService when invalid phone number id' do
|
||||
other_channel = create(:channel_whatsapp, phone_number: '+1987654', provider: 'whatsapp_cloud', sync_templates: false,
|
||||
validate_provider_config: false)
|
||||
|
||||
@@ -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