wuzapi 1.3.1 → 1.5.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/dist/index.js CHANGED
@@ -17,8 +17,7 @@ class BaseClient {
17
17
  this.axios = axios.create({
18
18
  baseURL: config.apiUrl,
19
19
  headers: {
20
- "Content-Type": "application/json",
21
- Authorization: config.token
20
+ "Content-Type": "application/json"
22
21
  }
23
22
  });
24
23
  this.axios.interceptors.response.use(
@@ -39,11 +38,29 @@ class BaseClient {
39
38
  }
40
39
  );
41
40
  }
42
- async request(method, endpoint, data) {
41
+ /**
42
+ * Resolve the token from request options or instance config
43
+ * Throws an error if no token is available
44
+ */
45
+ resolveToken(options) {
46
+ const token = options?.token || this.config.token;
47
+ if (!token) {
48
+ throw new WuzapiError(
49
+ 401,
50
+ "No authentication token provided. Either set a token in the client config or provide one in the request options."
51
+ );
52
+ }
53
+ return token;
54
+ }
55
+ async request(method, endpoint, data, options) {
56
+ const token = this.resolveToken(options);
43
57
  const response = await this.axios.request({
44
58
  method,
45
59
  url: endpoint,
46
- data
60
+ data,
61
+ headers: {
62
+ Authorization: token
63
+ }
47
64
  });
48
65
  if (!response.data.success) {
49
66
  throw new WuzapiError(
@@ -54,296 +71,505 @@ class BaseClient {
54
71
  }
55
72
  return response.data.data;
56
73
  }
57
- async get(endpoint) {
58
- return this.request("GET", endpoint);
74
+ async get(endpoint, options) {
75
+ return this.request("GET", endpoint, void 0, options);
76
+ }
77
+ async post(endpoint, data, options) {
78
+ return this.request("POST", endpoint, data, options);
59
79
  }
60
- async post(endpoint, data) {
61
- return this.request("POST", endpoint, data);
80
+ async put(endpoint, data, options) {
81
+ return this.request("PUT", endpoint, data, options);
62
82
  }
63
- async delete(endpoint) {
64
- return this.request("DELETE", endpoint);
83
+ async delete(endpoint, options) {
84
+ return this.request("DELETE", endpoint, void 0, options);
65
85
  }
66
86
  }
67
87
  class AdminModule extends BaseClient {
68
88
  /**
69
89
  * List all users
70
90
  */
71
- async listUsers() {
72
- return this.get("/admin/users");
91
+ async listUsers(options) {
92
+ return this.get("/admin/users", options);
73
93
  }
74
94
  /**
75
95
  * Add a new user
76
96
  */
77
- async addUser(user) {
78
- return this.post("/admin/users", user);
97
+ async addUser(user, options) {
98
+ return this.post("/admin/users", user, options);
99
+ }
100
+ /**
101
+ * Get a specific user by ID
102
+ */
103
+ async getUser(id, options) {
104
+ return this.get(`/admin/users/${id}`, options);
79
105
  }
80
106
  /**
81
107
  * Delete a user by ID
82
108
  */
83
- async deleteUser(id) {
84
- return this.delete(`/admin/users/${id}`);
109
+ async deleteUser(id, options) {
110
+ return this.delete(`/admin/users/${id}`, options);
111
+ }
112
+ /**
113
+ * Delete a user completely (full deletion) by ID
114
+ */
115
+ async deleteUserComplete(id, options) {
116
+ return this.delete(`/admin/users/${id}/full`, options);
85
117
  }
86
118
  }
87
119
  class SessionModule extends BaseClient {
88
120
  /**
89
121
  * Connect to WhatsApp servers
90
122
  */
91
- async connect(options) {
92
- return this.post("/session/connect", options);
123
+ async connect(request, options) {
124
+ return this.post("/session/connect", request, options);
93
125
  }
94
126
  /**
95
127
  * Disconnect from WhatsApp servers
96
128
  */
97
- async disconnect() {
98
- return this.post("/session/disconnect");
129
+ async disconnect(options) {
130
+ return this.post(
131
+ "/session/disconnect",
132
+ void 0,
133
+ options
134
+ );
99
135
  }
100
136
  /**
101
137
  * Logout and finish the session
102
138
  */
103
- async logout() {
104
- return this.post("/session/logout");
139
+ async logout(options) {
140
+ return this.post("/session/logout", void 0, options);
105
141
  }
106
142
  /**
107
143
  * Get session status
108
144
  */
109
- async getStatus() {
110
- return this.get("/session/status");
145
+ async getStatus(options) {
146
+ return this.get("/session/status", options);
111
147
  }
112
148
  /**
113
149
  * Get QR code for scanning
114
150
  */
115
- async getQRCode() {
116
- return this.get("/session/qr");
151
+ async getQRCode(options) {
152
+ return this.get("/session/qr", options);
117
153
  }
118
154
  /**
119
155
  * Configure S3 storage
120
156
  */
121
- async configureS3(config) {
122
- return this.post("/session/s3/config", config);
157
+ async configureS3(config, options) {
158
+ return this.post("/session/s3/config", config, options);
123
159
  }
124
160
  /**
125
161
  * Get S3 configuration
126
162
  */
127
- async getS3Config() {
128
- return this.get("/session/s3/config");
163
+ async getS3Config(options) {
164
+ return this.get("/session/s3/config", options);
129
165
  }
130
166
  /**
131
167
  * Test S3 connection
132
168
  */
133
- async testS3() {
134
- return this.post("/session/s3/test");
169
+ async testS3(options) {
170
+ return this.post("/session/s3/test", void 0, options);
135
171
  }
136
172
  /**
137
173
  * Delete S3 configuration
138
174
  */
139
- async deleteS3Config() {
140
- return this.delete("/session/s3/config");
175
+ async deleteS3Config(options) {
176
+ return this.delete("/session/s3/config", options);
177
+ }
178
+ /**
179
+ * Pair phone using verification code
180
+ */
181
+ async pairPhone(phone, code, options) {
182
+ const request = { Phone: phone, Code: code };
183
+ return this.post("/session/pairphone", request, options);
184
+ }
185
+ /**
186
+ * Request history sync from WhatsApp servers
187
+ */
188
+ async requestHistory(options) {
189
+ return this.get("/session/history", options);
190
+ }
191
+ /**
192
+ * Set proxy configuration
193
+ */
194
+ async setProxy(proxy, options) {
195
+ const request = { Proxy: proxy };
196
+ return this.post("/session/proxy", request, options);
141
197
  }
142
198
  }
143
199
  class UserModule extends BaseClient {
144
200
  /**
145
201
  * Get user details for specified phone numbers
146
202
  */
147
- async getInfo(phones) {
203
+ async getInfo(phones, options) {
148
204
  const request = { Phone: phones };
149
- return this.post("/user/info", request);
205
+ return this.post("/user/info", request, options);
150
206
  }
151
207
  /**
152
208
  * Check if phone numbers are registered WhatsApp users
153
209
  */
154
- async check(phones) {
210
+ async check(phones, options) {
155
211
  const request = { Phone: phones };
156
- return this.post("/user/check", request);
212
+ return this.post("/user/check", request, options);
157
213
  }
158
214
  /**
159
215
  * Get user avatar/profile picture
160
216
  */
161
- async getAvatar(phone, preview = true) {
217
+ async getAvatar(phone, preview = true, options) {
162
218
  const request = { Phone: phone, Preview: preview };
163
- return this.post("/user/avatar", request);
219
+ return this.post("/user/avatar", request, options);
164
220
  }
165
221
  /**
166
222
  * Get all contacts
167
223
  */
168
- async getContacts() {
169
- return this.get("/user/contacts");
224
+ async getContacts(options) {
225
+ return this.get("/user/contacts", options);
226
+ }
227
+ /**
228
+ * Send user presence (available/unavailable status)
229
+ */
230
+ async sendPresence(request, options) {
231
+ await this.post("/user/presence", request, options);
170
232
  }
171
233
  }
172
234
  class ChatModule extends BaseClient {
173
235
  /**
174
236
  * Send a text message
175
237
  */
176
- async sendText(request) {
177
- return this.post("/chat/send/text", request);
238
+ async sendText(request, options) {
239
+ return this.post("/chat/send/text", request, options);
178
240
  }
179
241
  /**
180
242
  * Send a template message with buttons
181
243
  */
182
- async sendTemplate(request) {
183
- return this.post("/chat/send/template", request);
244
+ async sendTemplate(request, options) {
245
+ return this.post(
246
+ "/chat/send/template",
247
+ request,
248
+ options
249
+ );
184
250
  }
185
251
  /**
186
252
  * Send an audio message
187
253
  */
188
- async sendAudio(request) {
189
- return this.post("/chat/send/audio", request);
254
+ async sendAudio(request, options) {
255
+ return this.post("/chat/send/audio", request, options);
190
256
  }
191
257
  /**
192
258
  * Send an image message
193
259
  */
194
- async sendImage(request) {
195
- return this.post("/chat/send/image", request);
260
+ async sendImage(request, options) {
261
+ return this.post("/chat/send/image", request, options);
196
262
  }
197
263
  /**
198
264
  * Send a document message
199
265
  */
200
- async sendDocument(request) {
201
- return this.post("/chat/send/document", request);
266
+ async sendDocument(request, options) {
267
+ return this.post(
268
+ "/chat/send/document",
269
+ request,
270
+ options
271
+ );
202
272
  }
203
273
  /**
204
274
  * Send a video message
205
275
  */
206
- async sendVideo(request) {
207
- return this.post("/chat/send/video", request);
276
+ async sendVideo(request, options) {
277
+ return this.post("/chat/send/video", request, options);
208
278
  }
209
279
  /**
210
280
  * Send a sticker message
211
281
  */
212
- async sendSticker(request) {
213
- return this.post("/chat/send/sticker", request);
282
+ async sendSticker(request, options) {
283
+ return this.post(
284
+ "/chat/send/sticker",
285
+ request,
286
+ options
287
+ );
214
288
  }
215
289
  /**
216
290
  * Send a location message
217
291
  */
218
- async sendLocation(request) {
219
- return this.post("/chat/send/location", request);
292
+ async sendLocation(request, options) {
293
+ return this.post(
294
+ "/chat/send/location",
295
+ request,
296
+ options
297
+ );
220
298
  }
221
299
  /**
222
300
  * Send a contact message
223
301
  */
224
- async sendContact(request) {
225
- return this.post("/chat/send/contact", request);
302
+ async sendContact(request, options) {
303
+ return this.post(
304
+ "/chat/send/contact",
305
+ request,
306
+ options
307
+ );
226
308
  }
227
309
  /**
228
310
  * Send chat presence indication (typing indicator)
229
311
  */
230
- async sendPresence(request) {
231
- await this.post("/chat/presence", request);
312
+ async sendPresence(request, options) {
313
+ await this.post("/chat/presence", request, options);
232
314
  }
233
315
  /**
234
316
  * Mark messages as read
235
317
  */
236
- async markRead(request) {
237
- await this.post("/chat/markread", request);
318
+ async markRead(request, options) {
319
+ await this.post("/chat/markread", request, options);
238
320
  }
239
321
  /**
240
322
  * React to a message
241
323
  */
242
- async react(request) {
243
- return this.post("/chat/react", request);
324
+ async react(request, options) {
325
+ return this.post("/chat/react", request, options);
244
326
  }
245
327
  /**
246
328
  * Download an image from a message
247
329
  */
248
- async downloadImage(request) {
249
- return this.post("/chat/downloadimage", request);
330
+ async downloadImage(request, options) {
331
+ return this.post(
332
+ "/chat/downloadimage",
333
+ request,
334
+ options
335
+ );
250
336
  }
251
337
  /**
252
338
  * Download a video from a message
253
339
  */
254
- async downloadVideo(request) {
255
- return this.post("/chat/downloadvideo", request);
340
+ async downloadVideo(request, options) {
341
+ return this.post(
342
+ "/chat/downloadvideo",
343
+ request,
344
+ options
345
+ );
256
346
  }
257
347
  /**
258
348
  * Download an audio from a message
259
349
  */
260
- async downloadAudio(request) {
261
- return this.post("/chat/downloadaudio", request);
350
+ async downloadAudio(request, options) {
351
+ return this.post(
352
+ "/chat/downloadaudio",
353
+ request,
354
+ options
355
+ );
262
356
  }
263
357
  /**
264
358
  * Download a document from a message
265
359
  */
266
- async downloadDocument(request) {
267
- return this.post("/chat/downloaddocument", request);
360
+ async downloadDocument(request, options) {
361
+ return this.post(
362
+ "/chat/downloaddocument",
363
+ request,
364
+ options
365
+ );
366
+ }
367
+ /**
368
+ * Delete a message
369
+ */
370
+ async deleteMessage(request, options) {
371
+ return this.post("/chat/delete", request, options);
372
+ }
373
+ /**
374
+ * Send interactive buttons message
375
+ */
376
+ async sendButtons(request, options) {
377
+ return this.post(
378
+ "/chat/send/buttons",
379
+ request,
380
+ options
381
+ );
382
+ }
383
+ /**
384
+ * Send list message
385
+ */
386
+ async sendList(request, options) {
387
+ return this.post("/chat/send/list", request, options);
388
+ }
389
+ /**
390
+ * Send poll message
391
+ */
392
+ async sendPoll(request, options) {
393
+ return this.post("/chat/send/poll", request, options);
394
+ }
395
+ /**
396
+ * Edit a message
397
+ */
398
+ async editMessage(request, options) {
399
+ return this.post("/chat/send/edit", request, options);
268
400
  }
269
401
  }
270
402
  class GroupModule extends BaseClient {
271
403
  /**
272
404
  * List all subscribed groups
273
405
  */
274
- async list() {
275
- return this.get("/group/list");
406
+ async list(options) {
407
+ return this.get("/group/list", options);
276
408
  }
277
409
  /**
278
410
  * Get group invite link
279
411
  */
280
- async getInviteLink(groupJID) {
412
+ async getInviteLink(groupJID, options) {
281
413
  const request = { GroupJID: groupJID };
282
- return this.post("/group/invitelink", request);
414
+ return this.post(
415
+ "/group/invitelink",
416
+ request,
417
+ options
418
+ );
283
419
  }
284
420
  /**
285
421
  * Get group information
286
422
  */
287
- async getInfo(groupJID) {
423
+ async getInfo(groupJID, options) {
288
424
  const request = { GroupJID: groupJID };
289
- return this.post("/group/info", request);
425
+ return this.post("/group/info", request, options);
290
426
  }
291
427
  /**
292
428
  * Change group photo (JPEG only)
293
429
  */
294
- async setPhoto(groupJID, image) {
430
+ async setPhoto(groupJID, image, options) {
295
431
  const request = { GroupJID: groupJID, Image: image };
296
- return this.post("/group/photo", request);
432
+ return this.post("/group/photo", request, options);
297
433
  }
298
434
  /**
299
435
  * Change group name
300
436
  */
301
- async setName(groupJID, name) {
437
+ async setName(groupJID, name, options) {
302
438
  const request = { GroupJID: groupJID, Name: name };
303
- return this.post("/group/name", request);
439
+ return this.post("/group/name", request, options);
304
440
  }
305
441
  /**
306
442
  * Create a new group
307
443
  */
308
- async create(name, participants) {
444
+ async create(name, participants, options) {
309
445
  const request = { name, participants };
310
- return this.post("/group/create", request);
446
+ return this.post("/group/create", request, options);
311
447
  }
312
448
  /**
313
449
  * Set group locked status
314
450
  */
315
- async setLocked(groupJID, locked) {
451
+ async setLocked(groupJID, locked, options) {
316
452
  const request = { groupjid: groupJID, locked };
317
- return this.post("/group/locked", request);
453
+ return this.post("/group/locked", request, options);
318
454
  }
319
455
  /**
320
456
  * Set disappearing messages timer
321
457
  */
322
- async setEphemeral(groupJID, duration) {
458
+ async setEphemeral(groupJID, duration, options) {
323
459
  const request = { groupjid: groupJID, duration };
324
- return this.post("/group/ephemeral", request);
460
+ return this.post(
461
+ "/group/ephemeral",
462
+ request,
463
+ options
464
+ );
325
465
  }
326
466
  /**
327
467
  * Remove group photo
328
468
  */
329
- async removePhoto(groupJID) {
469
+ async removePhoto(groupJID, options) {
330
470
  const request = { groupjid: groupJID };
331
- return this.post("/group/photo/remove", request);
471
+ return this.post(
472
+ "/group/photo/remove",
473
+ request,
474
+ options
475
+ );
476
+ }
477
+ /**
478
+ * Leave a group
479
+ */
480
+ async leave(groupJID, options) {
481
+ const request = { GroupJID: groupJID };
482
+ return this.post("/group/leave", request, options);
483
+ }
484
+ /**
485
+ * Set group topic/description
486
+ */
487
+ async setTopic(groupJID, topic, options) {
488
+ const request = { GroupJID: groupJID, Topic: topic };
489
+ return this.post("/group/topic", request, options);
490
+ }
491
+ /**
492
+ * Set group announcement setting (only admins can send messages)
493
+ */
494
+ async setAnnounce(groupJID, announce, options) {
495
+ const request = {
496
+ GroupJID: groupJID,
497
+ Announce: announce
498
+ };
499
+ return this.post(
500
+ "/group/announce",
501
+ request,
502
+ options
503
+ );
504
+ }
505
+ /**
506
+ * Join a group using invite link
507
+ */
508
+ async join(inviteLink, options) {
509
+ const request = { InviteLink: inviteLink };
510
+ return this.post("/group/join", request, options);
511
+ }
512
+ /**
513
+ * Get group invite information
514
+ */
515
+ async getInviteInfo(inviteLink, options) {
516
+ const request = { InviteLink: inviteLink };
517
+ return this.post(
518
+ "/group/inviteinfo",
519
+ request,
520
+ options
521
+ );
522
+ }
523
+ /**
524
+ * Update group participants (add/remove/promote/demote)
525
+ */
526
+ async updateParticipants(groupJID, action, participants, options) {
527
+ const request = {
528
+ GroupJID: groupJID,
529
+ Action: action,
530
+ Participants: participants
531
+ };
532
+ return this.post(
533
+ "/group/updateparticipants",
534
+ request,
535
+ options
536
+ );
332
537
  }
333
538
  }
334
539
  class WebhookModule extends BaseClient {
335
540
  /**
336
541
  * Set webhook URL and events to subscribe to
337
542
  */
338
- async setWebhook(webhookURL) {
543
+ async setWebhook(webhookURL, options) {
339
544
  const request = { webhookURL };
340
- return this.post("/webhook", request);
545
+ return this.post("/webhook", request, options);
341
546
  }
342
547
  /**
343
548
  * Get current webhook configuration
344
549
  */
345
- async getWebhook() {
346
- return this.get("/webhook");
550
+ async getWebhook(options) {
551
+ return this.get("/webhook", options);
552
+ }
553
+ /**
554
+ * Update webhook URL
555
+ */
556
+ async updateWebhook(webhookURL, options) {
557
+ const request = { webhookURL };
558
+ return this.put("/webhook", request, options);
559
+ }
560
+ /**
561
+ * Delete webhook configuration
562
+ */
563
+ async deleteWebhook(options) {
564
+ return this.delete("/webhook", options);
565
+ }
566
+ }
567
+ class NewsletterModule extends BaseClient {
568
+ /**
569
+ * List all subscribed newsletters
570
+ */
571
+ async list(options) {
572
+ return this.get("/newsletter/list", options);
347
573
  }
348
574
  }
349
575
  class WuzapiClient {
@@ -353,6 +579,7 @@ class WuzapiClient {
353
579
  chat;
354
580
  group;
355
581
  webhook;
582
+ newsletter;
356
583
  // Legacy aliases for convenience
357
584
  users;
358
585
  message;
@@ -363,15 +590,16 @@ class WuzapiClient {
363
590
  this.chat = new ChatModule(config);
364
591
  this.group = new GroupModule(config);
365
592
  this.webhook = new WebhookModule(config);
593
+ this.newsletter = new NewsletterModule(config);
366
594
  this.users = this.user;
367
595
  this.message = this.chat;
368
596
  }
369
597
  /**
370
598
  * Test connection to the API
371
599
  */
372
- async ping() {
600
+ async ping(options) {
373
601
  try {
374
- await this.session.getStatus();
602
+ await this.session.getStatus(options);
375
603
  return true;
376
604
  } catch {
377
605
  return false;
@@ -762,6 +990,7 @@ export {
762
990
  ListResponseMessageListType,
763
991
  MediaType,
764
992
  MessageStatus,
993
+ NewsletterModule,
765
994
  PaymentBackgroundType,
766
995
  PeerDataOperationRequestResponseMessagePeerDataOperationResult,
767
996
  PeerDataOperationRequestType,