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);
|
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
|
// Mark the chat as unread so it shows up as a notification/badge on the user's phone
|
||||||
|
// We add a 3-second delay because if we do it immediately, the phone might override it!
|
||||||
|
setTimeout(async () => {
|
||||||
try {
|
try {
|
||||||
const chat = await client.getChatById(targetJid);
|
const chat = await client.getChatById(targetJid);
|
||||||
await chat.markUnread();
|
await chat.markUnread();
|
||||||
|
console.log(`[WhatsApp Bot] Marked chat ${targetJid} as unread after delay.`);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('[WhatsApp Bot] Failed to mark chat as unread:', err);
|
console.error('[WhatsApp Bot] Failed to mark chat as unread:', err);
|
||||||
}
|
}
|
||||||
|
}, 3000);
|
||||||
|
|
||||||
res.json({ success: true, messageId: response.id._serialized, recipient: targetJid });
|
res.json({ success: true, messageId: response.id._serialized, recipient: targetJid });
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue