@roidev/kachina-md 2.0.4 → 2.0.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.
@@ -12,10 +12,6 @@ import { serialize } from '../helpers/serialize.js';
12
12
  import { PluginHandler } from '../handlers/PluginHandler.js';
13
13
  import {
14
14
  createSticker,
15
- createFullSticker,
16
- createCroppedSticker,
17
- createCircleSticker,
18
- createRoundedSticker,
19
15
  StickerTypes
20
16
  } from '../helpers/sticker.js';
21
17
 
@@ -68,6 +64,43 @@ export class Client extends EventEmitter {
68
64
 
69
65
  this.sock.ev.on('creds.update', saveCreds);
70
66
 
67
+ // Handle pairing code request (must be before connection)
68
+ if (this.config.loginMethod === 'pairing' && !state.creds.registered) {
69
+ if (!this.config.phoneNumber) {
70
+ throw new Error('Phone number is required for pairing method. Example: { phoneNumber: "628123456789" }');
71
+ }
72
+
73
+ // Format phone number (remove + and spaces)
74
+ const phoneNumber = this.config.phoneNumber.replace(/[^0-9]/g, '');
75
+
76
+ if (phoneNumber.length < 10) {
77
+ throw new Error('Invalid phone number format. Use country code without +. Example: 628123456789');
78
+ }
79
+
80
+ // Request pairing code after socket is initialized
81
+ setTimeout(async () => {
82
+ try {
83
+ const code = await this.sock.requestPairingCode(phoneNumber);
84
+ this.emit('pairing.code', code);
85
+
86
+ // Log to console with formatting
87
+ console.log('\n┌─────────────────────────────────────┐');
88
+ console.log('│ WhatsApp Pairing Code │');
89
+ console.log('├─────────────────────────────────────┤');
90
+ console.log(`│ Code: ${code} │`);
91
+ console.log('└─────────────────────────────────────┘');
92
+ console.log('\nSteps to pair:');
93
+ console.log('1. Open WhatsApp on your phone');
94
+ console.log('2. Go to Settings > Linked Devices');
95
+ console.log('3. Tap "Link a Device"');
96
+ console.log('4. Enter the code above\n');
97
+ } catch (error) {
98
+ this.emit('pairing.error', error);
99
+ console.error('Failed to request pairing code:', error.message);
100
+ }
101
+ }, 3000);
102
+ }
103
+
71
104
  this.sock.ev.on('connection.update', async (update) => {
72
105
  await this.handleConnectionUpdate(update);
73
106
  });
@@ -124,17 +157,15 @@ export class Client extends EventEmitter {
124
157
  this.user = this.sock.user;
125
158
  this.emit('ready', this.user);
126
159
 
127
- // Request pairing code if needed
128
- if (!this.sock.authState.creds.registered && this.config.loginMethod === 'pairing') {
129
- if (this.config.phoneNumber) {
130
- setTimeout(async () => {
131
- const code = await this.sock.requestPairingCode(this.config.phoneNumber);
132
- this.emit('pairing.code', code);
133
- }, 3000);
134
- }
160
+ // Log success message
161
+ if (this.config.loginMethod === 'pairing') {
162
+ console.log('\n✓ Successfully connected via pairing code!\n');
135
163
  }
136
164
  } else if (connection === 'connecting') {
137
165
  this.emit('connecting');
166
+ if (this.config.loginMethod === 'pairing') {
167
+ console.log('Waiting for pairing code confirmation...');
168
+ }
138
169
  }
139
170
  }
140
171
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@roidev/kachina-md",
3
- "version": "2.0.4",
3
+ "version": "2.0.5",
4
4
  "description": "WhatsApp Bot Framework - Simple, Fast, and Modular",
5
5
  "main": "lib/index.js",
6
6
  "type": "module",