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