@roidev/kachina-md 2.1.2 → 2.1.3

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.
@@ -3,7 +3,8 @@ import makeWASocket, {
3
3
  useMultiFileAuthState,
4
4
  makeCacheableSignalKeyStore,
5
5
  fetchLatestBaileysVersion,
6
- downloadMediaMessage
6
+ downloadMediaMessage,
7
+ Browsers
7
8
  } from 'baileys';
8
9
  import { Boom } from '@hapi/boom';
9
10
  import pino from 'pino';
@@ -109,7 +110,7 @@ export class Client extends EventEmitter {
109
110
  keys: makeCacheableSignalKeyStore(state.keys, this.config.logger)
110
111
  },
111
112
  logger: this.config.logger,
112
- browser: this.config.browser,
113
+ browser: Browsers.macOS('safari'),
113
114
  getMessage: async (key) => {
114
115
  if (this.store) {
115
116
  const msg = await this.store.loadMessage(key.remoteJid, key.id);
@@ -125,67 +126,56 @@ export class Client extends EventEmitter {
125
126
 
126
127
  this.sock.ev.on('creds.update', saveCreds);
127
128
 
128
- // Handle pairing code request (must be before connection)
129
+ // Handle pairing code request (before connection.update listener)
129
130
  if (this.config.loginMethod === 'pairing' && !state.creds.registered) {
130
131
  if (!this.config.phoneNumber) {
131
132
  throw new Error('Phone number is required for pairing method. Example: { phoneNumber: "628123456789" }');
132
133
  }
133
134
 
134
135
  const phoneNumber = this.config.phoneNumber.replace(/[^0-9]/g, '');
135
-
136
136
  if (phoneNumber.length < 10) {
137
137
  throw new Error('Invalid phone number format. Use country code without +. Example: 628123456789');
138
138
  }
139
139
 
140
140
  console.log('šŸ” Initiating pairing code process...');
141
141
 
142
- // Request pairing code with retry mechanism
143
- const requestPairingWithRetry = async () => {
144
- const maxRetries = 3;
145
- const delay = (ms) => new Promise(resolve => setTimeout(resolve, ms));
146
-
147
- for (let attempt = 0; attempt < maxRetries; attempt++) {
148
- try {
149
- // Wait for socket to be ready
150
- await delay(attempt === 0 ? 5000 : 2000);
151
-
152
- const code = await this.sock.requestPairingCode(phoneNumber);
153
- this.emit('pairing.code', code);
154
-
155
- // Log to console with formatting
156
- console.log('\nā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”');
157
- console.log('│ WhatsApp Pairing Code │');
158
- console.log('ā”œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¤');
159
- console.log(`│ Code: ${chalk.bgYellowBright.white(code)} │`);
160
- console.log('ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜');
161
- console.log('\nSteps to pair:');
162
- console.log('1. Open WhatsApp on your phone');
163
- console.log('2. Go to Settings > Linked Devices');
164
- console.log('3. Tap "Link a Device"');
165
- console.log('4. Enter the code above\n');
166
- console.log('āš ļø Make sure the phone number matches your WhatsApp account');
167
-
168
- return;
169
- } catch (error) {
170
- const isLastAttempt = attempt === maxRetries - 1;
171
- console.error(`Pairing attempt ${attempt + 1}/${maxRetries} failed:`, error.message);
172
-
173
- this.emit('pairing.error', error);
174
-
175
- if (isLastAttempt) {
176
- console.error('āŒ Max pairing retries reached. Please try again later.');
177
- throw error; // Re-throw on last attempt
178
- } else {
179
- console.log(`ā³ Retrying in 2 seconds...`);
180
- }
142
+ const delay = (ms) => new Promise(resolve => setTimeout(resolve, ms));
143
+ let retryCount = 0;
144
+ const maxRetries = 3;
145
+ let pairingSuccess = false;
146
+
147
+ while (retryCount < maxRetries && !pairingSuccess) {
148
+ try {
149
+ await delay(3000);
150
+ const code = await this.sock.requestPairingCode(phoneNumber);
151
+ this.emit('pairing.code', code);
152
+
153
+ console.log('\nā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”');
154
+ console.log('│ WhatsApp Pairing Code │');
155
+ console.log('ā”œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¤');
156
+ console.log(`│ Code: ${chalk.bgYellowBright.white(code)} │`);
157
+ console.log('ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜');
158
+ console.log('\nSteps to pair:');
159
+ console.log('1. Open WhatsApp on your phone');
160
+ console.log('2. Go to Settings > Linked Devices');
161
+ console.log('3. Tap "Link a Device"');
162
+ console.log('4. Enter the code above\n');
163
+
164
+ pairingSuccess = true;
165
+ break;
166
+ } catch (err) {
167
+ retryCount++;
168
+ console.error(`Pairing attempt ${retryCount}/${maxRetries} failed:`, err.message);
169
+ this.emit('pairing.error', err);
170
+
171
+ if (retryCount >= maxRetries) {
172
+ console.error('āŒ Max pairing retries reached. Please try again later.');
173
+ throw err;
181
174
  }
182
- }
183
- };
184
175
 
185
- // Execute pairing request (non-blocking)
186
- requestPairingWithRetry().catch(err => {
187
- console.error('Failed to complete pairing process:', err.message);
188
- });
176
+ await delay(2000);
177
+ }
178
+ }
189
179
  }
190
180
 
191
181
  this.sock.ev.on('connection.update', async (update) => {
@@ -233,6 +223,7 @@ export class Client extends EventEmitter {
233
223
  async handleConnectionUpdate(update) {
234
224
  const { connection, lastDisconnect, qr } = update;
235
225
 
226
+ // Handle QR code for QR login method
236
227
  if (qr && this.config.loginMethod === 'qr') {
237
228
  qrcode.generate(qr, { small: true });
238
229
  }
@@ -253,15 +244,11 @@ export class Client extends EventEmitter {
253
244
  this.user = this.sock.user;
254
245
  this.emit('ready', this.user);
255
246
 
256
- // Log success message
257
247
  if (this.config.loginMethod === 'pairing') {
258
248
  console.log('\nāœ“ Successfully connected via pairing code!\n');
259
249
  }
260
250
  } else if (connection === 'connecting') {
261
251
  this.emit('connecting');
262
- if (this.config.loginMethod === 'pairing') {
263
- console.log('Waiting for pairing code confirmation...');
264
- }
265
252
  }
266
253
  }
267
254
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@roidev/kachina-md",
3
- "version": "2.1.2",
3
+ "version": "2.1.3",
4
4
  "description": "WhatsApp Bot Framework - Simple, Fast, and Modular",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",