From 0a1752ce44a4f9a63dd61dc9d62909d3c253e53d Mon Sep 17 00:00:00 2001 From: Hamza-Ayed Date: Thu, 21 May 2026 22:55:06 +0300 Subject: [PATCH] Phase 4: Support LID identity scheme and fix incoming message parsing --- .gitignore | 5 +++++ whatsapp-gateway/baileys-client.js | 23 +++++++++++++++++++---- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 01cc53a..915d7fa 100644 --- a/.gitignore +++ b/.gitignore @@ -95,3 +95,8 @@ mobile/ios/DerivedData/ *.mode2v3 *.storyboardc *.nib + +# ========================================== +# 💬 WhatsApp Gateway +# ========================================== +whatsapp-gateway/sessions/ diff --git a/whatsapp-gateway/baileys-client.js b/whatsapp-gateway/baileys-client.js index 3c2839f..4dcd372 100644 --- a/whatsapp-gateway/baileys-client.js +++ b/whatsapp-gateway/baileys-client.js @@ -90,8 +90,12 @@ async function startSession(session_key, webhook_url) { if (msg.key.fromMe) continue; const remoteJid = msg.key.remoteJid; - // Only process direct messages from individuals (ignore groups/broadcasts) - if (!remoteJid || !remoteJid.endsWith('@s.whatsapp.net')) continue; + if (!remoteJid) continue; + + // Only process individual chats (ignore groups and broadcasts) + const isGroup = remoteJid.endsWith('@g.us'); + const isBroadcast = remoteJid.endsWith('@broadcast'); + if (isGroup || isBroadcast) continue; // Extract text body const body = msg.message?.conversation || @@ -102,10 +106,21 @@ async function startSession(session_key, webhook_url) { // For now, only process messages that have text content if (!body) continue; - const senderPhone = remoteJid.split('@')[0]; + // Extract sender phone number (handle LID privacy scheme) + let senderPhone = ''; + if (msg.key.senderPn && msg.key.senderPn.endsWith('@s.whatsapp.net')) { + senderPhone = msg.key.senderPn.split('@')[0]; + } else if (remoteJid.endsWith('@s.whatsapp.net')) { + senderPhone = remoteJid.split('@')[0]; + } else if (remoteJid.endsWith('@lid')) { + senderPhone = remoteJid.split('@')[0]; + } + + if (!senderPhone) continue; + const senderName = msg.pushName || ''; - console.log(`[Message] Received from ${senderPhone}: ${body}`); + console.log(`[Message] Received from ${senderPhone} (JID: ${remoteJid}): ${body}`); await sendWebhook(webhook_url, { session_key,