WhiskeySockets / Baileys

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

Added useSingleFileAuthState and fixed requestPairingCode #1134

Open fann22 opened 1 week ago

fann22 commented 1 week ago

I’ve added useSingleFileAuthState for easier authentication sharing. Unlike useMultiFileAuthState, which creates a folder with multiple files, useSingleFileAuthState stores authentication in a single file. This makes it simpler and more convenient to share or transfer without the hassle of managing multiple files.

whiskeysockets-bot commented 1 week ago

Thanks for your contribution.

The next step is to wait for review and approval to merge it to main repository

The community can help reacting with a thumb up (:thumbsup:) for approval and rocket (:rocket:) for who has tested it.

To test this PR you can run the following command below:

# NPM
npm install @whiskeysockets/baileys@fann22/Baileys#master
# YARN v2
yarn add @whiskeysockets/baileys@fann22/Baileys#master
fann22 commented 1 week ago

fixed precondition required issue with requestPairingCode

code for connection:

const P = (await import("pino")).default({ level: "silent" });
const sock = makeWASocket({
    auth: {
        creds: state.creds,
        keys: makeCacheableSignalKeyStore(state.keys, P),
    },
    logger: P,
    browser: Browsers.windows("Chrome"),
    printQRInTerminal: false
}}

sock.ev.on("creds.update", saveCreds);

if (!sock.authState.creds.registered) {
    let code = await sock.requestPairingCode('62.........64');
    code = code?.match(/.{1,4}/g)?.join("-") || code;
  console.log("Your Pairing Code :", code);
}

output before the changes:

/data/data/com.termux/files/home/wa/node_modules/@whiskeysockets/baileys/lib/Socket/socket.js:57
            throw new boom_1.Boom('Connection Closed', { statusCode: Types_1.DisconnectReason.connectionClosed });
                  ^

Error: Connection Closed                                                                                      at sendRawMessage (/data/data/com.termux/files/home/wa/node_modules/@whiskeysockets/baileys/lib/Socket/socket.js:57:19)
    at sendNode (/data/data/com.termux/files/home/wa/node_modules/@whiskeysockets/baileys/lib/Socket/socket.js:76:16)
    at Object.requestPairingCode (/data/data/com.termux/files/home/wa/node_modules/@whiskeysockets/baileys/lib/Socket/socket.js:370:15)                                                                             at async file:///data/data/com.termux/files/home/wa/test.js:92:16 {                                 data: null,
  isBoom: true,
  isServer: false,
  output: {
    statusCode: 428,
    payload: {                                                                                                  statusCode: 428,
      error: 'Precondition Required',
      message: 'Connection Closed'
    },
    headers: {}
  }
}

Node.js v22.8.0

output after the changes:

Your Pairing Code : 54K2-FT7J
SheIITear commented 1 week ago

I don't see any reason to revert back to single file auth, its terrible.

fann22 commented 1 week ago

I don't see any reason to revert back to single file auth, its terrible.

it was there before? i didn't know about that

SheIITear commented 1 week ago

I don't see any reason to revert back to single file auth, its terrible.

it was there before? i didn't know about that

Yes, it was removed in commit 5aaefa94d6dda04da68e8394ac4b2c858d19ae18.

fann22 commented 1 week ago

I don't see any reason to revert back to single file auth, its terrible.

it was there before? i didn't know about that

Yes, it was removed in commit 5aaefa9.

do u know why they decided to remove it?

SheIITear commented 1 week ago

I don't see any reason to revert back to single file auth, its terrible.

it was there before? i didn't know about that

Yes, it was removed in commit 5aaefa9.

do u know why they decided to remove it?

Because it has more faults than uses.

Salientekill commented 1 week ago

I don't see any reason to revert back to single file auth, its terrible.

Not if it's a database

SheIITear commented 1 week ago

I don't see any reason to revert back to single file auth, its terrible.

Not if it's a database

What?

Salientekill commented 1 week ago

I don't see any reason to revert back to single file auth, its terrible.

Not if it's a database

What?

Previously, JSON was used, so a database to store the connection would be better, but from what I saw, this will arrive in 6.8, right?

SheIITear commented 1 week ago

I don't see any reason to revert back to single file auth, its terrible.

Not if it's a database

What?

Previously, JSON was used, so a database to store the connection would be better, but from what I saw, this will arrive in 6.8, right?

How is this related to single file auth though?