@vielhuber/wahelper 1.5.4 → 1.5.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vielhuber/wahelper",
3
- "version": "1.5.4",
3
+ "version": "1.5.5",
4
4
  "description": "Lightweight whatsapp integration layer.",
5
5
  "main": "wahelper.js",
6
6
  "files": [
@@ -22,7 +22,7 @@
22
22
  "author": "David Vielhuber <david@vielhuber.de>",
23
23
  "license": "MIT",
24
24
  "dependencies": {
25
- "baileys": "^7.0.0-rc.9",
25
+ "baileys": "mtAlves/Baileys#fix/pairing-code",
26
26
  "qrcode-terminal": "^0.12.0"
27
27
  },
28
28
  "devDependencies": {
@@ -7,12 +7,15 @@ import makeWASocket, {
7
7
  fetchLatestBaileysVersion
8
8
  } from 'baileys';
9
9
  import P from 'pino';
10
+ import qrcodeTerminal from 'qrcode-terminal';
11
+
12
+ // set to false to use QR code instead
13
+ const USE_PAIRING_CODE = true;
10
14
  import { fileURLToPath } from 'url';
11
15
  import { dirname } from 'path';
12
16
  import fs from 'fs';
13
17
  import http from 'http';
14
18
  import { DatabaseSync } from 'node:sqlite';
15
- import qrcodeTerminal from 'qrcode-terminal';
16
19
 
17
20
  export default class wahelperDaemon {
18
21
  constructor() {
@@ -28,6 +31,8 @@ export default class wahelperDaemon {
28
31
  this.connected = false;
29
32
  this.connecting = false;
30
33
  this.qr = null;
34
+ this.pairingCode = null;
35
+ this.pairingCodeRequested = false;
31
36
  this.isFirstRun = false;
32
37
  this.reconnectDelay = 1000;
33
38
  this.httpServer = null;
@@ -457,8 +462,10 @@ export default class wahelperDaemon {
457
462
 
458
463
  useMultiFileAuthState(this.dirname + '/' + this.authFolder)
459
464
  .then(async ({ state, saveCreds }) => {
460
- console.log('Auth state loaded, fetching Baileys version...');
461
- let { version } = await fetchLatestBaileysVersion();
465
+ // WhatsApp rejected Platform.WEB (value 14) since 2026-02-24.
466
+ // fetchLatestBaileysVersion() returns a version that triggers a 405 — use a fixed working version instead.
467
+ // See: https://github.com/WhiskeySockets/Baileys/issues/2370
468
+ let version = [2, 3000, 1033893291];
462
469
  console.log('Baileys version: ' + version.join('.'));
463
470
 
464
471
  // close stale socket if present
@@ -504,12 +511,28 @@ export default class wahelperDaemon {
504
511
 
505
512
  if (qr) {
506
513
  this.isFirstRun = true;
507
- this.qr = qr;
508
- // display QR code in daemon terminal for scanning
509
- qrcodeTerminal.generate(qr, { small: true }, qrString => {
510
- console.log('\nScan this QR code with WhatsApp:');
511
- console.log(qrString);
512
- });
514
+ if (USE_PAIRING_CODE) {
515
+ // request pairing code once per session
516
+ if (!this.pairingCodeRequested && this.device) {
517
+ this.pairingCodeRequested = true;
518
+ this.sock
519
+ .requestPairingCode(this.device)
520
+ .then(code => {
521
+ this.pairingCode = code;
522
+ console.log('\nPairing code: ' + code);
523
+ })
524
+ .catch(err => {
525
+ this.log('Pairing code request failed: ' + err.message);
526
+ });
527
+ }
528
+ } else {
529
+ // use QR code
530
+ this.qr = qr;
531
+ qrcodeTerminal.generate(qr, { small: true }, qrString => {
532
+ console.log('\nScan this QR code with WhatsApp:');
533
+ console.log(qrString);
534
+ });
535
+ }
513
536
  } else {
514
537
  if (connection === 'close') {
515
538
  this.connected = false;
@@ -525,6 +548,8 @@ export default class wahelperDaemon {
525
548
  if (statusCode === DisconnectReason.loggedOut) {
526
549
  // logged out — delete auth and reconnect
527
550
  this.qr = null;
551
+ this.pairingCode = null;
552
+ this.pairingCodeRequested = false;
528
553
  this.log('Logged out, removing auth folder');
529
554
  console.log('Logged out, removing auth folder...');
530
555
  if (fs.existsSync(this.dirname + '/' + this.authFolder)) {
@@ -548,6 +573,8 @@ export default class wahelperDaemon {
548
573
  this.connected = true;
549
574
  this.connecting = false;
550
575
  this.qr = null;
576
+ this.pairingCode = null;
577
+ this.pairingCodeRequested = false;
551
578
  this.reconnectDelay = 1000;
552
579
  this.log('✅ Connected');
553
580
  console.log('✅ Connected (device: ' + this.device + ')');
@@ -591,7 +618,8 @@ export default class wahelperDaemon {
591
618
  success: true,
592
619
  connected: this.connected,
593
620
  device: this.device,
594
- qr: this.qr
621
+ qr: this.qr,
622
+ pairingCode: this.pairingCode
595
623
  });
596
624
  return;
597
625
  }
package/wahelper.js CHANGED
@@ -86,6 +86,10 @@ export default class wahelper {
86
86
  '⛔ Daemon not running. Start it with: npx wahelper-daemon --device ' + this.args.device
87
87
  );
88
88
  }
89
+ if (daemonStatus.message === 'pairing_required') {
90
+ console.log('\n⚠️ Pairing required. Enter this code in WhatsApp (Linked Devices), then retry.\n');
91
+ console.log('Pairing code: ' + daemonStatus.pairingCode);
92
+ }
89
93
  if (daemonStatus.message === 'qr_required') {
90
94
  console.log('\n⚠️ Pairing required. Scan the QR code with WhatsApp, then retry.\n');
91
95
  console.log(daemonStatus.qrString);
@@ -94,7 +98,7 @@ export default class wahelper {
94
98
  {
95
99
  success: false,
96
100
  message: daemonStatus.message,
97
- data: daemonStatus.qrString || null
101
+ data: daemonStatus.pairingCode || daemonStatus.qrString || null
98
102
  },
99
103
  true
100
104
  );
@@ -200,7 +204,7 @@ export default class wahelper {
200
204
  return status;
201
205
  }
202
206
 
203
- // poll up to 30s — return immediately when QR appears
207
+ // poll up to 30s — return immediately when pairing code appears
204
208
  console.log('Waiting for daemon to connect...');
205
209
  for (let i = 0; i < 30; i++) {
206
210
  await new Promise(resolve => setTimeout(resolve, 1000));
@@ -208,8 +212,11 @@ export default class wahelper {
208
212
  if (status.connected) {
209
213
  return status;
210
214
  }
215
+ if (status.pairingCode) {
216
+ return { connected: false, message: 'pairing_required', pairingCode: status.pairingCode };
217
+ }
211
218
  if (status.qr) {
212
- // render QR to ASCII string, return it in data field for PHP/MCP display
219
+ // render QR to ASCII string for display
213
220
  let qrString = await new Promise(resolve => {
214
221
  qrcodeTerminal.generate(status.qr, { small: true }, str => resolve('\n' + str));
215
222
  });