waengine 2.3.5 → 2.3.8-rc.1

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "waengine",
3
- "version": "2.3.5",
3
+ "version": "2.3.8-rc.1",
4
4
  "description": "🚀 WAEngine - The most powerful WhatsApp Bot Library with 860+ Working Features, Complete Baileys Integration & Production-Ready Stability",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
package/src/client.js CHANGED
@@ -138,12 +138,19 @@ export class WhatsAppClient {
138
138
  this.ui = new UIComponents(this);
139
139
 
140
140
  // Offline Message Ignore System - NEU!
141
- this.ignoreOfflineMessages = false;
141
+ // Automatisch aktivieren wenn Environment-Variable gesetzt ist
142
+ this.ignoreOfflineMessages = process.env.WAENGINE_IGNORE_OFFLINE_MESSAGES === 'true' || false;
142
143
  this.lastOnlineTimestamp = Date.now();
143
144
  this.connectionStartTime = null;
144
145
  this.ignoredMessagesCount = 0; // Counter für ignorierte Messages
145
146
  this.offlineMessageTimer = null; // Timer für finale Zusammenfassung
146
147
 
148
+ // Log wenn automatisch aktiviert
149
+ if (this.ignoreOfflineMessages) {
150
+ console.log('\n📵 Offline Message Ignore: AUTOMATISCH AKTIVIERT');
151
+ console.log(' └─ Grund: Session über Session Menu gestartet\n');
152
+ }
153
+
147
154
  // ===== GLOBAL VISUAL TYPING/RECORDING SYSTEM - NEU! =====
148
155
  this.globalVisualTyping = false; // Global aktiviert/deaktiviert
149
156
  this.globalVisualRecord = false; // Global aktiviert/deaktiviert
@@ -372,8 +379,9 @@ export class WhatsAppClient {
372
379
  syncFullHistory: true, // Wichtig für Message-Empfang
373
380
  markOnlineOnConnect: true,
374
381
  getMessage: async (key) => {
375
- // Wichtig für Message-Handling
376
- return { conversation: "Message not found" };
382
+ // WICHTIG: undefined zurückgeben statt "Message not found"
383
+ // Sonst wird es als echte Nachricht behandelt und spammt!
384
+ return undefined;
377
385
  },
378
386
  shouldIgnoreJid: jid => isJidBroadcast(jid),
379
387
  // Bessere Message-Synchronisation
@@ -392,8 +400,9 @@ export class WhatsAppClient {
392
400
  syncFullHistory: true, // Wichtig für Message-Empfang
393
401
  markOnlineOnConnect: true,
394
402
  getMessage: async (key) => {
395
- // Wichtig für Message-Handling
396
- return { conversation: "Message not found" };
403
+ // WICHTIG: undefined zurückgeben statt "Message not found"
404
+ // Sonst wird es als echte Nachricht behandelt und spammt!
405
+ return undefined;
397
406
  },
398
407
  shouldIgnoreJid: jid => isJidBroadcast(jid),
399
408
  // Bessere Message-Synchronisation
@@ -561,7 +570,9 @@ export class WhatsAppClient {
561
570
  // Connection Start Time für Offline Message Ignore setzen
562
571
  this.connectionStartTime = Date.now();
563
572
  if (this.ignoreOfflineMessages) {
564
- this.logger.info(`Offline Messages werden ignoriert (seit ${new Date(this.connectionStartTime).toLocaleString()})`);
573
+ console.log(`\n📵 Offline Message Ignore: AKTIV`);
574
+ console.log(` ├─ Verbunden seit: ${new Date(this.connectionStartTime).toLocaleString()}`);
575
+ console.log(` └─ Alle Messages vor diesem Zeitpunkt werden ignoriert\n`);
565
576
  }
566
577
 
567
578
  await closeBrowser(); // QR Browser schließen
@@ -968,17 +979,31 @@ export class WhatsAppClient {
968
979
  // DEBUG: Zeige alle Message-Types
969
980
  console.log(`📥 Message Event - Type: ${type}, Count: ${messages.length}`);
970
981
 
971
- // WICHTIG: Alle Types akzeptieren außer explizit ausgeschlossene
972
- // Nur "prepend" (alte History) ignorieren wenn gewünscht
973
- // if (type === "prepend") return; // Optional: Alte Messages ignorieren
982
+ // WICHTIG: Alte History-Messages ignorieren (prepend)
983
+ if (type === "prepend") {
984
+ console.log(`⏭️ Ignoriere ${messages.length} History Messages (prepend)`);
985
+ return;
986
+ }
974
987
 
975
988
  messages.forEach((msg) => {
989
+ // KRITISCHE VALIDIERUNG: Prüfe ob Message-Key existiert
990
+ if (!msg.key || !msg.key.remoteJid || !msg.key.id) {
991
+ console.log(`⚠️ Ungültige Message ohne Key - ignoriert`);
992
+ return;
993
+ }
994
+
976
995
  // Bessere Message-Validierung
977
996
  if (!msg.message || msg.key.fromMe) return;
978
997
 
979
998
  // OFFLINE MESSAGE IGNORE - DEINE NEUE FUNKTION!
980
999
  if (this.ignoreOfflineMessages && this.connectionStartTime) {
981
- const messageTimestamp = msg.messageTimestamp * 1000; // Convert to milliseconds
1000
+ // messageTimestamp kann in Sekunden oder Millisekunden sein
1001
+ let messageTimestamp = msg.messageTimestamp;
1002
+
1003
+ // Wenn Timestamp in Sekunden (< Jahr 2000 in Millisekunden), konvertiere zu Millisekunden
1004
+ if (messageTimestamp < 946684800000) {
1005
+ messageTimestamp = messageTimestamp * 1000;
1006
+ }
982
1007
 
983
1008
  // Ignoriere Messages die vor der Verbindung gesendet wurden
984
1009
  if (messageTimestamp < this.connectionStartTime) {
@@ -997,7 +1022,7 @@ export class WhatsAppClient {
997
1022
  }
998
1023
  }, 3000);
999
1024
 
1000
- return;
1025
+ return; // WICHTIG: Beende hier - verarbeite Message NICHT weiter!
1001
1026
  }
1002
1027
  }
1003
1028
 
package/src/message.js CHANGED
@@ -727,6 +727,100 @@ export class Message {
727
727
  }
728
728
  }
729
729
 
730
+ // ===== MESSAGE DEL - Lösche beliebige Message (Admin erforderlich in Gruppen) =====
731
+ async MessageDel(messageId, participantJid = null) {
732
+ try {
733
+ // Wenn keine Parameter, lösche die aktuelle Message
734
+ if (!messageId) {
735
+ return await this.deleteMessage();
736
+ }
737
+
738
+ // Prüfe in Gruppen ob Bot Admin ist
739
+ if (this.isGroup) {
740
+ const isBotAdmin = await this.isGroupAdmin(this.client.socket.user.id);
741
+ if (!isBotAdmin) {
742
+ console.log('⚠️ Bot ist kein Admin - kann nur eigene Messages löschen');
743
+ return {
744
+ success: false,
745
+ reason: 'not_admin',
746
+ error: 'Bot muss Admin sein um Messages von anderen zu löschen'
747
+ };
748
+ }
749
+ }
750
+
751
+ // Bot JID ermitteln
752
+ const botJid = this.client.socket.user?.id;
753
+ const botNumber = botJid?.split('@')[0]?.split(':')[0];
754
+
755
+ // Prüfe ob Message vom Bot ist
756
+ let isFromBot = false;
757
+ if (participantJid) {
758
+ const participantNumber = participantJid?.split('@')[0]?.split(':')[0];
759
+ isFromBot = botNumber === participantNumber;
760
+ }
761
+
762
+ // Erstelle Message Key
763
+ const messageKey = {
764
+ remoteJid: this.from,
765
+ id: messageId,
766
+ fromMe: isFromBot
767
+ };
768
+
769
+ // In Gruppen: participant hinzufügen wenn nicht vom Bot
770
+ if (this.isGroup && participantJid && !isFromBot) {
771
+ messageKey.participant = participantJid;
772
+ }
773
+
774
+ console.log('🗑️ MessageDel - Lösche Message:', {
775
+ messageId: messageId,
776
+ participant: participantJid,
777
+ isFromBot: isFromBot,
778
+ isGroup: this.isGroup,
779
+ key: messageKey
780
+ });
781
+
782
+ // Sende Delete Request
783
+ const result = await this.client.socket.sendMessage(this.from, {
784
+ delete: messageKey
785
+ });
786
+
787
+ console.log('✅ MessageDel erfolgreich:', result);
788
+ return {
789
+ success: true,
790
+ messageId: messageId,
791
+ participant: participantJid,
792
+ wasFromBot: isFromBot,
793
+ result: result
794
+ };
795
+
796
+ } catch (error) {
797
+ console.error('❌ MessageDel Fehler:', error.message);
798
+
799
+ // Spezifische Fehlerbehandlung
800
+ if (error.message?.includes('not-found') || error.message?.includes('404')) {
801
+ return {
802
+ success: false,
803
+ reason: 'message_not_found',
804
+ error: 'Message nicht gefunden oder zu alt'
805
+ };
806
+ }
807
+
808
+ if (error.message?.includes('forbidden') || error.message?.includes('403')) {
809
+ return {
810
+ success: false,
811
+ reason: 'no_permission',
812
+ error: 'Keine Berechtigung - Bot muss Admin sein'
813
+ };
814
+ }
815
+
816
+ return {
817
+ success: false,
818
+ reason: 'unknown_error',
819
+ error: error.message
820
+ };
821
+ }
822
+ }
823
+
730
824
  // ===== MEDIA DOWNLOAD - NEU in v1.7.9! =====
731
825
 
732
826
  async downloadMedia(options = {}) {
@@ -163,7 +163,8 @@ const botProcess = spawn('node', ['${this.userStartCommand}'], {
163
163
  ...process.env,
164
164
  WAENGINE_AUTH_DIR: '${session.authDir.replace(/\\/g, '/')}',
165
165
  WAENGINE_SESSION_NAME: '${sessionName}',
166
- __WAENGINE_SKIP_SESSION_MENU__: 'true'
166
+ __WAENGINE_SKIP_SESSION_MENU__: 'true',
167
+ WAENGINE_IGNORE_OFFLINE_MESSAGES: 'true' // Ignoriere Offline-Nachrichten automatisch
167
168
  },
168
169
  stdio: 'inherit'
169
170
  });