@raphaelvserafim/client-api-whatsapp 1.0.8 → 1.2.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.
Files changed (60) hide show
  1. package/README.md +512 -297
  2. package/dist/WhatsApp.d.ts +142 -31
  3. package/dist/WhatsApp.js +111 -167
  4. package/dist/WhatsApp.js.map +1 -1
  5. package/dist/client/HttpClient.d.ts +6 -0
  6. package/dist/client/HttpClient.js +29 -0
  7. package/dist/client/HttpClient.js.map +1 -0
  8. package/dist/client/IHttpClient.d.ts +9 -0
  9. package/dist/client/IHttpClient.js +3 -0
  10. package/dist/client/IHttpClient.js.map +1 -0
  11. package/dist/errors.d.ts +5 -0
  12. package/dist/errors.js +13 -0
  13. package/dist/errors.js.map +1 -0
  14. package/dist/index.d.ts +14 -1
  15. package/dist/index.js +33 -3
  16. package/dist/index.js.map +1 -1
  17. package/dist/services/ActionService.d.ts +9 -0
  18. package/dist/services/ActionService.js +32 -0
  19. package/dist/services/ActionService.js.map +1 -0
  20. package/dist/services/BusinessService.d.ts +10 -0
  21. package/dist/services/BusinessService.js +43 -0
  22. package/dist/services/BusinessService.js.map +1 -0
  23. package/dist/services/CallService.d.ts +8 -0
  24. package/dist/services/CallService.js +24 -0
  25. package/dist/services/CallService.js.map +1 -0
  26. package/dist/services/ChatService.d.ts +16 -0
  27. package/dist/services/ChatService.js +38 -0
  28. package/dist/services/ChatService.js.map +1 -0
  29. package/dist/services/CommunityService.d.ts +28 -0
  30. package/dist/services/CommunityService.js +76 -0
  31. package/dist/services/CommunityService.js.map +1 -0
  32. package/dist/services/ContactService.d.ts +15 -0
  33. package/dist/services/ContactService.js +30 -0
  34. package/dist/services/ContactService.js.map +1 -0
  35. package/dist/services/GroupService.d.ts +32 -0
  36. package/dist/services/GroupService.js +104 -0
  37. package/dist/services/GroupService.js.map +1 -0
  38. package/dist/services/InstanceService.d.ts +28 -0
  39. package/dist/services/InstanceService.js +124 -0
  40. package/dist/services/InstanceService.js.map +1 -0
  41. package/dist/services/LabelService.d.ts +17 -0
  42. package/dist/services/LabelService.js +43 -0
  43. package/dist/services/LabelService.js.map +1 -0
  44. package/dist/services/MessageService.d.ts +51 -0
  45. package/dist/services/MessageService.js +106 -0
  46. package/dist/services/MessageService.js.map +1 -0
  47. package/dist/types/index.d.ts +155 -11
  48. package/dist/types/index.js +10 -0
  49. package/dist/types/index.js.map +1 -1
  50. package/package.json +6 -11
  51. package/.babelrc +0 -3
  52. package/dist/exemple.d.ts +0 -1
  53. package/dist/exemple.js +0 -264
  54. package/dist/exemple.js.map +0 -1
  55. package/src/WhatsApp.ts +0 -245
  56. package/src/exemple.ts +0 -312
  57. package/src/index.ts +0 -2
  58. package/src/types/index.ts +0 -190
  59. package/tsconfig.compile.json +0 -15
  60. package/tsconfig.json +0 -35
package/README.md CHANGED
@@ -2,23 +2,22 @@
2
2
 
3
3
  ## About Our WhatsApp API
4
4
 
5
- 🔓 **Unlock the Potential of WhatsApp:** Powerful Integration with Our Unofficial API!
5
+ **Unlock the Potential of WhatsApp:** Powerful Integration with Our Unofficial API!
6
6
 
7
7
  ### Efficient Group Management on WhatsApp
8
8
 
9
- 📋 Our stable, though unofficial, API allows for efficient management of WhatsApp groups. Simplify administration, and easily add or remove members.
9
+ Our stable, though unofficial, API allows for efficient management of WhatsApp groups. Simplify administration, and easily add or remove members.
10
10
 
11
11
  ### Versatile Message Sending
12
12
 
