"requestPairingCode" Returns Invalid Code
The function "requestPairingCode" returns a pairing code, but it is invalid. This issue has been tested on more than 10 accounts with the same result. Please investigate and fix the problem.
Investigated and the problem is from your code not baileys
I think I found the reason for the error. When I define 'browser' in 'makeWASocket', the code doesn't connect.
Show us how the code looks where you create your connection (makeWASocket)
@joaoporth Yep, seems to be true.
I was implementing the Pairing and found that if I use the browser config, it does not work. Baileys does generate a CODE, but the standard Whatsapp notification does not arrive.
I will update the exact version of Browser that works here if any.
any update @AkashSaikia ?
@AkashSaikia please update.
same issue here
i tried, with and without socket browserconfig, with every value I could think of and I didn't manage to make ir work
any update on this?
requestPairingCode is not working for me. returns a code, but always invalid code
"@whiskeysockets/baileys": "^6.7.17",
const sock = makeWASocket({
version,
logger,
printQRInTerminal: false,
markOnlineOnConnect: false,
auth: {
creds: state.creds,
keys: makeCacheableSignalKeyStore(state.keys, logger),
},
defaultQueryTimeoutMs: undefined,
msgRetryCounterCache,
generateHighQualityLinkPreview: true,
browser: Browsers.macOS('Google Chrome'),
syncFullHistory: true
});
if (!client.authState.creds.registered) {
// Request pairing code
const formattedNumber = phoneNumber.replace(/[^0-9]/g, '');
// Set the browser to Google Chrome for pairing code request
client.authState.creds.browser = Browsers.macOS("Google Chrome");
const code = await client.requestPairingCode(formattedNumber);
}
I think I found the reason for the error. When I define 'browser' in 'makeWASocket', the code doesn't connect.
solved
any updates
It generates a code, but it is not valid and no WhatsApp notification is received.
const sock = makeWASocket({ version, logger, printQRInTerminal: true, auth: { creds: state.creds, keys: makeCacheableSignalKeyStore(state.keys, logger), }, // browser: ["WhatsApp Desktop", "Firefox", "1.0.0"], connectTimeoutMs: 60000, defaultQueryTimeoutMs: 60000, emitOwnEvents: true, markOnlineOnConnect: true, syncFullHistory: false, });
// Bağlantı durumunu dinle
sock.ev.on("connection.update", async (update) => {
const { connection, lastDisconnect, qr } = update;
console.log(`[${formattedNumber}] Bağlantı durumu:`, connection);
if (qr) {
console.log(`[${formattedNumber}] QR kodu görüntülendi.`);
}
if (connection === "close") {
const statusCode = lastDisconnect?.error?.output?.statusCode;
console.log(
`[${formattedNumber}] Bağlantı kapandı. Sebep: ${statusCode}`
);
console.log(
`[${formattedNumber}] Detay:`,
lastDisconnect?.error?.message
);
// Aktif bağlantıyı kaldır
activeConnections.delete(formattedNumber);
// Auth klasörünü sil
try {
const authPath = path.join(__dirname, "auth_info", formattedNumber);
if (fs.existsSync(authPath)) {
fs.rmSync(authPath, { recursive: true, force: true });
console.log(`[${formattedNumber}] Auth klasörü silindi`);
}
} catch (error) {
console.error(`[${formattedNumber}] Auth klasörü silme hatası:`, error);
}
// Yeniden bağlanma mantığı
if (
statusCode !== DisconnectReason.loggedOut &&
statusCode !== DisconnectReason.connectionReplaced
) {
console.log(`[${formattedNumber}] Yeniden bağlanılıyor...`);
setTimeout(() => {
startWhatsAppSession(formattedNumber).then(resolve).catch(reject);
}, 10000);
} else {
console.log(
`[${formattedNumber}] Oturum kapatıldı, yeni oturum gerekli`
);
reject(new Error("Oturum sonlandırıldı"));
}
} else if (connection === "open") {
console.log(`[${formattedNumber}] ✅ WhatsApp bağlantısı kuruldu!`);
await WhatsAppSession.findOneAndUpdate(
{ phoneNumber: formattedNumber },
{ isActive: true, isVerified: true }
);
// Event dinleyicileri ekle
setupEventListeners(sock, formattedNumber);
// Aktif bağlantıyı kaydet
activeConnections.set(formattedNumber, sock);
resolve(sock);
} else if (connection === "connecting") {
// Eğer başlangıç kimliği yoksa ve bağlanıyorsa, eşleştirme kodu iste
if (!state.creds.me) {
console.log(
`[${formattedNumber}] İlk bağlantı, kimlik doğrulama gerekli`
);
setTimeout(async () => {
try {
console.log(`[${formattedNumber}] Kod isteniyor...`);
if (!sock.authState.creds.registered) {
console.log(`[${formattedNumber}] Pairing code isteniyor...`);
const code = await sock.requestPairingCode(formattedNumber);
if (code) {
console.log(
`[${formattedNumber}] 🔐 GİRİŞ KODU: ${code} 🔐`
);
console.log(
`[${formattedNumber}] Giriş kodu SMS olarak gönderildi`
);
}
}
} catch (error) {
console.error(
`[${formattedNumber}] Kod gönderme hatası:`,
error
);
if (error.message.includes("429")) {
console.log(
`[${formattedNumber}] ⚠️ Çok fazla deneme yapıldı. Lütfen 30 saniye bekleyin.`
);
}
}
}, 6000);
}
}
});
// Kimlik bilgilerini kaydet
sock.ev.on("creds.update", saveCreds);
})
"@whiskeysockets/baileys": "^6.6.0",
@SheIITear why did you close it?
im having the same issue without initializing the browser. the code is created but invalid for connection.
"@whiskeysockets/baileys": "^6.7.17",
const sock = makeWASocket({
version,
logger,
printQRInTerminal: false,
markOnlineOnConnect: false,
auth: {
creds: state.creds,
keys: makeCacheableSignalKeyStore(state.keys, logger),
},
defaultQueryTimeoutMs: undefined,
msgRetryCounterCache,
generateHighQualityLinkPreview: true,
//browser: Browsers.macOS('Google Chrome'),
syncFullHistory: true
});
if (!client.authState.creds.registered) {
const code = await client.requestPairingCode(formattedNumber);
}
@Yaniv101, ### I solved the problem. You can use the following:
const sock = makeWASocket({ version, logger, printQRInTerminal: true, auth: { creds: state.creds, keys: makeCacheableSignalKeyStore(state.keys, logger), }, connectTimeoutMs: 60000, defaultQueryTimeoutMs: 60000, emitOwnEvents: true, markOnlineOnConnect: true, syncFullHistory: false, });
sock.ev.on("creds.update", saveCreds);
if (connection === "connecting")
if (!sock.authState.creds.registered) {
console.log([${formattedNumber}] waiting for code...);
const code = await sock.requestPairingCode(formattedNumber);
if (code) {
console.log(
[${formattedNumber}] 🔐 Code: ${code} 🔐
);
}
}
"@whiskeysockets/baileys": "^6.7.18",
Working great now Thank you