-
Notifications
You must be signed in to change notification settings - Fork 543
How to integrate WhatsApp Channel #703
Copy link
Copy link
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
I try to follow goclaw whatsapp integration.
but seems dont work.
then I try to create own directory to create whatsapp bridge
mkdir whatsapp-bridge && cd whatsapp-bridge
npm init -y
npm install whatsapp-web.js ws qrcode-terminal
create server.js
const { Client, LocalAuth } = require('whatsapp-web.js');
const { WebSocketServer } = require('ws');
const qrcode = require('qrcode-terminal');
const PORT = process.argv[2] || 3001;
const wss = new WebSocketServer({ port: PORT });
const client = new Client({ authStrategy: new LocalAuth() });
// Normalize @lid → @s.whatsapp.net
function normalizeJID(jid) {
if (!jid) return jid;
return jid.replace('@lid', '@s.whatsapp.net');
}
client.on('qr', qr => {
console.log('Scan QR:');
qrcode.generate(qr, { small: true });
});
client.on('ready', () => console.log('✅ WhatsApp connected!'));
client.on('message', msg => {
if (msg.fromMe) return;
const chat = normalizeJID(msg.from);
const sender = normalizeJID(msg.author || msg.from);
const payload = {
id: msg.id.id,
chat: chat,
sender: sender,
body: msg.body,
media: []
};
const json = JSON.stringify(payload);
console.log('📨 Sending to GoClaw:', json);
wss.clients.forEach(ws => {
if (ws.readyState === 1) ws.send(json);
});
});
wss.on('connection', ws => {
console.log('🔌 GoClaw connected!');
ws.on('message', data => {
console.log('📤 GoClaw wants to send:', data.toString());
try {
const { to, body } = JSON.parse(data);
const waTo = to.replace('@s.whatsapp.net', '@c.us');
client.sendMessage(waTo, body)
.then(() => console.log('✅ Sent to WhatsApp'))
.catch(e => console.error('❌ Send error:', e));
} catch (e) {
console.error('❌ Parse error:', e.message);
}
});
ws.on('close', () => console.log('🔌 GoClaw disconnected'));
});
client.initialize();
console.log(`🌉 Bridge on ws://localhost:${PORT}`);
then
node server.js
Logs said it's connected
reski@Reskis-Mac-mini whatsapp-bridge % node server4.js
🌉 Bridge on ws://localhost:3001
✅ WhatsApp connected!
🔌 GoClaw connected!
📨 Sending to GoClaw: {"id":"3ACE8EB00FBFCDC6FF80","chat":"1410809252847@s.whatsapp.net","sender":"1410709252847@s.whatsapp.net","body":"Brttf","media":[]}
🔌 GoClaw disconnected
🔌 GoClaw connected!
📨 Sending to GoClaw: {"id":"3AC7FCEB74DF3A7EE70B","chat":"1410897252847@s.whatsapp.net","sender":"1410709252847@s.whatsapp.net","body":"Tedt","media":[]}
📨 Sending to GoClaw: {"id":"3A926A973E5C0D507C2E","chat":"1410897252847@s.whatsapp.net","sender":"1410709252847@s.whatsapp.net","body":"Ggft","media":[]}
Goclaw dont response. Strange. any ideas to solve this?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working