Deploy: 2026-05-21 20:31:41

This commit is contained in:
Hamza-Ayed
2026-05-21 20:31:41 +03:00
parent 0eaeae99aa
commit 1c584174d9
2 changed files with 90 additions and 0 deletions

View File

@@ -74,6 +74,46 @@ async function startSession(session_key, webhook_url) {
sock.ev.on('creds.update', saveCreds);
// Listen for incoming messages
sock.ev.on('messages.upsert', async (m) => {
if (m.type !== 'notify') return;
for (const msg of m.messages) {
// Ignore messages sent by ourselves
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;
// Extract text body
const body = msg.message?.conversation ||
msg.message?.extendedTextMessage?.text ||
msg.message?.imageMessage?.caption ||
msg.message?.videoMessage?.caption || '';
// For now, only process messages that have text content
if (!body) continue;
const senderPhone = remoteJid.split('@')[0];
const senderName = msg.pushName || '';
console.log(`[Message] Received from ${senderPhone}: ${body}`);
await sendWebhook(webhook_url, {
session_key,
state: 'message_received',
message: {
id: msg.key.id,
phone: senderPhone,
name: senderName,
body: body,
timestamp: msg.messageTimestamp
}
});
}
});
sock.ev.on('connection.update', async (update) => {
const { connection, lastDisconnect, qr } = update;