From ee9fe6c60d5f5ed61f53f72b8d0af51764feb837 Mon Sep 17 00:00:00 2001 From: canove Date: Tue, 22 Sep 2020 17:55:22 -0300 Subject: [PATCH] fix: check message types on wbotMessageListener --- .../WbotServices/wbotMessageListener.ts | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/backend/src/services/WbotServices/wbotMessageListener.ts b/backend/src/services/WbotServices/wbotMessageListener.ts index d1dc5ed..fb5a7e8 100644 --- a/backend/src/services/WbotServices/wbotMessageListener.ts +++ b/backend/src/services/WbotServices/wbotMessageListener.ts @@ -146,6 +146,21 @@ const handleMessage = async ( }); }; +const isValidMsg = (msg: WbotMessage): boolean => { + if (msg.from === "status@broadcast" || msg.author) return false; + if ( + msg.type === "chat" || + msg.type === "audio" || + msg.type === "ptt" || + msg.type === "video" || + msg.type === "image" || + msg.type === "document" || + msg.type === "vcard" + ) + return true; + return false; +}; + const wbotMessageListener = (whatsapp: Whatsapp): void => { const whatsappId = whatsapp.id; const wbot = getWbot(whatsappId); @@ -159,12 +174,7 @@ const wbotMessageListener = (whatsapp: Whatsapp): void => { wbot.on("message_create", async msg => { console.log(msg.type); - if ( - msg.from === "status@broadcast" || - msg.type === "location" || - msg.type === "call_log" || - msg.author // Ignore Group Messages - ) { + if (!isValidMsg(msg)) { return; }