feat: Ability to receive location on whatsapp inbox (#5742)
- Ability to receive location messages on WhatsApp Inbox ref: https://github.com/chatwoot/chatwoot/issues/3398 Co-authored-by: Sojan Jose <sojan@pepalo.com>
This commit is contained in:
@@ -39,8 +39,8 @@ describe Whatsapp::IncomingMessageService do
|
||||
end
|
||||
end
|
||||
|
||||
context 'when ignores the message' do
|
||||
it 'with message type is ephemeral' do
|
||||
context 'when unsupported message types' do
|
||||
it 'ignores type ephemeral' do
|
||||
params = {
|
||||
'contacts' => [{ 'profile' => { 'name' => 'Sojan Jose' }, 'wa_id' => '2423423243' }],
|
||||
'messages' => [{ 'from' => '2423423243', 'id' => 'SDFADSf23sfasdafasdfa', 'text' => { 'body' => 'Test' },
|
||||
@@ -53,7 +53,7 @@ describe Whatsapp::IncomingMessageService do
|
||||
expect(whatsapp_channel.inbox.messages.count).to eq(0)
|
||||
end
|
||||
|
||||
it 'with message type is unsupported' do
|
||||
it 'ignores type unsupported' do
|
||||
params = {
|
||||
'contacts' => [{ 'profile' => { 'name' => 'Sojan Jose' }, 'wa_id' => '2423423243' }],
|
||||
'messages' => [{
|
||||
@@ -132,5 +132,30 @@ describe Whatsapp::IncomingMessageService do
|
||||
expect(whatsapp_channel.inbox.messages.first.attachments.present?).to be true
|
||||
end
|
||||
end
|
||||
|
||||
context 'when valid location message params' do
|
||||
it 'creates appropriate conversations, message and contacts' do
|
||||
params = {
|
||||
'contacts' => [{ 'profile' => { 'name' => 'Sojan Jose' }, 'wa_id' => '2423423243' }],
|
||||
'messages' => [{ 'from' => '2423423243', 'id' => 'SDFADSf23sfasdafasdfa',
|
||||
'location' => { 'id' => 'b1c68f38-8734-4ad3-b4a1-ef0c10d683',
|
||||
'address': 'San Francisco, CA, USA',
|
||||
'latitude': 37.7893768,
|
||||
'longitude': -122.3895553,
|
||||
'name': 'Bay Bridge',
|
||||
'url': 'http://location_url.test' },
|
||||
'timestamp' => '1633034394', 'type' => 'location' }]
|
||||
}.with_indifferent_access
|
||||
described_class.new(inbox: whatsapp_channel.inbox, params: params).perform
|
||||
expect(whatsapp_channel.inbox.conversations.count).not_to eq(0)
|
||||
expect(Contact.all.first.name).to eq('Sojan Jose')
|
||||
location_attachment = whatsapp_channel.inbox.messages.first.attachments.first
|
||||
expect(location_attachment.file_type).to eq('location')
|
||||
expect(location_attachment.fallback_title).to eq('Bay Bridge, San Francisco, CA, USA')
|
||||
expect(location_attachment.coordinates_lat).to eq(37.7893768)
|
||||
expect(location_attachment.coordinates_long).to eq(-122.3895553)
|
||||
expect(location_attachment.external_url).to eq('http://location_url.test')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user