WhiskeySockets / Baileys

Lightweight full-featured typescript/javascript WhatsApp Web API
https://baileys.whiskeysockets.io/
MIT License
3.78k stars 1.29k forks source link

[BUG] Failure to Connect After Scanning QR Code #702

Closed AbhishekSuresh2 closed 6 months ago

AbhishekSuresh2 commented 6 months ago

Bug: I M using this WhiskeySockets library for a long time without encountering this error, but it occurred unexpectedly today.

Sample Code Of Qr:

import makeWASocket, { DisconnectReason, BufferJSON, useMultiFileAuthState } from '@whiskeysockets/baileys'
import { Boom } from '@hapi/boom'

async function connectToWhatsApp () {
    const { state, saveCreds } = await useMultiFileAuthState('auth_info_baileys')

    const sock = makeWASocket({
        auth: state,
        printQRInTerminal: true, 
    });

    sock.ev.on('creds.update', saveCreds)

    sock.ev.on('connection.update', (update) => {
        const { connection, lastDisconnect } = update
        if (connection === 'close') {
            const shouldReconnect = (lastDisconnect?.error as Boom)?.output?.statusCode !== DisconnectReason.loggedOut
            console.log('Connection closed due to', lastDisconnect?.error, ', reconnecting', shouldReconnect)
            if (shouldReconnect) {
                connectToWhatsApp() // Reconnect if necessary
            }
        } else if (connection === 'open') {
            console.log('Opened connection')
        }
    });

    sock.ev.on('messages.upsert', m => {
        console.log("Message Received: " + m.messages[0].key.remoteJid);
    });

}

connectToWhatsApp()

To Reproduce:

  1. Create a new connection.
  2. Scan the QR code.
  3. Observe the connection failure.

Expected Behavior: After scanning the QR code, the connection should be established successfully, allowing communication with WhatsApp.

Environment:

Additional Context:

Alien-Alfa commented 6 months ago

I am not facing this issue on iOS. Please try the same on iOS

meetshamee commented 6 months ago

I am not facing this issue on iOS. Please try the same on iOS

I checked with ios, after little time it's going disconnected

arrocy commented 6 months ago

Anyone from India can do me a favor? I am still using Baileys v6.6.0 on my other site, and it seems like all of the +91 devices connected just fine (without disconnection issue).

Please report back here after you have done your test by adding device and scan QR code here: arrocy.com/devices

login: demo/password

dsusoftech commented 6 months ago

Anyone from India can do me a favor? I am still using Baileys v6.6.0 on my other site, and it seems like all of the +91 devices connected just fine (without disconnection issue).

Please report back here after you have done your test by adding device and scan QR code here: arrocy.com/devices

login: demo/password

Hey i can help you Dishang Here. tell me i have 4 indian numbers to test. My connected device already working perfectly only new device if i want to connect than throws an error.

hamidsaifi77 commented 6 months ago

Anyone from India can do me a favor? I am still using Baileys v6.6.0 on my other site, and it seems like all of the +91 devices connected just fine (without disconnection issue).

Please report back here after you have done your test by adding device and scan QR code here: arrocy.com/devices

login: demo/password

hello there, I have tried using your panel; however, it remains the same. Once the device is logged in then it logs out.

aarvee022 commented 6 months ago

Anyone from India can do me a favor? I am still using Baileys v6.6.0 on my other site, and it seems like all of the +91 devices connected just fine (without disconnection issue).

Please report back here after you have done your test by adding device and scan QR code here: arrocy.com/devices

login: demo/password

Hi i have tried on your panel as well. It is being disconnected after 2-3 seconds.

arrocy commented 6 months ago

looks like the +91 numbers that is already connected previously are not affected (have 6 ONLINE/connected devices from India).

Only new +91 connections that is affected.

aarvee022 commented 6 months ago

looks like the +91 numbers that is already connected previously are not affected (have 6 ONLINE/connected devices from India).

