beecork 1.4.4 → 1.4.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/dist/channels/whatsapp.js +2 -0
- package/dist/index.js +28 -6
- package/package.json +1 -1
|
@@ -37,9 +37,11 @@ export class WhatsAppChannel {
|
|
|
37
37
|
fs.mkdirSync(sessionPath, { recursive: true, mode: 0o700 });
|
|
38
38
|
const { state, saveCreds } = await useMultiFileAuthState(sessionPath);
|
|
39
39
|
const { version } = await fetchLatestBaileysVersion().catch(() => ({ version: undefined }));
|
|
40
|
+
const pino = (await import('pino')).default;
|
|
40
41
|
this.sock = makeWASocket({
|
|
41
42
|
auth: state,
|
|
42
43
|
version,
|
|
44
|
+
logger: pino({ level: 'silent' }),
|
|
43
45
|
});
|
|
44
46
|
const sock = this.sock;
|
|
45
47
|
sock.ev.on('creds.update', saveCreds);
|
package/dist/index.js
CHANGED
|
@@ -195,32 +195,56 @@ program
|
|
|
195
195
|
// Pair immediately — show QR code in this terminal
|
|
196
196
|
try {
|
|
197
197
|
const { default: makeWASocket, useMultiFileAuthState, DisconnectReason, fetchLatestBaileysVersion } = await import('@whiskeysockets/baileys');
|
|
198
|
+
const pino = (await import('pino')).default;
|
|
199
|
+
const silentLogger = pino({ level: 'silent' });
|
|
198
200
|
fs.mkdirSync(sessionPath, { recursive: true, mode: 0o700 });
|
|
199
201
|
let attempts = 0;
|
|
200
202
|
const maxAttempts = 5;
|
|
203
|
+
let paired = false;
|
|
201
204
|
const connect = async () => {
|
|
202
205
|
attempts++;
|
|
203
206
|
const { state, saveCreds } = await useMultiFileAuthState(sessionPath);
|
|
204
207
|
const { version } = await fetchLatestBaileysVersion().catch(() => ({ version: undefined }));
|
|
205
|
-
const sock = makeWASocket({ auth: state, version });
|
|
208
|
+
const sock = makeWASocket({ auth: state, version, logger: silentLogger });
|
|
206
209
|
sock.ev.on('creds.update', saveCreds);
|
|
207
210
|
sock.ev.on('connection.update', async (update) => {
|
|
208
211
|
if (update.qr) {
|
|
209
212
|
try {
|
|
210
213
|
const qrcodeTerminal = await import('qrcode-terminal');
|
|
211
214
|
(qrcodeTerminal.default || qrcodeTerminal).generate(update.qr, { small: true });
|
|
215
|
+
console.log('Scan the QR code above with your phone (WhatsApp → Linked Devices → Link a Device)\n');
|
|
212
216
|
}
|
|
213
217
|
catch {
|
|
214
218
|
console.log('QR data:', update.qr);
|
|
215
219
|
}
|
|
216
220
|
}
|
|
217
221
|
if (update.connection === 'open') {
|
|
218
|
-
|
|
219
|
-
console.log('
|
|
222
|
+
paired = true;
|
|
223
|
+
console.log('✓ WhatsApp paired successfully!');
|
|
220
224
|
sock.end(undefined);
|
|
225
|
+
// Auto-restart daemon
|
|
226
|
+
const { getDaemonPid } = await import('./cli/helpers.js');
|
|
227
|
+
const pid = getDaemonPid();
|
|
228
|
+
if (pid) {
|
|
229
|
+
console.log(' Restarting daemon with WhatsApp enabled...');
|
|
230
|
+
const { execSync } = await import('node:child_process');
|
|
231
|
+
try {
|
|
232
|
+
execSync('beecork stop', { stdio: 'ignore' });
|
|
233
|
+
execSync('beecork start', { stdio: 'ignore' });
|
|
234
|
+
console.log(' ✓ Daemon restarted.\n');
|
|
235
|
+
}
|
|
236
|
+
catch {
|
|
237
|
+
console.log(' Could not restart daemon. Run: beecork stop && beecork start\n');
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
else {
|
|
241
|
+
console.log(' Start the daemon: beecork start\n');
|
|
242
|
+
}
|
|
221
243
|
process.exit(0);
|
|
222
244
|
}
|
|
223
245
|
if (update.connection === 'close') {
|
|
246
|
+
if (paired)
|
|
247
|
+
return; // Expected disconnect after pairing
|
|
224
248
|
const reason = update.lastDisconnect?.error?.output?.statusCode;
|
|
225
249
|
if (reason === DisconnectReason.loggedOut) {
|
|
226
250
|
console.log('\n✗ WhatsApp logged out. Please try again.\n');
|
|
@@ -230,14 +254,12 @@ program
|
|
|
230
254
|
console.log(`\n✗ Could not connect after ${maxAttempts} attempts. Please try again later.\n`);
|
|
231
255
|
process.exit(1);
|
|
232
256
|
}
|
|
233
|
-
console.log(`Connection dropped, retrying (${attempts}/${maxAttempts})...`);
|
|
234
257
|
setTimeout(connect, 3000);
|
|
235
258
|
}
|
|
236
259
|
});
|
|
237
260
|
};
|
|
238
261
|
await connect();
|
|
239
|
-
console.log('
|
|
240
|
-
console.log('Waiting for pairing... (Ctrl+C to cancel)\n');
|
|
262
|
+
console.log('Waiting for QR code... (Ctrl+C to cancel)\n');
|
|
241
263
|
}
|
|
242
264
|
catch (err) {
|
|
243
265
|
console.error('Failed to connect to WhatsApp:', err instanceof Error ? err.message : err);
|