waengine 1.0.1 → 1.0.2

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.
Files changed (2) hide show
  1. package/package.json +3 -3
  2. package/src/client.js +34 -36
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "waengine",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "🚀 WAEngine - The most powerful WhatsApp Bot Library with Multi-Device Support & EasyBot API",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -47,9 +47,9 @@
47
47
  },
48
48
  "dependencies": {
49
49
  "@whiskeysockets/baileys": "^7.0.0-rc.9",
50
+ "pino": "^8.0.0",
50
51
  "playwright": "^1.58.1",
51
- "qrcode-terminal": "^0.12.0",
52
- "pino": "^8.0.0"
52
+ "qrcode-terminal": "^0.12.0"
53
53
  },
54
54
  "devDependencies": {
55
55
  "@types/node": "^20.0.0"
package/src/client.js CHANGED
@@ -1,4 +1,4 @@
1
- import makeWASocket, { useMultiFileAuthState, DisconnectReason } from "@whiskeysockets/baileys";
1
+ import { makeWASocket, useMultiFileAuthState, DisconnectReason, fetchLatestBaileysVersion } from "@whiskeysockets/baileys";
2
2
  import pino from "pino";
3
3
  import { generateQRCode, closeBrowser } from "./qr.js";
4
4
  import { Message } from "./message.js";
@@ -8,11 +8,13 @@ export class WhatsAppClient {
8
8
  this.options = {
9
9
  authDir: "./auth",
10
10
  printQR: false,
11
- browser: options.browser || ["MyLibrary", "1.0.0", ""],
11
+ browser: options.browser || ["Chrome", "121.0.0", ""], // Aktueller Chrome
12
12
  logLevel: options.logLevel || "silent", // Sauber ohne Debug
13
13
  ...options
14
14
  };
15
15
 
16
+ // Clean initialization
17
+
16
18
  this.socket = null;
17
19
  this.isConnected = false;
18
20
  this.eventHandlers = new Map();
@@ -32,66 +34,67 @@ export class WhatsAppClient {
32
34
  // ===== CONNECTION METHODS =====
33
35
 
34
36
  async connect() {
35
- console.log("🔄 Starte Verbindung...");
36
-
37
37
  if (this.socket && this.isConnected) {
38
- console.log("✅ Bereits verbunden");
39
38
  return this.socket;
40
39
  }
41
40
 
42
41
  const { state, saveCreds } = await useMultiFileAuthState(this.options.authDir);
43
- console.log("📁 Auth-Daten geladen");
44
-
45
- // Prüfen ob bereits eingeloggt
46
42
  const isLoggedIn = !!state.creds?.me?.id;
47
- console.log(`🔐 Login-Status: ${isLoggedIn ? 'Eingeloggt' : 'Nicht eingeloggt'}`);
48
43
 
49
- this.socket = makeWASocket({
50
- auth: state,
51
- printQRInTerminal: this.options.printQR,
52
- logger: pino({ level: this.options.logLevel }),
53
- browser: this.options.browser
54
- });
44
+ // Fetch latest Baileys version for compatibility
45
+ try {
46
+ const { version, isLatest } = await fetchLatestBaileysVersion();
47
+
48
+ this.socket = makeWASocket({
49
+ version,
50
+ auth: state,
51
+ printQRInTerminal: this.options.printQR,
52
+ logger: pino({ level: this.options.logLevel }),
53
+ browser: this.options.browser,
54
+ generateHighQualityLinkPreview: true,
55
+ syncFullHistory: false,
56
+ markOnlineOnConnect: true
57
+ });
58
+ } catch (versionError) {
59
+ this.socket = makeWASocket({
60
+ auth: state,
61
+ printQRInTerminal: this.options.printQR,
62
+ logger: pino({ level: this.options.logLevel }),
63
+ browser: this.options.browser,
64
+ generateHighQualityLinkPreview: true,
65
+ syncFullHistory: false,
66
+ markOnlineOnConnect: true
67
+ });
68
+ }
55
69
 
56
70
  console.log("🔌 Socket erstellt");
57
71
 
58
72
  // QR-Code Browser nur öffnen wenn nicht eingeloggt
59
73
  if (!this.options.printQR && !isLoggedIn) {
60
- console.log("🌐 Öffne Browser für QR-Code...");
61
74
  await generateQRCode();
62
- } else if (isLoggedIn) {
63
- console.log("✅ Bereits authentifiziert, verbinde direkt...");
64
75
  }
65
76
 
66
77
  return new Promise((resolve, reject) => {
67
78
  this.socket.ev.on("connection.update", async ({ connection, lastDisconnect, qr }) => {
68
- console.log(`🔄 Connection Status: ${connection}`);
69
-
70
79
  if (qr && !this.options.printQR && !isLoggedIn) {
71
- console.log("📱 QR Code empfangen, zeige im Browser...");
72
80
  await generateQRCode(qr);
73
81
  }
74
82
 
75
- if (connection === "connecting") {
76
- console.log("🔄 Verbinde mit WhatsApp...");
77
- }
78
-
79
83
  if (connection === "close") {
80
- console.log("🔴 Verbindung geschlossen");
81
- const shouldReconnect = lastDisconnect?.error?.output?.statusCode !== DisconnectReason.loggedOut;
84
+ const statusCode = lastDisconnect?.error?.output?.statusCode;
85
+ const shouldReconnect = statusCode !== DisconnectReason.loggedOut;
82
86
 
83
87
  if (shouldReconnect) {
84
- console.log("🔄 Wiederverbindung...");
85
88
  this.isConnected = false;
86
89
  this.socket = null;
87
90
  setTimeout(() => this.connect().then(resolve).catch(reject), 3000);
88
91
  } else {
89
- console.log("👋 Ausgeloggt - QR-Code wird beim nächsten Start benötigt");
90
92
  await closeBrowser();
91
93
  this.emit('disconnected', { reason: 'logged_out' });
94
+ reject(new Error('Logged out'));
92
95
  }
93
96
  } else if (connection === "open") {
94
- console.log("✅ WhatsApp erfolgreich verbunden!");
97
+ console.log("✅ WhatsApp verbunden!");
95
98
  this.isConnected = true;
96
99
  this.setupEventHandlers();
97
100
  this.emit('connected');
@@ -154,7 +157,7 @@ export class WhatsAppClient {
154
157
  }
155
158
 
156
159
  setupEventHandlers() {
157
- // Messages - Sauber ohne Debug-Spam
160
+ // Messages
158
161
  this.socket.ev.on("messages.upsert", ({ messages, type }) => {
159
162
  if (type !== "notify") return;
160
163
 
@@ -250,7 +253,6 @@ export class WhatsAppClient {
250
253
 
251
254
  setPrefix(prefix) {
252
255
  this.prefix = prefix;
253
- console.log(`🎯 Prefix gesetzt auf: "${prefix}"`);
254
256
  return this;
255
257
  }
256
258
 
@@ -260,15 +262,11 @@ export class WhatsAppClient {
260
262
 
261
263
  addCommand(command, handler) {
262
264
  this.commands.set(command.toLowerCase(), handler);
263
- console.log(`⚡ Command registriert: ${this.prefix || ''}${command}`);
264
265
  return this;
265
266
  }
266
267
 
267
268
  removeCommand(command) {
268
269
  const removed = this.commands.delete(command.toLowerCase());
269
- if (removed) {
270
- console.log(`🗑️ Command entfernt: ${command}`);
271
- }
272
270
  return this;
273
271
  }
274
272