From 60577cf8d3e6b597671ef3b3b2d5a7b897ef5609 Mon Sep 17 00:00:00 2001 From: DevAstro Date: Wed, 25 Jun 2025 13:05:12 +0100 Subject: [PATCH] allow custom pairing code (#1550) --- src/Socket/socket.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Socket/socket.ts b/src/Socket/socket.ts index 4f7b051..763513a 100644 --- a/src/Socket/socket.ts +++ b/src/Socket/socket.ts @@ -459,8 +459,15 @@ export const makeSocket = (config: SocketConfig) => { end(new Boom(msg || 'Intentional Logout', { statusCode: DisconnectReason.loggedOut })) } - const requestPairingCode = async (phoneNumber: string): Promise => { - authState.creds.pairingCode = bytesToCrockford(randomBytes(5)) + const requestPairingCode = async (phoneNumber: string, customPairingCode?: string): Promise => { + const pairingCode = customPairingCode ?? bytesToCrockford(randomBytes(5)) + + if (customPairingCode && customPairingCode?.length !== 8) { + throw new Error('Custom pairing code must be exactly 8 chars') + } + + authState.creds.pairingCode = pairingCode + authState.creds.me = { id: jidEncode(phoneNumber, 's.whatsapp.net'), name: '~'