@alannxds/baileys 0.0.0-stage → 6.2.11
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/LICENSE +24 -0
- package/README.md +609 -2
- package/WAProto/GenerateStatics.sh +3 -0
- package/WAProto/WAProto.proto +6902 -0
- package/WAProto/fix-imports.js +85 -0
- package/WAProto/index.d.ts +79257 -0
- package/WAProto/index.js +242946 -0
- package/engine-requirements.js +10 -0
- package/lib/Defaults/index.js +130 -0
- package/lib/Signal/Group/ciphertext-message.js +12 -0
- package/lib/Signal/Group/group-session-builder.js +30 -0
- package/lib/Signal/Group/group_cipher.js +82 -0
- package/lib/Signal/Group/index.js +12 -0
- package/lib/Signal/Group/keyhelper.js +18 -0
- package/lib/Signal/Group/sender-chain-key.js +26 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +63 -0
- package/lib/Signal/Group/sender-key-message.js +66 -0
- package/lib/Signal/Group/sender-key-name.js +48 -0
- package/lib/Signal/Group/sender-key-record.js +41 -0
- package/lib/Signal/Group/sender-key-state.js +84 -0
- package/lib/Signal/Group/sender-message-key.js +26 -0
- package/lib/Signal/libsignal.js +431 -0
- package/lib/Signal/lid-mapping.js +277 -0
- package/lib/Socket/Client/index.js +3 -0
- package/lib/Socket/Client/types.js +11 -0
- package/lib/Socket/Client/websocket.js +84 -0
- package/lib/Socket/business.js +379 -0
- package/lib/Socket/chats.js +1193 -0
- package/lib/Socket/communities.js +431 -0
- package/lib/Socket/groups.js +374 -0
- package/lib/Socket/index.js +12 -0
- package/lib/Socket/luxu.js +386 -0
- package/lib/Socket/messages-recv.js +1916 -0
- package/lib/Socket/messages-send.js +1453 -0
- package/lib/Socket/mex.js +41 -0
- package/lib/Socket/newsletter.js +251 -0
- package/lib/Socket/socket.js +980 -0
- package/lib/Socket/username.js +234 -0
- package/lib/Store/index.js +10 -0
- package/lib/Store/keyed-db.js +108 -0
- package/lib/Store/make-cache-manager-store.js +85 -0
- package/lib/Store/make-in-memory-store.js +198 -0
- package/lib/Store/make-ordered-dictionary.js +75 -0
- package/lib/Store/object-repository.js +32 -0
- package/lib/Types/Auth.js +2 -0
- package/lib/Types/Bussines.js +2 -0
- package/lib/Types/Call.js +2 -0
- package/lib/Types/Chat.js +8 -0
- package/lib/Types/Contact.js +2 -0
- package/lib/Types/Events.js +2 -0
- package/lib/Types/GroupMetadata.js +2 -0
- package/lib/Types/Label.js +25 -0
- package/lib/Types/LabelAssociation.js +7 -0
- package/lib/Types/Message.js +11 -0
- package/lib/Types/Mex.js +37 -0
- package/lib/Types/Product.js +2 -0
- package/lib/Types/Signal.js +2 -0
- package/lib/Types/Socket.js +3 -0
- package/lib/Types/State.js +56 -0
- package/lib/Types/USync.js +2 -0
- package/lib/Types/index.js +26 -0
- package/lib/Utils/auth-utils.js +302 -0
- package/lib/Utils/browser-utils.js +49 -0
- package/lib/Utils/business.js +231 -0
- package/lib/Utils/chat-utils.js +872 -0
- package/lib/Utils/companion-reg-client-utils.js +35 -0
- package/lib/Utils/crypto.js +118 -0
- package/lib/Utils/decode-wa-message.js +350 -0
- package/lib/Utils/event-buffer.js +622 -0
- package/lib/Utils/generics.js +403 -0
- package/lib/Utils/history.js +134 -0
- package/lib/Utils/identity-change-handler.js +50 -0
- package/lib/Utils/index.js +23 -0
- package/lib/Utils/link-preview.js +85 -0
- package/lib/Utils/logger.js +3 -0
- package/lib/Utils/lt-hash.js +8 -0
- package/lib/Utils/make-mutex.js +33 -0
- package/lib/Utils/message-composer.js +273 -0
- package/lib/Utils/message-retry-manager.js +265 -0
- package/lib/Utils/messages-media.js +788 -0
- package/lib/Utils/messages.js +1260 -0
- package/lib/Utils/noise-handler.js +201 -0
- package/lib/Utils/offline-node-processor.js +40 -0
- package/lib/Utils/pre-key-manager.js +106 -0
- package/lib/Utils/process-message.js +630 -0
- package/lib/Utils/reporting-utils.js +258 -0
- package/lib/Utils/signal.js +201 -0
- package/lib/Utils/stanza-ack.js +38 -0
- package/lib/Utils/sync-action-utils.js +49 -0
- package/lib/Utils/tc-token-utils.js +163 -0
- package/lib/Utils/use-multi-file-auth-state.js +121 -0
- package/lib/Utils/validate-connection.js +203 -0
- package/lib/WABinary/constants.js +1301 -0
- package/lib/WABinary/decode.js +262 -0
- package/lib/WABinary/encode.js +220 -0
- package/lib/WABinary/generic-utils.js +204 -0
- package/lib/WABinary/index.js +6 -0
- package/lib/WABinary/jid-utils.js +98 -0
- package/lib/WABinary/types.js +2 -0
- package/lib/WAM/BinaryInfo.js +10 -0
- package/lib/WAM/constants.js +22853 -0
- package/lib/WAM/encode.js +150 -0
- package/lib/WAM/index.js +4 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +52 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +54 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +27 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +38 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +25 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +51 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +29 -0
- package/lib/WAUSync/Protocols/index.js +6 -0
- package/lib/WAUSync/USyncQuery.js +98 -0
- package/lib/WAUSync/USyncUser.js +31 -0
- package/lib/WAUSync/index.js +4 -0
- package/lib/index.js +34 -0
- package/package.json +140 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 alannxd (AlannXD) and contributors
|
|
4
|
+
|
|
5
|
+
Based on Baileys (https://github.com/WhiskeySockets/Baileys), originally
|
|
6
|
+
created by Adhiraj Singh and the WhiskeySockets community, also MIT licensed.
|
|
7
|
+
|
|
8
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
9
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
10
|
+
in the Software without restriction, including without limitation the rights
|
|
11
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
12
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
13
|
+
furnished to do so, subject to the following conditions:
|
|
14
|
+
|
|
15
|
+
The above copyright notice and this permission notice shall be included in all
|
|
16
|
+
copies or substantial portions of the Software.
|
|
17
|
+
|
|
18
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
19
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
20
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
21
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
22
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
23
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
24
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,610 @@
|
|
|
1
|
-
#
|
|
1
|
+
# <div align='center'>Baileys - Typescript/Javascript WhatsApp Web API</div>
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
<p align="center">
|
|
4
|
+
<img src="https://img3.pixhost.to/images/6661/791050008_alanwinter.jpg" alt="Thumbnail" />
|
|
5
|
+
</p>
|
|
6
|
+
|
|
7
|
+
<div align='center'>
|
|
8
|
+
|
|
9
|
+

|
|
10
|
+

|
|
11
|
+

|
|
12
|
+

|
|
13
|
+

|
|
14
|
+

|
|
15
|
+

|
|
16
|
+
|
|
17
|
+
</div>
|
|
18
|
+
|
|
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
|
+
|
|
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
|
+
|
|
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.
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
### Main Features and Advantages
|
|
32
|
+
|
|
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
|
|
51
|
+
|
|
52
|
+
---
|
|
53
|
+
|
|
54
|
+
## Getting Started
|
|
55
|
+
|
|
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.
|
|
63
|
+
|
|
64
|
+
---
|
|
65
|
+
|
|
66
|
+
## Table of Contents
|
|
67
|
+
|
|
68
|
+
- [Requirements](#requirements)
|
|
69
|
+
- [Install](#install)
|
|
70
|
+
- [Quick Start](#quick-start)
|
|
71
|
+
- [Sending Messages](#sending-messages)
|
|
72
|
+
- [Raw Message Relay](#raw-message-relay)
|
|
73
|
+
- [Relay Examples](#relay-examples)
|
|
74
|
+
- [Events](#events)
|
|
75
|
+
- [Authentication](#authentication)
|
|
76
|
+
- [Complete Example](#complete-example)
|
|
77
|
+
- [Why Choose WhatsApp Baileys?](#why-choose-whatsapp-baileys)
|
|
78
|
+
- [Technical Notes](#technical-notes)
|
|
79
|
+
- [Contact Developer](#contact-developer)
|
|
80
|
+
- [Contributors outside the Baileys code](#contributors-outside-the-baileys-code)
|
|
81
|
+
- [Credits](#credits)
|
|
82
|
+
- [Disclaimer](#disclaimer)
|
|
83
|
+
|
|
84
|
+
---
|
|
85
|
+
|
|
86
|
+
## Requirements
|
|
87
|
+
|
|
88
|
+
- Node.js **>= 20**
|
|
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
|
+
---
|
|
96
|
+
|
|
97
|
+
## Install
|
|
98
|
+
|
|
99
|
+
Install the package using npm:
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
npm install @alannxd/baileys
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Or use it as an alias while keeping the standard Baileys package name in your source code:
|
|
106
|
+
|
|
107
|
+
```json
|
|
108
|
+
{
|
|
109
|
+
"dependencies": {
|
|
110
|
+
"@whiskeysockets/baileys": "npm:@alannxd/baileys@latest"
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
Then import it using:
|
|
116
|
+
|
|
117
|
+
```js
|
|
118
|
+
const makeWASocket =
|
|
119
|
+
require('@whiskeysockets/baileys').default
|
|
120
|
+
|
|
121
|
+
const {
|
|
122
|
+
useMultiFileAuthState
|
|
123
|
+
} = require('@whiskeysockets/baileys')
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
---
|
|
127
|
+
|
|
128
|
+
## Quick Start
|
|
129
|
+
|
|
130
|
+
The following example creates a basic WhatsApp connection, stores authentication credentials locally, and listens for connection updates.
|
|
131
|
+
|
|
132
|
+
```js
|
|
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
|
+
}
|
|
163
|
+
|
|
164
|
+
start()
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
The authentication state is stored inside the `session/` directory. Once authenticated, the same session can be reused when the application starts again.
|
|
168
|
+
|
|
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
|
+
)
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
### Image Message
|
|
185
|
+
|
|
186
|
+
```js
|
|
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
|
+
)
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
---
|
|
213
|
+
|
|
214
|
+
## Raw Message Relay
|
|
215
|
+
|
|
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.
|
|
219
|
+
|
|
220
|
+
```js
|
|
221
|
+
await sock.relayMessage(
|
|
222
|
+
target,
|
|
223
|
+
message,
|
|
224
|
+
{
|
|
225
|
+
messageId: message.key.id
|
|
226
|
+
}
|
|
227
|
+
)
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
### `Alanself`
|
|
231
|
+
|
|
232
|
+
Library ini menyediakan opsi tambahan `Alanself` pada relay message:
|
|
233
|
+
|
|
234
|
+
```js
|
|
235
|
+
await sock.relayMessage(
|
|
236
|
+
target,
|
|
237
|
+
message,
|
|
238
|
+
{
|
|
239
|
+
messageId: message.key.id,
|
|
240
|
+
Alanself: true
|
|
241
|
+
}
|
|
242
|
+
)
|
|
243
|
+
```
|
|
244
|
+
|
|
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
|
+
---
|
|
250
|
+
|
|
251
|
+
## Relay Examples
|
|
252
|
+
|
|
253
|
+
### Conversation
|
|
254
|
+
|
|
255
|
+
```js
|
|
256
|
+
await sock.relayMessage(
|
|
257
|
+
jid,
|
|
258
|
+
{
|
|
259
|
+
conversation: 'Hello'
|
|
260
|
+
},
|
|
261
|
+
{
|
|
262
|
+
Alanself: true
|
|
263
|
+
}
|
|
264
|
+
)
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
### Extended Text
|
|
268
|
+
|
|
269
|
+
```js
|
|
270
|
+
await sock.relayMessage(
|
|
271
|
+
jid,
|
|
272
|
+
{
|
|
273
|
+
extendedTextMessage: {
|
|
274
|
+
text: 'Hello'
|
|
275
|
+
}
|
|
276
|
+
},
|
|
277
|
+
{
|
|
278
|
+
Alanself: true
|
|
279
|
+
}
|
|
280
|
+
)
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
Raw message relay memungkinkan developer menggunakan struktur message yang lebih spesifik sesuai kebutuhan aplikasinya.
|
|
284
|
+
|
|
285
|
+
---
|
|
286
|
+
|
|
287
|
+
## Events
|
|
288
|
+
|
|
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
|
|
306
|
+
|
|
307
|
+
```js
|
|
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
|
+
```
|
|
320
|
+
|
|
321
|
+
### Credentials
|
|
322
|
+
|
|
323
|
+
```js
|
|
324
|
+
sock.ev.on(
|
|
325
|
+
'creds.update',
|
|
326
|
+
saveCreds
|
|
327
|
+
)
|
|
328
|
+
```
|
|
329
|
+
|
|
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
|
|
335
|
+
|
|
336
|
+
Session disimpan secara lokal menggunakan:
|
|
337
|
+
|
|
338
|
+
```js
|
|
339
|
+
useMultiFileAuthState()
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
Contoh struktur session:
|
|
343
|
+
|
|
344
|
+
```text
|
|
345
|
+
session/
|
|
346
|
+
├── creds.json
|
|
347
|
+
├── app-state-sync-key-*.json
|
|
348
|
+
└── ...
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
Folder tersebut berisi informasi authentication yang memungkinkan aplikasi mempertahankan session WhatsApp.
|
|
352
|
+
|
|
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
|
|
368
|
+
|
|
369
|
+
```js
|
|
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
|
+
)
|
|
405
|
+
}
|
|
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
|
+
)
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
start()
|
|
420
|
+
```
|
|
421
|
+
|
|
422
|
+
---
|
|
423
|
+
|
|
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.
|
|
435
|
+
|
|
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:
|
|
471
|
+
|
|
472
|
+
```js
|
|
473
|
+
useMultiFileAuthState()
|
|
474
|
+
```
|
|
475
|
+
|
|
476
|
+
Credential harus tetap disimpan melalui:
|
|
477
|
+
|
|
478
|
+
```js
|
|
479
|
+
sock.ev.on(
|
|
480
|
+
'creds.update',
|
|
481
|
+
saveCreds
|
|
482
|
+
)
|
|
483
|
+
```
|
|
484
|
+
|
|
485
|
+
Hal tersebut memungkinkan perubahan credential ditulis ke session secara otomatis.
|
|
486
|
+
|
|
487
|
+
### Raw Relay
|
|
488
|
+
|
|
489
|
+
`relayMessage()` bekerja menggunakan raw message object.
|
|
490
|
+
|
|
491
|
+
Contoh:
|
|
492
|
+
|
|
493
|
+
```js
|
|
494
|
+
await sock.relayMessage(
|
|
495
|
+
jid,
|
|
496
|
+
message,
|
|
497
|
+
{
|
|
498
|
+
messageId: message.key.id,
|
|
499
|
+
Alanself: true
|
|
500
|
+
}
|
|
501
|
+
)
|
|
502
|
+
```
|
|
503
|
+
|
|
504
|
+
Struktur message yang dikirim harus sesuai dengan format message yang dapat diproses oleh socket.
|
|
505
|
+
|
|
506
|
+
### Environment
|
|
507
|
+
|
|
508
|
+
Library dapat digunakan pada berbagai environment Node.js, termasuk:
|
|
509
|
+
|
|
510
|
+
```text
|
|
511
|
+
Linux
|
|
512
|
+
VPS
|
|
513
|
+
Docker
|
|
514
|
+
Termux
|
|
515
|
+
Local Development
|
|
516
|
+
```
|
|
517
|
+
|
|
518
|
+
### Session Security
|
|
519
|
+
|
|
520
|
+
Folder session sebaiknya tidak dibagikan, dikirim ke orang lain, atau diupload ke repository publik.
|
|
521
|
+
|
|
522
|
+
Jika session tidak sengaja terekspos, authentication dapat berisiko disalahgunakan.
|
|
523
|
+
|
|
524
|
+
### WhatsApp Web Compatibility
|
|
525
|
+
|
|
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.
|
|
527
|
+
|
|
528
|
+
Developer yang menggunakan library ini sebaiknya memperhatikan update dependency dan perubahan compatibility secara berkala.
|
|
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.
|
|
533
|
+
|
|
534
|
+
---
|
|
535
|
+
|
|
536
|
+
## Contact Developer
|
|
537
|
+
|
|
538
|
+
Untuk pertanyaan, support, laporan bug, collaboration, atau informasi mengenai project:
|
|
539
|
+
|
|
540
|
+
- **Telegram:** [Telegram Contact](https://t.me/alannxd)
|
|
541
|
+
- **WhatsApp Channel:** [Channel WhatsApp](https://whatsapp.com/channel/0029Vb3IiqTL7UVP9A9n0w1x)
|
|
542
|
+
|
|
543
|
+
Untuk informasi terbaru mengenai project dan update library, silakan mengikuti channel yang tersedia.
|
|
544
|
+
|
|
545
|
+
---
|
|
546
|
+
|
|
547
|
+
## Contributors outside the Baileys code
|
|
548
|
+
|
|
549
|
+
Thanks to the following awesome contributors who help improve this project.
|
|
550
|
+
|
|
551
|
+
<table>
|
|
552
|
+
<tr>
|
|
553
|
+
<td align="center">
|
|
554
|
+
<a href="https://github.com/alannzxd">
|
|
555
|
+
<img src="https://github.com/alannzxd.png" width="80px;" style="border-radius:50%;" alt="Developer"/>
|
|
556
|
+
<br />
|
|
557
|
+
<sub><b>AlannXD</b></sub>
|
|
558
|
+
</a>
|
|
559
|
+
</td>
|
|
560
|
+
<td align="center">
|
|
561
|
+
<a href="https://github.com/Xazepysk">
|
|
562
|
+
<img src="https://github.com/XazepysK.png" width="80px;" style="border-radius:50%;" alt="Contributor"/>
|
|
563
|
+
<br />
|
|
564
|
+
<sub><b>Xaz zepysK</b></sub>
|
|
565
|
+
</a>
|
|
566
|
+
</td>
|
|
567
|
+
<td align="center">
|
|
568
|
+
<a href="https://github.com/kiuur">
|
|
569
|
+
<img src="https://github.com/kiuur.png" width="80px;" style="border-radius:50%;" alt="Contributor"/>
|
|
570
|
+
<br />
|
|
571
|
+
<sub><b>KyuuRzy</b></sub>
|
|
572
|
+
</a>
|
|
573
|
+
</td>
|
|
574
|
+
<td align="center">
|
|
575
|
+
<a href="https://github.com/Xcoursed">
|
|
576
|
+
<img src="https://github.com/Xcoursed.png" width="80px;" style="border-radius:50%;" alt="Contributor"/>
|
|
577
|
+
<br />
|
|
578
|
+
<sub><b>Xcoursed</b></sub>
|
|
579
|
+
</a>
|
|
580
|
+
</td>
|
|
581
|
+
</tr>
|
|
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.
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
yarn pbjs -t static-module --no-beautify -w es6 --no-bundle --no-delimited --no-verify --no-comments -o ./index.js ./WAProto.proto;
|
|
2
|
+
yarn pbjs -t static-module --no-beautify -w es6 --no-bundle --no-delimited --no-verify ./WAProto.proto | yarn pbts --no-comments -o ./index.d.ts -;
|
|
3
|
+
node ./fix-imports.js
|