@roidev/kachina-md 2.0.3 → 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.
- package/lib/client/Client.js +43 -13
- package/package.json +1 -1
package/lib/client/Client.js
CHANGED
|
@@ -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
|
|
|
@@ -52,7 +48,6 @@ export class Client extends EventEmitter {
|
|
|
52
48
|
keys: makeCacheableSignalKeyStore(state.keys, this.config.logger)
|
|
53
49
|
},
|
|
54
50
|
logger: this.config.logger,
|
|
55
|
-
printQRInTerminal: this.config.printQRInTerminal && this.config.loginMethod === 'qr',
|
|
56
51
|
browser: this.config.browser,
|
|
57
52
|
getMessage: async (key) => {
|
|
58
53
|
if (this.store) {
|
|
@@ -69,6 +64,43 @@ export class Client extends EventEmitter {
|
|
|
69
64
|
|
|
70
65
|
this.sock.ev.on('creds.update', saveCreds);
|
|
71
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
|
+
|
|
72
104
|
this.sock.ev.on('connection.update', async (update) => {
|
|
73
105
|
await this.handleConnectionUpdate(update);
|
|
74
106
|
});
|
|
@@ -125,17 +157,15 @@ export class Client extends EventEmitter {
|
|
|
125
157
|
this.user = this.sock.user;
|
|
126
158
|
this.emit('ready', this.user);
|
|
127
159
|
|
|
128
|
-
//
|
|
129
|
-
if (
|
|
130
|
-
|
|
131
|
-
setTimeout(async () => {
|
|
132
|
-
const code = await this.sock.requestPairingCode(this.config.phoneNumber);
|
|
133
|
-
this.emit('pairing.code', code);
|
|
134
|
-
}, 3000);
|
|
135
|
-
}
|
|
160
|
+
// Log success message
|
|
161
|
+
if (this.config.loginMethod === 'pairing') {
|
|
162
|
+
console.log('\n✓ Successfully connected via pairing code!\n');
|
|
136
163
|
}
|
|
137
164
|
} else if (connection === 'connecting') {
|
|
138
165
|
this.emit('connecting');
|
|
166
|
+
if (this.config.loginMethod === 'pairing') {
|
|
167
|
+
console.log('Waiting for pairing code confirmation...');
|
|
168
|
+
}
|
|
139
169
|
}
|
|
140
170
|
}
|
|
141
171
|
|