Closed pakhermawan23 closed 2 weeks ago
I am trying to store incoming messages in a MySQL database with a table containing: pengirim, penerima, pesan, media, and tanggal. The script I’m using to save the messages is
const saveMessageToDatabase = async (message, receiver, filename = null) => { const isGroupMessage = message.key.remoteJid.endsWith('@g.us'); const sender = isGroupMessage ? message.key.participant.split('@')[0] : message.key.remoteJid.split('@')[0];
let caption = ''; if (message.message.conversation || message.message.extendedTextMessage) { caption = message.message.conversation || message.message.extendedTextMessage?.text || message.message?.extendedTextMessage?.contextInfo?.quotedMessage?.conversation; } else if (message.message.imageMessage) { caption = message.message.imageMessage.caption || ''; } else if (message.message.videoMessage) { caption = message.message.videoMessage.caption || ''; } else if (message.message.audioMessage) { caption = message.message.audioMessage.caption || 'File Audio'; } else if (message.message.documentWithCaptionMessage?.message?.documentMessage) { caption = message.message.documentWithCaptionMessage?.message?.documentMessage?.caption || ''; } else if (message.message.documentMessage) { caption = message.message.documentMessage.caption || ''; } else if (message.message.locationMessage) { caption = message.message.locationMessage.caption || 'Share Loc'; } const sql = 'INSERT INTO wa_inbox (pengirim, penerima, pesan, media) VALUES (?, ?, ?, ?)'; const values = [sender, receiver, caption, filename]; dbConnection.query(sql, values, (err, result) => { if (err) throw err; console.log('Pesan masuk : ', values); });
};
And what happened? It turns out that some messages aren’t saved, but the sender number and session name are saved.
Can anyone provide a solution?
Node: V18.116.0 Baileys: v6.6.0
I am trying to store incoming messages in a MySQL database with a table containing: pengirim, penerima, pesan, media, and tanggal. The script I’m using to save the messages is
const saveMessageToDatabase = async (message, receiver, filename = null) => { const isGroupMessage = message.key.remoteJid.endsWith('@g.us'); const sender = isGroupMessage ? message.key.participant.split('@')[0] : message.key.remoteJid.split('@')[0];
};
And what happened? It turns out that some messages aren’t saved, but the sender number and session name are saved.
Can anyone provide a solution?
Node: V18.116.0 Baileys: v6.6.0