@skyzopedia/baileys-pro 8.0.0 → 8.0.2
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 +288 -526
- package/README.md.bak +1223 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,129 +1,17 @@
|
|
|
1
|
-
<div align='center'>Baileys - Typescript/Javascript WhatsApp Web API</div>
|
|
2
|
-
|
|
1
|
+
# <div align='center'>Baileys - Typescript/Javascript WhatsApp Web API</div>
|
|
3
2
|
Then import the default function in your code:
|
|
4
|
-
|
|
5
3
|
```ts
|
|
6
4
|
import makeWASocket from 'baileys'
|
|
7
5
|
```
|
|
8
6
|
|
|
9
|
-
Links
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
Index
|
|
18
|
-
|
|
19
|
-
· Connecting Account
|
|
20
|
-
· Connect with QR-CODE
|
|
21
|
-
· Connect with Pairing Code
|
|
22
|
-
· Receive Full History
|
|
23
|
-
· Important Notes About Socket Config
|
|
24
|
-
· Caching Group Metadata (Recommended)
|
|
25
|
-
· Improve Retry System & Decrypt Poll Votes
|
|
26
|
-
· Receive Notifications in Whatsapp App
|
|
27
|
-
· Save Auth Info
|
|
28
|
-
· Handling Events
|
|
29
|
-
· Example to Start
|
|
30
|
-
· Decrypt Poll Votes
|
|
31
|
-
· Summary of Events on First Connection
|
|
32
|
-
· Implementing a Data Store
|
|
33
|
-
· Whatsapp IDs Explain
|
|
34
|
-
· Utility Functions
|
|
35
|
-
· JID Conversion Utilities
|
|
36
|
-
· Sending Messages
|
|
37
|
-
· Non-Media Messages
|
|
38
|
-
· Text Message
|
|
39
|
-
· Quote Message
|
|
40
|
-
· Mention User
|
|
41
|
-
· Forward Messages
|
|
42
|
-
· Location Message
|
|
43
|
-
· Contact Message
|
|
44
|
-
· Reaction Message
|
|
45
|
-
· Pin Message
|
|
46
|
-
· Poll Message
|
|
47
|
-
· Sending with Link Preview
|
|
48
|
-
· Media Messages
|
|
49
|
-
· Gif Message
|
|
50
|
-
· Video Message
|
|
51
|
-
· Audio Message
|
|
52
|
-
· Image Message
|
|
53
|
-
· ViewOnce Message
|
|
54
|
-
· Modify Messages
|
|
55
|
-
· Delete Messages (for everyone)
|
|
56
|
-
· Edit Messages
|
|
57
|
-
· Manipulating Media Messages
|
|
58
|
-
· Thumbnail in Media Messages
|
|
59
|
-
· Downloading Media Messages
|
|
60
|
-
· Re-upload Media Message to Whatsapp
|
|
61
|
-
· Reject Call
|
|
62
|
-
· Send States in Chat
|
|
63
|
-
· Reading Messages
|
|
64
|
-
· Update Presence
|
|
65
|
-
· Modifying Chats
|
|
66
|
-
· Archive a Chat
|
|
67
|
-
· Mute/Unmute a Chat
|
|
68
|
-
· Mark a Chat Read/Unread
|
|
69
|
-
· Delete a Message for Me
|
|
70
|
-
· Delete a Chat
|
|
71
|
-
· Star/Unstar a Message
|
|
72
|
-
· Disappearing Messages
|
|
73
|
-
· User Querys
|
|
74
|
-
· Check If ID Exists in Whatsapp
|
|
75
|
-
· Query Chat History (groups too)
|
|
76
|
-
· Fetch Status
|
|
77
|
-
· Fetch Profile Picture (groups too)
|
|
78
|
-
· Fetch Bussines Profile (such as description or category)
|
|
79
|
-
· Fetch Someone's Presence (if they're typing or online)
|
|
80
|
-
· Change Profile
|
|
81
|
-
· Change Profile Status
|
|
82
|
-
· Change Profile Name
|
|
83
|
-
· Change Display Picture (groups too)
|
|
84
|
-
· Remove display picture (groups too)
|
|
85
|
-
· Groups
|
|
86
|
-
· Create a Group
|
|
87
|
-
· Add/Remove or Demote/Promote
|
|
88
|
-
· Change Subject (name)
|
|
89
|
-
· Change Description
|
|
90
|
-
· Change Settings
|
|
91
|
-
· Leave a Group
|
|
92
|
-
· Get Invite Code
|
|
93
|
-
· Revoke Invite Code
|
|
94
|
-
· Join Using Invitation Code
|
|
95
|
-
· Get Group Info by Invite Code
|
|
96
|
-
· Query Metadata (participants, name, description...)
|
|
97
|
-
· Join using groupInviteMessage
|
|
98
|
-
· Get Request Join List
|
|
99
|
-
· Approve/Reject Request Join
|
|
100
|
-
· Get All Participating Groups Metadata
|
|
101
|
-
· Toggle Ephemeral
|
|
102
|
-
· Change Add Mode
|
|
103
|
-
· Privacy
|
|
104
|
-
· Block/Unblock User
|
|
105
|
-
· Get Privacy Settings
|
|
106
|
-
· Get BlockList
|
|
107
|
-
· Update LastSeen Privacy
|
|
108
|
-
· Update Online Privacy
|
|
109
|
-
· Update Profile Picture Privacy
|
|
110
|
-
· Update Status Privacy
|
|
111
|
-
· Update Read Receipts Privacy
|
|
112
|
-
· Update Groups Add Privacy
|
|
113
|
-
· Update Default Disappearing Mode
|
|
114
|
-
· Broadcast Lists & Stories
|
|
115
|
-
· Send Broadcast & Stories
|
|
116
|
-
· Query a Broadcast List's Recipients & Name
|
|
117
|
-
· Writing Custom Functionality
|
|
118
|
-
· Enabling Debug Level in Baileys Logs
|
|
119
|
-
· How Whatsapp Communicate With Us
|
|
120
|
-
· Register a Callback for Websocket Events
|
|
121
|
-
|
|
122
|
-
---
|
|
123
|
-
|
|
124
|
-
Connecting Account
|
|
125
|
-
|
|
126
|
-
WhatsApp provides a multi-device API that allows Baileys to be authenticated as a second WhatsApp client by scanning a QR code or Pairing Code with WhatsApp on your phone.
|
|
7
|
+
## Links
|
|
8
|
+
|
|
9
|
+
- [WhatsApp Channel](https://whatsapp.com/channel/0029VbBcgCK1SWstUXZnLh1o)
|
|
10
|
+
- [Contact Developer](https://t.me/Skyzopedia)
|
|
11
|
+
|
|
12
|
+
## Connecting Account
|
|
13
|
+
|
|
14
|
+
WhatsApp provides a multi-device API that allows Baileys to be authenticated as a second WhatsApp client by scanning a **QR code** or **Pairing Code** with WhatsApp on your phone.
|
|
127
15
|
|
|
128
16
|
```ts
|
|
129
17
|
import makeWASocket from 'baileys'
|
|
@@ -137,12 +25,13 @@ const sock = makeWASocket({
|
|
|
137
25
|
|
|
138
26
|
If the connection is successful, you will see a QR code printed on your terminal screen, scan it with WhatsApp on your phone and you'll be logged in!
|
|
139
27
|
|
|
140
|
-
Starting socket with Pairing Code
|
|
28
|
+
### Starting socket with **Pairing Code**
|
|
141
29
|
|
|
142
|
-
[!IMPORTANT]
|
|
143
|
-
Pairing Code isn't Mobile API, it's a method to connect Whatsapp Web without QR-CODE, you can connect only with one device, see here
|
|
144
30
|
|
|
145
|
-
|
|
31
|
+
> [!IMPORTANT]
|
|
32
|
+
> Pairing Code isn't Mobile API, it's a method to connect Whatsapp Web without QR-CODE, you can connect only with one device, see [here](https://faq.whatsapp.com/1324084875126592/?cms_platform=web)
|
|
33
|
+
|
|
34
|
+
The phone number can't have `+` or `()` or `-`, only numbers, you must provide country code
|
|
146
35
|
|
|
147
36
|
```ts
|
|
148
37
|
import makeWASocket from 'baileys'
|
|
@@ -159,11 +48,11 @@ if (!sock.authState.creds.registered) {
|
|
|
159
48
|
}
|
|
160
49
|
```
|
|
161
50
|
|
|
162
|
-
Receive Full History
|
|
51
|
+
### Receive Full History
|
|
163
52
|
|
|
164
|
-
1. Set syncFullHistory as true
|
|
53
|
+
1. Set `syncFullHistory` as `true`
|
|
165
54
|
2. Baileys, by default, use chrome browser config
|
|
166
|
-
|
|
55
|
+
- If you'd like to emulate a desktop connection (and receive more message history), this browser setting to your Socket config:
|
|
167
56
|
|
|
168
57
|
```ts
|
|
169
58
|
const sock = makeWASocket({
|
|
@@ -174,53 +63,49 @@ const sock = makeWASocket({
|
|
|
174
63
|
})
|
|
175
64
|
```
|
|
176
65
|
|
|
177
|
-
Important Notes About Socket Config
|
|
66
|
+
## Important Notes About Socket Config
|
|
178
67
|
|
|
179
|
-
Caching Group Metadata (Recommended)
|
|
68
|
+
### Caching Group Metadata (Recommended)
|
|
69
|
+
- If you use baileys for groups, we recommend you to set `cachedGroupMetadata` in socket config, you need to implement a cache like this:
|
|
180
70
|
|
|
181
|
-
|
|
182
|
-
```ts
|
|
71
|
+
```ts
|
|
183
72
|
const groupCache = new NodeCache({stdTTL: 5 * 60, useClones: false})
|
|
184
|
-
|
|
73
|
+
|
|
185
74
|
const sock = makeWASocket({
|
|
186
75
|
cachedGroupMetadata: async (jid) => groupCache.get(jid)
|
|
187
76
|
})
|
|
188
|
-
|
|
77
|
+
|
|
189
78
|
sock.ev.on('groups.update', async ([event]) => {
|
|
190
79
|
const metadata = await sock.groupMetadata(event.id)
|
|
191
80
|
groupCache.set(event.id, metadata)
|
|
192
81
|
})
|
|
193
|
-
|
|
82
|
+
|
|
194
83
|
sock.ev.on('group-participants.update', async (event) => {
|
|
195
84
|
const metadata = await sock.groupMetadata(event.id)
|
|
196
85
|
groupCache.set(event.id, metadata)
|
|
197
86
|
})
|
|
198
|
-
|
|
87
|
+
```
|
|
199
88
|
|
|
200
|
-
Improve Retry System & Decrypt Poll Votes
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
```ts
|
|
89
|
+
### Improve Retry System & Decrypt Poll Votes
|
|
90
|
+
- If you want to improve sending message, retrying when error occurs and decrypt poll votes, you need to have a store and set `getMessage` config in socket like this:
|
|
91
|
+
```ts
|
|
204
92
|
const sock = makeWASocket({
|
|
205
93
|
getMessage: async (key) => await getMessageFromStore(key)
|
|
206
94
|
})
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
Receive Notifications in Whatsapp App
|
|
95
|
+
```
|
|
210
96
|
|
|
211
|
-
|
|
212
|
-
|
|
97
|
+
### Receive Notifications in Whatsapp App
|
|
98
|
+
- If you want to receive notifications in whatsapp app, set `markOnlineOnConnect` to `false`
|
|
99
|
+
```ts
|
|
213
100
|
const sock = makeWASocket({
|
|
214
101
|
markOnlineOnConnect: false
|
|
215
102
|
})
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
Saving & Restoring Sessions
|
|
103
|
+
```
|
|
104
|
+
## Saving & Restoring Sessions
|
|
219
105
|
|
|
220
|
-
You obviously don't want to keep scanning the QR code every time you want to connect.
|
|
106
|
+
You obviously don't want to keep scanning the QR code every time you want to connect.
|
|
221
107
|
|
|
222
108
|
So, you can load the credentials to log back in:
|
|
223
|
-
|
|
224
109
|
```ts
|
|
225
110
|
import makeWASocket, { useMultiFileAuthState } from 'baileys'
|
|
226
111
|
|
|
@@ -234,19 +119,18 @@ const sock = makeWASocket({ auth: state })
|
|
|
234
119
|
sock.ev.on('creds.update', saveCreds)
|
|
235
120
|
```
|
|
236
121
|
|
|
237
|
-
[!IMPORTANT]
|
|
238
|
-
useMultiFileAuthState is a utility function to help save the auth state in a single folder, this function serves as a good guide to help write auth & key states for SQL/no-SQL databases, which I would recommend in any production grade system.
|
|
122
|
+
> [!IMPORTANT]
|
|
123
|
+
> `useMultiFileAuthState` is a utility function to help save the auth state in a single folder, this function serves as a good guide to help write auth & key states for SQL/no-SQL databases, which I would recommend in any production grade system.
|
|
239
124
|
|
|
240
|
-
[!NOTE]
|
|
241
|
-
When a message is received/sent, due to signal sessions needing updating, the auth keys (authState.keys) will update. Whenever that happens, you must save the updated keys (authState.keys.set() is called). Not doing so will prevent your messages from reaching the recipient & cause other unexpected consequences. The useMultiFileAuthState function automatically takes care of that, but for any other serious implementation -- you will need to be very careful with the key state management.
|
|
125
|
+
> [!NOTE]
|
|
126
|
+
> When a message is received/sent, due to signal sessions needing updating, the auth keys (`authState.keys`) will update. Whenever that happens, you must save the updated keys (`authState.keys.set()` is called). Not doing so will prevent your messages from reaching the recipient & cause other unexpected consequences. The `useMultiFileAuthState` function automatically takes care of that, but for any other serious implementation -- you will need to be very careful with the key state management.
|
|
242
127
|
|
|
243
|
-
Handling Events
|
|
128
|
+
## Handling Events
|
|
244
129
|
|
|
245
|
-
|
|
246
|
-
|
|
130
|
+
- Baileys uses the EventEmitter syntax for events.
|
|
131
|
+
They're all nicely typed up, so you shouldn't have any issues with an Intellisense editor like VS Code.
|
|
247
132
|
|
|
248
133
|
You can listen to these events like this:
|
|
249
|
-
|
|
250
134
|
```ts
|
|
251
135
|
const sock = makeWASocket()
|
|
252
136
|
sock.ev.on('messages.upsert', ({ messages }) => {
|
|
@@ -254,10 +138,10 @@ sock.ev.on('messages.upsert', ({ messages }) => {
|
|
|
254
138
|
})
|
|
255
139
|
```
|
|
256
140
|
|
|
257
|
-
Example to Start
|
|
141
|
+
### Example to Start
|
|
258
142
|
|
|
259
|
-
[!NOTE]
|
|
260
|
-
This example includes basic auth storage too
|
|
143
|
+
> [!NOTE]
|
|
144
|
+
> This example includes basic auth storage too
|
|
261
145
|
|
|
262
146
|
```ts
|
|
263
147
|
import makeWASocket, { DisconnectReason, useMultiFileAuthState } from 'baileys'
|
|
@@ -283,7 +167,7 @@ async function connectToWhatsApp () {
|
|
|
283
167
|
console.log('opened connection')
|
|
284
168
|
}
|
|
285
169
|
})
|
|
286
|
-
sock.ev.on('messages.upsert',
|
|
170
|
+
sock.ev.on('messages.upsert', event => {
|
|
287
171
|
for (const m of event.messages) {
|
|
288
172
|
console.log(JSON.stringify(m, undefined, 2))
|
|
289
173
|
|
|
@@ -299,16 +183,15 @@ async function connectToWhatsApp () {
|
|
|
299
183
|
connectToWhatsApp()
|
|
300
184
|
```
|
|
301
185
|
|
|
302
|
-
[!IMPORTANT]
|
|
303
|
-
In messages.upsert it's recommended to use a loop like for (const message of event.messages) to handle all messages in array
|
|
186
|
+
> [!IMPORTANT]
|
|
187
|
+
> In `messages.upsert` it's recommended to use a loop like `for (const message of event.messages)` to handle all messages in array
|
|
304
188
|
|
|
305
|
-
Decrypt Poll Votes
|
|
306
|
-
|
|
307
|
-
· By default poll votes are encrypted and handled in messages.update
|
|
308
|
-
· That's a simple example
|
|
189
|
+
### Decrypt Poll Votes
|
|
309
190
|
|
|
191
|
+
- By default poll votes are encrypted and handled in `messages.update`
|
|
192
|
+
- That's a simple example
|
|
310
193
|
```ts
|
|
311
|
-
sock.ev.on('messages.update',
|
|
194
|
+
sock.ev.on('messages.update', event => {
|
|
312
195
|
for(const { key, update } of event) {
|
|
313
196
|
if(update.pollUpdates) {
|
|
314
197
|
const pollCreation = await getMessage(key)
|
|
@@ -326,19 +209,19 @@ sock.ev.on('messages.update', async event => {
|
|
|
326
209
|
})
|
|
327
210
|
```
|
|
328
211
|
|
|
329
|
-
|
|
212
|
+
- `getMessage` is a [store](#implementing-a-data-store) implementation (in your end)
|
|
330
213
|
|
|
331
|
-
Summary of Events on First Connection
|
|
214
|
+
### Summary of Events on First Connection
|
|
332
215
|
|
|
333
|
-
1. When you connect first time, connection.update will be fired requesting you to restart sock
|
|
334
|
-
2. Then, history messages will be received in messaging-history.set
|
|
216
|
+
1. When you connect first time, `connection.update` will be fired requesting you to restart sock
|
|
217
|
+
2. Then, history messages will be received in `messaging-history.set`
|
|
335
218
|
|
|
336
|
-
Implementing a Data Store
|
|
219
|
+
## Implementing a Data Store
|
|
337
220
|
|
|
338
|
-
|
|
221
|
+
- Baileys does not come with a defacto storage for chats, contacts, or messages. However, a simple in-memory implementation has been provided. The store listens for chat updates, new messages, message updates, etc., to always have an up-to-date version of the data.
|
|
339
222
|
|
|
340
|
-
[!IMPORTANT]
|
|
341
|
-
I highly recommend building your own data store, as storing someone's entire chat history in memory is a terrible waste of RAM.
|
|
223
|
+
> [!IMPORTANT]
|
|
224
|
+
> I highly recommend building your own data store, as storing someone's entire chat history in memory is a terrible waste of RAM.
|
|
342
225
|
|
|
343
226
|
It can be used as follows:
|
|
344
227
|
|
|
@@ -368,31 +251,32 @@ sock.ev.on('chats.upsert', () => {
|
|
|
368
251
|
sock.ev.on('contacts.upsert', () => {
|
|
369
252
|
console.log('got contacts', Object.values(store.contacts))
|
|
370
253
|
})
|
|
254
|
+
|
|
371
255
|
```
|
|
372
256
|
|
|
373
|
-
The store also provides some simple functions such as loadMessages that utilize the store to speed up data retrieval.
|
|
257
|
+
The store also provides some simple functions such as `loadMessages` that utilize the store to speed up data retrieval.
|
|
374
258
|
|
|
375
|
-
Whatsapp IDs Explain
|
|
259
|
+
## Whatsapp IDs Explain
|
|
376
260
|
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
261
|
+
- `id` is the WhatsApp ID, called `jid` too, of the person or group you're sending the message to.
|
|
262
|
+
- It must be in the format ```[country code][phone number]@s.whatsapp.net```
|
|
263
|
+
- Example for people: ```+19999999999@s.whatsapp.net```.
|
|
264
|
+
- For groups, it must be in the format ``` 123456789-123345@g.us ```.
|
|
265
|
+
- For broadcast lists, it's `[timestamp of creation]@broadcast`.
|
|
266
|
+
- For stories, the ID is `status@broadcast`.
|
|
383
267
|
|
|
384
|
-
Utility Functions
|
|
268
|
+
## Utility Functions
|
|
385
269
|
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
270
|
+
- `getContentType`, returns the content type for any message
|
|
271
|
+
- `getDevice`, returns the device from message
|
|
272
|
+
- `makeCacheableSignalKeyStore`, make auth store more fast
|
|
273
|
+
- `downloadContentFromMessage`, download content from any message
|
|
390
274
|
|
|
391
|
-
JID Conversion Utilities
|
|
275
|
+
## JID Conversion Utilities
|
|
392
276
|
|
|
393
277
|
Baileys provides helper methods to convert between standard JIDs (@s.whatsapp.net) and LID (Local ID) format (@lid). These are useful when working with different WhatsApp ID formats.
|
|
394
278
|
|
|
395
|
-
Convert to LID (@lid)
|
|
279
|
+
#### Convert to LID (@lid)
|
|
396
280
|
|
|
397
281
|
```ts
|
|
398
282
|
const standardJid = '1234567890@s.whatsapp.net'
|
|
@@ -400,7 +284,7 @@ const lidJid = sock.toLid(standardJid)
|
|
|
400
284
|
// Result: '1234567890@lid'
|
|
401
285
|
```
|
|
402
286
|
|
|
403
|
-
Convert from LID to Standard (@s.whatsapp.net)
|
|
287
|
+
#### Convert from LID to Standard (@s.whatsapp.net)
|
|
404
288
|
|
|
405
289
|
```ts
|
|
406
290
|
const lidJid = '1234567890@lid'
|
|
@@ -408,37 +292,30 @@ const standardJid = sock.toPn(lidJid)
|
|
|
408
292
|
// Result: '1234567890@s.whatsapp.net'
|
|
409
293
|
```
|
|
410
294
|
|
|
411
|
-
|
|
412
|
-
These conversion utilities are helpful when interacting with systems or APIs that use different JID formats.
|
|
413
|
-
|
|
414
|
-
Sending Messages
|
|
295
|
+
## Sending Messages
|
|
415
296
|
|
|
416
297
|
```ts
|
|
417
298
|
const jid: string
|
|
418
299
|
const content: AnyMessageContent
|
|
419
300
|
const options: MiscMessageGenerationOptions
|
|
420
301
|
|
|
421
|
-
|
|
302
|
+
sock.sendMessage(jid, content, options)
|
|
422
303
|
```
|
|
423
304
|
|
|
424
|
-
Non-Media Messages
|
|
425
|
-
|
|
426
|
-
Text Message
|
|
305
|
+
### Non-Media Messages
|
|
427
306
|
|
|
307
|
+
#### Text Message
|
|
428
308
|
```ts
|
|
429
309
|
await sock.sendMessage(jid, { text: 'hello word' })
|
|
430
310
|
```
|
|
431
311
|
|
|
432
|
-
Quote Message (works with all types)
|
|
433
|
-
|
|
312
|
+
#### Quote Message (works with all types)
|
|
434
313
|
```ts
|
|
435
314
|
await sock.sendMessage(jid, { text: 'hello word' }, { quoted: message })
|
|
436
315
|
```
|
|
437
316
|
|
|
438
|
-
Mention User (works with most types)
|
|
439
|
-
|
|
440
|
-
· @number is to mention in text, it's optional
|
|
441
|
-
|
|
317
|
+
#### Mention User (works with most types)
|
|
318
|
+
- @number is to mention in text, it's optional
|
|
442
319
|
```ts
|
|
443
320
|
await sock.sendMessage(
|
|
444
321
|
jid,
|
|
@@ -449,15 +326,12 @@ await sock.sendMessage(
|
|
|
449
326
|
)
|
|
450
327
|
```
|
|
451
328
|
|
|
452
|
-
Forward Messages
|
|
453
|
-
|
|
454
329
|
```ts
|
|
455
330
|
const msg = getMessageFromStore() // implement this on your end
|
|
456
331
|
await sock.sendMessage(jid, { forward: msg }) // WA forward the message!
|
|
457
332
|
```
|
|
458
333
|
|
|
459
|
-
Location Message
|
|
460
|
-
|
|
334
|
+
#### Location Message
|
|
461
335
|
```ts
|
|
462
336
|
await sock.sendMessage(
|
|
463
337
|
jid,
|
|
@@ -469,9 +343,7 @@ await sock.sendMessage(
|
|
|
469
343
|
}
|
|
470
344
|
)
|
|
471
345
|
```
|
|
472
|
-
|
|
473
|
-
Contact Message
|
|
474
|
-
|
|
346
|
+
#### Contact Message
|
|
475
347
|
```ts
|
|
476
348
|
const vcard = 'BEGIN:VCARD\n' // metadata of the contact card
|
|
477
349
|
+ 'VERSION:3.0\n'
|
|
@@ -481,7 +353,7 @@ const vcard = 'BEGIN:VCARD\n' // metadata of the contact card
|
|
|
481
353
|
+ 'END:VCARD'
|
|
482
354
|
|
|
483
355
|
await sock.sendMessage(
|
|
484
|
-
|
|
356
|
+
id,
|
|
485
357
|
{
|
|
486
358
|
contacts: {
|
|
487
359
|
displayName: 'Jeff',
|
|
@@ -491,8 +363,6 @@ await sock.sendMessage(
|
|
|
491
363
|
)
|
|
492
364
|
```
|
|
493
365
|
|
|
494
|
-
Reaction Message
|
|
495
|
-
|
|
496
366
|
```ts
|
|
497
367
|
await sock.sendMessage(
|
|
498
368
|
jid,
|
|
@@ -505,15 +375,16 @@ await sock.sendMessage(
|
|
|
505
375
|
)
|
|
506
376
|
```
|
|
507
377
|
|
|
508
|
-
Pin Message
|
|
378
|
+
#### Pin Message
|
|
379
|
+
- You need to pass the key of message, you can retrieve from [store](#implementing-a-data-store) or use a [key](https://baileys.whiskeysockets.io/types/WAMessageKey.html) object
|
|
509
380
|
|
|
510
|
-
|
|
511
|
-
· Time can be:
|
|
381
|
+
- Time can be:
|
|
512
382
|
|
|
513
|
-
Time Seconds
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
383
|
+
| Time | Seconds |
|
|
384
|
+
|-------|----------------|
|
|
385
|
+
| 24h | 86.400 |
|
|
386
|
+
| 7d | 604.800 |
|
|
387
|
+
| 30d | 2.592.000 |
|
|
517
388
|
|
|
518
389
|
```ts
|
|
519
390
|
await sock.sendMessage(
|
|
@@ -528,8 +399,7 @@ await sock.sendMessage(
|
|
|
528
399
|
)
|
|
529
400
|
```
|
|
530
401
|
|
|
531
|
-
Poll Message
|
|
532
|
-
|
|
402
|
+
#### Poll Message
|
|
533
403
|
```ts
|
|
534
404
|
await sock.sendMessage(
|
|
535
405
|
jid,
|
|
@@ -544,13 +414,12 @@ await sock.sendMessage(
|
|
|
544
414
|
)
|
|
545
415
|
```
|
|
546
416
|
|
|
547
|
-
Sending Messages with Link Previews
|
|
417
|
+
### Sending Messages with Link Previews
|
|
548
418
|
|
|
549
419
|
1. By default, wa does not have link generation when sent from the web
|
|
550
420
|
2. Baileys has a function to generate the content for these link previews
|
|
551
|
-
3. To enable this function's usage, add link-preview-js as a dependency to your project with yarn add link-preview-js
|
|
421
|
+
3. To enable this function's usage, add `link-preview-js` as a dependency to your project with `yarn add link-preview-js`
|
|
552
422
|
4. Send a link:
|
|
553
|
-
|
|
554
423
|
```ts
|
|
555
424
|
await sock.sendMessage(
|
|
556
425
|
jid,
|
|
@@ -560,22 +429,20 @@ await sock.sendMessage(
|
|
|
560
429
|
)
|
|
561
430
|
```
|
|
562
431
|
|
|
563
|
-
Media Messages
|
|
432
|
+
### Media Messages
|
|
564
433
|
|
|
565
434
|
Sending media (video, stickers, images) is easier & more efficient than ever.
|
|
566
435
|
|
|
567
|
-
[!NOTE]
|
|
568
|
-
In media messages, you can pass { stream: Stream } or { url: Url } or Buffer directly, you can see more here
|
|
569
|
-
|
|
570
|
-
· When specifying a media url, Baileys never loads the entire buffer into memory; it even encrypts the media as a readable stream.
|
|
436
|
+
> [!NOTE]
|
|
437
|
+
> In media messages, you can pass `{ stream: Stream }` or `{ url: Url }` or `Buffer` directly, you can see more [here](https://baileys.whiskeysockets.io/types/WAMediaUpload.html)
|
|
571
438
|
|
|
572
|
-
|
|
573
|
-
It's recommended to use Stream or Url to save memory
|
|
439
|
+
- When specifying a media url, Baileys never loads the entire buffer into memory; it even encrypts the media as a readable stream.
|
|
574
440
|
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
· Whatsapp doesn't support .gif files, that's why we send gifs as common .mp4 video with gifPlayback flag
|
|
441
|
+
> [!TIP]
|
|
442
|
+
> It's recommended to use Stream or Url to save memory
|
|
578
443
|
|
|
444
|
+
#### Gif Message
|
|
445
|
+
- Whatsapp doesn't support `.gif` files, that's why we send gifs as common `.mp4` video with `gifPlayback` flag
|
|
579
446
|
```ts
|
|
580
447
|
await sock.sendMessage(
|
|
581
448
|
jid,
|
|
@@ -587,11 +454,10 @@ await sock.sendMessage(
|
|
|
587
454
|
)
|
|
588
455
|
```
|
|
589
456
|
|
|
590
|
-
Video Message
|
|
591
|
-
|
|
457
|
+
#### Video Message
|
|
592
458
|
```ts
|
|
593
459
|
await sock.sendMessage(
|
|
594
|
-
|
|
460
|
+
id,
|
|
595
461
|
{
|
|
596
462
|
video: {
|
|
597
463
|
url: './Media/ma_gif.mp4'
|
|
@@ -602,20 +468,18 @@ await sock.sendMessage(
|
|
|
602
468
|
)
|
|
603
469
|
```
|
|
604
470
|
|
|
605
|
-
Audio Message
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
```bash
|
|
471
|
+
#### Audio Message
|
|
472
|
+
- To audio message work in all devices you need to convert with some tool like `ffmpeg` with this flags:
|
|
473
|
+
```bash
|
|
609
474
|
codec: libopus //ogg file
|
|
610
475
|
ac: 1 //one channel
|
|
611
476
|
avoid_negative_ts
|
|
612
477
|
make_zero
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
478
|
+
```
|
|
479
|
+
- Example:
|
|
480
|
+
```bash
|
|
616
481
|
ffmpeg -i input.mp4 -avoid_negative_ts make_zero -ac 1 output.ogg
|
|
617
|
-
|
|
618
|
-
|
|
482
|
+
```
|
|
619
483
|
```ts
|
|
620
484
|
await sock.sendMessage(
|
|
621
485
|
jid,
|
|
@@ -628,11 +492,10 @@ await sock.sendMessage(
|
|
|
628
492
|
)
|
|
629
493
|
```
|
|
630
494
|
|
|
631
|
-
Image Message
|
|
632
|
-
|
|
495
|
+
#### Image Message
|
|
633
496
|
```ts
|
|
634
497
|
await sock.sendMessage(
|
|
635
|
-
|
|
498
|
+
id,
|
|
636
499
|
{
|
|
637
500
|
image: {
|
|
638
501
|
url: './Media/ma_img.png'
|
|
@@ -642,13 +505,13 @@ await sock.sendMessage(
|
|
|
642
505
|
)
|
|
643
506
|
```
|
|
644
507
|
|
|
645
|
-
View Once Message
|
|
508
|
+
#### View Once Message
|
|
646
509
|
|
|
647
|
-
|
|
510
|
+
- You can send all messages above as `viewOnce`, you only need to pass `viewOnce: true` in content object
|
|
648
511
|
|
|
649
512
|
```ts
|
|
650
513
|
await sock.sendMessage(
|
|
651
|
-
|
|
514
|
+
id,
|
|
652
515
|
{
|
|
653
516
|
image: {
|
|
654
517
|
url: './Media/ma_img.png'
|
|
@@ -659,21 +522,20 @@ await sock.sendMessage(
|
|
|
659
522
|
)
|
|
660
523
|
```
|
|
661
524
|
|
|
662
|
-
Modify Messages
|
|
525
|
+
## Modify Messages
|
|
663
526
|
|
|
664
|
-
Deleting Messages (for everyone)
|
|
527
|
+
### Deleting Messages (for everyone)
|
|
665
528
|
|
|
666
529
|
```ts
|
|
667
530
|
const msg = await sock.sendMessage(jid, { text: 'hello word' })
|
|
668
531
|
await sock.sendMessage(jid, { delete: msg.key })
|
|
669
532
|
```
|
|
670
533
|
|
|
671
|
-
Note
|
|
672
|
-
|
|
673
|
-
Editing Messages
|
|
534
|
+
**Note:** deleting for oneself is supported via `chatModify`, see in [this section](#modifying-chats)
|
|
674
535
|
|
|
675
|
-
|
|
536
|
+
### Editing Messages
|
|
676
537
|
|
|
538
|
+
- You can pass all editable contents here
|
|
677
539
|
```ts
|
|
678
540
|
await sock.sendMessage(jid, {
|
|
679
541
|
text: 'updated text goes here',
|
|
@@ -681,71 +543,65 @@ await sock.sendMessage(jid, {
|
|
|
681
543
|
});
|
|
682
544
|
```
|
|
683
545
|
|
|
684
|
-
Manipulating Media Messages
|
|
546
|
+
## Manipulating Media Messages
|
|
685
547
|
|
|
686
|
-
Thumbnail in Media Messages
|
|
548
|
+
### Thumbnail in Media Messages
|
|
549
|
+
- For media messages, the thumbnail can be generated automatically for images & stickers provided you add `jimp` or `sharp` as a dependency in your project using `yarn add jimp` or `yarn add sharp`.
|
|
550
|
+
- Thumbnails for videos can also be generated automatically, though, you need to have `ffmpeg` installed on your system.
|
|
687
551
|
|
|
688
|
-
|
|
689
|
-
· Thumbnails for videos can also be generated automatically, though, you need to have ffmpeg installed on your system.
|
|
690
|
-
|
|
691
|
-
Downloading Media Messages
|
|
552
|
+
### Downloading Media Messages
|
|
692
553
|
|
|
693
554
|
If you want to save the media you received
|
|
694
|
-
|
|
695
555
|
```ts
|
|
696
556
|
import { createWriteStream } from 'fs'
|
|
697
557
|
import { downloadMediaMessage, getContentType } from 'baileys'
|
|
698
558
|
|
|
699
|
-
sock.ev.on('messages.upsert', async ({
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
stream.pipe(writeStream)
|
|
721
|
-
}
|
|
559
|
+
sock.ev.on('messages.upsert', async ({ [m] }) => {
|
|
560
|
+
if (!m.message) return // if there is no text or media message
|
|
561
|
+
const messageType = getContentType(m) // get what type of message it is (text, image, video...)
|
|
562
|
+
|
|
563
|
+
// if the message is an image
|
|
564
|
+
if (messageType === 'imageMessage') {
|
|
565
|
+
// download the message
|
|
566
|
+
const stream = await downloadMediaMessage(
|
|
567
|
+
m,
|
|
568
|
+
'stream', // can be 'buffer' too
|
|
569
|
+
{ },
|
|
570
|
+
{
|
|
571
|
+
logger,
|
|
572
|
+
// pass this so that baileys can request a reupload of media
|
|
573
|
+
// that has been deleted
|
|
574
|
+
reuploadRequest: sock.updateMediaMessage
|
|
575
|
+
}
|
|
576
|
+
)
|
|
577
|
+
// save to file
|
|
578
|
+
const writeStream = createWriteStream('./my-download.jpeg')
|
|
579
|
+
stream.pipe(writeStream)
|
|
722
580
|
}
|
|
723
|
-
}
|
|
581
|
+
}
|
|
724
582
|
```
|
|
725
583
|
|
|
726
|
-
Re-upload Media Message to Whatsapp
|
|
727
|
-
|
|
728
|
-
· WhatsApp automatically removes old media from their servers. For the device to access said media -- a re-upload is required by another device that has it. This can be accomplished using:
|
|
584
|
+
### Re-upload Media Message to Whatsapp
|
|
729
585
|
|
|
586
|
+
- WhatsApp automatically removes old media from their servers. For the device to access said media -- a re-upload is required by another device that has it. This can be accomplished using:
|
|
730
587
|
```ts
|
|
731
588
|
await sock.updateMediaMessage(msg)
|
|
732
589
|
```
|
|
733
590
|
|
|
734
|
-
Reject Call
|
|
591
|
+
## Reject Call
|
|
735
592
|
|
|
736
|
-
|
|
593
|
+
- You can obtain `callId` and `callFrom` from `call` event
|
|
737
594
|
|
|
738
595
|
```ts
|
|
739
596
|
await sock.rejectCall(callId, callFrom)
|
|
740
597
|
```
|
|
741
598
|
|
|
742
|
-
Send States in Chat
|
|
743
|
-
|
|
744
|
-
Reading Messages
|
|
599
|
+
## Send States in Chat
|
|
745
600
|
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
601
|
+
### Reading Messages
|
|
602
|
+
- A set of message [keys](https://baileys.whiskeysockets.io/types/WAMessageKey.html) must be explicitly marked read now.
|
|
603
|
+
- You cannot mark an entire 'chat' read as it were with Baileys Web.
|
|
604
|
+
This means you have to keep track of unread messages.
|
|
749
605
|
|
|
750
606
|
```ts
|
|
751
607
|
const key: WAMessageKey
|
|
@@ -754,43 +610,42 @@ await sock.readMessages([key])
|
|
|
754
610
|
```
|
|
755
611
|
|
|
756
612
|
The message ID is the unique identifier of the message that you are marking as read.
|
|
757
|
-
On
|
|
613
|
+
On a `WAMessage`, the `messageID` can be accessed using ```messageID = message.key.id```.
|
|
758
614
|
|
|
759
|
-
Update Presence
|
|
615
|
+
### Update Presence
|
|
760
616
|
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
617
|
+
- ``` presence ``` can be one of [these](https://baileys.whiskeysockets.io/types/WAPresence.html)
|
|
618
|
+
- The presence expires after about 10 seconds.
|
|
619
|
+
- This lets the person/group with `jid` know whether you're online, offline, typing etc.
|
|
764
620
|
|
|
765
621
|
```ts
|
|
766
622
|
await sock.sendPresenceUpdate('available', jid)
|
|
767
623
|
```
|
|
768
624
|
|
|
769
|
-
[!NOTE]
|
|
770
|
-
If a desktop client is active, WA doesn't send push notifications to the device. If you would like to receive said notifications -- mark your Baileys client offline using sock.sendPresenceUpdate('unavailable')
|
|
625
|
+
> [!NOTE]
|
|
626
|
+
> If a desktop client is active, WA doesn't send push notifications to the device. If you would like to receive said notifications -- mark your Baileys client offline using `sock.sendPresenceUpdate('unavailable')`
|
|
771
627
|
|
|
772
|
-
Modifying Chats
|
|
628
|
+
## Modifying Chats
|
|
773
629
|
|
|
774
630
|
WA uses an encrypted form of communication to send chat/app updates. This has been implemented mostly and you can send the following updates:
|
|
775
631
|
|
|
776
|
-
[!IMPORTANT]
|
|
777
|
-
If you mess up one of your updates, WA can log you out of all your devices and you'll have to log in again.
|
|
778
|
-
|
|
779
|
-
Archive a Chat
|
|
632
|
+
> [!IMPORTANT]
|
|
633
|
+
> If you mess up one of your updates, WA can log you out of all your devices and you'll have to log in again.
|
|
780
634
|
|
|
635
|
+
### Archive a Chat
|
|
781
636
|
```ts
|
|
782
637
|
const lastMsgInChat = await getLastMessageInChat(jid) // implement this on your end
|
|
783
638
|
await sock.chatModify({ archive: true, lastMessages: [lastMsgInChat] }, jid)
|
|
784
639
|
```
|
|
640
|
+
### Mute/Unmute a Chat
|
|
785
641
|
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
· Supported times:
|
|
642
|
+
- Supported times:
|
|
789
643
|
|
|
790
|
-
Time Miliseconds
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
644
|
+
| Time | Miliseconds |
|
|
645
|
+
|-------|-----------------|
|
|
646
|
+
| Remove | null |
|
|
647
|
+
| 8h | 86.400.000 |
|
|
648
|
+
| 7d | 604.800.000 |
|
|
794
649
|
|
|
795
650
|
```ts
|
|
796
651
|
// mute for 8 hours
|
|
@@ -798,17 +653,14 @@ await sock.chatModify({ mute: 8 * 60 * 60 * 1000 }, jid)
|
|
|
798
653
|
// unmute
|
|
799
654
|
await sock.chatModify({ mute: null }, jid)
|
|
800
655
|
```
|
|
801
|
-
|
|
802
|
-
Mark a Chat Read/Unread
|
|
803
|
-
|
|
656
|
+
### Mark a Chat Read/Unread
|
|
804
657
|
```ts
|
|
805
658
|
const lastMsgInChat = await getLastMessageInChat(jid) // implement this on your end
|
|
806
659
|
// mark it unread
|
|
807
660
|
await sock.chatModify({ markRead: false, lastMessages: [lastMsgInChat] }, jid)
|
|
808
661
|
```
|
|
809
662
|
|
|
810
|
-
Delete a Message for Me
|
|
811
|
-
|
|
663
|
+
### Delete a Message for Me
|
|
812
664
|
```ts
|
|
813
665
|
await sock.chatModify(
|
|
814
666
|
{
|
|
@@ -824,10 +676,9 @@ await sock.chatModify(
|
|
|
824
676
|
},
|
|
825
677
|
jid
|
|
826
678
|
)
|
|
827
|
-
```
|
|
828
|
-
|
|
829
|
-
Delete a Chat
|
|
830
679
|
|
|
680
|
+
```
|
|
681
|
+
### Delete a Chat
|
|
831
682
|
```ts
|
|
832
683
|
const lastMsgInChat = await getLastMessageInChat(jid) // implement this on your end
|
|
833
684
|
await sock.chatModify({
|
|
@@ -842,9 +693,7 @@ await sock.chatModify({
|
|
|
842
693
|
jid
|
|
843
694
|
)
|
|
844
695
|
```
|
|
845
|
-
|
|
846
|
-
Pin/Unpin a Chat
|
|
847
|
-
|
|
696
|
+
### Pin/Unpin a Chat
|
|
848
697
|
```ts
|
|
849
698
|
await sock.chatModify({
|
|
850
699
|
pin: true // or `false` to unpin
|
|
@@ -852,9 +701,7 @@ await sock.chatModify({
|
|
|
852
701
|
jid
|
|
853
702
|
)
|
|
854
703
|
```
|
|
855
|
-
|
|
856
|
-
Star/Unstar a Message
|
|
857
|
-
|
|
704
|
+
### Star/Unstar a Message
|
|
858
705
|
```ts
|
|
859
706
|
await sock.chatModify({
|
|
860
707
|
star: {
|
|
@@ -871,21 +718,20 @@ await sock.chatModify({
|
|
|
871
718
|
)
|
|
872
719
|
```
|
|
873
720
|
|
|
874
|
-
Disappearing Messages
|
|
721
|
+
### Disappearing Messages
|
|
875
722
|
|
|
876
|
-
|
|
723
|
+
- Ephemeral can be:
|
|
877
724
|
|
|
878
|
-
Time Seconds
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
725
|
+
| Time | Seconds |
|
|
726
|
+
|-------|----------------|
|
|
727
|
+
| Remove | 0 |
|
|
728
|
+
| 24h | 86.400 |
|
|
729
|
+
| 7d | 604.800 |
|
|
730
|
+
| 90d | 7.776.000 |
|
|
883
731
|
|
|
884
|
-
|
|
732
|
+
- You need to pass in **Seconds**, default is 7 days
|
|
885
733
|
|
|
886
734
|
```ts
|
|
887
|
-
import { WA_DEFAULT_EPHEMERAL } from 'baileys'
|
|
888
|
-
|
|
889
735
|
// turn on disappearing messages
|
|
890
736
|
await sock.sendMessage(
|
|
891
737
|
jid,
|
|
@@ -903,19 +749,17 @@ await sock.sendMessage(
|
|
|
903
749
|
)
|
|
904
750
|
```
|
|
905
751
|
|
|
906
|
-
User Querys
|
|
907
|
-
|
|
908
|
-
Check If ID Exists in Whatsapp
|
|
752
|
+
## User Querys
|
|
909
753
|
|
|
754
|
+
### Check If ID Exists in Whatsapp
|
|
910
755
|
```ts
|
|
911
756
|
const [result] = await sock.onWhatsApp(jid)
|
|
912
757
|
if (result.exists) console.log (`${jid} exists on WhatsApp, as jid: ${result.jid}`)
|
|
913
758
|
```
|
|
914
759
|
|
|
915
|
-
Query Chat History (groups too)
|
|
916
|
-
|
|
917
|
-
· You need to have oldest message in chat
|
|
760
|
+
### Query Chat History (groups too)
|
|
918
761
|
|
|
762
|
+
- You need to have oldest message in chat
|
|
919
763
|
```ts
|
|
920
764
|
const msg = await getOldestMessageInChat(jid)
|
|
921
765
|
await sock.fetchMessageHistory(
|
|
@@ -924,20 +768,16 @@ await sock.fetchMessageHistory(
|
|
|
924
768
|
msg.messageTimestamp
|
|
925
769
|
)
|
|
926
770
|
```
|
|
771
|
+
- Messages will be received in `messaging-history.set` event
|
|
927
772
|
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
Fetch Status
|
|
931
|
-
|
|
773
|
+
### Fetch Status
|
|
932
774
|
```ts
|
|
933
775
|
const status = await sock.fetchStatus(jid)
|
|
934
776
|
console.log('status: ' + status)
|
|
935
777
|
```
|
|
936
778
|
|
|
937
|
-
Fetch Profile Picture (groups too)
|
|
938
|
-
|
|
939
|
-
· To get the display picture of some person/group
|
|
940
|
-
|
|
779
|
+
### Fetch Profile Picture (groups too)
|
|
780
|
+
- To get the display picture of some person/group
|
|
941
781
|
```ts
|
|
942
782
|
// for low res picture
|
|
943
783
|
const ppUrl = await sock.profilePictureUrl(jid)
|
|
@@ -947,15 +787,13 @@ console.log(ppUrl)
|
|
|
947
787
|
const ppUrl = await sock.profilePictureUrl(jid, 'image')
|
|
948
788
|
```
|
|
949
789
|
|
|
950
|
-
Fetch Bussines Profile (such as description or category)
|
|
951
|
-
|
|
790
|
+
### Fetch Bussines Profile (such as description or category)
|
|
952
791
|
```ts
|
|
953
792
|
const profile = await sock.getBusinessProfile(jid)
|
|
954
793
|
console.log('business description: ' + profile.description + ', category: ' + profile.category)
|
|
955
794
|
```
|
|
956
795
|
|
|
957
|
-
Fetch Someone's Presence (if they're typing or online)
|
|
958
|
-
|
|
796
|
+
### Fetch Someone's Presence (if they're typing or online)
|
|
959
797
|
```ts
|
|
960
798
|
// the presence update is fetched and called here
|
|
961
799
|
sock.ev.on('presence.update', console.log)
|
|
@@ -964,52 +802,42 @@ sock.ev.on('presence.update', console.log)
|
|
|
964
802
|
await sock.presenceSubscribe(jid)
|
|
965
803
|
```
|
|
966
804
|
|
|
967
|
-
Change Profile
|
|
968
|
-
|
|
969
|
-
Change Profile Status
|
|
805
|
+
## Change Profile
|
|
970
806
|
|
|
807
|
+
### Change Profile Status
|
|
971
808
|
```ts
|
|
972
809
|
await sock.updateProfileStatus('Hello World!')
|
|
973
810
|
```
|
|
974
|
-
|
|
975
|
-
Change Profile Name
|
|
976
|
-
|
|
811
|
+
### Change Profile Name
|
|
977
812
|
```ts
|
|
978
813
|
await sock.updateProfileName('My name')
|
|
979
814
|
```
|
|
815
|
+
### Change Display Picture (groups too)
|
|
816
|
+
- To change your display picture or a group's
|
|
980
817
|
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
· To change your display picture or a group's
|
|
984
|
-
|
|
985
|
-
[!NOTE]
|
|
986
|
-
Like media messages, you can pass { stream: Stream } or { url: Url } or Buffer directly, you can see more here
|
|
818
|
+
> [!NOTE]
|
|
819
|
+
> Like media messages, you can pass `{ stream: Stream }` or `{ url: Url }` or `Buffer` directly, you can see more [here](https://baileys.whiskeysockets.io/types/WAMediaUpload.html)
|
|
987
820
|
|
|
988
821
|
```ts
|
|
989
822
|
await sock.updateProfilePicture(jid, { url: './new-profile-picture.jpeg' })
|
|
990
823
|
```
|
|
991
|
-
|
|
992
|
-
Remove display picture (groups too)
|
|
993
|
-
|
|
824
|
+
### Remove display picture (groups too)
|
|
994
825
|
```ts
|
|
995
826
|
await sock.removeProfilePicture(jid)
|
|
996
827
|
```
|
|
997
828
|
|
|
998
|
-
Groups
|
|
829
|
+
## Groups
|
|
999
830
|
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
Create a Group
|
|
831
|
+
- To change group properties you need to be admin
|
|
1003
832
|
|
|
833
|
+
### Create a Group
|
|
1004
834
|
```ts
|
|
1005
835
|
// title & participants
|
|
1006
836
|
const group = await sock.groupCreate('My Fab Group', ['1234@s.whatsapp.net', '4564@s.whatsapp.net'])
|
|
1007
837
|
console.log('created group with id: ' + group.gid)
|
|
1008
838
|
await sock.sendMessage(group.id, { text: 'hello there' }) // say hello to everyone on the group
|
|
1009
839
|
```
|
|
1010
|
-
|
|
1011
|
-
Add/Remove or Demote/Promote
|
|
1012
|
-
|
|
840
|
+
### Add/Remove or Demote/Promote
|
|
1013
841
|
```ts
|
|
1014
842
|
// id & people to add to the group (will throw error if it fails)
|
|
1015
843
|
await sock.groupParticipantsUpdate(
|
|
@@ -1018,21 +846,15 @@ await sock.groupParticipantsUpdate(
|
|
|
1018
846
|
'add' // replace this parameter with 'remove' or 'demote' or 'promote'
|
|
1019
847
|
)
|
|
1020
848
|
```
|
|
1021
|
-
|
|
1022
|
-
Change Subject (name)
|
|
1023
|
-
|
|
849
|
+
### Change Subject (name)
|
|
1024
850
|
```ts
|
|
1025
851
|
await sock.groupUpdateSubject(jid, 'New Subject!')
|
|
1026
852
|
```
|
|
1027
|
-
|
|
1028
|
-
Change Description
|
|
1029
|
-
|
|
853
|
+
### Change Description
|
|
1030
854
|
```ts
|
|
1031
855
|
await sock.groupUpdateDescription(jid, 'New Description!')
|
|
1032
856
|
```
|
|
1033
|
-
|
|
1034
|
-
Change Settings
|
|
1035
|
-
|
|
857
|
+
### Change Settings
|
|
1036
858
|
```ts
|
|
1037
859
|
// only allow admins to send messages
|
|
1038
860
|
await sock.groupSettingUpdate(jid, 'announcement')
|
|
@@ -1043,69 +865,49 @@ await sock.groupSettingUpdate(jid, 'unlocked')
|
|
|
1043
865
|
// only allow admins to modify the group's settings
|
|
1044
866
|
await sock.groupSettingUpdate(jid, 'locked')
|
|
1045
867
|
```
|
|
1046
|
-
|
|
1047
|
-
Leave a Group
|
|
1048
|
-
|
|
868
|
+
### Leave a Group
|
|
1049
869
|
```ts
|
|
1050
870
|
// will throw error if it fails
|
|
1051
871
|
await sock.groupLeave(jid)
|
|
1052
872
|
```
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
· To create link with code use 'https://chat.whatsapp.com/' + code
|
|
1057
|
-
|
|
873
|
+
### Get Invite Code
|
|
874
|
+
- To create link with code use `'https://chat.whatsapp.com/' + code`
|
|
1058
875
|
```ts
|
|
1059
876
|
const code = await sock.groupInviteCode(jid)
|
|
1060
877
|
console.log('group code: ' + code)
|
|
1061
878
|
```
|
|
1062
|
-
|
|
1063
|
-
Revoke Invite Code
|
|
1064
|
-
|
|
879
|
+
### Revoke Invite Code
|
|
1065
880
|
```ts
|
|
1066
881
|
const code = await sock.groupRevokeInvite(jid)
|
|
1067
882
|
console.log('New group code: ' + code)
|
|
1068
883
|
```
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
· Code can't have https://chat.whatsapp.com/, only code
|
|
1073
|
-
|
|
884
|
+
### Join Using Invitation Code
|
|
885
|
+
- Code can't have `https://chat.whatsapp.com/`, only code
|
|
1074
886
|
```ts
|
|
1075
887
|
const response = await sock.groupAcceptInvite(code)
|
|
1076
888
|
console.log('joined to: ' + response)
|
|
1077
889
|
```
|
|
1078
|
-
|
|
1079
|
-
Get Group Info by Invite Code
|
|
1080
|
-
|
|
890
|
+
### Get Group Info by Invite Code
|
|
1081
891
|
```ts
|
|
1082
892
|
const response = await sock.groupGetInviteInfo(code)
|
|
1083
893
|
console.log('group information: ' + response)
|
|
1084
894
|
```
|
|
1085
|
-
|
|
1086
|
-
Query Metadata (participants, name, description...)
|
|
1087
|
-
|
|
895
|
+
### Query Metadata (participants, name, description...)
|
|
1088
896
|
```ts
|
|
1089
897
|
const metadata = await sock.groupMetadata(jid)
|
|
1090
898
|
console.log(metadata.id + ', title: ' + metadata.subject + ', description: ' + metadata.desc)
|
|
1091
899
|
```
|
|
1092
|
-
|
|
1093
|
-
Join using groupInviteMessage
|
|
1094
|
-
|
|
900
|
+
### Join using `groupInviteMessage`
|
|
1095
901
|
```ts
|
|
1096
902
|
const response = await sock.groupAcceptInviteV4(jid, groupInviteMessage)
|
|
1097
903
|
console.log('joined to: ' + response)
|
|
1098
904
|
```
|
|
1099
|
-
|
|
1100
|
-
Get Request Join List
|
|
1101
|
-
|
|
905
|
+
### Get Request Join List
|
|
1102
906
|
```ts
|
|
1103
907
|
const response = await sock.groupRequestParticipantsList(jid)
|
|
1104
908
|
console.log(response)
|
|
1105
909
|
```
|
|
1106
|
-
|
|
1107
|
-
Approve/Reject Request Join
|
|
1108
|
-
|
|
910
|
+
### Approve/Reject Request Join
|
|
1109
911
|
```ts
|
|
1110
912
|
const response = await sock.groupRequestParticipantsUpdate(
|
|
1111
913
|
jid, // group id
|
|
@@ -1114,30 +916,27 @@ const response = await sock.groupRequestParticipantsUpdate(
|
|
|
1114
916
|
)
|
|
1115
917
|
console.log(response)
|
|
1116
918
|
```
|
|
1117
|
-
|
|
1118
|
-
Get All Participating Groups Metadata
|
|
1119
|
-
|
|
919
|
+
### Get All Participating Groups Metadata
|
|
1120
920
|
```ts
|
|
1121
921
|
const response = await sock.groupFetchAllParticipating()
|
|
1122
922
|
console.log(response)
|
|
1123
923
|
```
|
|
924
|
+
### Toggle Ephemeral
|
|
1124
925
|
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
· Ephemeral can be:
|
|
926
|
+
- Ephemeral can be:
|
|
1128
927
|
|
|
1129
|
-
Time Seconds
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
928
|
+
| Time | Seconds |
|
|
929
|
+
|-------|----------------|
|
|
930
|
+
| Remove | 0 |
|
|
931
|
+
| 24h | 86.400 |
|
|
932
|
+
| 7d | 604.800 |
|
|
933
|
+
| 90d | 7.776.000 |
|
|
1134
934
|
|
|
1135
935
|
```ts
|
|
1136
936
|
await sock.groupToggleEphemeral(jid, 86400)
|
|
1137
937
|
```
|
|
1138
938
|
|
|
1139
|
-
Change Add Mode
|
|
1140
|
-
|
|
939
|
+
### Change Add Mode
|
|
1141
940
|
```ts
|
|
1142
941
|
await sock.groupMemberAddMode(
|
|
1143
942
|
jid,
|
|
@@ -1145,92 +944,73 @@ await sock.groupMemberAddMode(
|
|
|
1145
944
|
)
|
|
1146
945
|
```
|
|
1147
946
|
|
|
1148
|
-
Privacy
|
|
1149
|
-
|
|
1150
|
-
Block/Unblock User
|
|
947
|
+
## Privacy
|
|
1151
948
|
|
|
949
|
+
### Block/Unblock User
|
|
1152
950
|
```ts
|
|
1153
951
|
await sock.updateBlockStatus(jid, 'block') // Block user
|
|
1154
952
|
await sock.updateBlockStatus(jid, 'unblock') // Unblock user
|
|
1155
953
|
```
|
|
1156
|
-
|
|
1157
|
-
Get Privacy Settings
|
|
1158
|
-
|
|
954
|
+
### Get Privacy Settings
|
|
1159
955
|
```ts
|
|
1160
956
|
const privacySettings = await sock.fetchPrivacySettings(true)
|
|
1161
957
|
console.log('privacy settings: ' + privacySettings)
|
|
1162
958
|
```
|
|
1163
|
-
|
|
1164
|
-
Get BlockList
|
|
1165
|
-
|
|
959
|
+
### Get BlockList
|
|
1166
960
|
```ts
|
|
1167
961
|
const response = await sock.fetchBlocklist()
|
|
1168
962
|
console.log(response)
|
|
1169
963
|
```
|
|
1170
|
-
|
|
1171
|
-
Update LastSeen Privacy
|
|
1172
|
-
|
|
964
|
+
### Update LastSeen Privacy
|
|
1173
965
|
```ts
|
|
1174
966
|
const value = 'all' // 'contacts' | 'contact_blacklist' | 'none'
|
|
1175
967
|
await sock.updateLastSeenPrivacy(value)
|
|
1176
968
|
```
|
|
1177
|
-
|
|
1178
|
-
Update Online Privacy
|
|
1179
|
-
|
|
969
|
+
### Update Online Privacy
|
|
1180
970
|
```ts
|
|
1181
971
|
const value = 'all' // 'match_last_seen'
|
|
1182
972
|
await sock.updateOnlinePrivacy(value)
|
|
1183
973
|
```
|
|
1184
|
-
|
|
1185
|
-
Update Profile Picture Privacy
|
|
1186
|
-
|
|
974
|
+
### Update Profile Picture Privacy
|
|
1187
975
|
```ts
|
|
1188
976
|
const value = 'all' // 'contacts' | 'contact_blacklist' | 'none'
|
|
1189
977
|
await sock.updateProfilePicturePrivacy(value)
|
|
1190
978
|
```
|
|
1191
|
-
|
|
1192
|
-
Update Status Privacy
|
|
1193
|
-
|
|
979
|
+
### Update Status Privacy
|
|
1194
980
|
```ts
|
|
1195
981
|
const value = 'all' // 'contacts' | 'contact_blacklist' | 'none'
|
|
1196
982
|
await sock.updateStatusPrivacy(value)
|
|
1197
983
|
```
|
|
1198
|
-
|
|
1199
|
-
Update Read Receipts Privacy
|
|
1200
|
-
|
|
984
|
+
### Update Read Receipts Privacy
|
|
1201
985
|
```ts
|
|
1202
986
|
const value = 'all' // 'none'
|
|
1203
987
|
await sock.updateReadReceiptsPrivacy(value)
|
|
1204
988
|
```
|
|
1205
|
-
|
|
1206
|
-
Update Groups Add Privacy
|
|
1207
|
-
|
|
989
|
+
### Update Groups Add Privacy
|
|
1208
990
|
```ts
|
|
1209
991
|
const value = 'all' // 'contacts' | 'contact_blacklist'
|
|
1210
992
|
await sock.updateGroupsAddPrivacy(value)
|
|
1211
993
|
```
|
|
994
|
+
### Update Default Disappearing Mode
|
|
1212
995
|
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
· Like this, ephemeral can be:
|
|
996
|
+
- Like [this](#disappearing-messages), ephemeral can be:
|
|
1216
997
|
|
|
1217
|
-
Time Seconds
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
998
|
+
| Time | Seconds |
|
|
999
|
+
|-------|----------------|
|
|
1000
|
+
| Remove | 0 |
|
|
1001
|
+
| 24h | 86.400 |
|
|
1002
|
+
| 7d | 604.800 |
|
|
1003
|
+
| 90d | 7.776.000 |
|
|
1222
1004
|
|
|
1223
1005
|
```ts
|
|
1224
1006
|
const ephemeral = 86400
|
|
1225
1007
|
await sock.updateDefaultDisappearingMode(ephemeral)
|
|
1226
1008
|
```
|
|
1227
1009
|
|
|
1228
|
-
Broadcast Lists & Stories
|
|
1229
|
-
|
|
1230
|
-
Send Broadcast & Stories
|
|
1231
|
-
|
|
1232
|
-
· Messages can be sent to broadcasts & stories. You need to add the following message options in sendMessage, like this:
|
|
1010
|
+
## Broadcast Lists & Stories
|
|
1233
1011
|
|
|
1012
|
+
### Send Broadcast & Stories
|
|
1013
|
+
- Messages can be sent to broadcasts & stories. You need to add the following message options in sendMessage, like this:
|
|
1234
1014
|
```ts
|
|
1235
1015
|
await sock.sendMessage(
|
|
1236
1016
|
jid,
|
|
@@ -1248,47 +1028,39 @@ await sock.sendMessage(
|
|
|
1248
1028
|
}
|
|
1249
1029
|
)
|
|
1250
1030
|
```
|
|
1031
|
+
- Message body can be a `extendedTextMessage` or `imageMessage` or `videoMessage` or `voiceMessage`, see [here](https://baileys.whiskeysockets.io/types/AnyRegularMessageContent.html)
|
|
1032
|
+
- You can add `backgroundColor` and other options in the message options, see [here](https://baileys.whiskeysockets.io/types/MiscMessageGenerationOptions.html)
|
|
1033
|
+
- `broadcast: true` enables broadcast mode
|
|
1034
|
+
- `statusJidList`: a list of people that you can get which you need to provide, which are the people who will get this status message.
|
|
1251
1035
|
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
· You can send messages to broadcast lists the same way you send messages to groups & individual chats.
|
|
1257
|
-
· Right now, WA Web does not support creating broadcast lists, but you can still delete them.
|
|
1258
|
-
· Broadcast IDs are in the format 12345678@broadcast
|
|
1259
|
-
|
|
1260
|
-
Query a Broadcast List's Recipients & Name
|
|
1261
|
-
|
|
1036
|
+
- You can send messages to broadcast lists the same way you send messages to groups & individual chats.
|
|
1037
|
+
- Right now, WA Web does not support creating broadcast lists, but you can still delete them.
|
|
1038
|
+
- Broadcast IDs are in the format `12345678@broadcast`
|
|
1039
|
+
### Query a Broadcast List's Recipients & Name
|
|
1262
1040
|
```ts
|
|
1263
1041
|
const bList = await sock.getBroadcastListInfo('1234@broadcast')
|
|
1264
1042
|
console.log (`list name: ${bList.name}, recps: ${bList.recipients}`)
|
|
1265
1043
|
```
|
|
1266
1044
|
|
|
1267
|
-
Writing Custom Functionality
|
|
1268
|
-
|
|
1045
|
+
## Writing Custom Functionality
|
|
1269
1046
|
Baileys is written with custom functionality in mind. Instead of forking the project & re-writing the internals, you can simply write your own extensions.
|
|
1270
1047
|
|
|
1271
|
-
Enabling Debug Level in Baileys Logs
|
|
1272
|
-
|
|
1048
|
+
### Enabling Debug Level in Baileys Logs
|
|
1273
1049
|
First, enable the logging of unhandled messages from WhatsApp by setting:
|
|
1274
|
-
|
|
1275
1050
|
```ts
|
|
1276
|
-
import P from 'pino'
|
|
1277
|
-
|
|
1278
1051
|
const sock = makeWASocket({
|
|
1279
1052
|
logger: P({ level: 'debug' }),
|
|
1280
1053
|
})
|
|
1281
1054
|
```
|
|
1055
|
+
This will enable you to see all sorts of messages WhatsApp sends in the console.
|
|
1282
1056
|
|
|
1283
|
-
|
|
1057
|
+
### How Whatsapp Communicate With Us
|
|
1284
1058
|
|
|
1285
|
-
|
|
1059
|
+
> [!TIP]
|
|
1060
|
+
> If you want to learn whatsapp protocol, we recommend to study about Libsignal Protocol and Noise Protocol
|
|
1286
1061
|
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
· Example: Functionality to track the battery percentage of your phone. You enable logging and you'll see a message about your battery pop up in the console:
|
|
1291
|
-
```
|
|
1062
|
+
- **Example:** Functionality to track the battery percentage of your phone. You enable logging and you'll see a message about your battery pop up in the console:
|
|
1063
|
+
```
|
|
1292
1064
|
{
|
|
1293
1065
|
"level": 10,
|
|
1294
1066
|
"fromMe": false,
|
|
@@ -1316,19 +1088,18 @@ If you want to learn whatsapp protocol, we recommend to study about Libsignal Pr
|
|
|
1316
1088
|
},
|
|
1317
1089
|
"msg":"communication"
|
|
1318
1090
|
}
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
The 'frame' is what the message received is, it has three components:
|
|
1091
|
+
```
|
|
1322
1092
|
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1093
|
+
The `'frame'` is what the message received is, it has three components:
|
|
1094
|
+
- `tag` -- what this frame is about (eg. message will have 'message')
|
|
1095
|
+
- `attrs` -- a string key-value pair with some metadata (contains ID of the message usually)
|
|
1096
|
+
- `content` -- the actual data (eg. a message node will have the actual message content in it)
|
|
1097
|
+
- read more about this format [here](/src/WABinary/readme.md)
|
|
1327
1098
|
|
|
1328
|
-
Register a Callback for Websocket Events
|
|
1099
|
+
### Register a Callback for Websocket Events
|
|
1329
1100
|
|
|
1330
|
-
[!TIP]
|
|
1331
|
-
Recommended to see onMessageReceived function in socket.ts file to understand how websockets events are fired
|
|
1101
|
+
> [!TIP]
|
|
1102
|
+
> Recommended to see `onMessageReceived` function in `socket.ts` file to understand how websockets events are fired
|
|
1332
1103
|
|
|
1333
1104
|
```ts
|
|
1334
1105
|
// for any message with tag 'edge_routing'
|
|
@@ -1341,14 +1112,5 @@ sock.ws.on('CB:edge_routing,id:abcd', (node: BinaryNode) => { })
|
|
|
1341
1112
|
sock.ws.on('CB:edge_routing,id:abcd,routing_info', (node: BinaryNode) => { })
|
|
1342
1113
|
```
|
|
1343
1114
|
|
|
1344
|
-
[!NOTE]
|
|
1345
|
-
Also, this repo is now licenced under GPL 3 since it uses libsignal-node
|
|
1346
|
-
|
|
1347
|
-
---
|
|
1348
|
-
|
|
1349
|
-
Support Channels
|
|
1350
|
-
|
|
1351
|
-
· WhatsApp Channel: Join Here
|
|
1352
|
-
· Telegram: t.me/Skyzopedia (Skyzopedia)
|
|
1353
|
-
|
|
1354
|
-
For any issues, questions, or discussions about Baileys, feel free to join our support channels above. Our community and developers are active and ready to help!
|
|
1115
|
+
> [!NOTE]
|
|
1116
|
+
> Also, this repo is now licenced under GPL 3 since it uses [libsignal-node](https://git.questbook.io/backend/service-coderunner/-/merge_requests/1)
|