Phase 4: Support LID identity scheme and fix incoming message parsing
This commit is contained in:
5
.gitignore
vendored
5
.gitignore
vendored
@@ -95,3 +95,8 @@ mobile/ios/DerivedData/
|
|||||||
*.mode2v3
|
*.mode2v3
|
||||||
*.storyboardc
|
*.storyboardc
|
||||||
*.nib
|
*.nib
|
||||||
|
|
||||||
|
# ==========================================
|
||||||
|
# 💬 WhatsApp Gateway
|
||||||
|
# ==========================================
|
||||||
|
whatsapp-gateway/sessions/
|
||||||
|
|||||||
@@ -90,8 +90,12 @@ async function startSession(session_key, webhook_url) {
|
|||||||
if (msg.key.fromMe) continue;
|
if (msg.key.fromMe) continue;
|
||||||
|
|
||||||
const remoteJid = msg.key.remoteJid;
|
const remoteJid = msg.key.remoteJid;
|
||||||
// Only process direct messages from individuals (ignore groups/broadcasts)
|
if (!remoteJid) continue;
|
||||||
if (!remoteJid || !remoteJid.endsWith('@s.whatsapp.net')) 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
|
// Extract text body
|
||||||
const body = msg.message?.conversation ||
|
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
|
// For now, only process messages that have text content
|
||||||
if (!body) continue;
|
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 || '';
|
const senderName = msg.pushName || '';
|
||||||
|
|
||||||
console.log(`[Message] Received from ${senderPhone}: ${body}`);
|
console.log(`[Message] Received from ${senderPhone} (JID: ${remoteJid}): ${body}`);
|
||||||
|
|
||||||
await sendWebhook(webhook_url, {
|
await sendWebhook(webhook_url, {
|
||||||
session_key,
|
session_key,
|
||||||
|
|||||||
Reference in New Issue
Block a user