Only new +91 connections that is affected.

Yes, previously connected numbers are not affected. They are working fine on my panel as well but new numbers are not getting connected.

dsusoftech commented 6 months ago

Yes previously connected number not affected even this new indian number registration issue was reported by my client before 4 days.. still i ignore and yesterday taken seriously.

meetshamee commented 6 months ago

yes i have 45 previously connected +91 numbers without No issue, Issue with new number connectivity.

Riders004 commented 6 months ago

Anyone from India can do me a favor? I am still using Baileys v6.6.0 on my other site, and it seems like all of the +91 devices connected just fine (without disconnection issue).

Please report back here after you have done your test by adding device and scan QR code here: arrocy.com/devices

login: demo/password

It's a issue with ip not with number

Riders004 commented 6 months ago

It's a issue related login to foreign country yesterday I checked with my pair when I try to login with that hosted on koyeb it's disconnected my device and when I'm try after turn on in Termux it's connected successfully

souravkl11 commented 6 months ago

Anyone from India can do me a favor? I am still using Baileys v6.6.0 on my other site, and it seems like all of the +91 devices connected just fine (without disconnection issue). Please report back here after you have done your test by adding device and scan QR code here: arrocy.com/devices login: demo/password

It's a issue with ip not with number

Not really, it happens when we try to scan QR or use pairing code to make a new connection using Baileys. I tried on multiple accounts on the same app and here's the result:

• +91 (India): Logs out suddenly ❌ • +1 (US): No issues, works as usual ✅ • +852 (Hong Kong): No issues ✅ • +44 (UK): No issues ✅

(On the same server, on the same IP)

Edit: Previously logged in accounts have no issues even on +91. It's for the new connections

arrocy commented 6 months ago

Seems like no problem after downgrade to Baileys v5.0.0

Scan QR code here: arrocy.com/devices login: demo/password

hamidsaifi77 commented 6 months ago

demo

yes you are correct its working fine. Please answer a couple of doubts:- a:- are you using any proxy in baileys ? b:- which file you changed from old Baileys 5.0.0

Thanks

souravkl11 commented 6 months ago

Seems like no problem after downgrade to Baileys v5.0.0

Scan QR code here: arrocy.com/devices login: demo/password

Works ofc, lemme try

arrocy commented 6 months ago

demo

yes you are correct its working fine. Please answer a couple of doubts:- a:- are you using any proxy in baileys ? b:- which file you changed from old Baileys 5.0.0

Thanks

a. yes, using proxyscrape.com b. no change, direct replacement. Baileys-v6 folder -> replace with ->Baileys-v5 folder

meetshamee commented 6 months ago

Baileys v5.0.0

here Issue Solved with Downgrade

hamidsaifi77 commented 6 months ago

demo

yes you are correct its working fine. Please answer a couple of doubts:- a:- are you using any proxy in baileys ? b:- which file you changed from old Baileys 5.0.0

Thanks

a. yes, using proxyscrape.com

b. no change, direct replacement. Baileys-v6 folder -> replace with ->Baileys-v5 folder

Thanknyou for the quick response. Can i have your proxy connection method. And is it working your side without using proxy too ?

dsusoftech commented 6 months ago

demo

yes you are correct its working fine. Please answer a couple of doubts:- a:- are you using any proxy in baileys ? b:- which file you changed from old Baileys 5.0.0

Thanks

a. yes, using proxyscrape.com b. no change, direct replacement. Baileys-v6 folder -> replace with ->Baileys-v5 folder

Thanknyou for the quick response. Can i have your proxy connection method. And is it working your side without using proxy too ?

Yes without proxy working and all old devices will be stay connected

meetshamee commented 6 months ago

Some developers warn that baileys old version may cause WhatsApp ban. is it true?

souravkl11 commented 6 months ago

Some developers warn that baileys old version may cause WhatsApp ban. is it true?

