Baileys icon indicating copy to clipboard operation
Baileys copied to clipboard

Always online

Open Elalitareq opened this issue 1 year ago • 5 comments

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

Elalitareq avatar Oct 11 '23 06:10 Elalitareq

Just add markOnlineOnConnect: false in your auth configuration.

const WA = makeWASocket({
      auth: state,
      ...,
      markOnlineOnConnect: false,
      });

kyraex avatar Oct 11 '23 09:10 kyraex

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 }); }, });

Elalitareq avatar Oct 11 '23 10:10 Elalitareq

sock.sendPresenceUpdate('unavailable') after every message send or any logic you want

ChargerMc avatar Oct 11 '23 16:10 ChargerMc

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

kyraex avatar Oct 13 '23 18:10 kyraex

sock.sendPresenceUpdate('unavailable') after every message send or any logic you want

For me, this work!

renerlemes avatar Nov 05 '23 18:11 renerlemes

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')...

jbaladao avatar Feb 22 '24 13:02 jbaladao

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)

Elalitareq avatar Feb 22 '24 14:02 Elalitareq

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

AtifShakeel avatar Mar 24 '24 08:03 AtifShakeel

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()`

AtifShakeel avatar Mar 24 '24 08:03 AtifShakeel