fix WhatsApp group chat support and self-message handling
Bridge: allow fromMe messages in groups, include participant field in message queue, bind to 0.0.0.0 for network access, QR served as HTML. Adapter: process registered group messages (route to Claude), extract participant for user identification, fix unbound 'phone' variable. Tested end-to-end: WhatsApp group chat with Claude working. 442 tests pass. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -7,7 +7,7 @@ const QRCode = require('qrcode');
|
||||
const path = require('path');
|
||||
|
||||
const PORT = 8098;
|
||||
const HOST = '127.0.0.1';
|
||||
const HOST = '0.0.0.0';
|
||||
const AUTH_DIR = path.join(__dirname, 'auth');
|
||||
const MAX_RECONNECT_ATTEMPTS = 5;
|
||||
|
||||
@@ -84,26 +84,27 @@ async function startConnection() {
|
||||
if (type !== 'notify') return;
|
||||
|
||||
for (const msg of messages) {
|
||||
// Skip own messages
|
||||
if (msg.key.fromMe) continue;
|
||||
// Skip status broadcasts
|
||||
if (msg.key.remoteJid === 'status@broadcast') continue;
|
||||
// Skip own messages in private chats (allow in groups for self-chat)
|
||||
const isGroup = msg.key.remoteJid.endsWith('@g.us');
|
||||
if (msg.key.fromMe && !isGroup) continue;
|
||||
// Only text messages
|
||||
const text = msg.message?.conversation || msg.message?.extendedTextMessage?.text;
|
||||
if (!text) continue;
|
||||
|
||||
const isGroup = msg.key.remoteJid.endsWith('@g.us');
|
||||
|
||||
messageQueue.push({
|
||||
from: msg.key.remoteJid,
|
||||
participant: msg.key.participant || null,
|
||||
pushName: msg.pushName || null,
|
||||
text,
|
||||
timestamp: msg.messageTimestamp,
|
||||
id: msg.key.id,
|
||||
isGroup,
|
||||
fromMe: msg.key.fromMe || false,
|
||||
});
|
||||
|
||||
console.log(`[whatsapp] Message from ${msg.pushName || msg.key.remoteJid}: ${text.substring(0, 80)}`);
|
||||
console.log(`[whatsapp] Message from ${msg.pushName || 'unknown'} in ${msg.key.remoteJid}: ${text.substring(0, 80)}`);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -128,7 +129,14 @@ app.get('/qr', (_req, res) => {
|
||||
if (!currentQR) {
|
||||
return res.json({ error: 'no QR code available yet' });
|
||||
}
|
||||
res.json({ qr: currentQR });
|
||||
// Return as HTML page with QR image for easy scanning
|
||||
const html = `<!DOCTYPE html>
|
||||
<html><head><title>WhatsApp QR</title>
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1">
|
||||
<style>body{display:flex;justify-content:center;align-items:center;min-height:100vh;margin:0;background:#111;flex-direction:column;font-family:sans-serif;color:#fff}
|
||||
img{width:400px;height:400px;border-radius:12px}p{margin-top:16px;opacity:.6}</style></head>
|
||||
<body><img src="${currentQR}" alt="QR Code"/><p>Scan with WhatsApp → Linked Devices</p></body></html>`;
|
||||
res.type('html').send(html);
|
||||
});
|
||||
|
||||
app.post('/send', async (req, res) => {
|
||||
|
||||
Reference in New Issue
Block a user