waengine 1.0.4 → 1.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/package.json +1 -1
- package/src/client.js +27 -59
package/package.json
CHANGED
package/src/client.js
CHANGED
|
@@ -87,7 +87,7 @@ export class WhatsAppClient {
|
|
|
87
87
|
});
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
-
console.log("🔌
|
|
90
|
+
console.log("🔌 WAEngine startet...");
|
|
91
91
|
|
|
92
92
|
// QR-Code Browser nur öffnen wenn nicht eingeloggt
|
|
93
93
|
if (!this.options.printQR && !isLoggedIn) {
|
|
@@ -99,10 +99,7 @@ export class WhatsAppClient {
|
|
|
99
99
|
this.setupEventHandlers();
|
|
100
100
|
|
|
101
101
|
this.socket.ev.on("connection.update", async ({ connection, lastDisconnect, qr }) => {
|
|
102
|
-
console.log(`🔄 Connection Update: ${connection}`);
|
|
103
|
-
|
|
104
102
|
if (qr) {
|
|
105
|
-
console.log("📱 QR-Code empfangen");
|
|
106
103
|
if (this.options.printQR) {
|
|
107
104
|
// Terminal QR
|
|
108
105
|
console.log("\n📱 QR-CODE IM TERMINAL:");
|
|
@@ -113,21 +110,21 @@ export class WhatsAppClient {
|
|
|
113
110
|
console.log("📲 Scanne den QR-Code mit WhatsApp!");
|
|
114
111
|
} else {
|
|
115
112
|
// Browser QR
|
|
113
|
+
console.log("📱 QR-Code im Browser angezeigt");
|
|
116
114
|
await generateQRCode(qr);
|
|
117
115
|
}
|
|
118
116
|
}
|
|
119
117
|
|
|
120
118
|
if (connection === "connecting") {
|
|
121
|
-
console.log("🔄 Verbinde
|
|
119
|
+
console.log("🔄 Verbinde...");
|
|
122
120
|
}
|
|
123
121
|
|
|
124
122
|
if (connection === "close") {
|
|
125
|
-
console.log("🔴 Verbindung geschlossen");
|
|
126
123
|
const statusCode = lastDisconnect?.error?.output?.statusCode;
|
|
127
124
|
const shouldReconnect = statusCode !== DisconnectReason.loggedOut;
|
|
128
125
|
|
|
129
126
|
if (shouldReconnect) {
|
|
130
|
-
console.log("🔄 Wiederverbindung
|
|
127
|
+
console.log("🔄 Wiederverbindung...");
|
|
131
128
|
this.isConnected = false;
|
|
132
129
|
this.socket = null;
|
|
133
130
|
setTimeout(() => this.connect().then(resolve).catch(reject), 3000);
|
|
@@ -201,49 +198,37 @@ export class WhatsAppClient {
|
|
|
201
198
|
}
|
|
202
199
|
|
|
203
200
|
setupEventHandlers() {
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
// Messages - Verbesserte Message-Erkennung
|
|
201
|
+
// Messages - Saubere Message-Erkennung ohne Debug-Spam
|
|
207
202
|
this.socket.ev.on("messages.upsert", ({ messages, type }) => {
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
// Alle Message-Types verarbeiten, nicht nur "notify"
|
|
211
|
-
if (type !== "notify" && type !== "append") {
|
|
212
|
-
console.log(`⚠️ Ignoriere Message-Type: ${type}`);
|
|
213
|
-
return;
|
|
214
|
-
}
|
|
203
|
+
// Nur relevante Message-Types verarbeiten
|
|
204
|
+
if (type !== "notify" && type !== "append") return;
|
|
215
205
|
|
|
216
|
-
messages.forEach((msg
|
|
217
|
-
console.log(`🔍 Processing message ${index + 1}/${messages.length}`);
|
|
218
|
-
console.log(` - From: ${msg.key.remoteJid}`);
|
|
219
|
-
console.log(` - FromMe: ${msg.key.fromMe}`);
|
|
220
|
-
console.log(` - Message Keys: ${Object.keys(msg.message || {}).join(', ')}`);
|
|
221
|
-
|
|
206
|
+
messages.forEach((msg) => {
|
|
222
207
|
// Bessere Message-Validierung
|
|
223
|
-
if (!msg.message)
|
|
224
|
-
console.log(" ❌ Keine Message-Daten");
|
|
225
|
-
return;
|
|
226
|
-
}
|
|
208
|
+
if (!msg.message || msg.key.fromMe) return;
|
|
227
209
|
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
210
|
+
// Ignoriere System-Messages (protocolMessage, etc.)
|
|
211
|
+
if (msg.message.protocolMessage ||
|
|
212
|
+
msg.message.reactionMessage ||
|
|
213
|
+
msg.message.ephemeralMessage ||
|
|
214
|
+
msg.message.viewOnceMessage) {
|
|
215
|
+
return; // Ignoriere ohne Debug-Output
|
|
231
216
|
}
|
|
232
217
|
|
|
233
218
|
// Ignoriere Broadcast-Messages
|
|
234
|
-
if (msg.key.remoteJid && isJidBroadcast(msg.key.remoteJid))
|
|
235
|
-
console.log(" ❌ Broadcast-Message - ignoriert");
|
|
236
|
-
return;
|
|
237
|
-
}
|
|
219
|
+
if (msg.key.remoteJid && isJidBroadcast(msg.key.remoteJid)) return;
|
|
238
220
|
|
|
239
221
|
const messageData = this.parseMessage(msg);
|
|
240
|
-
console.log(` ✅ Text extrahiert: "${messageData.text}"`);
|
|
241
|
-
console.log(` ✅ Type: ${messageData.type}`);
|
|
242
222
|
|
|
243
|
-
// Nur verarbeiten wenn Text vorhanden oder
|
|
244
|
-
if (!messageData.text &&
|
|
245
|
-
|
|
246
|
-
return;
|
|
223
|
+
// Nur verarbeiten wenn Text vorhanden oder unterstützte Typen
|
|
224
|
+
if (!messageData.text &&
|
|
225
|
+
!['image', 'video', 'audio', 'document', 'sticker', 'location', 'contact'].includes(messageData.type)) {
|
|
226
|
+
return; // Ignoriere ohne Debug-Output
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// Nur bei echten Nachrichten loggen
|
|
230
|
+
if (messageData.text || messageData.type !== 'unknown') {
|
|
231
|
+
console.log(`📨 ${messageData.type}: "${messageData.text || '[Media]'}" von ${messageData.from}`);
|
|
247
232
|
}
|
|
248
233
|
|
|
249
234
|
const messageObj = new Message(this, messageData);
|
|
@@ -253,7 +238,7 @@ export class WhatsAppClient {
|
|
|
253
238
|
const commandText = messageData.text.slice(this.prefix.length).trim();
|
|
254
239
|
const [command, ...args] = commandText.split(' ');
|
|
255
240
|
|
|
256
|
-
console.log(
|
|
241
|
+
console.log(`⚡ Command: ${this.prefix}${command}`);
|
|
257
242
|
|
|
258
243
|
messageObj.isCommand = true;
|
|
259
244
|
messageObj.command = command.toLowerCase();
|
|
@@ -266,59 +251,42 @@ export class WhatsAppClient {
|
|
|
266
251
|
// Spezifischen Command Handler aufrufen falls vorhanden
|
|
267
252
|
if (this.commands.has(command.toLowerCase())) {
|
|
268
253
|
const handler = this.commands.get(command.toLowerCase());
|
|
269
|
-
console.log(` 🎯 Führe Command-Handler aus: ${command}`);
|
|
270
254
|
try {
|
|
271
255
|
handler(messageObj, args);
|
|
272
256
|
} catch (error) {
|
|
273
257
|
console.error(`❌ Fehler in Command '${command}':`, error);
|
|
274
258
|
}
|
|
275
|
-
} else {
|
|
276
|
-
console.log(` ❓ Kein Handler für Command: ${command}`);
|
|
277
259
|
}
|
|
278
260
|
} else {
|
|
279
261
|
messageObj.isCommand = false;
|
|
280
262
|
messageObj.command = null;
|
|
281
263
|
messageObj.args = [];
|
|
282
|
-
console.log(" 📝 Normale Nachricht");
|
|
283
264
|
}
|
|
284
265
|
|
|
285
|
-
console.log(" 📤 Emittiere Message-Event");
|
|
286
266
|
this.emit('message', messageObj);
|
|
287
|
-
console.log(" ✅ Message verarbeitet");
|
|
288
267
|
});
|
|
289
268
|
});
|
|
290
269
|
|
|
291
|
-
//
|
|
270
|
+
// Andere Events ohne Debug-Spam
|
|
292
271
|
this.socket.ev.on("messages.update", (updates) => {
|
|
293
|
-
console.log(`📝 Messages.update - Count: ${updates.length}`);
|
|
294
272
|
this.emit('messages.update', updates);
|
|
295
273
|
});
|
|
296
274
|
|
|
297
|
-
// Bessere Presence-Handling
|
|
298
275
|
this.socket.ev.on("presence.update", (update) => {
|
|
299
|
-
console.log(`👤 Presence.update - ID: ${update.id}`);
|
|
300
276
|
this.emit('presence.update', update);
|
|
301
277
|
});
|
|
302
278
|
|
|
303
|
-
// Group updates
|
|
304
279
|
this.socket.ev.on("group-participants.update", (update) => {
|
|
305
|
-
console.log(`👥 Group-participants.update - Group: ${update.id}`);
|
|
306
280
|
this.emit('group.participants.update', update);
|
|
307
281
|
});
|
|
308
282
|
|
|
309
|
-
// Chats updates für bessere Synchronisation
|
|
310
283
|
this.socket.ev.on("chats.upsert", (chats) => {
|
|
311
|
-
console.log(`💬 Chats.upsert - Count: ${chats.length}`);
|
|
312
284
|
this.emit('chats.upsert', chats);
|
|
313
285
|
});
|
|
314
286
|
|
|
315
|
-
// Contacts updates
|
|
316
287
|
this.socket.ev.on("contacts.upsert", (contacts) => {
|
|
317
|
-
console.log(`📞 Contacts.upsert - Count: ${contacts.length}`);
|
|
318
288
|
this.emit('contacts.upsert', contacts);
|
|
319
289
|
});
|
|
320
|
-
|
|
321
|
-
console.log("✅ Event-Handler registriert!");
|
|
322
290
|
}
|
|
323
291
|
|
|
324
292
|
parseMessage(msg) {
|