Then just use the old version for initial connection as of now. And after a successful connection, use that auth info to login in using the latest version.

bentacos commented 6 months ago

Some developers warn that baileys old version may cause WhatsApp ban. is it true?

yes

arrocy commented 6 months ago

demo

yes you are correct its working fine. Please answer a couple of doubts:- a:- are you using any proxy in baileys ? b:- which file you changed from old Baileys 5.0.0

Thanks

a. yes, using proxyscrape.com b. no change, direct replacement. Baileys-v6 folder -> replace with ->Baileys-v5 folder

Thanknyou for the quick response. Can i have your proxy connection method. And is it working your side without using proxy too ?

const { ProxyAgent } = require('proxy-agent');
let agent, proxyUrls, proxyUrl, proxyLength, rand;

const fetchProxyScrape = async () => {
  try {
    const proxyScrape = await fetch('https://api.proxyscrape.com/v2/?request=displayproxies&protocol=http&timeout=10000&country=in&ssl=no&anonymity=all');
    const proxyText = await proxyScrape.text();
    proxyUrls = proxyText.split('\r\n').filter(Boolean);
    proxyLength = proxyUrls.length;
  } catch (error) {
    console.log('FREE PROXYSCRAPE ERROR', error);
  }
};
fetchProxyScrape();

const startSock = async() => {
  if (proxyLength > 0) {
    rand = Math.floor(Math.random() * Math.floor(proxyLength));
    proxyUrl = 'http://' + proxyUrls[rand];
    agent = new ProxyAgent(proxyUrl);
  }
  const { state, saveCreds } = await useMultiFileAuthState('baileys_auth_info')
    const { version, isLatest } = await fetchLatestBaileysVersion()
    console.log(`using WA v${version.join('.')}, isLatest: ${isLatest}`)

    const sock = makeWASocket({
                agent,
        version,
        logger,
        printQRInTerminal: !usePairingCode,
        mobile: useMobile,
        auth: {
            creds: state.creds,
            keys: makeCacheableSignalKeyStore(state.keys, logger),
        },
        msgRetryCounterCache,
        generateHighQualityLinkPreview: true,
        getMessage,
    })

    store?.bind(sock.ev)

  // the rest of the codes here
}
startSock();
SheIITear commented 6 months ago

Ok, I tested with +254 number (@V-E-N-O-X brought up having the same issue with them) that has not been used before on few different servers and had no problems. I still cannot reproduce this unfortunately. I'll try to find a number from India that I can use to test.

meetshamee commented 6 months ago

we Continue with temporary solution (old version). Can someone fix this in the new version?

dhirennjaypal commented 6 months ago

we Continue with temporary solution (old version). Can someone fix this in the new version?

Old version is not working for me, it gives error 405 'Method Not Allowed'.

SheIITear commented 6 months ago

Does anyone have Indian number to lend for testing? Can't find any working one.

meetshamee commented 6 months ago

Does anyone have Indian number to lend for testing? Can't find any working one.

Yes. PM me

myselfviral commented 6 months ago

I tried with window server. Its working fine with same code but when we try to scan for another connection then 1st one close. Error code 515. look like code 515 and 516 both are related WhatsApp close.

allburov commented 6 months ago

If we revert Baileys to https://github.com/WhiskeySockets/Baileys/commit/b7878e531144133b48d9e5970787e7b256d21063 It works with no issue with Indian phone numbers.

sahilbrandwala commented 6 months ago

If we revert Baileys to b7878e5 It works with no issue with Indian phone numbers.

qr code not come

ujwalvj commented 6 months ago

Does anyone have Indian number to lend for testing? Can't find any working one.

yes I can help , if needed.

SheIITear commented 6 months ago

Does anyone have Indian number to lend for testing? Can't find any working one.

yes I can help , if needed.

Hi, whats your discord? @meetshamee sent dm on dc.

ujwalvj commented 6 months ago

