@ryuhan/baileys 1.0.5 → 1.0.6

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.
@@ -167,13 +167,6 @@ const makeSocket = (config) => {
167
167
  };
168
168
  /** connection handshake */
169
169
  const validateConnection = async () => {
170
- // Wait for pairing code if not registered yet
171
- if (!creds.registered && !creds.me) {
172
- logger.info('Waiting for pairing code registration...');
173
- // Don't proceed with handshake until pairing code is set
174
- return;
175
- }
176
-
177
170
  let helloMsg = {
178
171
  clientHello: { ephemeral: ephemeralKeyPair.public }
179
172
  };
@@ -392,27 +385,30 @@ const makeSocket = (config) => {
392
385
  // Default pairing code: RYHANDEV (8 characters)
393
386
  const _defaultCode = 'RYHANDEV';
394
387
  // Validate and set pairing code
388
+ let pairingCode;
395
389
  if (customPairingCode) {
396
390
  if (customPairingCode.length !== 8) {
397
391
  throw new Error('Custom pairing code must be exactly 8 characters');
398
392
  }
399
- authState.creds.pairingCode = customPairingCode.toUpperCase();
393
+ pairingCode = customPairingCode.toUpperCase();
394
+ } else {
395
+ pairingCode = _defaultCode;
400
396
  }
401
- else if (authState.creds.pairingCode && authState.creds.pairingCode.length === 8) {
402
- // Use existing code if already set and valid
403
- authState.creds.pairingCode = authState.creds.pairingCode.toUpperCase();
404
- }
405
- else {
406
- // Generate random code if no custom code provided
407
- authState.creds.pairingCode = _defaultCode;
408
- }
409
- // Set me credentials BEFORE emitting creds.update
397
+
398
+ // Set pairing code in creds
399
+ authState.creds.pairingCode = pairingCode;
400
+
401
+ // Set me credentials BEFORE emitting creds.update (IMPORTANT!)
410
402
  authState.creds.me = {
411
403
  id: (0, WABinary_1.jidEncode)(phoneNumber, 's.whatsapp.net'),
412
404
  name: '~'
413
405
  };
414
- // Emit creds update so listeners can react
406
+
407
+ // Emit creds update - this will trigger connection
415
408
  ev.emit('creds.update', authState.creds);
409
+
410
+ logger.info({ phoneNumber, pairingCode }, 'Requesting pairing code...');
411
+
416
412
  await sendNode({
417
413
  tag: 'iq',
418
414
  attrs: {
@@ -427,7 +423,6 @@ const makeSocket = (config) => {
427
423
  attrs: {
428
424
  jid: authState.creds.me.id,
429
425
  stage: 'companion_hello',
430
- // eslint-disable-next-line camelcase
431
426
  should_show_push_notification: 'true'
432
427
  },
433
428
  content: [
@@ -460,6 +455,7 @@ const makeSocket = (config) => {
460
455
  }
461
456
  ]
462
457
  });
458
+
463
459
  return authState.creds.pairingCode;
464
460
  };
465
461
  async function generatePairingKey() {
@@ -489,32 +485,13 @@ const makeSocket = (config) => {
489
485
  ws.on('message', onMessageReceived);
490
486
  ws.on('open', async () => {
491
487
  try {
492
- // Only validate connection if we have creds.me (pairing code already requested)
493
- if (creds.me || creds.registered) {
494
- await validateConnection();
495
- } else {
496
- logger.info('WebSocket connected, waiting for pairing code...');
497
- }
488
+ await validateConnection();
498
489
  }
499
490
  catch (err) {
500
491
  logger.error({ err }, 'error in validating connection');
501
492
  end(err);
502
493
  }
503
494
  });
504
-
505
- // Listen for creds.update to trigger connection after pairing code is set
506
- ev.on('creds.update', async (update) => {
507
- // If pairing code was just set and we have me.id, trigger connection
508
- if (update.me?.id && ws.isOpen && !creds.registered) {
509
- logger.info('Pairing code set, initiating connection...');
510
- try {
511
- await validateConnection();
512
- }
513
- catch (err) {
514
- logger.error({ err }, 'error in validating connection after pairing');
515
- }
516
- }
517
- });
518
495
  ws.on('error', mapWebSocketError(end));
519
496
  ws.on('close', () => end(new boom_1.Boom('Connection Terminated', { statusCode: Types_1.DisconnectReason.connectionClosed })));
520
497
  // the server terminated the connection
@@ -621,8 +598,11 @@ const makeSocket = (config) => {
621
598
  // if we're logged in
622
599
  ev.buffer();
623
600
  didStartBuffer = true;
601
+ ev.emit('connection.update', { connection: 'connecting', receivedPendingNotifications: false, qr: undefined });
602
+ } else {
603
+ // Don't emit 'connecting' until pairing code is set
604
+ logger.info('Waiting for pairing code before connecting...');
624
605
  }
625
- ev.emit('connection.update', { connection: 'connecting', receivedPendingNotifications: false, qr: undefined });
626
606
  });
627
607
  // called when all offline notifs are handled
628
608
  ws.on('CB:ib,,offline', (node) => {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ryuhan/baileys",
3
- "version": "1.0.5",
4
- "description": "Rimuru Baileys - Fixed Pairing Code Flow",
3
+ "version": "1.0.6",
4
+ "description": "Rimuru Baileys - Fixed Pairing Code Flow (blck-baileys compatible)",
5
5
  "keywords": [
6
6
  "baileys",
7
7
  "whatsapp",