13
- 💬 With our API, you can send text, audio, video, and image messages quickly and easily. Adapt to your business communication needs comprehensively.
13
+ With our API, you can send text, audio, video, and image messages quickly and easily. Adapt to your business communication needs comprehensively.
14
14
 
15
15
  ### Receive Instant Events
16
16
 
17
- 🔔 Stay updated with our API, receiving real-time events when new messages are received. Stay connected and agile in responding to interactions on WhatsApp.
17
+ Stay updated with our API, receiving real-time events when new messages are received. Stay connected and agile in responding to interactions on WhatsApp.
18
18
 
19
- 🔗 **Create Your Account:** Visit [https://api-wa.me/sign-up](https://api-wa.me/sign-up) to create your account and start using our API today!
19
+ **Create Your Account:** Visit [https://api-wa.me/sign-up](https://api-wa.me/sign-up) to create your account and start using our API today!
20
20
 
21
- 🎁 **Special Discount:** Use the coupon **GIT20** and get 20% off on your first instance!
22
21
 
23
22
  ## Contact Support
24
23
 
@@ -27,364 +26,580 @@
27
26
  - **Website:** [https://api-wa.me](https://api-wa.me)
28
27
 
29
28
  ## Installation
29
+
30
30
  ```bash
31
31
  npm i @raphaelvserafim/client-api-whatsapp
32
32
  ```
33
+
33
34
  ```bash
34
35
  yarn add @raphaelvserafim/client-api-whatsapp
35
36
  ```
36
37
 
37
- ```js
38
- import { WhatsApp, StatusPresence, TypeMessage, } from '@raphaelvserafim/client-api-whatsapp';
38
+ ## Quick Start
39
39
 
40
- const whatsapp = new WhatsApp({ server: "https://us.api-wa.me", key: "12345678" });
40
+ ```ts
41
+ import { WhatsApp, TypeMessage, StatusPresence } from '@raphaelvserafim/client-api-whatsapp';
41
42
 
42
- const to = "559999999999" // If you want to send it to the group = 123456789@us
43
- ```
43
+ const wa = new WhatsApp({ server: "https://us.api-wa.me", key: "YOUR_KEY" });
44
44
 
45
- ### Get Information
46
- ```js
47
- whatsapp.info().then((response) => {
48
- console.log(response)
49
- }).catch(console.error)
45
+ const to = "559999999999"; // Group: "123456789@g.us"
50
46
  ```
51
47
 
52
- ### Connect to WhatsApp
53
- ```js
54
- whatsapp.connect().then((response) => {
55
- console.log(response)
56
- }).catch(console.error);
48
+ > **Backward Compatible:** All legacy methods (`wa.sendMessage()`, `wa.groups()`, etc.) still work. The new service-based API is optional.
49
+
50
+ ---
51
+
52
+ ## Instance
53
+
54
+ ```ts
55
+ // Connect via QR Code
56
+ const qr = await wa.instance.connect();
57
+
58
+ // Connect via Pairing Code
59
+ const code = await wa.instance.pairingCode("559999999999");
60
+
61
+ // Get instance info
62
+ const info = await wa.instance.info();
63
+
64
+ // Logout
65
+ await wa.instance.logout();
66
+
67
+ // Restart
68
+ await wa.instance.restart();
69
+
70
+ // Settings
71
+ await wa.instance.setting({
72
+ markMessageRead: true,
73
+ saveMedia: false,
74
+ receiveStatusMessage: false,
75
+ receivePresence: false,
76
+ });
77
+
78
+ // Webhook
79
+ await wa.instance.updateWebhook({
80
+ allowWebhook: true,
81
+ allowNumber: "all",
82
+ webhookMessage: "https://your-webhook.com/message",
83
+ webhookGroup: "",
84
+ webhookConnection: "",
85
+ webhookQrCode: "",
86
+ webhookMessageFromMe: "",
87
+ webhookHistory: "",
88
+ });
89
+
90
+ // Webhook Statistics
91
+ const stats = await wa.instance.webhookStatistics();
92
+
93
+ // Profile
94
+ await wa.instance.updateProfileName("My Bot");
95
+ await wa.instance.updateProfileStatus("Online");
96
+ await wa.instance.updateProfilePicture("https://avatars.githubusercontent.com/u/68257896");
97
+ await wa.instance.removeProfilePicture();
98
+
99
+ // Proxy
100
+ await wa.instance.setProxy("http://user:pass@ip:port");
101
+
102
+ // MongoDB
103
+ await wa.instance.addMongoDb("mongodb+srv://...", "mydb");
104
+
105
+ // Mobile Registration (3 steps)
106
+ await wa.instance.mobileRegisterPrepare({
107
+ phoneNumberCountryCode: "55",
108
+ phoneNumberNationalNumber: "99999999999",
109
+ phoneNumberMobileCountryCode: "724",
110
+ phoneNumberMobileNetworkCode: "11",
111
+ });
112
+ await wa.instance.mobileRequestCode("sms");
113
+ await wa.instance.mobileVerifyCode("123456");
57
114
  ```
58
115
 
59
- ### Logout
60
- ```js
61
- whatsapp.logout().then((response) => {
62
- console.log(response)
63
- }).catch(console.error);
64
- ```
116
+ ## Messages
65
117
 
66
- ### Get Contacts
67
- ```js
68
- whatsapp.contacts().then((response) => {
69
- console.log(response)
70
- }).catch(console.error)
71
- ```
118
+ ### Send Messages
72
119
 
73
- ## Send Messages
120
+ ```ts
121
+ // Text
122
+ await wa.message.send({
123
+ type: TypeMessage.TEXT,
124
+ body: { to, text: "Hello!" },
125
+ });
74
126
 
75
- ### Presence
76
- ```js
77
- whatsapp.sendMessage({
78
- type: TypeMessage.PRESENCE,
127
+ // Image
128
+ await wa.message.send({
129
+ type: TypeMessage.IMAGE,
130
+ body: { to, url: "https://a.cdn-hotels.com/gdcs/production190/d988/1071675e-1bd7-4a81-8b40-735eb9241410.jpg", caption: "Toronto" },
131
+ });
132
+
133
+ // Audio
134
+ await wa.message.send({
135
+ type: TypeMessage.AUDIO,
136
+ body: { to, url: "https://www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3" },
137
+ });
138
+
139
+ // Video
140
+ await wa.message.send({
141
+ type: TypeMessage.VIDEO,
142
+ body: { to, url: "https://www.w3schools.com/html/mov_bbb.mp4", caption: "Big Buck Bunny" },
143
+ });
144
+
145
+ // Document
146
+ await wa.message.send({
147
+ type: TypeMessage.DOCUMENT,
148
+ body: { to, url: "https://raphaelvserafim.com/RaphaelSerafimResume.pdf", mimetype: "application/pdf", fileName: "Resume.pdf" },
149
+ });
150
+
151
+ // Contact
152
+ await wa.message.send({
153
+ type: TypeMessage.CONTACT,
79
154
  body: {
80
- to: to,
81
- status: StatusPresence.COMPOSING
82
- }
83
- }).then((response) => {
84
- console.log(response)
85
- }).catch(console.error)
86
- ```
155
+ to,
156
+ contact: { fullName: "Raphael", phoneNumber: "559999999999", organization: "api-wa.me" },
157
+ },
158
+ });
87
159
 
88
- ### Text
89
- ```js
90
- whatsapp.sendMessage({
91
- type: TypeMessage.TEXT,
160
+ // Location
161
+ await wa.message.send({
162
+ type: TypeMessage.LOCATION,
92
163
  body: {
93
- to: to,
94
- text: "Hey"
95
- }
96
- }).then((response) => {
97
- console.log(response)
98
- }).catch(console.error)
164
+ to,
165
+ location: { latitude: 37.7749, longitude: -122.4194, address: "San Francisco, CA" },
166
+ },
167
+ });
168
+
169
+ // Reaction
170
+ await wa.message.send({
171
+ type: TypeMessage.REACTION,
172
+ body: { to, msgId: "MESSAGE_ID", text: "👍" },
173
+ });
174
+
175
+ // Link Preview
176
+ await wa.message.send({
177
+ type: TypeMessage.LINK,
178
+ body: {
179
+ to,
180
+ title: "API WhatsApp",
181
+ text: "Check out our API",
182
+ description: "Powerful WhatsApp integration",
183
+ thumbnailUrl: "https://avatars.githubusercontent.com/u/68257896",
184
+ sourceUrl: "https://api-wa.me",
185
+ },
186
+ });
187
+
188
+ // Title with Footer
189
+ await wa.message.send({
190
+ type: TypeMessage.TITLE,
191
+ body: { to, title: "Order #123", text: "Your order is ready", footer: "Thank you!" },
192
+ });
193
+
194
+ // Presence
195
+ await wa.message.send({
196
+ type: TypeMessage.PRESENCE,
197
+ body: { to, status: StatusPresence.COMPOSING },
198
+ });
99
199
  ```
100
200
 
201
+ ### Reply to a Message
101
202
 
102
- ### Cobrança Pix
103
- ```js
104
- whatsapp.sendMessage({
105
- type: TypeMessage.BUTTON_PIX,
106
- body: {
107
- to: "14375223417",
108
- title: "Pizza",
109
- text: "Pizza ",
110
- referenceId: "apiwame",
111
- code: "0020",
112
- key: "23711695000115",
113
- merchantName: "CACHE SISTEMAS WEB",
114
- keyType: "CNPJ",
115
- items: [
116
- {
117
- id: "123",
118
- name: "Pizza G",
119
- price: 10,
120
- quantity: 10
121
- },
122
- ],
123
- subtotal: "90",
124
- totalAmount: "100"
125
- }
126
- }).then((response) => {
127
- console.log(response)
128
- }).catch(console.error)
203
+ Pass `true` as second argument and include `msgId`:
204
+
205
+ ```ts
206
+ await wa.message.send({
207
+ type: TypeMessage.TEXT,
208
+ body: { to, text: "This is a reply!", msgId: "ORIGINAL_MSG_ID" },
209
+ }, true);
129
210
  ```
130
211
 
212
+ ### Button Messages
131
213
 
132
- ### Buttons Reply
133
- ```js
134
- whatsapp.sendMessage({
214
+ ```ts
215
+ // Quick Reply Buttons
216
+ await wa.message.send({
135
217
  type: TypeMessage.BUTTON_REPLY,
136
218
  body: {
137
- to: "14375223417",
138
- header: {
139
- title: "Example Header",
219
+ to,
220
+ header: { title: "Choose an option" },
221
+ text: "What do you prefer?",
222
+ footer: "Select one",
223
+ buttons: [
224
+ { type: "quick_reply", id: "1", text: "Yes" },
225
+ { type: "quick_reply", id: "2", text: "No" },
226
+ ],
140
227
  },
141
- text: "This is a test",
142
- footer: "choose an option",
143
- buttons: [
144
- {
145
- type: "quick_reply",
146
- id: "uniqId1",
147
- text: "Yes"
148
- },
149
- {
150
- type: "quick_reply",
151
- id: "uniqId2",
152
- text: "No"
153
- }
154
- ]
155
- }
156
- }).then((response) => {
157
- console.log(response)
158
- }).catch(console.error)
159
- ```
160
-
228
+ });
161
229
 
162
- ### Buttons ACTION
163
- ```js
164
- whatsapp.sendMessage({
230
+ // Call to Action Buttons
231
+ await wa.message.send({
165
232
  type: TypeMessage.BUTTON_ACTION,
166
233
  body: {
167
- to: "14375223417",
168
- header: {
169
- title: "Example Header",
234
+ to,
235
+ header: { title: "Actions" },
236
+ text: "Choose an action",
237
+ footer: "Select one",
238
+ buttons: [
239
+ { type: "cta_url", url: "https://api-wa.me", text: "Visit website" },
240
+ { type: "cta_call", phone_number: "+559999999999", text: "Call us" },
241
+ { type: "cta_copy", copy_code: "PROMO2025", text: "Copy code" },
242
+ ],
170
243
  },
171
- text: "This is a test",
172
- footer: "choose an option",
173
- buttons: [
174
- {
175
- type: "cta_copy",
176
- copy_code: "1234567890",
177
- text: "Copy barcode"
178
- },
179
- {
180
- type: "cta_url",
181
- url: "https://api-wa.me",
182
- text: "Access the website"
244
+ });
245
+
246
+ // Buttons with Media Header
247
+ await wa.message.send({
248
+ type: TypeMessage.BUTTON_REPLY,
249
+ body: {
250
+ to,
251
+ header: {
252
+ title: "Check this out",
253
+ hasMediaAttachment: true,
254
+ imageMessage: { url: "https://a.cdn-hotels.com/gdcs/production190/d988/1071675e-1bd7-4a81-8b40-735eb9241410.jpg" },
183
255
  },
184
- {
185
- type: "cta_call",
186
- phone_number: "+5566996852025",
187
- text: "Call us"
188
- }
189
- ]
190
- }
191
- }).then((response) => {
192
- console.log(response)
193
- }).catch(console.error)
256
+ text: "What do you think?",
257
+ buttons: [
258
+ { type: "quick_reply", id: "1", text: "Like" },
259
+ { type: "quick_reply", id: "2", text: "Dislike" },
260
+ ],
261
+ },
262
+ });
194
263
  ```
195
264
 
196
-
197
265
  ### List Menu
198
- ```js
199
- whatsapp.sendMessage({
266
+
267
+ ```ts
268
+ await wa.message.send({
200
269
  type: TypeMessage.MENU,
201
270
  body: {
202
- to: "14375223417",
203
- buttonText: "Menu",
204
- text: "string",
205
- title: "Menu",
206
- description: "Description",
207
- footer: "footer",
208
- sections: [
209
- {
210
- title: "Pizza",
211
- rows: [
212
- {
213
- title: "Pizza 01",
214
- description: "Example pizza 01",
215
- rowId: "1"
216
- }
217
- ]
218
- }
219
- ]
220
- }
221
- }).then((response) => {
222
- console.log(response)
223
- }).catch(console.error)
271
+ to,
272
+ buttonText: "View Menu",
273
+ text: "Choose an item",
274
+ title: "Menu",
275
+ description: "Our products",
276
+ footer: "Prices may vary",
277
+ sections: [
278
+ {
279
+ title: "Pizzas",
280
+ rows: [
281
+ { title: "Margherita", description: "Classic cheese pizza", rowId: "1" },
282
+ { title: "Pepperoni", description: "Spicy pepperoni", rowId: "2" },
283
+ ],
284
+ },
285
+ {
286
+ title: "Drinks",
287
+ rows: [
288
+ { title: "Cola", description: "350ml", rowId: "3" },
289
+ ],
290
+ },
291
+ ],
292
+ },
293
+ });
224
294
  ```
225
295
 
226
- ### POLL
227
- ```js
228
- whatsapp.sendMessage({
296
+ ### Poll / Survey
297
+
298
+ ```ts
299
+ // Survey (via sendMessage)
300
+ await wa.message.send({
229
301
  type: TypeMessage.POLL,
230
- body: {
231
- to: "14375223417",
232
- name: "Do you like PHP?",
233
- options: [
234
- "Yes",
235
- "No"
236
- ],
237
- }
238
- }).then((response) => {
239
- console.log(response)
240
- }).catch(console.error)
302
+ body: { to, name: "Do you like TypeScript?", options: ["Yes", "No"] },
303
+ });
304
+
305
+ // Poll (dedicated method with selectableCount)
306
+ await wa.message.sendPoll(to, "Favorite language?", ["TypeScript", "Python", "Go"], 1);
241
307
  ```
242
308
 
243
- ### Link
244
- ```js
245
- whatsapp.sendMessage({
246
- type: TypeMessage.LINK,
309
+ ### PIX Payment
310
+
311
+ ```ts
312
+ await wa.message.send({
313
+ type: TypeMessage.BUTTON_PIX,
247
314
  body: {
248
- to: to,
249
- text: "\n",
250
- title:"API WhatsApp",
251
- description:"Simplify communication, send messages in a versatile way and achieve exceptional results for your business",
252
- thumbnailUrl:"",
253
- sourceUrl:"https://api-wa.me",
254
- }
255
- }).then((response) => {
256
- console.log(response)
257
- }).catch(console.error)
315
+ to,
316
+ title: "Pizza Order",
317
+ text: "Your order details",
318
+ referenceId: "order-123",
319
+ code: "0020101021226700014br.gov.bcb.pix",
320
+ key: "23711695000115",
321
+ merchantName: "MY STORE",
322
+ keyType: "CNPJ",
323
+ items: [
324
+ { id: "1", name: "Pizza G", price: 45, quantity: 2 },
325
+ { id: "2", name: "Soda", price: 8, quantity: 2 },
326
+ ],
327
+ subtotal: "106",
328
+ totalAmount: "106",
329
+ },
330
+ });
258
331
  ```
259
332
 
260
- ### Audio
261
- ```js
262
- whatsapp.sendMessage({
263
- type: TypeMessage.AUDIO,
264
- body: {
265
- to: to,
266
- url: ""
267
- }
268
- }).then((response) => {
269
- console.log(response)
270
- }).catch(console.error)
333
+ ### Sticker, Video Note, Event, Pin, Call Link
334
+
335
+ ```ts
336
+ // Sticker
337
+ await wa.message.sendSticker(to, "https://www.gstatic.com/webp/gallery/1.webp");
338
+
339
+ // Video Note (circular/PTV)
340
+ await wa.message.sendVideoNote(to, "https://www.w3schools.com/html/mov_bbb.mp4");
341
+
342
+ // Event
343
+ await wa.message.sendEvent({
344
+ to,
345
+ name: "Team Meeting",
346
+ description: "Weekly sync",
347
+ startTime: "2025-01-15T14:00:00Z",
348
+ locationName: "Office",
349
+ locationAddress: "123 Main St",
350
+ });
351
+
352
+ // Pin Message
353
+ await wa.message.pin("MESSAGE_ID", 604800); // 7 days in seconds
354
+
355
+ // Call Link
356
+ await wa.message.sendCallLink(to, "video", "Join the meeting");
271
357
  ```
272
358
 
273
- ### Image
274
- ```js
275
- whatsapp.sendMessage({
276
- type: TypeMessage.IMAGE,
277
- body: {
278
- to: to,
279
- url: ""
280
- }
281
- }).then((response) => {
282
- console.log(response)
283
- }).catch(console.error)
359
+ ### Base64 Messages
360
+
361
+ ```ts
362
+ await wa.message.sendImageBase64(to, "data:image/png;base64,...", "Caption");
363
+ await wa.message.sendAudioBase64(to, "data:audio/mp3;base64,...");
364
+ await wa.message.sendDocumentBase64(to, "data:application/pdf;base64,...", "application/pdf", "file.pdf", "My document");
284
365
  ```
285
366
 
286
- ### Video
287
- ```js
288
- whatsapp.sendMessage({
289
- type: TypeMessage.VIDEO,
290
- body: {
291
- to: to,
292
- url: ""
293
- }
294
- }).then((response) => {
295
- console.log(response)
296
- }).catch(console.error)
367
+ ### Forward & List Messages
368
+
369
+ ```ts
370
+ // Forward a message
371
+ await wa.message.forward(to, "MESSAGE_ID");
372
+
373
+ // List messages from a contact
374
+ const messages = await wa.message.list("559999999999", 1, 20);
297
375
  ```
298
376
 
377
+ ## Chat
299
378
 
300
- ### Document
301
- ```js
302
- whatsapp.sendMessage({
303
- type: TypeMessage.DOCUMENT,
304
- body: {
305
- to: to,
306
- url: "",
307
- mimetype: "",
308
- fileName: ""
309
- }
310
- }).then((response) => {
311
- console.log(response)
312
- }).catch(console.error)
379
+ ```ts
380
+ // List all chats
381
+ const chats = await wa.chat.list();
382
+
383
+ // Get messages from a chat
384
+ const msgs = await wa.chat.messages("559999999999@s.whatsapp.net");
385
+
386
+ // Mark as read
387
+ await wa.chat.modify("559999999999@s.whatsapp.net", "markRead", true);
388
+
389
+ // Pin chat
390
+ await wa.chat.modify("559999999999@s.whatsapp.net", "pin", true);
391
+
392
+ // Delete chat
393
+ await wa.chat.delete("559999999999@s.whatsapp.net");
313
394
  ```
314
395
 
315
- ### Contact
316
- ```js
317
- whatsapp.sendMessage({
318
- type: TypeMessage.CONTACT,
319
- body: {
320
- to: to,
321
- contact: {
322
- fullName: "Raphael",
323
- phoneNumber: to,
324
- organization: "api-wa.me"
325
- }
326
- }
327
- }).then((response) => {
328
- console.log(response)
329
- }).catch(console.error)
396
+ ## Call
397
+
398
+ ```ts
399
+ // Make a call
400
+ await wa.call.call(to, false); // audio
401
+ await wa.call.call(to, true); // video
402
+
403
+ // Reject a call
404
+ await wa.call.reject("CALL_ID", "559999999999@s.whatsapp.net");
330
405
  ```
331
406
 
332
- ### Reaction
333
- ```js
334
- whatsapp.sendMessage({
335
- type: TypeMessage.REACTION,
336
- body: {
337
- to: to,
338
- msgId: "ASDDF872AHDURBSG",
339
- text: "🤖"
340
- }
341
- }).then((response) => {
342
- console.log(response)
343
- }).catch(console.error)
407
+ ## Labels
408
+
409
+ ```ts
410
+ // List labels
411
+ const labels = await wa.label.list();
412
+
413
+ // Create label
414
+ await wa.label.create("VIP");
415
+
416
+ // Add label to chat
417
+ await wa.label.addToChat("label_id", to);
418
+
419
+ // Get chats with label
420
+ const labeled = await wa.label.getChats("label_id");
421
+
422
+ // Remove label from chat
423
+ await wa.label.removeFromChat("label_id", to);
344
424
  ```
345
425
 
346
- ### All types of submissions you can respond to a message, so for example
426
+ ## Contacts
347
427
 
348
- ### Text
349
- ```js
350
- whatsapp.sendMessage({
351
- type: TypeMessage.TEXT,
352
- body: {
353
- msgId: "SKJH455AJKJ",
354
- to: to,
355
- text: "Hey"
356
- }
357
- }, true ).then((response) => {
358
- console.log(response)
359
- }).catch(console.error)
428
+ ```ts
429
+ // List all contacts
430
+ const contacts = await wa.contact.list();
431
+
432
+ // Get contact profile
433
+ const profile = await wa.contact.profile("559999999999");
434
+
435
+ // Block / Unblock
436
+ await wa.contact.block("559999999999", "block");
437
+ await wa.contact.block("559999999999", "unblock");
438
+
439
+ // Check if registered on WhatsApp
440
+ const check = await wa.action.checkRegistered("559999999999");
360
441
  ```
361
442
 
362
- ## Group Management
443
+ ## Groups
444
+
445
+ ```ts
446
+ // List groups
447
+ const groups = await wa.group.list();
448
+
449
+ // Group info
450
+ const info = await wa.group.info("123456789@g.us");
363
451
 
364
- ### List Groups
365
- ```js
366
- whatsapp.groups().then((response) => {
367
- console.log(response)
368
- }).catch(console.error)
452
+ // Create group
453
+ const newGroup = await wa.group.create("Developers", ["559999999999"]);
454
+
455
+ // Update group
456
+ await wa.group.update("123456789@g.us", "New Name", "New description");
457
+
458
+ // Change settings
459
+ await wa.group.changeSettings("123456789@g.us", "announcement"); // only admins can send
460
+ await wa.group.changeSettings("123456789@g.us", "not_announcement"); // everyone can send
461
+ await wa.group.changeSettings("123456789@g.us", "locked"); // only admins edit info
462
+ await wa.group.changeSettings("123456789@g.us", "unlocked"); // everyone can edit info
463
+
464
+ // Invite code
465
+ const invite = await wa.group.getInviteCode("123456789@g.us");
466
+
467
+ // Group picture
468
+ await wa.group.updatePicture("123456789@g.us", "https://a.cdn-hotels.com/gdcs/production190/d988/1071675e-1bd7-4a81-8b40-735eb9241410.jpg");
469
+ await wa.group.removePicture("123456789@g.us");
470
+
471
+ // Participants
472
+ await wa.group.addParticipants("123456789@g.us", ["559999999999"]);
473
+ await wa.group.removeParticipants("123456789@g.us", ["559999999999"]);
474
+ await wa.group.updateParticipantRole("123456789@g.us", "promote", ["559999999999"]);
475
+ await wa.group.updateParticipantRole("123456789@g.us", "demote", ["559999999999"]);
476
+
477
+ // Pending participants
478
+ const pending = await wa.group.getRequestParticipants("123456789@g.us");
479
+ await wa.group.updateRequestParticipants("123456789@g.us", {
480
+ participants: ["559999999999"],
481
+ action: "approve",
482
+ });
483
+
484
+ // Leave group
485
+ await wa.group.leave("123456789@g.us");
486
+ ```
487
+
488
+ ## Community
489
+
490
+ ```ts
491
+ // List communities
492
+ const communities = await wa.community.list();
493
+
494
+ // Create community
495
+ const newComm = await wa.community.create({ name: "My Community", subject: "Tech" });
496
+
497
+ // Community info
498
+ const commInfo = await wa.community.info("community_id");
499
+
500
+ // Update community
501
+ await wa.community.update("community_id", { subject: "Updated", description: "New description" });
502
+
503
+ // Community picture
504
+ await wa.community.updatePicture("community_id", "https://a.cdn-hotels.com/gdcs/production190/d988/1071675e-1bd7-4a81-8b40-735eb9241410.jpg");
505
+
506
+ // Invite code
507
+ const commInvite = await wa.community.getInviteCode("community_id");
508
+
509
+ // Participants
510
+ await wa.community.removeParticipants("community_id", ["559999999999"]);
511
+ const commPending = await wa.community.getRequestParticipants("community_id");
512
+ await wa.community.updateRequestParticipants("community_id", {
513
+ participants: ["559999999999"],
514
+ action: "approve",
515
+ });
516
+
517
+ // Leave community
518
+ await wa.community.leave("community_id");
369
519
  ```
370
520
 
371
- ### Group Information
372
- ```js
373
- whatsapp.infoGroup("123456789@us").then((response) => {
374
- console.log(response)
375
- }).catch(console.error)
521
+ ## Business
522
+
523
+ ```ts
524
+ // Get catalog
525
+ const catalog = await wa.business.getCatalog();
526
+ const catalogPage = await wa.business.getCatalog(10, "cursor_token");
527
+
528
+ // Create product
529
+ await wa.business.createProduct({
530
+ name: "Premium T-Shirt",
531
+ description: "100% cotton",
532
+ originCountryCode: "BR",
533
+ currency: "BRL",
534
+ price: 79.90,
535
+ images: [{ url: "https://a.cdn-hotels.com/gdcs/production190/d988/1071675e-1bd7-4a81-8b40-735eb9241410.jpg" }],
536
+ });
537
+
538
+ // Update product
539
+ await wa.business.updateProduct("product_id", {
540
+ name: "Premium T-Shirt v2",
541
+ price: 89.90,
542
+ });
543
+
544
+ // Delete product
545
+ await wa.business.deleteProduct("product_id");
376
546
  ```
377
547
 
378
- ### Create a Group
379
- ```js
380
- whatsapp.createGroup("Devs", [to]).then((response) => {
381
- console.log(response)
382
- }).catch(console.error)
548
+ ## Actions
549
+
550
+ ```ts
551
+ // Check if number is on WhatsApp
552
+ const result = await wa.action.checkRegistered("559999999999");
553
+
554
+ // Download media (deprecated)
555
+ const media = await wa.action.downloadMedia("image", {
556
+ mediaKey: "...",
557
+ directPath: "...",
558
+ url: "...",
559
+ });
560
+
561
+ // Delete stored media
562
+ await wa.action.deleteStorage();
383
563
  ```
384
564
 
385
- ### Update a Group
386
- ```js
387
- whatsapp.updateGroup("123456789@us", "Devs", "Only developers !").then((response) => {
388
- console.log(response)
389
- }).catch(console.error)
390
- ```
565
+ ## Custom HTTP Client
566
+
567
+ You can inject your own HTTP client (e.g., `fetch`, `got`, `undici`) for full control:
568
+
569
+ ```ts
570
+ import { WhatsApp, IHttpClient, RequestOptions } from '@raphaelvserafim/client-api-whatsapp';
571
+
572
+ class MyHttpClient implements IHttpClient {
573
+ async request<T>(options: RequestOptions): Promise<T> {
574
+ const response = await fetch(`https://us.api-wa.me/MY_KEY/${options.route}`, {
575
+ method: options.method,
576
+ headers: { 'Content-Type': 'application/json' },
577
+ body: options.body ? JSON.stringify(options.body) : undefined,
578
+ });
579
+ return response.json() as Promise<T>;
580
+ }
581
+ }
582
+
583
+ const wa = new WhatsApp(
584
+ { server: "https://us.api-wa.me", key: "MY_KEY" },
585
+ new MyHttpClient(),
586
+ );
587
+ ```
588
+
589
+ ## Error Handling
590
+
591
+ All API errors throw `WhatsAppError` with status code and response body:
592
+
593
+ ```ts
594
+ import { WhatsAppError } from '@raphaelvserafim/client-api-whatsapp';
595
+
596
+ try {
597
+ await wa.message.send({ type: TypeMessage.TEXT, body: { to, text: "Hello" } });
598
+ } catch (error) {
599
+ if (error instanceof WhatsAppError) {
600
+ console.error(error.message); // Error message
601
+ console.error(error.statusCode); // HTTP status code (e.g., 401, 404)
602
+ console.error(error.responseBody); // API response body
603
+ }
604
+ }
605
+ ```