Does anyone have Indian number to lend for testing? Can't find any working one.

yes I can help , if needed.

Hi, whats your discord? @meetshamee sent dm on dc.

@ujwal2865

Teamolduser commented 6 months ago

Maybe I think Baileys need update with WhatsApp web

meetshamee commented 6 months ago

@SheIITear Given a chance but failed. Yes the problem is sudden logout

SheIITear commented 6 months ago

@SheIITear Given a chance but failed. Yes the problem is sudden logout

Don't be so fast :D. I already fixed it. I will pr later.

meetshamee commented 6 months ago

@SheIITear Tested successfully, can you share how?

SheIITear commented 6 months ago

Till it gets merged you can try using this branch -> https://github.com/WhiskeySockets/Baileys/tree/fix-516

Riders004 commented 6 months ago

Till it gets merged you can try using this branch -> https://github.com/WhiskeySockets/Baileys/tree/fix-516

Thanks brother it's working

aarvee022 commented 6 months ago

Till it gets merged you can try using this branch -> https://github.com/WhiskeySockets/Baileys/tree/fix-516

Working Now Thanks

harshitpeer commented 6 months ago

That works, thanks! @SheIITear

If anyone is wondering how to use the branch.

yarn add github:WhiskeySockets/Baileys#fix-516 or npm i github:WhiskeySockets/Baileys#fix-516

ujwalvj commented 6 months ago

Till it gets merged you can try using this branch -> https://github.com/WhiskeySockets/Baileys/tree/fix-516

this worked for me. Thanks!!

rsaisankalp commented 6 months ago

with fix-516: getting this error with node 18 version 0|baileys | This is caused by either a bug in Node.js or incorrect usage of Node.js internals. 0|baileys | Please open an issue with this stack trace at https://github.com/nodejs/node/issues 0|baileys | 0|baileys | at new NodeError (node:internal/errors:405:5) 0|baileys | at assert (node:internal/assert:14:11) 0|baileys | at getMessage (node:internal/errors:451:5) 0|baileys | at new NodeError (node:internal/errors:379:21) 0|baileys | at legacyMainResolve (node:internal/modules/esm/resolve:218:9) 0|baileys | at packageResolve (node:internal/modules/esm/resolve:903:14) 0|baileys | at moduleResolve (node:internal/modules/esm/resolve:973:20) 0|baileys | at defaultResolve (node:internal/modules/esm/resolve:1193:11) 0|baileys | at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:404:12) 0|baileys | at ModuleLoader.resolve (node:internal/modules/esm/loader:373:25) { 0|baileys | code: 'ERR_INTERNAL_ASSERTION' 0|baileys | }

Riders004 commented 6 months ago

with fix-516: getting this error with node 18 version 0|baileys | This is caused by either a bug in Node.js or incorrect usage of Node.js internals. 0|baileys | Please open an issue with this stack trace at https://github.com/nodejs/node/issues 0|baileys | 0|baileys | at new NodeError (node:internal/errors:405:5) 0|baileys | at assert (node:internal/assert:14:11) 0|baileys | at getMessage (node:internal/errors:451:5) 0|baileys | at new NodeError (node:internal/errors:379:21) 0|baileys | at legacyMainResolve (node:internal/modules/esm/resolve:218:9) 0|baileys | at packageResolve (node:internal/modules/esm/resolve:903:14) 0|baileys | at moduleResolve (node:internal/modules/esm/resolve:973:20) 0|baileys | at defaultResolve (node:internal/modules/esm/resolve:1193:11) 0|baileys | at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:404:12) 0|baileys | at ModuleLoader.resolve (node:internal/modules/esm/loader:373:25) { 0|baileys | code: 'ERR_INTERNAL_ASSERTION' 0|baileys | }

Do npm install or yarn install before running

Riders004 commented 4 months ago

Getting this problem again we can't link device in WhatsApp with whiskeysockets baileys

