ookamiiixd / baileys-api

Simple WhatsApp REST API with multiple device support
MIT License
431 stars 327 forks source link

Session Bug #18

Closed jealvin closed 2 years ago

jealvin commented 2 years ago

Session id found after refresh qrcode.

ookamiiixd commented 2 years ago

Can you add more details with your problem?

saifulcoder commented 2 years ago

d found after refresh qrcode.

use qr requests each 20 second

utqinadhif commented 2 years ago

How to refresh qr code without wait 20 second?

netrixken commented 2 years ago

How to refresh qr code without wait 20 second?

use different id or delete used id first

jealvin commented 2 years ago

yes here is it : while request qrcode from post /session/add im checking the user is connected using the session (/session/find/:id) first time got "Session not found." second request got "Session found." waiting for a while got "Session not found."

on the log its got this

{"level":30,"time":1646283218284,"pid":15284,"hostname":"DESKTOP-78ODD95","class":"baileys","error":{"data":null,"isBoom":true,"isServer":false,"output":{"statusCode":408,"payload":{"statusCode":408,"error":"Request Time-out","message":"QR refs atte
mpts ended"},"headers":{}}},"msg":"connection closed"}

@ookamiiixd

Can you add more details with your problem?

ookamiiixd commented 2 years ago

Well, during QR generation the session status will be found no matter it's connected or not because the socket has been started and the session id is on use. Is this clear for you now?

utqinadhif commented 2 years ago

How to refresh qr code without wait 20 second?

use different id or delete used id first

Yes, i try to delete first, but how to check if connect?

ookamiiixd commented 2 years ago

How to refresh qr code without wait 20 second?

use different id or delete used id first

Yes, i try to delete first, but how to check if connect?

If you want to check if session has been successfully connected and authenticated, you can check for user properties. For Beta Multi-Device session, check in session.user. For Legacy (Normal WhatsApp Web) session, check in session.state.legacy.user. Both should return undefined if the session hasn't been authenticated.

jealvin commented 2 years ago

How to refresh qr code without wait 20 second?

use different id or delete used id first

Yes, i try to delete first, but how to check if connect?

If you want to check if session has been successfully connected and authenticated, you can check for user properties. For Beta Multi-Device session, check in session.user. For Legacy (Normal WhatsApp Web) session, check in session.state.legacy.user. Both should return undefined if the session hasn't been authenticated.

then we need to add new router to check session user is hasn't been authenticated or not.

ookamiiixd commented 2 years ago

How to refresh qr code without wait 20 second?

use different id or delete used id first

Yes, i try to delete first, but how to check if connect?

If you want to check if session has been successfully connected and authenticated, you can check for user properties. For Beta Multi-Device session, check in session.user. For Legacy (Normal WhatsApp Web) session, check in session.state.legacy.user. Both should return undefined if the session hasn't been authenticated.

then we need to add new router to check session user is hasn't been authenticated or not.

Yep, i might do this if i have free time.

utqinadhif commented 2 years ago

How to refresh qr code without wait 20 second?

use different id or delete used id first

Yes, i try to delete first, but how to check if connect?

If you want to check if session has been successfully connected and authenticated, you can check for user properties. For Beta Multi-Device session, check in session.user. For Legacy (Normal WhatsApp Web) session, check in session.state.legacy.user. Both should return undefined if the session hasn't been authenticated.

then we need to add new router to check session user is hasn't been authenticated or not.

yes, i do that, but for 20 second if i hit /session/add, the session still found, so how many seconds for session/add can create new qr?

ookamiiixd commented 2 years ago

How to refresh qr code without wait 20 second?

use different id or delete used id first

Yes, i try to delete first, but how to check if connect?

If you want to check if session has been successfully connected and authenticated, you can check for user properties. For Beta Multi-Device session, check in session.user. For Legacy (Normal WhatsApp Web) session, check in session.state.legacy.user. Both should return undefined if the session hasn't been authenticated.

then we need to add new router to check session user is hasn't been authenticated or not.

yes, i do that, but for 20 second if i hit /session/add, the session still found, so how many seconds for session/add can create new qr?

Typically 20 seconds, if you want to wait until it available then add some seconds. 25-30 seconds should do.

jealvin commented 2 years ago

How to refresh qr code without wait 20 second?

use different id or delete used id first

Yes, i try to delete first, but how to check if connect?

If you want to check if session has been successfully connected and authenticated, you can check for user properties. For Beta Multi-Device session, check in session.user. For Legacy (Normal WhatsApp Web) session, check in session.state.legacy.user. Both should return undefined if the session hasn't been authenticated.

then we need to add new router to check session user is hasn't been authenticated or not.

Yep, i might do this if i have free time.

already create it add into whatsapp.js

const isLogedin = (sessionId) =>{
    const sessionFileLegacy = 'legacy_' + sessionId
    const sessionFileMD = 'md_' + sessionId
    var SESSION_FILE_PATH_LEGACY = join(__dirname, 'sessions', `${sessionFileLegacy}.json`);
    var SESSION_FILE_PATH_MD = join(__dirname, 'sessions', `${sessionFileMD}.json`);
    if (existsSync(SESSION_FILE_PATH_LEGACY) || existsSync(SESSION_FILE_PATH_MD) ) {
        return true
    }else{
        return false
    }    
}

this func to check if session exists or not

jealvin commented 2 years ago

How to refresh qr code without wait 20 second?

use different id or delete used id first

Yes, i try to delete first, but how to check if connect?

If you want to check if session has been successfully connected and authenticated, you can check for user properties. For Beta Multi-Device session, check in session.user. For Legacy (Normal WhatsApp Web) session, check in session.state.legacy.user. Both should return undefined if the session hasn't been authenticated.

then we need to add new router to check session user is hasn't been authenticated or not.

yes, i do that, but for 20 second if i hit /session/add, the session still found, so how many seconds for session/add can create new qr?

Typically 20 seconds, if you want to wait until it available then add some seconds. 25-30 seconds should do.

its better if you create socket to detect if new QR recieved or not

ookamiiixd commented 2 years ago

If this already clear for you guys, i will close this issue.