fix: ignore protocolMessages (#34)
* fix: handle protocol messages in IncomingMessageBaileysService and ignore it * fix: ignore protocol messages before create conversation and contact * chore: update test description for contact inbox and message creation * chore: simplify protocol message check in handle_message method
This commit is contained in:
parent
669e60d9ca
commit
a52a4cf8ce
@ -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
|
||||
|
||||
@ -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
|
||||
{
|
||||
|
||||
Loading…
Reference in New Issue
Block a user