@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.
- package/README.md +512 -297
- package/dist/WhatsApp.d.ts +142 -31
- package/dist/WhatsApp.js +111 -167
- package/dist/WhatsApp.js.map +1 -1
- package/dist/client/HttpClient.d.ts +6 -0
- package/dist/client/HttpClient.js +29 -0
- package/dist/client/HttpClient.js.map +1 -0
- package/dist/client/IHttpClient.d.ts +9 -0
- package/dist/client/IHttpClient.js +3 -0
- package/dist/client/IHttpClient.js.map +1 -0
- package/dist/errors.d.ts +5 -0
- package/dist/errors.js +13 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +14 -1
- package/dist/index.js +33 -3
- package/dist/index.js.map +1 -1
- package/dist/services/ActionService.d.ts +9 -0
- package/dist/services/ActionService.js +32 -0
- package/dist/services/ActionService.js.map +1 -0
- package/dist/services/BusinessService.d.ts +10 -0
- package/dist/services/BusinessService.js +43 -0
- package/dist/services/BusinessService.js.map +1 -0
- package/dist/services/CallService.d.ts +8 -0
- package/dist/services/CallService.js +24 -0
- package/dist/services/CallService.js.map +1 -0
- package/dist/services/ChatService.d.ts +16 -0
- package/dist/services/ChatService.js +38 -0
- package/dist/services/ChatService.js.map +1 -0
- package/dist/services/CommunityService.d.ts +28 -0
- package/dist/services/CommunityService.js +76 -0
- package/dist/services/CommunityService.js.map +1 -0
- package/dist/services/ContactService.d.ts +15 -0
- package/dist/services/ContactService.js +30 -0
- package/dist/services/ContactService.js.map +1 -0
- package/dist/services/GroupService.d.ts +32 -0
- package/dist/services/GroupService.js +104 -0
- package/dist/services/GroupService.js.map +1 -0
- package/dist/services/InstanceService.d.ts +28 -0
- package/dist/services/InstanceService.js +124 -0
- package/dist/services/InstanceService.js.map +1 -0
- package/dist/services/LabelService.d.ts +17 -0
- package/dist/services/LabelService.js +43 -0
- package/dist/services/LabelService.js.map +1 -0
- package/dist/services/MessageService.d.ts +51 -0
- package/dist/services/MessageService.js +106 -0
- package/dist/services/MessageService.js.map +1 -0
- package/dist/types/index.d.ts +155 -11
- package/dist/types/index.js +10 -0
- package/dist/types/index.js.map +1 -1
- package/package.json +6 -11
- package/.babelrc +0 -3
- package/dist/exemple.d.ts +0 -1
- package/dist/exemple.js +0 -264
- package/dist/exemple.js.map +0 -1
- package/src/WhatsApp.ts +0 -245
- package/src/exemple.ts +0 -312
- package/src/index.ts +0 -2
- package/src/types/index.ts +0 -190
- package/tsconfig.compile.json +0 -15
- package/tsconfig.json +0 -35
package/README.md
CHANGED
|
@@ -2,23 +2,22 @@
|
|
|
2
2
|
|
|
3
3
|
## About Our WhatsApp API
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
**Unlock the Potential of WhatsApp:** Powerful Integration with Our Unofficial API!
|
|
6
6
|
|
|
7
7
|
### Efficient Group Management on WhatsApp
|
|
8
8
|
|
|
9
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
38
|
-
import { WhatsApp, StatusPresence, TypeMessage, } from '@raphaelvserafim/client-api-whatsapp';
|
|
38
|
+
## Quick Start
|
|
39
39
|
|
|
40
|
-
|
|
40
|
+
```ts
|
|
41
|
+
import { WhatsApp, TypeMessage, StatusPresence } from '@raphaelvserafim/client-api-whatsapp';
|
|
41
42
|
|
|
42
|
-
const
|
|
43
|
-
```
|
|
43
|
+
const wa = new WhatsApp({ server: "https://us.api-wa.me", key: "YOUR_KEY" });
|
|
44
44
|
|
|
45
|
-
|
|
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
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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
|
-
|
|
60
|
-
```js
|
|
61
|
-
whatsapp.logout().then((response) => {
|
|
62
|
-
console.log(response)
|
|
63
|
-
}).catch(console.error);
|
|
64
|
-
```
|
|
116
|
+
## Messages
|
|
65
117
|
|
|
66
|
-
###
|
|
67
|
-
```js
|
|
68
|
-
whatsapp.contacts().then((response) => {
|
|
69
|
-
console.log(response)
|
|
70
|
-
}).catch(console.error)
|
|
71
|
-
```
|
|
118
|
+
### Send Messages
|
|
72
119
|
|
|
73
|
-
|
|
120
|
+
```ts
|
|
121
|
+
// Text
|
|
122
|
+
await wa.message.send({
|
|
123
|
+
type: TypeMessage.TEXT,
|
|
124
|
+
body: { to, text: "Hello!" },
|
|
125
|
+
});
|
|
74
126
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
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
|
|
81
|
-
|
|
82
|
-
}
|
|
83
|
-
})
|
|
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
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
type: TypeMessage.TEXT,
|
|
160
|
+
// Location
|
|
161
|
+
await wa.message.send({
|
|
162
|
+
type: TypeMessage.LOCATION,
|
|
92
163
|
body: {
|
|
93
|
-
to
|
|
94
|
-
|
|
95
|
-
}
|
|
96
|
-
})
|
|
97
|
-
|
|
98
|
-
|
|
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
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
to: "
|
|
108
|
-
|
|
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
|
-
|
|
133
|
-
|
|
134
|
-
|
|
214
|
+
```ts
|
|
215
|
+
// Quick Reply Buttons
|
|
216
|
+
await wa.message.send({
|
|
135
217
|
type: TypeMessage.BUTTON_REPLY,
|
|
136
218
|
body: {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
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
|
-
|
|
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
|
-
|
|
163
|
-
|
|
164
|
-
whatsapp.sendMessage({
|
|
230
|
+
// Call to Action Buttons
|
|
231
|
+
await wa.message.send({
|
|
165
232
|
type: TypeMessage.BUTTON_ACTION,
|
|
166
233
|
body: {
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
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
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
url: "https://
|
|
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
|
-
|
|
186
|
-
|
|
187
|
-
text: "
|
|
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
|
-
|
|
199
|
-
|
|
266
|
+
|
|
267
|
+
```ts
|
|
268
|
+
await wa.message.send({
|
|
200
269
|
type: TypeMessage.MENU,
|
|
201
270
|
body: {
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
title: "
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
}
|
|
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
|
-
###
|
|
227
|
-
|
|
228
|
-
|
|
296
|
+
### Poll / Survey
|
|
297
|
+
|
|
298
|
+
```ts
|
|
299
|
+
// Survey (via sendMessage)
|
|
300
|
+
await wa.message.send({
|
|
229
301
|
type: TypeMessage.POLL,
|
|
230
|
-
body: {
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
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
|
-
###
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
309
|
+
### PIX Payment
|
|
310
|
+
|
|
311
|
+
```ts
|
|
312
|
+
await wa.message.send({
|
|
313
|
+
type: TypeMessage.BUTTON_PIX,
|
|
247
314
|
body: {
|
|
248
|
-
to
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
}
|
|
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
|
-
###
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
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
|
-
###
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
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
|
-
###
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
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
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
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
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
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
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
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
|
-
|
|
426
|
+
## Contacts
|
|
347
427
|
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
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
|
-
##
|
|
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
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
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
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
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
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
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
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
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
|
+
```
|