waengine 1.8.0 → 1.8.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.
package/FEATURES.md CHANGED
@@ -61,6 +61,12 @@ const newsletter = await msg.createNewsletter('Name', 'Description');
61
61
  2. [⚡ EasyBot Features](#-easybot-features)
62
62
  3. [🔥 Multi-Device System](#-multi-device-system)
63
63
  4. [💬 Message System](#-message-system)
64
+ - [Basic Messaging](#basic-messaging)
65
+ - [Media Messages](#media-messages)
66
+ - [SendChat API - NEU!](#sendchat-api---nachrichten-an-andere-chats-senden--neu)
67
+ - [Special Messages](#special-messages)
68
+ - [Message Deletion](#message-deletion-neu-v178)
69
+ - [Message Properties](#message-properties)
64
70
  5. [🎭 Typing Indicator](#-typing-indicator)
65
71
  6. [👥 Group Management](#-group-management)
66
72
  7. [🛡️ Permission System](#️-permission-system)
@@ -291,6 +297,96 @@ await msg.sendSticker("path/sticker.webp")
291
297
  await msg.sendDocument("path/file.pdf", "filename.pdf", [mentions])
292
298
  ```
293
299
 
300
+ ### **SendChat API - Nachrichten an andere Chats senden! 📤 NEU!**
301
+ ```javascript
302
+ // Einfache Nachricht an anderen Chat
303
+ await msg.sendChat("49123456789@s.whatsapp.net", "Hallo!")
304
+
305
+ // Kurz-Format (automatische Formatierung)
306
+ await msg.sendChat("49123456789", "Hallo!")
307
+
308
+ // Nachricht an Gruppe
309
+ await msg.sendChat("120363421640574094@g.us", "Gruppen-Nachricht!")
310
+
311
+ // Mit Bild
312
+ await msg.sendChat("49123456789@s.whatsapp.net", "Schau dir das an!", {
313
+ image: "./path/to/image.jpg"
314
+ })
315
+
316
+ // Mit Video
317
+ await msg.sendChat("49123456789@s.whatsapp.net", "Cooles Video!", {
318
+ video: "./path/to/video.mp4"
319
+ })
320
+
321
+ // Mit Mentions
322
+ await msg.sendChat("120363421640574094@g.us", "Hey @user!", {
323
+ mentions: ["49123456789@s.whatsapp.net"]
324
+ })
325
+
326
+ // Broadcast an mehrere Chats
327
+ const jids = [
328
+ "49123456789@s.whatsapp.net",
329
+ "49987654321@s.whatsapp.net",
330
+ "120363421640574094@g.us"
331
+ ];
332
+ const results = await msg.sendToMultipleChats(jids, "📢 Broadcast!", {
333
+ delay: 2000 // 2 Sekunden zwischen Nachrichten
334
+ });
335
+
336
+ // Nachricht weiterleiten (mit Forward-Tag)
337
+ await msg.forwardToChat("49123456789@s.whatsapp.net");
338
+
339
+ // Nachricht kopieren (ohne Forward-Tag)
340
+ await msg.copyToChat("49123456789@s.whatsapp.net");
341
+ ```
342
+
343
+ **SendChat API Features:**
344
+ - ✅ **Sende an beliebige Chats** - Privat oder Gruppe
345
+ - ✅ **Automatische JID-Formatierung** - Nur Nummer angeben reicht
346
+ - ✅ **Broadcast-Funktion** - An mehrere Chats gleichzeitig
347
+ - ✅ **Media-Support** - Bilder, Videos, Audio, Dokumente
348
+ - ✅ **Mentions** - Erwähne User in anderen Chats
349
+ - ✅ **Forward & Copy** - Mit oder ohne Forward-Tag
350
+ - ✅ **Fehlerbehandlung** - Detaillierte Ergebnis-Reports
351
+
352
+ **Praktische Anwendungen:**
353
+ ```javascript
354
+ // Admin-Benachrichtigung
355
+ if (msg.text.includes('wichtig')) {
356
+ await msg.sendChat(adminJid, `⚠️ Wichtige Nachricht: ${msg.text}`);
357
+ }
358
+
359
+ // Support-System
360
+ client.addCommand('support', async (msg, args) => {
361
+ const message = args.join(' ');
362
+ await msg.sendChat(supportJid,
363
+ `💬 Support-Anfrage von ${msg.getSender()}: ${message}`
364
+ );
365
+ await msg.reply('✅ Support wurde kontaktiert!');
366
+ });
367
+
368
+ // Gruppen-Synchronisation
369
+ if (msg.from === sourceGroupJid) {
370
+ await msg.copyToChat(targetGroupJid);
371
+ }
372
+
373
+ // Broadcast-System
374
+ client.addCommand('broadcast', async (msg, args) => {
375
+ if (!await msg.isAdmin()) return;
376
+
377
+ const results = await msg.sendToMultipleChats(
378
+ subscriberJids,
379
+ args.join(' '),
380
+ { delay: 2000 }
381
+ );
382
+
383
+ const successful = results.filter(r => r.success).length;
384
+ await msg.reply(`✅ ${successful}/${results.length} gesendet!`);
385
+ });
386
+ ```
387
+
388
+ **Siehe auch:** `SENDCHAT-API.md` für vollständige Dokumentation
389
+
294
390
  ### **Special Messages**
295
391
  ```javascript
296
392
  // Location
package/README.md CHANGED
@@ -140,6 +140,25 @@ client.on('truly_connected', (data) => {
140
140
  - **Send Profile Pictures** - Send profile pics in chat
141
141
  - **Commands**: `!profilpic @user` and `!meinprofil`
142
142
 
143
+ ### 📤 **SendChat API - NEW!**
144
+ - **Send to Other Chats** - Send messages to any chat/group
145
+ - **Broadcast Messages** - Send to multiple chats at once
146
+ - **Forward Messages** - Forward with or without forward tag
147
+ - **Smart JID Formatting** - Automatic phone number formatting
148
+ - **Media Support** - Send images, videos, audio, documents
149
+ - **See**: `SENDCHAT-API.md` for full documentation
150
+
151
+ ```javascript
152
+ // Send to another chat
153
+ await msg.sendChat("49123456789@s.whatsapp.net", "Hello!");
154
+
155
+ // Broadcast to multiple chats
156
+ await msg.sendToMultipleChats([jid1, jid2], "Broadcast!");
157
+
158
+ // Forward message
159
+ await msg.forwardToChat(targetJid);
160
+ ```
161
+
143
162
  ### 🌍 **Universal Cross-Platform QR System**
144
163
  - **Works everywhere** - Windows, macOS, Linux, Docker, Raspberry Pi, Android
145
164
  - **Intelligent browser detection** - Edge, Chrome, Firefox, Safari auto-detection
@@ -0,0 +1,134 @@
1
+ // ===== SENDCHAT API - EINFACHES BEISPIEL =====
2
+ // Zeigt wie man Nachrichten an andere Chats sendet
3
+
4
+ import { WhatsAppClient } from "../src/client.js";
5
+
6
+ const client = new WhatsAppClient({
7
+ authDir: "./auth",
8
+ printQR: true,
9
+ logLevel: "silent"
10
+ });
11
+
12
+ console.log("🚀 SendChat Beispiel wird gestartet...\n");
13
+
14
+ // ===== KONFIGURATION =====
15
+ // WICHTIG: Ersetze diese mit echten JIDs!
16
+ const ADMIN_JID = "49123456789@s.whatsapp.net"; // Deine Admin-Nummer
17
+ const TARGET_GROUP = "120363421640574094@g.us"; // Ziel-Gruppe (optional)
18
+
19
+ client.on('message', async (msg) => {
20
+ try {
21
+ const text = msg.text?.toLowerCase() || '';
22
+
23
+ // ===== BEISPIEL 1: Einfache Nachricht an Admin =====
24
+ if (text === '!notify') {
25
+ await msg.reply("📤 Sende Benachrichtigung an Admin...");
26
+
27
+ await msg.sendChat(ADMIN_JID,
28
+ `⚠️ Neue Nachricht von ${msg.getSender()}:\n\n"${msg.text}"`
29
+ );
30
+
31
+ await msg.reply("✅ Admin wurde benachrichtigt!");
32
+ }
33
+
34
+ // ===== BEISPIEL 2: Nachricht mit Bild =====
35
+ if (text === '!sendpic') {
36
+ await msg.reply("📸 Sende Bild...");
37
+
38
+ // Beispiel: Sende ein Bild an einen anderen Chat
39
+ await msg.sendChat(ADMIN_JID, "Schau dir das an!", {
40
+ image: "./path/to/image.jpg" // Ersetze mit echtem Pfad
41
+ });
42
+
43
+ await msg.reply("✅ Bild gesendet!");
44
+ }
45
+
46
+ // ===== BEISPIEL 3: Weiterleitung =====
47
+ if (text === '!forward') {
48
+ await msg.reply("📤 Leite Nachricht weiter...");
49
+
50
+ // Leite die aktuelle Nachricht an Admin weiter
51
+ await msg.forwardToChat(ADMIN_JID);
52
+
53
+ await msg.reply("✅ Weitergeleitet!");
54
+ }
55
+
56
+ // ===== BEISPIEL 4: Broadcast =====
57
+ if (text === '!broadcast' && await msg.isAdmin()) {
58
+ const subscribers = [
59
+ "49123456789@s.whatsapp.net",
60
+ "49987654321@s.whatsapp.net"
61
+ // Füge weitere JIDs hinzu
62
+ ];
63
+
64
+ await msg.reply("📢 Sende Broadcast...");
65
+
66
+ const results = await msg.sendToMultipleChats(
67
+ subscribers,
68
+ "📢 Wichtige Ankündigung vom Bot!",
69
+ { delay: 2000 } // 2 Sekunden zwischen Nachrichten
70
+ );
71
+
72
+ const successful = results.filter(r => r.success).length;
73
+ await msg.reply(`✅ Broadcast: ${successful}/${results.length} erfolgreich`);
74
+ }
75
+
76
+ // ===== BEISPIEL 5: Support-System =====
77
+ if (text.startsWith('!support ')) {
78
+ const message = text.replace('!support ', '');
79
+
80
+ await msg.reply("📨 Deine Nachricht wird an den Support weitergeleitet...");
81
+
82
+ await msg.sendChat(ADMIN_JID,
83
+ `💬 *Support-Anfrage*\n\n` +
84
+ `Von: ${msg.getSender()}\n` +
85
+ `Chat: ${msg.from}\n` +
86
+ `Zeit: ${new Date().toLocaleString()}\n\n` +
87
+ `Nachricht:\n${message}`
88
+ );
89
+
90
+ await msg.reply("✅ Support wurde kontaktiert! Wir melden uns bald.");
91
+ }
92
+
93
+ // ===== BEISPIEL 6: Auto-Forward bei Keywords =====
94
+ if (text.includes('wichtig') || text.includes('dringend')) {
95
+ // Automatisch an Admin weiterleiten
96
+ await msg.forwardToChat(ADMIN_Jid);
97
+ console.log(`⚠️ Wichtige Nachricht an Admin weitergeleitet`);
98
+ }
99
+
100
+ // ===== HILFE =====
101
+ if (text === '!help' || text === '!hilfe') {
102
+ const helpText = `
103
+ 🤖 *SendChat API Beispiele*
104
+
105
+ 📤 *Verfügbare Commands:*
106
+ !notify - Benachrichtige Admin
107
+ !sendpic - Sende Bild an Admin
108
+ !forward - Leite Nachricht weiter
109
+ !broadcast - Sende Broadcast (nur Admin)
110
+ !support <text> - Kontaktiere Support
111
+
112
+ 💡 *Auto-Features:*
113
+ - Nachrichten mit "wichtig" oder "dringend" werden automatisch weitergeleitet
114
+
115
+ 📚 *Mehr Infos:*
116
+ Siehe SENDCHAT-API.md für vollständige Dokumentation
117
+ `.trim();
118
+
119
+ await msg.reply(helpText);
120
+ }
121
+
122
+ } catch (error) {
123
+ console.error("❌ Fehler:", error);
124
+ await msg.reply(`❌ Fehler: ${error.message}`);
125
+ }
126
+ });
127
+
128
+ // Start Bot
129
+ client.connect().catch(error => {
130
+ console.error("❌ Verbindungsfehler:", error);
131
+ process.exit(1);
132
+ });
133
+
134
+ console.log("✅ Bot läuft! Sende !help für Hilfe");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "waengine",
3
- "version": "1.8.0",
3
+ "version": "1.8.2",
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
@@ -1413,6 +1413,125 @@ class DemoteAPI {
1413
1413
  });
1414
1414
  }
1415
1415
 
1416
+ // ===== SENDCHAT API - Nachrichten an beliebige Chats senden! =====
1417
+
1418
+ /**
1419
+ * Sendet eine Nachricht an einen beliebigen Chat (außerhalb von Message-Context)
1420
+ * @param {string} targetJid - Die JID des Ziel-Chats
1421
+ * @param {string|object} content - Text oder Message-Objekt
1422
+ * @param {object} options - Optionale Einstellungen
1423
+ * @returns {Promise} Gesendete Nachricht
1424
+ */
1425
+ async sendChat(targetJid, content, options = {}) {
1426
+ try {
1427
+ if (!this.socket || !this.isConnected) {
1428
+ throw new Error('❌ Bot ist nicht verbunden!');
1429
+ }
1430
+
1431
+ // Validiere JID Format
1432
+ if (!targetJid || typeof targetJid !== 'string') {
1433
+ throw new Error('❌ Ungültige JID! Format: "nummer@s.whatsapp.net" oder "gruppenid@g.us"');
1434
+ }
1435
+
1436
+ // Normalisiere JID falls nötig
1437
+ let normalizedJid = targetJid;
1438
+ if (!targetJid.includes('@')) {
1439
+ normalizedJid = `${targetJid}@s.whatsapp.net`;
1440
+ }
1441
+
1442
+ // Erstelle Message-Objekt
1443
+ let messageObj;
1444
+
1445
+ if (typeof content === 'string') {
1446
+ messageObj = { text: content };
1447
+
1448
+ // Füge optionale Features hinzu
1449
+ if (options.mentions && Array.isArray(options.mentions)) {
1450
+ messageObj.mentions = options.mentions;
1451
+ }
1452
+
1453
+ if (options.image) {
1454
+ messageObj.image = { url: options.image };
1455
+ messageObj.caption = content;
1456
+ delete messageObj.text;
1457
+ }
1458
+
1459
+ if (options.video) {
1460
+ messageObj.video = { url: options.video };
1461
+ messageObj.caption = content;
1462
+ delete messageObj.text;
1463
+ }
1464
+
1465
+ if (options.audio) {
1466
+ messageObj.audio = { url: options.audio };
1467
+ messageObj.mimetype = 'audio/mp4';
1468
+ delete messageObj.text;
1469
+ }
1470
+
1471
+ if (options.sticker) {
1472
+ messageObj.sticker = { url: options.sticker };
1473
+ delete messageObj.text;
1474
+ delete messageObj.caption;
1475
+ }
1476
+
1477
+ if (options.document) {
1478
+ messageObj.document = { url: options.document };
1479
+ messageObj.fileName = options.fileName || 'document';
1480
+ messageObj.mimetype = options.mimetype || 'application/octet-stream';
1481
+ if (content) messageObj.caption = content;
1482
+ delete messageObj.text;
1483
+ }
1484
+
1485
+ } else if (typeof content === 'object') {
1486
+ messageObj = content;
1487
+ } else {
1488
+ throw new Error('❌ Content muss String oder Objekt sein');
1489
+ }
1490
+
1491
+ // Sende Nachricht
1492
+ console.log(`📤 Sende Nachricht an ${normalizedJid}`);
1493
+ const result = await this.socket.sendMessage(normalizedJid, messageObj);
1494
+ console.log('✅ Nachricht erfolgreich gesendet:', result?.key?.id);
1495
+
1496
+ return result;
1497
+
1498
+ } catch (error) {
1499
+ console.error('❌ Fehler beim Senden an anderen Chat:', error);
1500
+ throw error;
1501
+ }
1502
+ }
1503
+
1504
+ /**
1505
+ * Sendet eine Nachricht an mehrere Chats gleichzeitig (Broadcast)
1506
+ * @param {Array<string>} targetJids - Array von JIDs
1507
+ * @param {string|object} content - Nachricht
1508
+ * @param {object} options - Optionale Einstellungen
1509
+ * @returns {Promise<Array>} Array mit Ergebnissen
1510
+ */
1511
+ async sendToMultipleChats(targetJids, content, options = {}) {
1512
+ if (!Array.isArray(targetJids) || targetJids.length === 0) {
1513
+ throw new Error('❌ targetJids muss ein nicht-leeres Array sein');
1514
+ }
1515
+
1516
+ const results = [];
1517
+ const delay = options.delay || 1000;
1518
+
1519
+ for (const jid of targetJids) {
1520
+ try {
1521
+ const result = await this.sendChat(jid, content, options);
1522
+ results.push({ jid, success: true, result });
1523
+
1524
+ if (delay > 0 && jid !== targetJids[targetJids.length - 1]) {
1525
+ await new Promise(resolve => setTimeout(resolve, delay));
1526
+ }
1527
+ } catch (error) {
1528
+ results.push({ jid, success: false, error: error.message });
1529
+ }
1530
+ }
1531
+
1532
+ return results;
1533
+ }
1534
+
1416
1535
  // ===== ERROR RECOVERY =====
1417
1536
 
1418
1537
  async recoverFromError(error) {
package/src/message.js CHANGED
@@ -1787,6 +1787,155 @@ export class Message {
1787
1787
  }
1788
1788
  }
1789
1789
 
1790
+ // ===== SEND TO OTHER CHATS API - NEU! =====
1791
+
1792
+ /**
1793
+ * Sendet eine Nachricht an einen anderen Chat/Gruppe
1794
+ * @param {string} targetJid - Die JID des Ziel-Chats (z.B. "49123456789@s.whatsapp.net" oder "120363...@g.us")
1795
+ * @param {string|object} content - Text oder Message-Objekt
1796
+ * @param {object} options - Optionale Einstellungen
1797
+ * @returns {Promise} Gesendete Nachricht
1798
+ *
1799
+ * Beispiele:
1800
+ * - msg.sendChat("49123456789@s.whatsapp.net", "Hallo!")
1801
+ * - msg.sendChat("120363...@g.us", "Gruppen-Nachricht")
1802
+ * - msg.sendChat("49123456789@s.whatsapp.net", { text: "Hi", mentions: [...] })
1803
+ * - msg.sendChat("49123456789@s.whatsapp.net", "Test", { image: "./bild.jpg" })
1804
+ */
1805
+ async sendChat(targetJid, content, options = {}) {
1806
+ try {
1807
+ // Validiere JID Format
1808
+ if (!targetJid || typeof targetJid !== 'string') {
1809
+ throw new Error('❌ Ungültige JID! Format: "nummer@s.whatsapp.net" oder "gruppenid@g.us"');
1810
+ }
1811
+
1812
+ // Normalisiere JID falls nötig
1813
+ let normalizedJid = targetJid;
1814
+ if (!targetJid.includes('@')) {
1815
+ // Wenn nur Nummer angegeben, füge @s.whatsapp.net hinzu
1816
+ normalizedJid = `${targetJid}@s.whatsapp.net`;
1817
+ }
1818
+
1819
+ // Erstelle Message-Objekt
1820
+ let messageObj;
1821
+
1822
+ if (typeof content === 'string') {
1823
+ // Einfacher Text
1824
+ messageObj = { text: content };
1825
+
1826
+ // Füge optionale Features hinzu
1827
+ if (options.mentions && Array.isArray(options.mentions)) {
1828
+ messageObj.mentions = options.mentions;
1829
+ }
1830
+
1831
+ if (options.image) {
1832
+ messageObj.image = { url: options.image };
1833
+ messageObj.caption = content;
1834
+ delete messageObj.text;
1835
+ }
1836
+
1837
+ if (options.video) {
1838
+ messageObj.video = { url: options.video };
1839
+ messageObj.caption = content;
1840
+ delete messageObj.text;
1841
+ }
1842
+
1843
+ if (options.audio) {
1844
+ messageObj.audio = { url: options.audio };
1845
+ messageObj.mimetype = 'audio/mp4';
1846
+ delete messageObj.text;
1847
+ }
1848
+
1849
+ if (options.sticker) {
1850
+ messageObj.sticker = { url: options.sticker };
1851
+ delete messageObj.text;
1852
+ delete messageObj.caption;
1853
+ }
1854
+
1855
+ if (options.document) {
1856
+ messageObj.document = { url: options.document };
1857
+ messageObj.fileName = options.fileName || 'document';
1858
+ messageObj.mimetype = options.mimetype || 'application/octet-stream';
1859
+ if (content) messageObj.caption = content;
1860
+ delete messageObj.text;
1861
+ }
1862
+
1863
+ } else if (typeof content === 'object') {
1864
+ // Direktes Message-Objekt
1865
+ messageObj = content;
1866
+ } else {
1867
+ throw new Error('❌ Content muss String oder Objekt sein');
1868
+ }
1869
+
1870
+ // Sende Nachricht
1871
+ console.log(`📤 Sende Nachricht an ${normalizedJid}:`, messageObj);
1872
+ const result = await this.client.socket.sendMessage(normalizedJid, messageObj);
1873
+ console.log('✅ Nachricht erfolgreich gesendet:', result?.key?.id);
1874
+
1875
+ return result;
1876
+
1877
+ } catch (error) {
1878
+ console.error('❌ Fehler beim Senden an anderen Chat:', error);
1879
+ throw error;
1880
+ }
1881
+ }
1882
+
1883
+ /**
1884
+ * Sendet eine Text-Nachricht an mehrere Chats gleichzeitig
1885
+ * @param {Array<string>} targetJids - Array von JIDs
1886
+ * @param {string|object} content - Nachricht
1887
+ * @param {object} options - Optionale Einstellungen
1888
+ * @returns {Promise<Array>} Array mit Ergebnissen
1889
+ *
1890
+ * Beispiel:
1891
+ * - msg.sendToMultipleChats(["49123@s.whatsapp.net", "49456@s.whatsapp.net"], "Broadcast!")
1892
+ */
1893
+ async sendToMultipleChats(targetJids, content, options = {}) {
1894
+ if (!Array.isArray(targetJids) || targetJids.length === 0) {
1895
+ throw new Error('❌ targetJids muss ein nicht-leeres Array sein');
1896
+ }
1897
+
1898
+ const results = [];
1899
+ const delay = options.delay || 1000; // 1 Sekunde Verzögerung zwischen Nachrichten
1900
+
1901
+ for (const jid of targetJids) {
1902
+ try {
1903
+ const result = await this.sendChat(jid, content, options);
1904
+ results.push({ jid, success: true, result });
1905
+
1906
+ // Verzögerung um Spam zu vermeiden
1907
+ if (delay > 0 && jid !== targetJids[targetJids.length - 1]) {
1908
+ await new Promise(resolve => setTimeout(resolve, delay));
1909
+ }
1910
+ } catch (error) {
1911
+ results.push({ jid, success: false, error: error.message });
1912
+ }
1913
+ }
1914
+
1915
+ return results;
1916
+ }
1917
+
1918
+ /**
1919
+ * Sendet die aktuelle Nachricht an einen anderen Chat weiter (mit Forward-Tag)
1920
+ * Alias für forwardTo() mit besserem Namen
1921
+ */
1922
+ async forwardToChat(targetJid) {
1923
+ return await this.forwardTo(targetJid);
1924
+ }
1925
+
1926
+ /**
1927
+ * Kopiert die aktuelle Nachricht in einen anderen Chat (ohne Forward-Tag)
1928
+ */
1929
+ async copyToChat(targetJid) {
1930
+ try {
1931
+ const messageContent = this.raw.message;
1932
+ return await this.client.socket.sendMessage(targetJid, messageContent);
1933
+ } catch (error) {
1934
+ console.error('❌ Fehler beim Kopieren in anderen Chat:', error);
1935
+ throw error;
1936
+ }
1937
+ }
1938
+
1790
1939
  async copyMessage() {
1791
1940
  // Erstellt eine Kopie der Nachricht ohne Forward-Tag
1792
1941
  try {