@deathnaitsa/wa-api 2.0.29 → 2.1.0

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/CONFIG.md ADDED
@@ -0,0 +1,350 @@
1
+ # Config-System - Nishi WhatsApp API
2
+
3
+ ## 🎯 Überblick
4
+
5
+ Das neue Config-System ermöglicht zentrale Konfiguration aller API-Einstellungen über eine `wa-api.config.js` Datei.
6
+
7
+ ## ✨ Vorteile
8
+
9
+ - **Keine Wiederholungen**: Einmal konfigurieren, überall verwenden
10
+ - **Zentrale Verwaltung**: Alle Einstellungen an einem Ort
11
+ - **Einfaches Deployment**: Config-Datei bearbeiten statt Code ändern
12
+ - **Footer/Wasserzeichen**: Automatisch auf alle Nachrichten anwenden
13
+ - **Überschreibbar**: Config-Defaults können jederzeit überschrieben werden
14
+
15
+ ## 🚀 Quick Start
16
+
17
+ ### 1. Config erstellen
18
+
19
+ ```javascript
20
+ import { initConfig } from '@deathnaitsa/wa-api';
21
+
22
+ initConfig(); // Erstellt wa-api.config.js
23
+ ```
24
+
25
+ ### 2. Config anpassen
26
+
27
+ ```javascript
28
+ // wa-api.config.js
29
+ export const waApiConfig = {
30
+ session: {
31
+ useSqlByDefault: true, // Alle Sessions verwenden SQLite
32
+ autoReconnect: true, // Auto-Reconnect für alle
33
+ printQR: true,
34
+ },
35
+
36
+ footer: {
37
+ enabled: true, // Footer aktivieren
38
+ text: 'Made with Nishi API 🚀',
39
+ },
40
+ };
41
+ ```
42
+
43
+ ### 3. Verwenden
44
+
45
+ ```javascript
46
+ // Verwendet automatisch Config-Einstellungen
47
+ await startSession('bot1'); // SQLite + Auto-Reconnect aktiv!
48
+
49
+ // Footer wird automatisch angehängt
50
+ await sendText('bot1', jid, 'Hallo!');
51
+ ```
52
+
53
+ ## 📋 Verfügbare Config-Optionen
54
+
55
+ ### Session-Einstellungen
56
+ ```javascript
57
+ session: {
58
+ useSqlByDefault: false, // SQLite als Standard
59
+ browser: ['Chrome', '120.0.0', 'Windows'],
60
+ printQR: true,
61
+ credentialsDir: './sessions',
62
+ autoReconnect: false,
63
+ logLevel: 'silent',
64
+ markOnlineOnConnect: false,
65
+ }
66
+ ```
67
+
68
+ ### Auto-Reconnect
69
+ ```javascript
70
+ reconnect: {
71
+ maxRetries: 5,
72
+ initialDelay: 2000,
73
+ maxDelay: 30000,
74
+ multiplier: 2,
75
+ }
76
+ ```
77
+
78
+ ### Footer/Wasserzeichen ⭐ NEU
79
+ ```javascript
80
+ footer: {
81
+ enabled: false, // Footer aktivieren/deaktivieren
82
+ text: 'Nishi WhatsApp API', // Footer-Text
83
+ applyToTypes: ['text', 'image', 'video', 'audio', 'document', 'sticker'], // Alle Typen!
84
+ onlyOutgoing: true, // Nur ausgehende Nachrichten
85
+ }
86
+ ```
87
+
88
+ ### Rate Limiting
89
+ ```javascript
90
+ rateLimit: {
91
+ enabled: false,
92
+ maxMessages: 20,
93
+ interval: 60000,
94
+ queueInterval: 1000,
95
+ }
96
+ ```
97
+
98
+ ### Webhooks
99
+ ```javascript
100
+ webhook: {
101
+ defaultUrl: null,
102
+ timeout: 5000,
103
+ retry: true,
104
+ maxRetries: 3,
105
+ }
106
+ ```
107
+
108
+ ### Statistiken
109
+ ```javascript
110
+ stats: {
111
+ enabled: true,
112
+ filePath: './sessions/stats.json',
113
+ autoSaveInterval: 60000,
114
+ }
115
+ ```
116
+
117
+ ### Message Store
118
+ ```javascript
119
+ messageStore: {
120
+ enabled: true,
121
+ maxMessages: 1000,
122
+ maxAge: 24, // Stunden
123
+ }
124
+ ```
125
+
126
+ ### Media
127
+ ```javascript
128
+ media: {
129
+ autoDownload: false,
130
+ downloadDir: './media',
131
+ maxFileSize: 100, // MB
132
+ }
133
+ ```
134
+
135
+ ### Sticker
136
+ ```javascript
137
+ sticker: {
138
+ packname: 'Nishi API',
139
+ author: 'WhatsApp Bot',
140
+ categories: ['🤖', '🚀'],
141
+ }
142
+ ```
143
+
144
+ ### Features
145
+ ```javascript
146
+ features: {
147
+ groupManagement: true,
148
+ stories: true,
149
+ polls: true,
150
+ broadcast: true,
151
+ contacts: true,
152
+ }
153
+ ```
154
+
155
+ ### Developer
156
+ ```javascript
157
+ developer: {
158
+ debug: false,
159
+ verbose: false,
160
+ showStackTrace: true,
161
+ }
162
+ ```
163
+
164
+ ## 🎨 Use Cases
165
+
166
+ ### Use Case 1: Production Setup
167
+ ```javascript
168
+ // wa-api.config.js
169
+ export const waApiConfig = {
170
+ session: {
171
+ useSqlByDefault: true, // Nur 1 DB statt 100+ JSON-Files
172
+ autoReconnect: true, // Auto-Reconnect aktiviert
173
+ logLevel: 'error', // Nur Errors loggen
174
+ },
175
+ footer: {
176
+ enabled: true,
177
+ text: 'Support: @mybot',
178
+ },
179
+ stats: {
180
+ enabled: true,
181
+ autoSaveInterval: 300000, // Alle 5 Minuten
182
+ },
183
+ };
184
+ ```
185
+
186
+ ### Use Case 2: Development Setup
187
+ ```javascript
188
+ // wa-api.config.js
189
+ export const waApiConfig = {
190
+ session: {
191
+ useSqlByDefault: false, // JSON-Files für schnelles Testen
192
+ autoReconnect: false, // Kein Auto-Reconnect beim Debuggen
193
+ printQR: true,
194
+ },
195
+ footer: {
196
+ enabled: false, // Kein Footer im Dev-Modus
197
+ },
198
+ developer: {
199
+ debug: true,
200
+ verbose: true,
201
+ showStackTrace: true,
202
+ },
203
+ };
204
+ ```
205
+
206
+ ### Use Case 3: Bot mit Branding
207
+ ```javascript
208
+ // wa-api.config.js
209
+ export const waApiConfig = {
210
+ session: {
211
+ useSqlByDefault: true,
212
+ autoReconnect: true,
213
+ },
214
+ footer: {
215
+ enabled: true,
216
+ text: '🤖 MyCompany Bot | support@mycompany.com',
217
+ applyToTypes: ['text'],
218
+ },
219
+ sticker: {
220
+ packname: 'MyCompany Stickers',
221
+ author: 'MyCompany Bot',
222
+ },
223
+ };
224
+ ```
225
+
226
+ ## 🔄 Config überschreiben
227
+
228
+ Config-Defaults können jederzeit überschrieben werden:
229
+
230
+ ```javascript
231
+ // Config sagt: useSqlByDefault: true
232
+ await startSession('bot1'); // Verwendet SQLite
233
+
234
+ // Für diese Session JSON-Files verwenden:
235
+ await startSession('bot2', { sql: false }); // Überschreibt Config
236
+ ```
237
+
238
+ ## 📝 Footer-Implementierung
239
+
240
+ Der Footer wird über WhatsApp's `interactiveMessage` mit `viewOnceMessage` implementiert und funktioniert für ALLE Nachrichtentypen:
241
+
242
+ ```javascript
243
+ // Automatisch bei aktiviertem Footer:
244
+ await sendText('bot', jid, 'Hallo Welt!');
245
+ await sendImage('bot', jid, image, 'Schau mal!');
246
+ await sendVideo('bot', jid, video, 'Cool!');
247
+ await sendAudio('bot', jid, audio);
248
+ await sendDocument('bot', jid, doc, 'Dokument');
249
+
250
+ // Alle haben den Footer:
251
+ // ┌─────────────────┐
252
+ // │ Nachricht │
253
+ // │ oder Media │
254
+ // │ │
255
+ // │ Made with ❤️ │ ← Footer
256
+ // └─────────────────┘
257
+ ```
258
+
259
+ **Unterstützte Typen:**
260
+ - ✅ Text
261
+ - ✅ Image (mit Caption)
262
+ - ✅ Video (mit Caption)
263
+ - ✅ Audio
264
+ - ✅ Document
265
+ - ✅ Sticker
266
+
267
+ ## 🛠️ API
268
+
269
+ ### initConfig(targetDir)
270
+ Erstellt `wa-api.config.js` im angegebenen Verzeichnis.
271
+
272
+ ```javascript
273
+ import { initConfig } from '@deathnaitsa/wa-api';
274
+
275
+ initConfig(); // Erstellt in process.cwd()
276
+ initConfig('./my-project'); // Erstellt in ./my-project
277
+ ```
278
+
279
+ ### loadConfig(targetDir)
280
+ Lädt Config aus Verzeichnis oder fällt zurück auf Defaults.
281
+
282
+ ```javascript
283
+ import { loadConfig } from '@deathnaitsa/wa-api';
284
+
285
+ const config = await loadConfig();
286
+ console.log(config.footer.enabled);
287
+ ```
288
+
289
+ ### getConfigPath(targetDir)
290
+ Gibt den Config-Pfad zurück.
291
+
292
+ ```javascript
293
+ import { getConfigPath } from '@deathnaitsa/wa-api';
294
+
295
+ console.log(getConfigPath()); // /path/to/project/wa-api.config.js
296
+ ```
297
+
298
+ ## 📦 Migration
299
+
300
+ ### Vorher (ohne Config)
301
+ ```javascript
302
+ await startSession('bot1', {
303
+ sql: true,
304
+ autoReconnect: true,
305
+ printQR: true
306
+ });
307
+ await startSession('bot2', {
308
+ sql: true,
309
+ autoReconnect: true,
310
+ printQR: true
311
+ });
312
+ await startSession('bot3', {
313
+ sql: true,
314
+ autoReconnect: true,
315
+ printQR: true
316
+ });
317
+ ```
318
+
319
+ ### Nachher (mit Config)
320
+ ```javascript
321
+ // wa-api.config.js
322
+ export const waApiConfig = {
323
+ session: {
324
+ useSqlByDefault: true,
325
+ autoReconnect: true,
326
+ printQR: true,
327
+ },
328
+ };
329
+
330
+ // Code
331
+ await startSession('bot1');
332
+ await startSession('bot2');
333
+ await startSession('bot3');
334
+ ```
335
+
336
+ ## 🎯 Zusammenfassung
337
+
338
+ Das Config-System bietet:
339
+ - ✅ Zentrale Konfiguration
340
+ - ✅ Footer/Wasserzeichen Support
341
+ - ✅ Keine Code-Änderungen für Config-Updates
342
+ - ✅ Überschreibbare Defaults
343
+ - ✅ Production-Ready
344
+ - ✅ Development-Friendly
345
+
346
+ Perfect für:
347
+ - 🏢 Production Deployments
348
+ - 🤖 Bot-Projekte mit Branding
349
+ - 📊 Multi-Session Setups
350
+ - 🔧 Flexible Konfigurationen
package/README.md CHANGED
@@ -8,8 +8,7 @@ Eine minimalistische, stabile WhatsApp Multi-Device API basierend auf Baileys mi
8
8
  - [Features](#-features)
9
9
  - [Installation](#-installation)
10
10
  - [Quick Start](#-quick-start)
11
- - [ES Modules](#es-modules-empfohlen)
12
- - [CommonJS](#commonjs)
11
+ - [Configuration](#-configuration)
13
12
  - [API Dokumentation](#-api-dokumentation)
14
13
  - [Session Management](#-session-management-implementiert)
15
14
  - [Nachrichten](#-nachrichten-implementiert)
@@ -87,13 +86,46 @@ npm install
87
86
  npm install better-sqlite3
88
87
  ```
89
88
 
89
+ **Config-Datei erstellen (empfohlen)**
90
+ ```bash
91
+ node -e "import('@deathnaitsa/wa-api').then(m => m.initConfig())"
92
+ ```
93
+
94
+ Dies erstellt eine `wa-api.config.js` im Hauptverzeichnis mit allen verfügbaren Einstellungen.
95
+
90
96
  **Unterstützt beide Formate:**
91
97
  - ✅ **ES Modules** (import)
92
98
  - ✅ **CommonJS** (require)
93
99
 
94
100
  ## 🚀 Quick Start
95
101
 
96
- ### ES Modules (empfohlen)
102
+ ### 1. Config erstellen (optional, aber empfohlen)
103
+ ```javascript
104
+ import { initConfig } from '@deathnaitsa/wa-api';
105
+
106
+ // Erstellt wa-api.config.js im Hauptverzeichnis
107
+ initConfig();
108
+ ```
109
+
110
+ Dann in `wa-api.config.js` deine Einstellungen anpassen:
111
+ ```javascript
112
+ export const waApiConfig = {
113
+ session: {
114
+ useSqlByDefault: true, // SQLite als Standard
115
+ printQR: true,
116
+ autoReconnect: true,
117
+ },
118
+ footer: {
119
+ enabled: true, // Footer aktivieren
120
+ text: 'Powered by Nishi API 🚀',
121
+ },
122
+ // ... weitere Einstellungen
123
+ };
124
+ ```
125
+
126
+ ### 2. Session starten
127
+
128
+ #### ES Modules (empfohlen)
97
129
  ```javascript
98
130
  import { startSession, onMessage, sendText } from '@deathnaitsa/wa-api';
99
131
 
@@ -108,7 +140,7 @@ onMessage(async (msg) => {
108
140
  });
109
141
  ```
110
142
 
111
- ### CommonJS
143
+ #### CommonJS
112
144
  ```javascript
113
145
  const { startSession, onMessage, sendText } = require('@deathnaitsa/wa-api');
114
146
 
@@ -193,6 +225,114 @@ await startSession('main', {
193
225
  npm install better-sqlite3
194
226
  ```
195
227
 
228
+ ## ⚙️ Configuration
229
+
230
+ Die Nishi WhatsApp API kann über eine zentrale Config-Datei konfiguriert werden. Dies erspart dir, bei jedem `startSession()` Aufruf die gleichen Optionen anzugeben.
231
+
232
+ ### Config-Datei erstellen
233
+
234
+ ```javascript
235
+ import { initConfig } from '@deathnaitsa/wa-api';
236
+
237
+ initConfig(); // Erstellt wa-api.config.js im Hauptverzeichnis
238
+ ```
239
+
240
+ Oder über CLI:
241
+ ```bash
242
+ node -e "import('@deathnaitsa/wa-api').then(m => m.initConfig())"
243
+ ```
244
+
245
+ ### Verfügbare Config-Optionen
246
+
247
+ ```javascript
248
+ // wa-api.config.js
249
+ export const waApiConfig = {
250
+ // Session-Einstellungen
251
+ session: {
252
+ useSqlByDefault: true, // SQLite statt JSON-Files
253
+ browser: ['Chrome', '120.0.0', 'Windows'],
254
+ printQR: true,
255
+ credentialsDir: './sessions',
256
+ autoReconnect: true,
257
+ logLevel: 'silent', // 'trace', 'debug', 'info', 'warn', 'error', 'fatal', 'silent'
258
+ markOnlineOnConnect: false,
259
+ },
260
+
261
+ // Auto-Reconnect Einstellungen
262
+ reconnect: {
263
+ maxRetries: 5,
264
+ initialDelay: 2000,
265
+ maxDelay: 30000,
266
+ multiplier: 2,
267
+ },
268
+
269
+ // Footer/Wasserzeichen für Nachrichten ✨ NEU!
270
+ footer: {
271
+ enabled: true, // Footer aktivieren
272
+ text: 'Powered by Nishi API 🚀', // Footer-Text
273
+ applyToTypes: ['text', 'image', 'video', 'audio', 'document', 'sticker'], // Alle Typen!
274
+ onlyOutgoing: true,
275
+ },
276
+
277
+ // Rate Limiting
278
+ rateLimit: {
279
+ enabled: false,
280
+ maxMessages: 20,
281
+ interval: 60000,
282
+ queueInterval: 1000,
283
+ },
284
+
285
+ // Webhook, Stats, Media, Sticker, Features, Developer...
286
+ // Siehe wa-api.config.js für alle Optionen
287
+ };
288
+ ```
289
+
290
+ ### Config verwenden
291
+
292
+ **Mit Config-Datei:**
293
+ ```javascript
294
+ // wa-api.config.js: useSqlByDefault: true, autoReconnect: true
295
+
296
+ import { startSession } from '@deathnaitsa/wa-api';
297
+
298
+ // Verwendet automatisch SQLite und Auto-Reconnect aus Config
299
+ await startSession('bot1');
300
+ ```
301
+
302
+ **Config überschreiben:**
303
+ ```javascript
304
+ // Config sagt: useSqlByDefault: true
305
+ // Aber für diese Session wollen wir JSON-Files:
306
+ await startSession('bot1', { sql: false });
307
+ ```
308
+
309
+ ### Footer/Wasserzeichen Beispiel
310
+
311
+ ```javascript
312
+ // wa-api.config.js
313
+ footer: {
314
+ enabled: true,
315
+ text: '🤖 Powered by Nishi Bot',
316
+ applyToTypes: ['text'],
317
+ }
318
+ ```
319
+
320
+ Jetzt haben **alle** Text-Nachrichten automatisch einen Footer:
321
+ ```javascript
322
+ await sendText('bot1', jid, 'Hallo Welt!');
323
+ // Wird gesendet mit Footer "🤖 Powered by Nishi Bot"
324
+
325
+ // Funktioniert auch für Media:
326
+ await sendImage('bot1', jid, image, 'Schau mal!');
327
+ // Bild mit Caption + Footer
328
+
329
+ await sendVideo('bot1', jid, video, 'Cool!');
330
+ // Video mit Caption + Footer
331
+
332
+ await sendDocument('bot1', jid, doc);
333
+ // Dokument mit Footer
334
+ ```
335
+
196
336
  #### ✅ Nachrichten (Implementiert)
197
337
  ```javascript
198
338
  import { sendText, onMessage } from '@deathnaitsa/wa-api';