@alannxd/baileys 6.1.7 → 6.2.8
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 +440 -203
- package/lib/Defaults/index.js +2 -2
- package/lib/Socket/Client/websocket.js +35 -5
- package/lib/Socket/chats.js +0 -5
- package/lib/Socket/index.js +1 -9
- package/lib/Socket/luxu.js +4 -5
- package/lib/Socket/messages-recv.js +1 -1
- package/lib/Socket/messages-send.js +56 -114
- package/lib/Socket/mex.js +38 -51
- package/lib/Socket/newsletter.js +276 -745
- package/lib/Socket/socket.js +27 -161
- package/lib/Socket/username.js +204 -206
- package/lib/Store/make-in-memory-store.js +1 -47
- package/lib/Types/Mex.js +2 -76
- package/lib/Utils/browser-utils.js +1 -0
- package/lib/Utils/generics.js +2 -2
- package/lib/Utils/index.js +0 -1
- package/lib/Utils/messages-media.js +0 -82
- package/lib/Utils/messages.js +2 -136
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +50 -52
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +52 -55
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +25 -28
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +36 -37
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +23 -25
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +51 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +29 -0
- package/lib/WAUSync/Protocols/index.js +6 -12
- package/lib/WAUSync/USyncQuery.js +96 -149
- package/lib/WAUSync/USyncUser.js +29 -54
- package/lib/WAUSync/index.js +4 -3
- package/lib/index.js +5 -2
- package/package.json +14 -13
- package/lib/Socket/graphql.js +0 -716
- package/lib/Socket/interop.js +0 -463
- package/lib/Socket/message-builder.js +0 -475
- package/lib/Socket/privacy.js +0 -318
- package/lib/Utils/sticker.js +0 -133
- package/lib/Utils/use-sqlite-auth-state.js +0 -162
- package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +0 -53
- package/lib/WAUSync/Protocols/USyncBusinessProtocol.js +0 -43
- package/lib/WAUSync/Protocols/USyncFeatureProtocol.js +0 -58
- package/lib/WAUSync/Protocols/USyncLIDProtocol.js +0 -30
- package/lib/WAUSync/Protocols/USyncPictureProtocol.js +0 -32
- package/lib/WAUSync/Protocols/USyncSidelistProtocol.js +0 -28
- package/lib/WAUSync/Protocols/USyncTextStatusProtocol.js +0 -38
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# <div align='center'>Baileys - Typescript/Javascript WhatsApp Web API</div>
|
|
2
2
|
|
|
3
3
|
<p align="center">
|
|
4
|
-
<img src="https://
|
|
4
|
+
<img src="https://img3.pixhost.to/images/6052/775950487_alanwinter.jpg" alt="Thumbnail" />
|
|
5
5
|
</p>
|
|
6
6
|
|
|
7
7
|
<div align='center'>
|
|
@@ -16,30 +16,50 @@
|
|
|
16
16
|
|
|
17
17
|
</div>
|
|
18
18
|
|
|
19
|
-
WhatsApp Baileys is an open-source library designed
|
|
19
|
+
WhatsApp Baileys is an open-source TypeScript/JavaScript library designed for developers who need direct and flexible integration with WhatsApp Web. It allows applications to establish WhatsApp connections through WebSocket communication without requiring a browser such as Chrome or Chromium.
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
This library provides a modular interface for authentication, session management, message processing, event handling, and raw message relay. It can be integrated into various Node.js applications, including automation systems, business bots, customer service platforms, notification services, and other communication-related projects.
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
The project also focuses on making the authentication and pairing workflow easier to integrate into custom applications. QR authentication and pairing code authentication can be combined with persistent session storage, allowing applications to reconnect without requiring users to authenticate every time the process restarts.
|
|
24
|
+
|
|
25
|
+
Baileys is designed to provide developers with direct access to WhatsApp Web functionality while keeping the implementation relatively lightweight. Because the library operates through a WebSocket connection rather than browser automation, it can be deployed on environments such as Linux servers, VPS instances, Docker containers, and development environments such as Termux.
|
|
26
|
+
|
|
27
|
+
This project is developed and maintained independently and is not affiliated with WhatsApp or Meta.
|
|
24
28
|
|
|
25
29
|
---
|
|
26
30
|
|
|
27
31
|
### Main Features and Advantages
|
|
28
32
|
|
|
29
|
-
-
|
|
30
|
-
-
|
|
31
|
-
-
|
|
32
|
-
-
|
|
33
|
-
-
|
|
34
|
-
-
|
|
35
|
-
-
|
|
36
|
-
-
|
|
33
|
+
- WhatsApp Web connection through WebSocket
|
|
34
|
+
- QR Code authentication
|
|
35
|
+
- Pairing Code authentication
|
|
36
|
+
- Multi-device authentication
|
|
37
|
+
- Persistent local session management
|
|
38
|
+
- Automatic credential updates
|
|
39
|
+
- `sendMessage` support
|
|
40
|
+
- `relayMessage` support
|
|
41
|
+
- Raw message object support
|
|
42
|
+
- Custom message structures
|
|
43
|
+
- Interactive messages and action buttons
|
|
44
|
+
- Poll and quiz message support
|
|
45
|
+
- Product and order message support
|
|
46
|
+
- Group-related message functionality
|
|
47
|
+
- Event-based message and connection handling
|
|
48
|
+
- Lightweight Node.js integration
|
|
49
|
+
- Suitable for VPS, Linux, Docker, and Termux environments
|
|
50
|
+
- Ready-to-use examples for common use cases
|
|
37
51
|
|
|
38
52
|
---
|
|
39
53
|
|
|
40
54
|
## Getting Started
|
|
41
55
|
|
|
42
|
-
|
|
56
|
+
Before starting development, make sure Node.js 20 or newer is installed on your environment.
|
|
57
|
+
|
|
58
|
+
Install the package using npm, configure the authentication state, then create a WhatsApp socket using `makeWASocket()`.
|
|
59
|
+
|
|
60
|
+
The simplest setup uses `useMultiFileAuthState()` to store authentication data locally. Once the credentials have been saved, the same session can be reused when the application is restarted.
|
|
61
|
+
|
|
62
|
+
The examples below use CommonJS syntax so they can be integrated directly into most existing Node.js projects.
|
|
43
63
|
|
|
44
64
|
---
|
|
45
65
|
|
|
@@ -48,297 +68,485 @@ Begin by installing the library via your preferred package manager, then follow
|
|
|
48
68
|
- [Requirements](#requirements)
|
|
49
69
|
- [Install](#install)
|
|
50
70
|
- [Quick Start](#quick-start)
|
|
51
|
-
- [QR Code login](#login-with-qr-code)
|
|
52
|
-
- [Pairing Code login](#login-with-pairing-code)
|
|
53
|
-
- [Store](#store)
|
|
54
71
|
- [Sending Messages](#sending-messages)
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
- [Special message types](#special-message-types)
|
|
72
|
+
- [Raw Message Relay](#raw-message-relay)
|
|
73
|
+
- [Relay Examples](#relay-examples)
|
|
58
74
|
- [Events](#events)
|
|
59
|
-
- [
|
|
60
|
-
- [
|
|
61
|
-
- [Why Choose WhatsApp Baileys?](#why-choose-whatsapp-baileys
|
|
75
|
+
- [Authentication](#authentication)
|
|
76
|
+
- [Complete Example](#complete-example)
|
|
77
|
+
- [Why Choose WhatsApp Baileys?](#why-choose-whatsapp-baileys)
|
|
62
78
|
- [Technical Notes](#technical-notes)
|
|
63
79
|
- [Contact Developer](#contact-developer)
|
|
64
|
-
- [Contributors](#contributors-outside-the-baileys-code)
|
|
80
|
+
- [Contributors outside the Baileys code](#contributors-outside-the-baileys-code)
|
|
81
|
+
- [Credits](#credits)
|
|
82
|
+
- [Disclaimer](#disclaimer)
|
|
83
|
+
|
|
84
|
+
---
|
|
65
85
|
|
|
66
86
|
## Requirements
|
|
67
87
|
|
|
68
88
|
- Node.js **>= 20**
|
|
69
|
-
-
|
|
89
|
+
- npm
|
|
90
|
+
- Internet connection
|
|
91
|
+
- A WhatsApp account for authentication
|
|
92
|
+
|
|
93
|
+
Depending on the features being used, additional dependencies may be required by the project.
|
|
94
|
+
|
|
95
|
+
---
|
|
70
96
|
|
|
71
97
|
## Install
|
|
72
98
|
|
|
99
|
+
Install the package using npm:
|
|
100
|
+
|
|
73
101
|
```bash
|
|
74
102
|
npm install @alannxd/baileys
|
|
75
103
|
```
|
|
76
104
|
|
|
77
|
-
Or
|
|
105
|
+
Or use it as an alias while keeping the standard Baileys package name in your source code:
|
|
78
106
|
|
|
79
107
|
```json
|
|
80
108
|
{
|
|
81
109
|
"dependencies": {
|
|
82
|
-
"@
|
|
110
|
+
"@whiskeysockets/baileys": "npm:@alannxd/baileys@latest"
|
|
83
111
|
}
|
|
84
112
|
}
|
|
85
113
|
```
|
|
86
114
|
|
|
115
|
+
Then import it using:
|
|
116
|
+
|
|
87
117
|
```js
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
118
|
+
const makeWASocket =
|
|
119
|
+
require('@whiskeysockets/baileys').default
|
|
120
|
+
|
|
121
|
+
const {
|
|
122
|
+
useMultiFileAuthState
|
|
123
|
+
} = require('@whiskeysockets/baileys')
|
|
91
124
|
```
|
|
92
125
|
|
|
126
|
+
---
|
|
127
|
+
|
|
93
128
|
## Quick Start
|
|
94
129
|
|
|
95
|
-
|
|
130
|
+
The following example creates a basic WhatsApp connection, stores authentication credentials locally, and listens for connection updates.
|
|
96
131
|
|
|
97
132
|
```js
|
|
98
|
-
|
|
133
|
+
const makeWASocket =
|
|
134
|
+
require('@whiskeysockets/baileys').default
|
|
135
|
+
|
|
136
|
+
const {
|
|
137
|
+
useMultiFileAuthState
|
|
138
|
+
} = require('@whiskeysockets/baileys')
|
|
139
|
+
|
|
140
|
+
async function start() {
|
|
141
|
+
const { state, saveCreds } =
|
|
142
|
+
await useMultiFileAuthState('./session')
|
|
143
|
+
|
|
144
|
+
const sock = makeWASocket({
|
|
145
|
+
auth: state
|
|
146
|
+
})
|
|
147
|
+
|
|
148
|
+
sock.ev.on(
|
|
149
|
+
'creds.update',
|
|
150
|
+
saveCreds
|
|
151
|
+
)
|
|
152
|
+
|
|
153
|
+
sock.ev.on(
|
|
154
|
+
'connection.update',
|
|
155
|
+
({ connection }) => {
|
|
156
|
+
console.log(
|
|
157
|
+
'Connection:',
|
|
158
|
+
connection
|
|
159
|
+
)
|
|
160
|
+
}
|
|
161
|
+
)
|
|
162
|
+
}
|
|
99
163
|
|
|
100
|
-
|
|
164
|
+
start()
|
|
165
|
+
```
|
|
101
166
|
|
|
102
|
-
|
|
103
|
-
browser: Browsers.ubuntu('Chrome'),
|
|
104
|
-
printQRInTerminal: true,
|
|
105
|
-
auth: state
|
|
106
|
-
})
|
|
167
|
+
The authentication state is stored inside the `session/` directory. Once authenticated, the same session can be reused when the application starts again.
|
|
107
168
|
|
|
108
|
-
|
|
169
|
+
---
|
|
170
|
+
|
|
171
|
+
## Sending Messages
|
|
172
|
+
|
|
173
|
+
### Text Message
|
|
174
|
+
|
|
175
|
+
```js
|
|
176
|
+
await sock.sendMessage(
|
|
177
|
+
'628xxxxxxxxxx@s.whatsapp.net',
|
|
178
|
+
{
|
|
179
|
+
text: 'Hello'
|
|
180
|
+
}
|
|
181
|
+
)
|
|
109
182
|
```
|
|
110
183
|
|
|
111
|
-
###
|
|
184
|
+
### Image Message
|
|
112
185
|
|
|
113
186
|
```js
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
187
|
+
await sock.sendMessage(
|
|
188
|
+
'628xxxxxxxxxx@s.whatsapp.net',
|
|
189
|
+
{
|
|
190
|
+
image: {
|
|
191
|
+
url: './image.jpg'
|
|
192
|
+
},
|
|
193
|
+
caption: 'Hello'
|
|
194
|
+
}
|
|
195
|
+
)
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
### Video Message
|
|
199
|
+
|
|
200
|
+
```js
|
|
201
|
+
await sock.sendMessage(
|
|
202
|
+
'628xxxxxxxxxx@s.whatsapp.net',
|
|
203
|
+
{
|
|
204
|
+
video: {
|
|
205
|
+
url: './video.mp4'
|
|
206
|
+
},
|
|
207
|
+
caption: 'Hello'
|
|
208
|
+
}
|
|
209
|
+
)
|
|
135
210
|
```
|
|
136
211
|
|
|
137
|
-
|
|
212
|
+
---
|
|
213
|
+
|
|
214
|
+
## Raw Message Relay
|
|
138
215
|
|
|
139
|
-
`
|
|
140
|
-
|
|
216
|
+
`relayMessage()` digunakan untuk mengirim raw message object secara langsung.
|
|
217
|
+
|
|
218
|
+
Metode ini berguna ketika aplikasi membutuhkan kontrol yang lebih langsung terhadap struktur message dibandingkan penggunaan helper `sendMessage()` biasa.
|
|
141
219
|
|
|
142
220
|
```js
|
|
143
|
-
|
|
144
|
-
|
|
221
|
+
await sock.relayMessage(
|
|
222
|
+
target,
|
|
223
|
+
message,
|
|
224
|
+
{
|
|
225
|
+
messageId: message.key.id
|
|
226
|
+
}
|
|
227
|
+
)
|
|
228
|
+
```
|
|
145
229
|
|
|
146
|
-
|
|
147
|
-
logger: pino().child({ level: 'silent', stream: 'store' })
|
|
148
|
-
})
|
|
230
|
+
### `Alanself`
|
|
149
231
|
|
|
150
|
-
|
|
151
|
-
store.bind(client.ev)
|
|
232
|
+
Library ini menyediakan opsi tambahan `Alanself` pada relay message:
|
|
152
233
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
234
|
+
```js
|
|
235
|
+
await sock.relayMessage(
|
|
236
|
+
target,
|
|
237
|
+
message,
|
|
238
|
+
{
|
|
239
|
+
messageId: message.key.id,
|
|
240
|
+
Alanself: true
|
|
241
|
+
}
|
|
242
|
+
)
|
|
156
243
|
```
|
|
157
244
|
|
|
158
|
-
|
|
245
|
+
`Alanself: true` digunakan pada implementasi tertentu untuk mengatur bagaimana pesan hasil relay diperlakukan terhadap sinkronisasi pesan milik perangkat pengirim.
|
|
246
|
+
|
|
247
|
+
Karena opsi ini merupakan bagian dari modifikasi/penyesuaian project, perilakunya dapat bergantung pada implementasi socket yang digunakan.
|
|
248
|
+
|
|
249
|
+
---
|
|
159
250
|
|
|
160
|
-
|
|
251
|
+
## Relay Examples
|
|
161
252
|
|
|
162
|
-
|
|
163
|
-
survives restarts without needing an external database:
|
|
253
|
+
### Conversation
|
|
164
254
|
|
|
165
255
|
```js
|
|
166
|
-
|
|
256
|
+
await sock.relayMessage(
|
|
257
|
+
jid,
|
|
258
|
+
{
|
|
259
|
+
conversation: 'Hello'
|
|
260
|
+
},
|
|
261
|
+
{
|
|
262
|
+
Alanself: true
|
|
263
|
+
}
|
|
264
|
+
)
|
|
265
|
+
```
|
|
167
266
|
|
|
168
|
-
|
|
169
|
-
const stopAutoSave = store.writeToFileInterval('./store.json')
|
|
267
|
+
### Extended Text
|
|
170
268
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
269
|
+
```js
|
|
270
|
+
await sock.relayMessage(
|
|
271
|
+
jid,
|
|
272
|
+
{
|
|
273
|
+
extendedTextMessage: {
|
|
274
|
+
text: 'Hello'
|
|
275
|
+
}
|
|
276
|
+
},
|
|
277
|
+
{
|
|
278
|
+
Alanself: true
|
|
279
|
+
}
|
|
280
|
+
)
|
|
175
281
|
```
|
|
176
282
|
|
|
177
|
-
|
|
283
|
+
Raw message relay memungkinkan developer menggunakan struktur message yang lebih spesifik sesuai kebutuhan aplikasinya.
|
|
178
284
|
|
|
179
|
-
|
|
285
|
+
---
|
|
286
|
+
|
|
287
|
+
## Events
|
|
180
288
|
|
|
181
|
-
|
|
289
|
+
Semua event tersedia melalui `sock.ev`.
|
|
290
|
+
|
|
291
|
+
### Connection
|
|
292
|
+
|
|
293
|
+
```js
|
|
294
|
+
sock.ev.on(
|
|
295
|
+
'connection.update',
|
|
296
|
+
({ connection }) => {
|
|
297
|
+
console.log(
|
|
298
|
+
'Connection:',
|
|
299
|
+
connection
|
|
300
|
+
)
|
|
301
|
+
}
|
|
302
|
+
)
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
### Incoming Message
|
|
182
306
|
|
|
183
307
|
```js
|
|
184
|
-
|
|
185
|
-
|
|
308
|
+
sock.ev.on(
|
|
309
|
+
'messages.upsert',
|
|
310
|
+
({ messages }) => {
|
|
311
|
+
for (const message of messages) {
|
|
312
|
+
console.log(
|
|
313
|
+
'Incoming:',
|
|
314
|
+
message.message
|
|
315
|
+
)
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
)
|
|
319
|
+
```
|
|
186
320
|
|
|
187
|
-
|
|
188
|
-
|
|
321
|
+
### Credentials
|
|
322
|
+
|
|
323
|
+
```js
|
|
324
|
+
sock.ev.on(
|
|
325
|
+
'creds.update',
|
|
326
|
+
saveCreds
|
|
327
|
+
)
|
|
189
328
|
```
|
|
190
329
|
|
|
191
|
-
|
|
330
|
+
Event system memungkinkan aplikasi menangani berbagai perubahan secara asynchronous, termasuk status koneksi, pesan masuk, pembaruan credential, dan event lain yang tersedia pada socket.
|
|
331
|
+
|
|
332
|
+
---
|
|
333
|
+
|
|
334
|
+
## Authentication
|
|
192
335
|
|
|
193
|
-
|
|
336
|
+
Session disimpan secara lokal menggunakan:
|
|
194
337
|
|
|
195
338
|
```js
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
339
|
+
useMultiFileAuthState()
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
Contoh struktur session:
|
|
343
|
+
|
|
344
|
+
```text
|
|
345
|
+
session/
|
|
346
|
+
├── creds.json
|
|
347
|
+
├── app-state-sync-key-*.json
|
|
348
|
+
└── ...
|
|
203
349
|
```
|
|
204
350
|
|
|
205
|
-
|
|
351
|
+
Folder tersebut berisi informasi authentication yang memungkinkan aplikasi mempertahankan session WhatsApp.
|
|
206
352
|
|
|
207
|
-
|
|
208
|
-
|
|
353
|
+
Jangan upload folder `session` ke repository publik.
|
|
354
|
+
|
|
355
|
+
Tambahkan ke `.gitignore`:
|
|
356
|
+
|
|
357
|
+
```gitignore
|
|
358
|
+
session/
|
|
359
|
+
node_modules/
|
|
360
|
+
.env
|
|
361
|
+
```
|
|
362
|
+
|
|
363
|
+
Credential session sebaiknya diperlakukan sebagai data sensitif karena dapat digunakan untuk mempertahankan authentication pada perangkat yang menjalankan aplikasi.
|
|
364
|
+
|
|
365
|
+
---
|
|
366
|
+
|
|
367
|
+
## Complete Example
|
|
209
368
|
|
|
210
369
|
```js
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
370
|
+
const makeWASocket =
|
|
371
|
+
require('@whiskeysockets/baileys').default
|
|
372
|
+
|
|
373
|
+
const {
|
|
374
|
+
useMultiFileAuthState
|
|
375
|
+
} = require('@whiskeysockets/baileys')
|
|
376
|
+
|
|
377
|
+
async function start() {
|
|
378
|
+
const { state, saveCreds } =
|
|
379
|
+
await useMultiFileAuthState('./session')
|
|
380
|
+
|
|
381
|
+
const sock = makeWASocket({
|
|
382
|
+
auth: state
|
|
383
|
+
})
|
|
384
|
+
|
|
385
|
+
sock.ev.on(
|
|
386
|
+
'creds.update',
|
|
387
|
+
saveCreds
|
|
388
|
+
)
|
|
389
|
+
|
|
390
|
+
sock.ev.on(
|
|
391
|
+
'connection.update',
|
|
392
|
+
({ connection }) => {
|
|
393
|
+
console.log(
|
|
394
|
+
'[ CONNECTION ]',
|
|
395
|
+
connection
|
|
396
|
+
)
|
|
397
|
+
}
|
|
398
|
+
)
|
|
399
|
+
|
|
400
|
+
async function sendText(jid, text) {
|
|
401
|
+
return sock.sendMessage(
|
|
402
|
+
jid,
|
|
403
|
+
{ text }
|
|
404
|
+
)
|
|
224
405
|
}
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
// Poll result snapshot (usually from a newsletter)
|
|
237
|
-
await client.sendMessage(jid, {
|
|
238
|
-
pollResultMessage: {
|
|
239
|
-
name: 'Poll Title',
|
|
240
|
-
options: [{ optionName: 'Option 1' }, { optionName: 'Option 2' }],
|
|
241
|
-
newsletter: { newsletterName: 'Newsletter Name', newsletterJid: '1234567890@newsletter' }
|
|
406
|
+
|
|
407
|
+
async function relay(jid, message) {
|
|
408
|
+
return sock.relayMessage(
|
|
409
|
+
jid,
|
|
410
|
+
message,
|
|
411
|
+
{
|
|
412
|
+
messageId: message.key.id,
|
|
413
|
+
Alanself: true
|
|
414
|
+
}
|
|
415
|
+
)
|
|
242
416
|
}
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
await client.sendMessage(jid, {
|
|
247
|
-
image: { url: './banner.jpg' },
|
|
248
|
-
text: 'Message body',
|
|
249
|
-
title: 'Title',
|
|
250
|
-
footer: 'Footer',
|
|
251
|
-
interactiveButtons: [{
|
|
252
|
-
name: 'cta_url',
|
|
253
|
-
buttonParamsJson: JSON.stringify({ display_text: 'Visit', url: 'https://example.com' })
|
|
254
|
-
}]
|
|
255
|
-
})
|
|
256
|
-
|
|
257
|
-
// Group member label
|
|
258
|
-
await client.sendMessage(jid, {
|
|
259
|
-
groupLabel: { labelText: 'Admin' }
|
|
260
|
-
})
|
|
261
|
-
|
|
262
|
-
// Broadcast to specific group members
|
|
263
|
-
await client.sendMessageMembers(jid, { extendedTextMessage: { text: 'Announcement' } }, {})
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
start()
|
|
264
420
|
```
|
|
265
421
|
|
|
266
|
-
|
|
267
|
-
> `sendMessage`/`relayMessage` are used for group-participant send context — see
|
|
268
|
-
> [`docs/API.md`](docs/API.md) for details on each socket layer.
|
|
422
|
+
---
|
|
269
423
|
|
|
270
|
-
##
|
|
424
|
+
## Why Choose WhatsApp Baileys?
|
|
425
|
+
|
|
426
|
+
Baileys memberikan pendekatan yang relatif ringan untuk membuat aplikasi yang terhubung dengan WhatsApp Web tanpa harus menjalankan browser automation.
|
|
427
|
+
|
|
428
|
+
Beberapa karakteristik utama yang membuat library ini cocok untuk berbagai kebutuhan development:
|
|
429
|
+
|
|
430
|
+
- **Direct WebSocket Connection**
|
|
431
|
+
Aplikasi dapat berkomunikasi dengan WhatsApp Web melalui koneksi WebSocket tanpa membutuhkan browser sebagai perantara.
|
|
432
|
+
|
|
433
|
+
- **Flexible Authentication**
|
|
434
|
+
Mendukung authentication berbasis QR Code maupun Pairing Code serta penyimpanan session secara lokal.
|
|
271
435
|
|
|
272
|
-
|
|
436
|
+
- **Multi-Device Support**
|
|
437
|
+
Mendukung sistem multi-device WhatsApp sehingga aplikasi dapat digunakan dengan mekanisme authentication modern.
|
|
438
|
+
|
|
439
|
+
- **Raw Message Access**
|
|
440
|
+
`relayMessage()` memungkinkan developer bekerja dengan message object secara lebih langsung ketika `sendMessage()` standar tidak cukup untuk kebutuhan tertentu.
|
|
441
|
+
|
|
442
|
+
- **Event-Based Architecture**
|
|
443
|
+
Berbagai aktivitas dapat dipantau menggunakan event seperti `connection.update`, `messages.upsert`, dan `creds.update`.
|
|
444
|
+
|
|
445
|
+
- **Lightweight Deployment**
|
|
446
|
+
Dapat digunakan pada VPS, Linux server, Docker, maupun Termux tanpa memerlukan browser automation.
|
|
447
|
+
|
|
448
|
+
- **Flexible Integration**
|
|
449
|
+
API dapat digunakan sebagai bagian dari bot, automation system, notification service, customer service application, maupun project Node.js lainnya.
|
|
450
|
+
|
|
451
|
+
- **Customizable**
|
|
452
|
+
Karena source dan struktur library dapat dikembangkan lebih lanjut, developer dapat menyesuaikannya dengan kebutuhan aplikasi masing-masing.
|
|
453
|
+
|
|
454
|
+
---
|
|
455
|
+
|
|
456
|
+
## Technical Notes
|
|
457
|
+
|
|
458
|
+
### Node.js Version
|
|
459
|
+
|
|
460
|
+
Library ditujukan untuk environment Node.js versi:
|
|
461
|
+
|
|
462
|
+
```text
|
|
463
|
+
Node.js >= 20
|
|
464
|
+
```
|
|
465
|
+
|
|
466
|
+
Menggunakan versi Node.js yang sesuai membantu memastikan fitur JavaScript modern dan dependency dapat berjalan sebagaimana mestinya.
|
|
467
|
+
|
|
468
|
+
### Authentication State
|
|
469
|
+
|
|
470
|
+
Authentication state menggunakan:
|
|
273
471
|
|
|
274
472
|
```js
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
})
|
|
473
|
+
useMultiFileAuthState()
|
|
474
|
+
```
|
|
278
475
|
|
|
279
|
-
|
|
280
|
-
for (const m of messages) {
|
|
281
|
-
console.log('Incoming message:', m.message)
|
|
282
|
-
}
|
|
283
|
-
})
|
|
476
|
+
Credential harus tetap disimpan melalui:
|
|
284
477
|
|
|
285
|
-
|
|
478
|
+
```js
|
|
479
|
+
sock.ev.on(
|
|
480
|
+
'creds.update',
|
|
481
|
+
saveCreds
|
|
482
|
+
)
|
|
286
483
|
```
|
|
287
484
|
|
|
288
|
-
|
|
485
|
+
Hal tersebut memungkinkan perubahan credential ditulis ke session secara otomatis.
|
|
289
486
|
|
|
290
|
-
|
|
487
|
+
### Raw Relay
|
|
291
488
|
|
|
292
|
-
|
|
489
|
+
`relayMessage()` bekerja menggunakan raw message object.
|
|
293
490
|
|
|
294
|
-
|
|
295
|
-
- [`examples/pairing-code.js`](examples/pairing-code.js) — pairing code login
|
|
296
|
-
- [`examples/store-usage.js`](examples/store-usage.js) — using the in-memory store
|
|
491
|
+
Contoh:
|
|
297
492
|
|
|
298
|
-
|
|
493
|
+
```js
|
|
494
|
+
await sock.relayMessage(
|
|
495
|
+
jid,
|
|
496
|
+
message,
|
|
497
|
+
{
|
|
498
|
+
messageId: message.key.id,
|
|
499
|
+
Alanself: true
|
|
500
|
+
}
|
|
501
|
+
)
|
|
502
|
+
```
|
|
299
503
|
|
|
300
|
-
|
|
301
|
-
- **Console banner on import** — every time the package is `import`ed, an ASCII art banner and promotional link are printed to stdout. In production or multi-instance setups this becomes log noise.
|
|
302
|
-
- **`optionHash` for per-option image polls** is not implemented — it appears to require further reverse-engineering at the WhatsApp APK level.
|
|
303
|
-
- See [`docs/API.md`](docs/API.md#️-important-notes) for other technical notes.
|
|
504
|
+
Struktur message yang dikirim harus sesuai dengan format message yang dapat diproses oleh socket.
|
|
304
505
|
|
|
305
|
-
|
|
506
|
+
### Environment
|
|
306
507
|
|
|
307
|
-
|
|
508
|
+
Library dapat digunakan pada berbagai environment Node.js, termasuk:
|
|
308
509
|
|
|
309
|
-
|
|
510
|
+
```text
|
|
511
|
+
Linux
|
|
512
|
+
VPS
|
|
513
|
+
Docker
|
|
514
|
+
Termux
|
|
515
|
+
Local Development
|
|
516
|
+
```
|
|
310
517
|
|
|
311
|
-
###
|
|
518
|
+
### Session Security
|
|
312
519
|
|
|
313
|
-
|
|
314
|
-
- Fixes previous issues related to pairing and authentication
|
|
315
|
-
- Features interactive messages and action buttons for dynamic menu creation
|
|
316
|
-
- Automatic and efficient session management for long-term stability
|
|
317
|
-
- Compatible with the latest multi-device features from WhatsApp
|
|
318
|
-
- Easy to integrate and customize based on your needs
|
|
319
|
-
- Perfect for developing bots, customer service automation, and other communication applications
|
|
320
|
-
- Has 1 newsletter follow, only the developer's WhatsApp channel: [WhatsApp Channel](https://whatsapp.com/channel/0029Vb3IiqTL7UVP9A9n0w1x)
|
|
520
|
+
Folder session sebaiknya tidak dibagikan, dikirim ke orang lain, atau diupload ke repository publik.
|
|
321
521
|
|
|
322
|
-
|
|
522
|
+
Jika session tidak sengaja terekspos, authentication dapat berisiko disalahgunakan.
|
|
523
|
+
|
|
524
|
+
### WhatsApp Web Compatibility
|
|
323
525
|
|
|
324
|
-
|
|
526
|
+
WhatsApp dapat melakukan perubahan pada sisi Web maupun protocol. Karena itu, perubahan pada WhatsApp dapat menyebabkan bagian tertentu dari library membutuhkan update atau penyesuaian.
|
|
325
527
|
|
|
326
|
-
|
|
528
|
+
Developer yang menggunakan library ini sebaiknya memperhatikan update dependency dan perubahan compatibility secara berkala.
|
|
327
529
|
|
|
530
|
+
### Additional Features
|
|
531
|
+
|
|
532
|
+
Project ini juga menyediakan berbagai kemampuan message seperti interactive message, action button, poll, quiz, product message, order message, group-related message, dan beberapa struktur message lainnya tergantung versi library yang digunakan.
|
|
328
533
|
|
|
329
534
|
---
|
|
330
535
|
|
|
536
|
+
## Contact Developer
|
|
537
|
+
|
|
538
|
+
Untuk pertanyaan, support, laporan bug, collaboration, atau informasi mengenai project:
|
|
331
539
|
|
|
332
|
-
|
|
540
|
+
- **Telegram:** [Telegram Contact](https://t.me/alannxd)
|
|
541
|
+
- **WhatsApp Channel:** [Channel WhatsApp](https://whatsapp.com/channel/0029Vb3IiqTL7UVP9A9n0w1x)
|
|
333
542
|
|
|
334
|
-
|
|
543
|
+
Untuk informasi terbaru mengenai project dan update library, silakan mengikuti channel yang tersedia.
|
|
335
544
|
|
|
336
|
-
|
|
337
|
-
- **Channel WhatsApp**: [Channel WhatsApp](https://whatsapp.com/channel/0029Vb3IiqTL7UVP9A9n0w1x)
|
|
545
|
+
---
|
|
338
546
|
|
|
339
|
-
|
|
547
|
+
## Contributors outside the Baileys code
|
|
340
548
|
|
|
341
|
-
Thanks to the following awesome contributors who help improve this project
|
|
549
|
+
Thanks to the following awesome contributors who help improve this project.
|
|
342
550
|
|
|
343
551
|
<table>
|
|
344
552
|
<tr>
|
|
@@ -352,10 +560,11 @@ Thanks to the following awesome contributors who help improve this project
|
|
|
352
560
|
<td align="center">
|
|
353
561
|
<a href="https://github.com/Xazepysk">
|
|
354
562
|
<img src="https://github.com/XazepysK.png" width="80px;" style="border-radius:50%;" alt="Contributor"/>
|
|
355
|
-
<br
|
|
563
|
+
<br />
|
|
564
|
+
<sub><b>Xaz zepysK</b></sub>
|
|
356
565
|
</a>
|
|
357
566
|
</td>
|
|
358
|
-
<td align="center">
|
|
567
|
+
<td align="center">
|
|
359
568
|
<a href="https://github.com/kiuur">
|
|
360
569
|
<img src="https://github.com/kiuur.png" width="80px;" style="border-radius:50%;" alt="Contributor"/>
|
|
361
570
|
<br />
|
|
@@ -370,4 +579,32 @@ Thanks to the following awesome contributors who help improve this project
|
|
|
370
579
|
</a>
|
|
371
580
|
</td>
|
|
372
581
|
</tr>
|
|
373
|
-
</table>
|
|
582
|
+
</table>
|
|
583
|
+
|
|
584
|
+
---
|
|
585
|
+
|
|
586
|
+
## Credits
|
|
587
|
+
|
|
588
|
+
<div align="center">
|
|
589
|
+
|
|
590
|
+
**AlannXD**
|
|
591
|
+
|
|
592
|
+
Developer & Maintainer
|
|
593
|
+
|
|
594
|
+
<br>
|
|
595
|
+
|
|
596
|
+
Based on:
|
|
597
|
+
|
|
598
|
+
**Baileys**
|
|
599
|
+
|
|
600
|
+
</div>
|
|
601
|
+
|
|
602
|
+
---
|
|
603
|
+
|
|
604
|
+
## Disclaimer
|
|
605
|
+
|
|
606
|
+
Project ini dibuat untuk keperluan **development dan educational**.
|
|
607
|
+
|
|
608
|
+
Developer tidak bertanggung jawab atas penyalahgunaan library, pembatasan akun, kehilangan session, atau pelanggaran Terms of Service WhatsApp.
|
|
609
|
+
|
|
610
|
+
Gunakan library secara bertanggung jawab dan ikuti ketentuan layanan WhatsApp yang berlaku.
|