wuzapi 1.5.4 → 1.6.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/README.md +148 -121
- package/dist/modules/admin.d.ts +2 -6
- package/dist/modules/admin.js +0 -6
- package/dist/modules/admin.js.map +1 -1
- package/dist/modules/chat.d.ts +5 -5
- package/dist/modules/chat.js +30 -5
- package/dist/modules/chat.js.map +1 -1
- package/dist/modules/group.d.ts +3 -3
- package/dist/modules/group.js +20 -15
- package/dist/modules/group.js.map +1 -1
- package/dist/modules/session.d.ts +2 -2
- package/dist/modules/session.js +4 -4
- package/dist/modules/session.js.map +1 -1
- package/dist/modules/user.d.ts +2 -2
- package/dist/modules/user.js +3 -2
- package/dist/modules/user.js.map +1 -1
- package/dist/modules/webhook.d.ts +3 -3
- package/dist/modules/webhook.js +9 -5
- package/dist/modules/webhook.js.map +1 -1
- package/dist/types/admin.d.ts +40 -7
- package/dist/types/chat.d.ts +15 -16
- package/dist/types/common.d.ts +1 -1
- package/dist/types/group.d.ts +13 -16
- package/dist/types/index.js.map +1 -1
- package/dist/types/newsletter.d.ts +41 -12
- package/dist/types/session.d.ts +3 -3
- package/dist/types/user.d.ts +4 -3
- package/dist/types/webhook.d.ts +10 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@ A comprehensive TypeScript client library for the [WuzAPI WhatsApp API](https://
|
|
|
4
4
|
|
|
5
5
|
## 🚀 Features
|
|
6
6
|
|
|
7
|
-
- 🔥 **Full TypeScript Support** - Complete type definitions for all API endpoints
|
|
7
|
+
- 🔥 **Full TypeScript Support** - Complete type definitions for all API endpoints
|
|
8
8
|
- 🏗️ **Modular Architecture** - Organized by functionality (admin, session, chat, user, group, webhook)
|
|
9
9
|
- 🚀 **Promise-based** - Modern async/await support
|
|
10
10
|
- 🛡️ **Error Handling** - Comprehensive error handling with detailed error types
|
|
@@ -52,6 +52,7 @@ await client.chat.sendText({
|
|
|
52
52
|
### Login Options
|
|
53
53
|
|
|
54
54
|
#### Option 1: QR Code (Traditional)
|
|
55
|
+
|
|
55
56
|
```typescript
|
|
56
57
|
// Get QR code for scanning
|
|
57
58
|
const qr = await client.session.getQRCode();
|
|
@@ -59,17 +60,18 @@ console.log("Scan this QR code:", qr.QRCode);
|
|
|
59
60
|
```
|
|
60
61
|
|
|
61
62
|
#### Option 2: Phone Pairing (New!)
|
|
63
|
+
|
|
62
64
|
```typescript
|
|
63
|
-
// Pair using verification code
|
|
64
|
-
await client.session.pairPhone("5491155554444"
|
|
65
|
+
// Pair using phone number (generates verification code)
|
|
66
|
+
await client.session.pairPhone("5491155554444");
|
|
65
67
|
```
|
|
66
68
|
|
|
67
69
|
## 🔧 Configuration
|
|
68
70
|
|
|
69
71
|
```typescript
|
|
70
72
|
interface WuzapiConfig {
|
|
71
|
-
apiUrl: string;
|
|
72
|
-
token?: string;
|
|
73
|
+
apiUrl: string; // Your WuzAPI server URL
|
|
74
|
+
token?: string; // Authentication token (can be provided per request)
|
|
73
75
|
}
|
|
74
76
|
|
|
75
77
|
// Global token approach
|
|
@@ -117,27 +119,29 @@ await client.chat.sendButtons({
|
|
|
117
119
|
});
|
|
118
120
|
|
|
119
121
|
// Send list menu
|
|
120
|
-
await client.chat.sendList(
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
122
|
+
await client.chat.sendList(
|
|
123
|
+
"5491155554444", // Phone
|
|
124
|
+
"View Menu", // Button text
|
|
125
|
+
"Select from menu:", // Description
|
|
126
|
+
"Options", // Top text/title
|
|
127
|
+
[
|
|
128
|
+
{
|
|
129
|
+
// Sections
|
|
130
|
+
Title: "Main Options",
|
|
131
|
+
Rows: [
|
|
132
|
+
{ Title: "Option 1", Desc: "First choice", RowId: "opt1" },
|
|
133
|
+
{ Title: "Option 2", Desc: "Second choice", RowId: "opt2" },
|
|
134
|
+
],
|
|
135
|
+
},
|
|
136
|
+
]
|
|
137
|
+
);
|
|
133
138
|
|
|
134
|
-
// Send poll
|
|
135
|
-
await client.chat.sendPoll(
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
});
|
|
139
|
+
// Send poll (for groups only)
|
|
140
|
+
await client.chat.sendPoll(
|
|
141
|
+
"120362023605733675@g.us", // Group JID
|
|
142
|
+
"What's your favorite color?", // Header
|
|
143
|
+
["Red", "Blue", "Green"] // Options array
|
|
144
|
+
);
|
|
141
145
|
```
|
|
142
146
|
|
|
143
147
|
## 👥 Group Management
|
|
@@ -153,11 +157,7 @@ const group = await client.group.create("My Group", [
|
|
|
153
157
|
const info = await client.group.getInfo(group.JID);
|
|
154
158
|
|
|
155
159
|
// Add participants
|
|
156
|
-
await client.group.updateParticipants(
|
|
157
|
-
group.JID,
|
|
158
|
-
"add",
|
|
159
|
-
["5491155553936"]
|
|
160
|
-
);
|
|
160
|
+
await client.group.updateParticipants(group.JID, "add", ["5491155553936"]);
|
|
161
161
|
|
|
162
162
|
// Set group settings
|
|
163
163
|
await client.group.setName(group.JID, "New Group Name");
|
|
@@ -178,23 +178,27 @@ const info = await client.user.getInfo(["5491155554444"]);
|
|
|
178
178
|
const contacts = await client.user.getContacts();
|
|
179
179
|
|
|
180
180
|
// Send presence status
|
|
181
|
-
await client.user.sendPresence(
|
|
182
|
-
Phone: "5491155554444",
|
|
183
|
-
State: "available",
|
|
184
|
-
});
|
|
181
|
+
await client.user.sendPresence("available");
|
|
185
182
|
```
|
|
186
183
|
|
|
187
184
|
## 🔗 Webhook Setup
|
|
188
185
|
|
|
189
186
|
```typescript
|
|
190
|
-
// Set webhook URL
|
|
191
|
-
await client.webhook.setWebhook("https://your-server.com/webhook"
|
|
187
|
+
// Set webhook URL with events
|
|
188
|
+
await client.webhook.setWebhook("https://your-server.com/webhook", [
|
|
189
|
+
"Message",
|
|
190
|
+
"ReadReceipt",
|
|
191
|
+
]);
|
|
192
192
|
|
|
193
193
|
// Get webhook config
|
|
194
194
|
const config = await client.webhook.getWebhook();
|
|
195
195
|
|
|
196
|
-
// Update webhook
|
|
197
|
-
await client.webhook.updateWebhook(
|
|
196
|
+
// Update webhook with new URL, events, and status
|
|
197
|
+
await client.webhook.updateWebhook(
|
|
198
|
+
"https://new-server.com/webhook",
|
|
199
|
+
["Message", "ReadReceipt"],
|
|
200
|
+
true
|
|
201
|
+
);
|
|
198
202
|
```
|
|
199
203
|
|
|
200
204
|
## 📚 Examples
|
|
@@ -202,7 +206,7 @@ await client.webhook.updateWebhook("https://new-server.com/webhook");
|
|
|
202
206
|
Check out the complete examples in the `examples/` directory:
|
|
203
207
|
|
|
204
208
|
- **[basic-usage.js](examples/basic-usage.js)** - Getting started, connection, basic operations
|
|
205
|
-
- **[advanced-features.js](examples/advanced-features.js)** - Phone pairing, interactive messages, advanced group management
|
|
209
|
+
- **[advanced-features.js](examples/advanced-features.js)** - Phone pairing, interactive messages, advanced group management
|
|
206
210
|
- **[chatbot-example.js](examples/chatbot-example.js)** - Complete bot with commands and auto-replies
|
|
207
211
|
- **[webhook-events-example.js](examples/webhook-events-example.js)** - Comprehensive webhook event handling
|
|
208
212
|
|
|
@@ -212,7 +216,7 @@ Check out the complete examples in the `examples/` directory:
|
|
|
212
216
|
# Basic usage
|
|
213
217
|
node examples/basic-usage.js
|
|
214
218
|
|
|
215
|
-
# Advanced features
|
|
219
|
+
# Advanced features
|
|
216
220
|
node examples/advanced-features.js
|
|
217
221
|
|
|
218
222
|
# Start chatbot
|
|
@@ -231,16 +235,16 @@ const client = new WuzapiClient({
|
|
|
231
235
|
|
|
232
236
|
// Connect and wait for messages
|
|
233
237
|
await client.session.connect({ Subscribe: ["Message"] });
|
|
234
|
-
await client.webhook.setWebhook("https://your-server.com/webhook");
|
|
238
|
+
await client.webhook.setWebhook("https://your-server.com/webhook", ["Message"]);
|
|
235
239
|
|
|
236
240
|
// In your webhook handler:
|
|
237
241
|
app.post("/webhook", async (req, res) => {
|
|
238
242
|
const { event } = req.body;
|
|
239
|
-
|
|
243
|
+
|
|
240
244
|
if (event?.Message?.conversation) {
|
|
241
245
|
const message = event.Message.conversation;
|
|
242
246
|
const from = event.Info.RemoteJid.replace("@s.whatsapp.net", "");
|
|
243
|
-
|
|
247
|
+
|
|
244
248
|
if (message.toLowerCase().includes("hello")) {
|
|
245
249
|
await client.chat.sendText({
|
|
246
250
|
Phone: from,
|
|
@@ -248,7 +252,7 @@ app.post("/webhook", async (req, res) => {
|
|
|
248
252
|
});
|
|
249
253
|
}
|
|
250
254
|
}
|
|
251
|
-
|
|
255
|
+
|
|
252
256
|
res.json({ success: true });
|
|
253
257
|
});
|
|
254
258
|
```
|
|
@@ -261,6 +265,7 @@ app.post("/webhook", async (req, res) => {
|
|
|
261
265
|
<summary><strong>📱 Session Module</strong> - Connection and authentication</summary>
|
|
262
266
|
|
|
263
267
|
### Connection
|
|
268
|
+
|
|
264
269
|
```typescript
|
|
265
270
|
// Connect to WhatsApp
|
|
266
271
|
await client.session.connect({
|
|
@@ -279,21 +284,23 @@ await client.session.logout();
|
|
|
279
284
|
```
|
|
280
285
|
|
|
281
286
|
### Authentication
|
|
287
|
+
|
|
282
288
|
```typescript
|
|
283
289
|
// Get QR code for scanning
|
|
284
290
|
const qr = await client.session.getQRCode();
|
|
285
291
|
|
|
286
|
-
// Pair phone using
|
|
287
|
-
await client.session.pairPhone("5491155554444"
|
|
292
|
+
// Pair phone using phone number (generates verification code)
|
|
293
|
+
await client.session.pairPhone("5491155554444");
|
|
288
294
|
|
|
289
295
|
// Request message history sync
|
|
290
296
|
await client.session.requestHistory();
|
|
291
297
|
|
|
292
298
|
// Configure proxy
|
|
293
|
-
await client.session.setProxy("socks5://user:pass@proxy:port");
|
|
299
|
+
await client.session.setProxy("socks5://user:pass@proxy:port", true);
|
|
294
300
|
```
|
|
295
301
|
|
|
296
302
|
### S3 Storage
|
|
303
|
+
|
|
297
304
|
```typescript
|
|
298
305
|
// Configure S3 storage
|
|
299
306
|
await client.session.configureS3({
|
|
@@ -324,6 +331,7 @@ await client.session.deleteS3Config();
|
|
|
324
331
|
<summary><strong>💬 Chat Module</strong> - Send and manage messages</summary>
|
|
325
332
|
|
|
326
333
|
### Basic Messages
|
|
334
|
+
|
|
327
335
|
```typescript
|
|
328
336
|
// Send text message
|
|
329
337
|
await client.chat.sendText({
|
|
@@ -344,6 +352,7 @@ await client.chat.sendText({
|
|
|
344
352
|
```
|
|
345
353
|
|
|
346
354
|
### Media Messages
|
|
355
|
+
|
|
347
356
|
```typescript
|
|
348
357
|
// Send image
|
|
349
358
|
await client.chat.sendImage({
|
|
@@ -380,6 +389,7 @@ await client.chat.sendSticker({
|
|
|
380
389
|
```
|
|
381
390
|
|
|
382
391
|
### Interactive Messages
|
|
392
|
+
|
|
383
393
|
```typescript
|
|
384
394
|
// Send buttons
|
|
385
395
|
await client.chat.sendButtons({
|
|
@@ -393,46 +403,43 @@ await client.chat.sendButtons({
|
|
|
393
403
|
});
|
|
394
404
|
|
|
395
405
|
// Send list message
|
|
396
|
-
await client.chat.sendList(
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
406
|
+
await client.chat.sendList(
|
|
407
|
+
"5491155554444", // Phone
|
|
408
|
+
"View Menu", // Button text
|
|
409
|
+
"Please select from the menu:", // Description
|
|
410
|
+
"Menu Options", // Top text/title
|
|
411
|
+
[
|
|
402
412
|
{
|
|
413
|
+
// Sections
|
|
403
414
|
Title: "Main Course",
|
|
404
415
|
Rows: [
|
|
405
|
-
{ Title: "Pizza",
|
|
406
|
-
{ Title: "Burger",
|
|
416
|
+
{ Title: "Pizza", Desc: "Delicious pizza", RowId: "pizza" },
|
|
417
|
+
{ Title: "Burger", Desc: "Tasty burger", RowId: "burger" },
|
|
407
418
|
],
|
|
408
419
|
},
|
|
409
|
-
]
|
|
410
|
-
|
|
420
|
+
]
|
|
421
|
+
);
|
|
411
422
|
|
|
412
|
-
// Send poll
|
|
413
|
-
await client.chat.sendPoll(
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
});
|
|
423
|
+
// Send poll (for groups only)
|
|
424
|
+
await client.chat.sendPoll(
|
|
425
|
+
"120362023605733675@g.us", // Group JID
|
|
426
|
+
"What's your favorite color?", // Header
|
|
427
|
+
["Red", "Blue", "Green"] // Options array
|
|
428
|
+
);
|
|
419
429
|
```
|
|
420
430
|
|
|
421
431
|
### Message Management
|
|
432
|
+
|
|
422
433
|
```typescript
|
|
423
434
|
// Delete a message
|
|
424
|
-
await client.chat.deleteMessage(
|
|
425
|
-
Phone: "5491155554444",
|
|
426
|
-
Id: "message-id-to-delete",
|
|
427
|
-
Remote: true, // Delete for everyone
|
|
428
|
-
});
|
|
435
|
+
await client.chat.deleteMessage("message-id-to-delete");
|
|
429
436
|
|
|
430
437
|
// Edit a message
|
|
431
|
-
await client.chat.editMessage(
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
438
|
+
await client.chat.editMessage(
|
|
439
|
+
"message-id-to-edit",
|
|
440
|
+
"5491155554444",
|
|
441
|
+
"This is the updated message text"
|
|
442
|
+
);
|
|
436
443
|
|
|
437
444
|
// React to message
|
|
438
445
|
await client.chat.react({
|
|
@@ -456,6 +463,7 @@ await client.chat.sendPresence({
|
|
|
456
463
|
```
|
|
457
464
|
|
|
458
465
|
### Location and Contacts
|
|
466
|
+
|
|
459
467
|
```typescript
|
|
460
468
|
// Send location
|
|
461
469
|
await client.chat.sendLocation({
|
|
@@ -469,11 +477,13 @@ await client.chat.sendLocation({
|
|
|
469
477
|
await client.chat.sendContact({
|
|
470
478
|
Phone: "5491155554444",
|
|
471
479
|
Name: "John Doe",
|
|
472
|
-
Vcard:
|
|
480
|
+
Vcard:
|
|
481
|
+
"BEGIN:VCARD\nVERSION:3.0\nN:Doe;John;;;\nFN:John Doe\nTEL:+1234567890\nEND:VCARD",
|
|
473
482
|
});
|
|
474
483
|
```
|
|
475
484
|
|
|
476
485
|
### Media Download
|
|
486
|
+
|
|
477
487
|
```typescript
|
|
478
488
|
// Download media
|
|
479
489
|
const media = await client.chat.downloadImage({
|
|
@@ -504,11 +514,7 @@ const avatar = await client.user.getAvatar("5491155554444", true); // true for p
|
|
|
504
514
|
const contacts = await client.user.getContacts();
|
|
505
515
|
|
|
506
516
|
// Send user presence (online/offline status)
|
|
507
|
-
await client.user.sendPresence(
|
|
508
|
-
Phone: "5491155554444",
|
|
509
|
-
State: "available", // or "unavailable"
|
|
510
|
-
LastSeen: Date.now(),
|
|
511
|
-
});
|
|
517
|
+
await client.user.sendPresence("available"); // or "unavailable"
|
|
512
518
|
```
|
|
513
519
|
|
|
514
520
|
</details>
|
|
@@ -517,6 +523,7 @@ await client.user.sendPresence({
|
|
|
517
523
|
<summary><strong>👥 Group Module</strong> - Group management</summary>
|
|
518
524
|
|
|
519
525
|
### Basic Group Operations
|
|
526
|
+
|
|
520
527
|
```typescript
|
|
521
528
|
// List all groups
|
|
522
529
|
const groups = await client.group.list();
|
|
@@ -535,6 +542,7 @@ await client.group.leave("120362023605733675@g.us");
|
|
|
535
542
|
```
|
|
536
543
|
|
|
537
544
|
### Group Settings
|
|
545
|
+
|
|
538
546
|
```typescript
|
|
539
547
|
// Set group name
|
|
540
548
|
await client.group.setName("120362023605733675@g.us", "New Group Name");
|
|
@@ -556,6 +564,7 @@ await client.group.setEphemeral("120362023605733675@g.us", "24h"); // '24h', '7d
|
|
|
556
564
|
```
|
|
557
565
|
|
|
558
566
|
### Group Media
|
|
567
|
+
|
|
559
568
|
```typescript
|
|
560
569
|
// Set group photo (JPEG only)
|
|
561
570
|
await client.group.setPhoto(
|
|
@@ -568,15 +577,20 @@ await client.group.removePhoto("120362023605733675@g.us");
|
|
|
568
577
|
```
|
|
569
578
|
|
|
570
579
|
### Invites and Participants
|
|
580
|
+
|
|
571
581
|
```typescript
|
|
572
582
|
// Get invite link
|
|
573
583
|
const invite = await client.group.getInviteLink("120362023605733675@g.us");
|
|
574
584
|
|
|
575
585
|
// Join a group using invite link
|
|
576
|
-
const joinResult = await client.group.join(
|
|
586
|
+
const joinResult = await client.group.join(
|
|
587
|
+
"https://chat.whatsapp.com/XXXXXXXXX"
|
|
588
|
+
);
|
|
577
589
|
|
|
578
590
|
// Get group invite information
|
|
579
|
-
const inviteInfo = await client.group.getInviteInfo(
|
|
591
|
+
const inviteInfo = await client.group.getInviteInfo(
|
|
592
|
+
"https://chat.whatsapp.com/XXXXXXXXX"
|
|
593
|
+
);
|
|
580
594
|
|
|
581
595
|
// Update group participants (add, remove, promote, demote)
|
|
582
596
|
await client.group.updateParticipants(
|
|
@@ -595,37 +609,39 @@ await client.group.updateParticipants(
|
|
|
595
609
|
// List all users
|
|
596
610
|
const users = await client.admin.listUsers({ token: "admin-token" });
|
|
597
611
|
|
|
598
|
-
// Get a specific user by ID
|
|
599
|
-
const user = await client.admin.getUser(2, { token: "admin-token" });
|
|
600
|
-
|
|
601
612
|
// Add new user
|
|
602
|
-
const newUser = await client.admin.addUser(
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
613
|
+
const newUser = await client.admin.addUser(
|
|
614
|
+
{
|
|
615
|
+
name: "John Doe",
|
|
616
|
+
token: "user-token-123",
|
|
617
|
+
webhook: "https://example.com/webhook",
|
|
618
|
+
events: "Message,ReadReceipt", // optional
|
|
619
|
+
proxyConfig: {
|
|
620
|
+
enabled: true,
|
|
621
|
+
proxyURL: "socks5://user:pass@proxy:port",
|
|
622
|
+
},
|
|
623
|
+
s3Config: {
|
|
624
|
+
enabled: true,
|
|
625
|
+
endpoint: "https://s3.amazonaws.com",
|
|
626
|
+
region: "us-east-1",
|
|
627
|
+
bucket: "user-media-bucket",
|
|
628
|
+
accessKey: "AKIA...",
|
|
629
|
+
secretKey: "secret...",
|
|
630
|
+
pathStyle: false,
|
|
631
|
+
mediaDelivery: "both",
|
|
632
|
+
retentionDays: 30,
|
|
633
|
+
},
|
|
621
634
|
},
|
|
622
|
-
|
|
635
|
+
{ token: "admin-token" }
|
|
636
|
+
);
|
|
623
637
|
|
|
624
|
-
// Delete user
|
|
625
|
-
await client.admin.deleteUser(
|
|
638
|
+
// Delete user by ID (ID is a string)
|
|
639
|
+
await client.admin.deleteUser("user-id-string", { token: "admin-token" });
|
|
626
640
|
|
|
627
641
|
// Delete user completely (full deletion including all data)
|
|
628
|
-
await client.admin.deleteUserComplete(
|
|
642
|
+
await client.admin.deleteUserComplete("user-id-string", {
|
|
643
|
+
token: "admin-token",
|
|
644
|
+
});
|
|
629
645
|
```
|
|
630
646
|
|
|
631
647
|
</details>
|
|
@@ -634,16 +650,23 @@ await client.admin.deleteUserComplete(2, { token: "admin-token" });
|
|
|
634
650
|
<summary><strong>🔗 Webhook Module</strong> - Webhook configuration</summary>
|
|
635
651
|
|
|
636
652
|
```typescript
|
|
637
|
-
// Set webhook URL
|
|
638
|
-
await client.webhook.setWebhook("https://my-server.com/webhook"
|
|
653
|
+
// Set webhook URL with specific events
|
|
654
|
+
await client.webhook.setWebhook("https://my-server.com/webhook", [
|
|
655
|
+
"Message",
|
|
656
|
+
"ReadReceipt",
|
|
657
|
+
]);
|
|
639
658
|
|
|
640
659
|
// Get current webhook configuration
|
|
641
660
|
const webhookConfig = await client.webhook.getWebhook();
|
|
642
661
|
console.log("Webhook URL:", webhookConfig.webhook);
|
|
643
662
|
console.log("Subscribed events:", webhookConfig.subscribe);
|
|
644
663
|
|
|
645
|
-
// Update webhook URL
|
|
646
|
-
await client.webhook.updateWebhook(
|
|
664
|
+
// Update webhook URL, events, and status
|
|
665
|
+
await client.webhook.updateWebhook(
|
|
666
|
+
"https://my-new-server.com/webhook",
|
|
667
|
+
["Message", "ReadReceipt", "Presence"],
|
|
668
|
+
true
|
|
669
|
+
);
|
|
647
670
|
|
|
648
671
|
// Delete webhook configuration
|
|
649
672
|
await client.webhook.deleteWebhook();
|
|
@@ -691,22 +714,22 @@ const client = new WuzapiClient({
|
|
|
691
714
|
app.post("/webhook", async (req, res) => {
|
|
692
715
|
try {
|
|
693
716
|
const webhookPayload = req.body;
|
|
694
|
-
|
|
717
|
+
|
|
695
718
|
// Handle S3 media if present
|
|
696
719
|
if (hasS3Media(webhookPayload)) {
|
|
697
720
|
console.log("S3 Media:", webhookPayload.s3.url);
|
|
698
721
|
}
|
|
699
|
-
|
|
722
|
+
|
|
700
723
|
const event = webhookPayload.event || webhookPayload;
|
|
701
|
-
|
|
724
|
+
|
|
702
725
|
// Handle messages
|
|
703
726
|
if (event.Message && event.Info) {
|
|
704
727
|
const messageContent = getMessageContent(event.Message);
|
|
705
728
|
const from = event.Info.RemoteJid.replace("@s.whatsapp.net", "");
|
|
706
|
-
|
|
729
|
+
|
|
707
730
|
if (messageContent?.type === "text") {
|
|
708
731
|
console.log(`Message from ${from}: ${messageContent.content}`);
|
|
709
|
-
|
|
732
|
+
|
|
710
733
|
// Auto-reply
|
|
711
734
|
if (messageContent.content.toLowerCase().includes("hello")) {
|
|
712
735
|
await client.chat.sendText({
|
|
@@ -716,7 +739,7 @@ app.post("/webhook", async (req, res) => {
|
|
|
716
739
|
}
|
|
717
740
|
}
|
|
718
741
|
}
|
|
719
|
-
|
|
742
|
+
|
|
720
743
|
res.json({ success: true });
|
|
721
744
|
} catch (error) {
|
|
722
745
|
console.error("Webhook error:", error);
|
|
@@ -743,7 +766,10 @@ switch (messageContent?.type) {
|
|
|
743
766
|
console.log("Button clicked:", messageContent.content.selectedButtonId);
|
|
744
767
|
break;
|
|
745
768
|
case "listResponse":
|
|
746
|
-
console.log(
|
|
769
|
+
console.log(
|
|
770
|
+
"List selection:",
|
|
771
|
+
messageContent.content.singleSelectReply?.selectedRowId
|
|
772
|
+
);
|
|
747
773
|
break;
|
|
748
774
|
// ... handle other types
|
|
749
775
|
}
|
|
@@ -778,8 +804,9 @@ try {
|
|
|
778
804
|
```
|
|
779
805
|
|
|
780
806
|
### Common Error Codes
|
|
807
|
+
|
|
781
808
|
- **401**: Authentication required
|
|
782
|
-
- **404**: Endpoint not found
|
|
809
|
+
- **404**: Endpoint not found
|
|
783
810
|
- **500**: Server error
|
|
784
811
|
|
|
785
812
|
</details>
|
|
@@ -794,7 +821,7 @@ import { BaseClient } from "wuzapi";
|
|
|
794
821
|
class CustomClient extends BaseClient {
|
|
795
822
|
constructor(config) {
|
|
796
823
|
super(config);
|
|
797
|
-
|
|
824
|
+
|
|
798
825
|
// Add custom interceptors
|
|
799
826
|
this.axios.interceptors.request.use((config) => {
|
|
800
827
|
console.log("Making request:", config.url);
|
package/dist/modules/admin.d.ts
CHANGED
|
@@ -10,16 +10,12 @@ export declare class AdminModule extends BaseClient {
|
|
|
10
10
|
* Add a new user
|
|
11
11
|
*/
|
|
12
12
|
addUser(user: CreateUserRequest, options?: RequestOptions): Promise<CreateUserResponse>;
|
|
13
|
-
/**
|
|
14
|
-
* Get a specific user by ID
|
|
15
|
-
*/
|
|
16
|
-
getUser(id: number, options?: RequestOptions): Promise<User>;
|
|
17
13
|
/**
|
|
18
14
|
* Delete a user by ID
|
|
19
15
|
*/
|
|
20
|
-
deleteUser(id:
|
|
16
|
+
deleteUser(id: string, options?: RequestOptions): Promise<DeleteUserResponse>;
|
|
21
17
|
/**
|
|
22
18
|
* Delete a user completely (full deletion) by ID
|
|
23
19
|
*/
|
|
24
|
-
deleteUserComplete(id:
|
|
20
|
+
deleteUserComplete(id: string, options?: RequestOptions): Promise<DeleteUserResponse>;
|
|
25
21
|
}
|
package/dist/modules/admin.js
CHANGED
|
@@ -14,12 +14,6 @@ class AdminModule extends client.BaseClient {
|
|
|
14
14
|
async addUser(user, options) {
|
|
15
15
|
return this.post("/admin/users", user, options);
|
|
16
16
|
}
|
|
17
|
-
/**
|
|
18
|
-
* Get a specific user by ID
|
|
19
|
-
*/
|
|
20
|
-
async getUser(id, options) {
|
|
21
|
-
return this.get(`/admin/users/${id}`, options);
|
|
22
|
-
}
|
|
23
17
|
/**
|
|
24
18
|
* Delete a user by ID
|
|
25
19
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"admin.js","sources":["../../src/modules/admin.ts"],"sourcesContent":["import { BaseClient } from \"../client.js\";\nimport { RequestOptions } from \"../types/common.js\";\nimport {\n User,\n CreateUserRequest,\n CreateUserResponse,\n DeleteUserResponse,\n} from \"../types/admin.js\";\n\nexport class AdminModule extends BaseClient {\n /**\n * List all users\n */\n async listUsers(options?: RequestOptions): Promise<User[]> {\n return this.get<User[]>(\"/admin/users\", options);\n }\n\n /**\n * Add a new user\n */\n async addUser(\n user: CreateUserRequest,\n options?: RequestOptions\n ): Promise<CreateUserResponse> {\n return this.post<CreateUserResponse>(\"/admin/users\", user, options);\n }\n\n /**\n *
|
|
1
|
+
{"version":3,"file":"admin.js","sources":["../../src/modules/admin.ts"],"sourcesContent":["import { BaseClient } from \"../client.js\";\nimport { RequestOptions } from \"../types/common.js\";\nimport {\n User,\n CreateUserRequest,\n CreateUserResponse,\n DeleteUserResponse,\n} from \"../types/admin.js\";\n\nexport class AdminModule extends BaseClient {\n /**\n * List all users\n */\n async listUsers(options?: RequestOptions): Promise<User[]> {\n return this.get<User[]>(\"/admin/users\", options);\n }\n\n /**\n * Add a new user\n */\n async addUser(\n user: CreateUserRequest,\n options?: RequestOptions\n ): Promise<CreateUserResponse> {\n return this.post<CreateUserResponse>(\"/admin/users\", user, options);\n }\n\n /**\n * Delete a user by ID\n */\n async deleteUser(\n id: string,\n options?: RequestOptions\n ): Promise<DeleteUserResponse> {\n return this.delete<DeleteUserResponse>(`/admin/users/${id}`, options);\n }\n\n /**\n * Delete a user completely (full deletion) by ID\n */\n async deleteUserComplete(\n id: string,\n options?: RequestOptions\n ): Promise<DeleteUserResponse> {\n return this.delete<DeleteUserResponse>(`/admin/users/${id}/full`, options);\n }\n}\n"],"names":["BaseClient"],"mappings":";;;AASO,MAAM,oBAAoBA,OAAAA,WAAW;AAAA;AAAA;AAAA;AAAA,EAI1C,MAAM,UAAU,SAA2C;AACzD,WAAO,KAAK,IAAY,gBAAgB,OAAO;AAAA,EACjD;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,QACJ,MACA,SAC6B;AAC7B,WAAO,KAAK,KAAyB,gBAAgB,MAAM,OAAO;AAAA,EACpE;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,WACJ,IACA,SAC6B;AAC7B,WAAO,KAAK,OAA2B,gBAAgB,EAAE,IAAI,OAAO;AAAA,EACtE;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,mBACJ,IACA,SAC6B;AAC7B,WAAO,KAAK,OAA2B,gBAAgB,EAAE,SAAS,OAAO;AAAA,EAC3E;AACF;;"}
|
package/dist/modules/chat.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BaseClient } from '../client.js';
|
|
2
2
|
import { RequestOptions } from '../types/common.js';
|
|
3
|
-
import { SendMessageResponse, SendTextRequest, SendTemplateRequest, SendAudioRequest, SendImageRequest, SendDocumentRequest, SendVideoRequest, SendStickerRequest, SendLocationRequest, SendContactRequest, ChatPresenceRequest, MarkReadRequest, ReactRequest, DownloadMediaRequest, DownloadMediaResponse,
|
|
3
|
+
import { SendMessageResponse, SendTextRequest, SendTemplateRequest, SendAudioRequest, SendImageRequest, SendDocumentRequest, SendVideoRequest, SendStickerRequest, SendLocationRequest, SendContactRequest, ChatPresenceRequest, MarkReadRequest, ReactRequest, DownloadMediaRequest, DownloadMediaResponse, DeleteMessageResponse, SendButtonsRequest, ListSection } from '../types/chat.js';
|
|
4
4
|
export declare class ChatModule extends BaseClient {
|
|
5
5
|
/**
|
|
6
6
|
* Send a text message
|
|
@@ -69,7 +69,7 @@ export declare class ChatModule extends BaseClient {
|
|
|
69
69
|
/**
|
|
70
70
|
* Delete a message
|
|
71
71
|
*/
|
|
72
|
-
deleteMessage(
|
|
72
|
+
deleteMessage(messageId: string, options?: RequestOptions): Promise<DeleteMessageResponse>;
|
|
73
73
|
/**
|
|
74
74
|
* Send interactive buttons message
|
|
75
75
|
*/
|
|
@@ -77,13 +77,13 @@ export declare class ChatModule extends BaseClient {
|
|
|
77
77
|
/**
|
|
78
78
|
* Send list message
|
|
79
79
|
*/
|
|
80
|
-
sendList(
|
|
80
|
+
sendList(phone: string, buttonText: string, description: string, topText: string, sections?: ListSection[], footerText?: string, id?: string, options?: RequestOptions): Promise<SendMessageResponse>;
|
|
81
81
|
/**
|
|
82
82
|
* Send poll message
|
|
83
83
|
*/
|
|
84
|
-
sendPoll(
|
|
84
|
+
sendPoll(groupJID: string, header: string, options: string[], id?: string, requestOptions?: RequestOptions): Promise<SendMessageResponse>;
|
|
85
85
|
/**
|
|
86
86
|
* Edit a message
|
|
87
87
|
*/
|
|
88
|
-
editMessage(
|
|
88
|
+
editMessage(messageId: string, phone: string, newBody: string, options?: RequestOptions): Promise<SendMessageResponse>;
|
|
89
89
|
}
|