@PurpShell @SheIITear

kj2222 commented 4 months ago

Same issue:

connection update { connection: 'close', lastDisconnect: { error: Error: Stream Errored (restart required) at WebSocketClient. (/Users/a/Documents/GitHub/Baileysfinal/src/Socket/socket.ts:662:7) at WebSocketClient.emit (node:events:518:28) at WebSocketClient.emit (node:domain:488:12) at /Users/a/Documents/GitHub/Baileysfinal/src/Socket/socket.ts:338:23 at Object.decodeFrame (/Users/a/Documents/GitHub/Baileysfinal/src/Utils/noise-handler.ts:176:5) at WebSocketClient.onMessageReceived (/Users/a/Documents/GitHub/Baileysfinal/src/Socket/socket.ts:310:9) at WebSocketClient.emit (node:events:518:28) at WebSocketClient.emit (node:domain:488:12) at WebSocket. (/Users/a/Documents/GitHub/Baileysfinal/src/Socket/Client/web-socket-client.ts:40:52) at WebSocket.emit (node:events:518:28) { data: [Object], isBoom: true, isServer: true, output: [Object] }, date: 2024-05-11T19:52:34.215Z } }

Riders004 commented 4 months ago

Same issue:

connection update { connection: 'close', lastDisconnect: { error: Error: Stream Errored (restart required) at WebSocketClient. (/Users/a/Documents/GitHub/Baileysfinal/src/Socket/socket.ts:662:7) at WebSocketClient.emit (node:events:518:28) at WebSocketClient.emit (node:domain:488:12) at /Users/a/Documents/GitHub/Baileysfinal/src/Socket/socket.ts:338:23 at Object.decodeFrame (/Users/a/Documents/GitHub/Baileysfinal/src/Utils/noise-handler.ts:176:5) at WebSocketClient.onMessageReceived (/Users/a/Documents/GitHub/Baileysfinal/src/Socket/socket.ts:310:9) at WebSocketClient.emit (node:events:518:28) at WebSocketClient.emit (node:domain:488:12) at WebSocket. (/Users/a/Documents/GitHub/Baileysfinal/src/Socket/Client/web-socket-client.ts:40:52) at WebSocket.emit (node:events:518:28) { data: [Object], isBoom: true, isServer: true, output: [Object] }, date: 2024-05-11T19:52:34.215Z } }

It's not a issue it aski for restart so restart your bot or application if your are using external pair or qr like hermit raganork lyfee inrl so it's don't need you can ignore this

kj2222 commented 4 months ago

Same issue: connection update { connection: 'close', lastDisconnect: { error: Error: Stream Errored (restart required) at WebSocketClient. (/Users/a/Documents/GitHub/Baileysfinal/src/Socket/socket.ts:662:7) at WebSocketClient.emit (node:events:518:28) at WebSocketClient.emit (node:domain:488:12) at /Users/a/Documents/GitHub/Baileysfinal/src/Socket/socket.ts:338:23 at Object.decodeFrame (/Users/a/Documents/GitHub/Baileysfinal/src/Utils/noise-handler.ts:176:5) at WebSocketClient.onMessageReceived (/Users/a/Documents/GitHub/Baileysfinal/src/Socket/socket.ts:310:9) at WebSocketClient.emit (node:events:518:28) at WebSocketClient.emit (node:domain:488:12) at WebSocket. (/Users/a/Documents/GitHub/Baileysfinal/src/Socket/Client/web-socket-client.ts:40:52) at WebSocket.emit (node:events:518:28) { data: [Object], isBoom: true, isServer: true, output: [Object] }, date: 2024-05-11T19:52:34.215Z } }

It's not a issue it aski for restart so restart your bot or application if your are using external pair or qr like hermit raganork lyfee inrl so it's don't need you can ignore this

Yeah we obviously tried restarting! The issue persists, it seems to be a critical issue