Add delay to mark unread
This commit is contained in:
parent
ffb6638f04
commit
5efc41af3d
|
|
@ -199,12 +199,16 @@ const handleSendMessage = async (req, res) => {
|
|||
const response = await client.sendMessage(targetJid, message);
|
||||
|
||||
// Mark the chat as unread so it shows up as a notification/badge on the user's phone
|
||||
try {
|
||||
const chat = await client.getChatById(targetJid);
|
||||
await chat.markUnread();
|
||||
} catch (err) {
|
||||
console.error('[WhatsApp Bot] Failed to mark chat as unread:', err);
|
||||
}
|
||||
// We add a 3-second delay because if we do it immediately, the phone might override it!
|
||||
setTimeout(async () => {
|
||||
try {
|
||||
const chat = await client.getChatById(targetJid);
|
||||
await chat.markUnread();
|
||||
console.log(`[WhatsApp Bot] Marked chat ${targetJid} as unread after delay.`);
|
||||
} catch (err) {
|
||||
console.error('[WhatsApp Bot] Failed to mark chat as unread:', err);
|
||||
}
|
||||
}, 3000);
|
||||
|
||||
res.json({ success: true, messageId: response.id._serialized, recipient: targetJid });
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue