Baileys
Baileys copied to clipboard
Always online
When I login to Whatsapp through baileys I stop receiving notifications on phone and stopped even receiving calls and always appear online can you add an option to keep the presence offline
Just add markOnlineOnConnect: false
in your auth configuration.
const WA = makeWASocket({
auth: state,
...,
markOnlineOnConnect: false,
});
Just add
markOnlineOnConnect: false
in your auth configuration.const WA = makeWASocket({ auth: state, ..., markOnlineOnConnect: false, });
its already there const socket = makeWASocket({ auth: authState?.state, browser: ["TestApi", "Desktop", "10.0"], logger: Logger({ level: "debug" }), syncFullHistory: false, markOnlineOnConnect: false, printQRInTerminal: true, getMessage: async (key) => { return await store.operation.messages.get({ "key.id": key.id }); }, });
sock.sendPresenceUpdate('unavailable') after every message send or any logic you want
Just add
markOnlineOnConnect: false
in your auth configuration.const WA = makeWASocket({ auth: state, ..., markOnlineOnConnect: false, });
its already there const socket = makeWASocket({ auth: authState?.state, browser: ["TestApi", "Desktop", "10.0"], logger: Logger({ level: "debug" }), syncFullHistory: false, markOnlineOnConnect: false, printQRInTerminal: true, getMessage: async (key) => { return await store.operation.messages.get({ "key.id": key.id }); }, });
If you use any presence update, you should consider https://github.com/WhiskeySockets/Baileys/issues/431#issuecomment-1758057135
sock.sendPresenceUpdate('unavailable') after every message send or any logic you want
For me, this work!
sock.sendPresenceUpdate('unavailable') after every message send or any logic you want
For me, this work!
How do you fix your code? Here not working after define sock.sendPresenceUpdate('unavailable')...
sock.sendPresenceUpdate('unavailable') after every message send or any logic you want
For me, this work!
How do you fix your code? Here not working after define sock.sendPresenceUpdate('unavailable')...
In my case i set timeout to send presenceupdate and tracked that timeout so that when i send a message it will update status after 1 minutes unless they send another message which will clear timeout of the previous one and sets it again
I also added a set interval to send presence update every 10 minutes (in my case it worked not sure if this is the correct approach or not)
file:///d:/Coding/JavaScript/Node%20Js%20Javascript/Whatsapp%20API/index.js:5 const sock = makeWASocket({ ^
TypeError: makeWASocket is not a function at connectToWhatsApp (file:///d:/Coding/JavaScript/Node%20Js%20Javascript/Whatsapp%20API/index.js:5:18) at file:///d:/Coding/JavaScript/Node%20Js%20Javascript/Whatsapp%20API/index.js:29:1 at ModuleJob.run (node:internal/modules/esm/module_job:218:25) at async ModuleLoader.import (node:internal/modules/esm/loader:329:24) at async loadESM (node:internal/process/esm_loader:28:7) at async handleMainPromise (node:internal/modules/run_main:113:12)
Node.js v20.11.1
[Done] exited with code=1 in 4.042 seconds
My code is
`import makeWASocket, { DisconnectReason } from '@whiskeysockets/baileys' import { Boom } from '@hapi/boom'
async function connectToWhatsApp () { const sock = makeWASocket({ // can provide additional config here printQRInTerminal: true }) sock.ev.on('connection.update', (update) => { const { connection, lastDisconnect } = update if(connection === 'close') { const shouldReconnect = (lastDisconnect.error)?.output?.statusCode !== DisconnectReason.loggedOut console.log('connection closed due to ', lastDisconnect.error, ', reconnecting ', shouldReconnect) // reconnect if not logged out if(shouldReconnect) { connectToWhatsApp() } } else if(connection === 'open') { console.log('opened connection') } }) sock.ev.on('messages.upsert', m => { console.log(JSON.stringify(m, undefined, 2))
console.log('replying to', m.messages[0].key.remoteJid)
})
} // run in main file connectToWhatsApp()`