diff --git a/app/services/whatsapp/incoming_message_base_service.rb b/app/services/whatsapp/incoming_message_base_service.rb index da08e02d6..ff5ab2ce8 100644 --- a/app/services/whatsapp/incoming_message_base_service.rb +++ b/app/services/whatsapp/incoming_message_base_service.rb @@ -87,7 +87,7 @@ class Whatsapp::IncomingMessageBaseService end def unprocessable_message_type? - %w[reaction contacts].include?(message_type) + %w[reaction contacts ephemeral unsupported].include?(message_type) end def attach_files diff --git a/spec/services/whatsapp/incoming_message_service_spec.rb b/spec/services/whatsapp/incoming_message_service_spec.rb index 22340f1b5..4eca2e48e 100644 --- a/spec/services/whatsapp/incoming_message_service_spec.rb +++ b/spec/services/whatsapp/incoming_message_service_spec.rb @@ -39,6 +39,37 @@ describe Whatsapp::IncomingMessageService do end end + context 'when ignores the message' do + it 'with message type is ephemeral' do + params = { + 'contacts' => [{ 'profile' => { 'name' => 'Sojan Jose' }, 'wa_id' => '2423423243' }], + 'messages' => [{ 'from' => '2423423243', 'id' => 'SDFADSf23sfasdafasdfa', 'text' => { 'body' => 'Test' }, + 'timestamp' => '1633034394', 'type' => 'ephemeral' }] + }.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') + expect(whatsapp_channel.inbox.messages.count).to eq(0) + end + + it 'with message type is unsupported' do + params = { + 'contacts' => [{ 'profile' => { 'name' => 'Sojan Jose' }, 'wa_id' => '2423423243' }], + 'messages' => [{ + 'errors' => [{ 'code': 131_051, 'title': 'Message type is currently not supported.' }], + 'from': '2423423243', 'id': 'wamid.SDFADSf23sfasdafasdfa', + 'timestamp': '1667047370', 'type': 'unsupported' + }] + }.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') + expect(whatsapp_channel.inbox.messages.count).to eq(0) + end + end + context 'when valid interactive message params' do it 'creates appropriate conversations, message and contacts' do params = {