diff --git a/app/services/whatsapp/incoming_message_baileys_service.rb b/app/services/whatsapp/incoming_message_baileys_service.rb index 3b466edc6..9b9501024 100644 --- a/app/services/whatsapp/incoming_message_baileys_service.rb +++ b/app/services/whatsapp/incoming_message_baileys_service.rb @@ -50,6 +50,7 @@ class Whatsapp::IncomingMessageBaileysService < Whatsapp::IncomingMessageBaseSer def handle_message return if jid_type != 'user' return if find_message_by_source_id(message_id) || message_under_process? + return if message_type == 'protocol' cache_message_source_id_in_redis set_contact @@ -106,7 +107,7 @@ class Whatsapp::IncomingMessageBaileysService < Whatsapp::IncomingMessageBaseSer when 'image', 'file', 'video', 'audio', 'sticker' create_message attach_media - else + when 'unsupported' create_unsupported_message Rails.logger.warn "Baileys unsupported message type: #{message_type}" end @@ -140,18 +141,13 @@ class Whatsapp::IncomingMessageBaileysService < Whatsapp::IncomingMessageBaseSer msg = @raw_message[:message] return 'text' if msg.key?(:conversation) || msg.dig(:extendedTextMessage, :text).present? - return 'contacts' if msg.key?(:contactMessage) return 'image' if msg.key?(:imageMessage) return 'audio' if msg.key?(:audioMessage) return 'video' if msg.key?(:videoMessage) - return 'video_note' if msg.key?(:ptvMessage) - return 'location' if msg.key?(:locationMessage) - return 'live_location' if msg.key?(:liveLocationMessage) return 'file' if msg.key?(:documentMessage) - return 'poll' if msg.key?(:pollCreationMessageV3) - return 'event' if msg.key?(:eventMessage) return 'sticker' if msg.key?(:stickerMessage) return 'reaction' if msg.key?(:reactionMessage) + return 'protocol' if msg.key?(:protocolMessage) 'unsupported' end diff --git a/spec/services/whatsapp/incoming_message_baileys_service_spec.rb b/spec/services/whatsapp/incoming_message_baileys_service_spec.rb index 580523ccd..9b7013c16 100644 --- a/spec/services/whatsapp/incoming_message_baileys_service_spec.rb +++ b/spec/services/whatsapp/incoming_message_baileys_service_spec.rb @@ -185,6 +185,29 @@ describe Whatsapp::IncomingMessageBaileysService do end end + context 'when message is protocol message' do + let(:raw_message) do + { key: { id: 'msg_123', remoteJid: '5511912345678@s.whatsapp.net', fromMe: false }, + message: { protocolMessage: { type: 1 } }, + pushName: 'John Doe' } + end + let(:params) do + { webhookVerifyToken: webhook_verify_token, + event: 'messages.upsert', + data: { + type: 'notify', + messages: [raw_message] + } } + end + + it 'does not create contact inbox nor message' do + described_class.new(inbox: inbox, params: params).perform + + expect(inbox.contact_inboxes.count).to be(0) + expect(inbox.messages.count).to be(0) + end + end + context 'when message is not from a user' do let(:raw_message) do {