@kelvdra/baileys 1.0.3 → 1.0.4
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 +75 -1499
- package/lib/Defaults/index.d.ts +62 -0
- package/lib/Defaults/index.js +2 -2
- package/lib/Defaults/phonenumber-mcc.json +223 -0
- package/lib/Signal/Group/ciphertext-message.d.ts +10 -0
- package/lib/Signal/Group/group-session-builder.d.ts +15 -0
- package/lib/Signal/Group/group_cipher.d.ts +17 -0
- package/lib/Signal/Group/index.d.ts +12 -0
- package/lib/Signal/Group/keyhelper.d.ts +11 -0
- package/lib/Signal/Group/sender-chain-key.d.ts +14 -0
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +17 -0
- package/lib/Signal/Group/sender-key-message.d.ts +19 -0
- package/lib/Signal/Group/sender-key-name.d.ts +18 -0
- package/lib/Signal/Group/sender-key-record.d.ts +31 -0
- package/lib/Signal/Group/sender-key-state.d.ts +39 -0
- package/lib/Signal/Group/sender-message-key.d.ts +12 -0
- package/lib/Signal/libsignal.d.ts +5 -0
- package/lib/Signal/lid-mapping.d.ts +23 -0
- package/lib/Socket/Client/index.d.ts +3 -0
- package/lib/Socket/Client/types.d.ts +16 -0
- package/lib/Socket/Client/websocket.d.ts +13 -0
- package/lib/Socket/business.d.ts +190 -0
- package/lib/Socket/chats.d.ts +100 -0
- package/lib/Socket/chats.js +14 -13
- package/lib/Socket/communities.d.ts +246 -0
- package/lib/Socket/groups.d.ts +139 -0
- package/lib/Socket/groups.js +2 -3
- package/lib/Socket/hydra.js +1 -2
- package/lib/Socket/index.d.ts +233 -0
- package/lib/Socket/messages-recv.d.ts +175 -0
- package/lib/Socket/messages-recv.js +325 -515
- package/lib/Socket/messages-send.d.ts +171 -0
- package/lib/Socket/messages-send.js +104 -467
- package/lib/Socket/mex.d.ts +3 -0
- package/lib/Socket/newsletter.d.ts +149 -0
- package/lib/Socket/socket.d.ts +53 -0
- package/lib/Socket/socket.js +52 -51
- package/lib/Store/index.d.ts +4 -0
- package/lib/Store/make-cache-manager-store.d.ts +14 -0
- package/lib/Store/make-in-memory-store.d.ts +123 -0
- package/lib/Store/make-ordered-dictionary.d.ts +12 -0
- package/lib/Store/object-repository.d.ts +10 -0
- package/lib/Types/Auth.d.ts +115 -0
- package/lib/Types/Bussines.d.ts +25 -0
- package/lib/Types/Call.d.ts +14 -0
- package/lib/Types/Chat.d.ts +123 -0
- package/lib/Types/Contact.d.ts +24 -0
- package/lib/Types/Events.d.ts +202 -0
- package/lib/Types/GroupMetadata.d.ts +67 -0
- package/lib/Types/Label.d.ts +47 -0
- package/lib/Types/LabelAssociation.d.ts +30 -0
- package/lib/Types/Message.d.ts +382 -0
- package/lib/Types/Newsletter.d.ts +135 -0
- package/lib/Types/Product.d.ts +79 -0
- package/lib/Types/Signal.d.ts +76 -0
- package/lib/Types/Socket.d.ts +133 -0
- package/lib/Types/State.d.ts +39 -0
- package/lib/Types/USync.d.ts +26 -0
- package/lib/Types/index.d.ts +65 -0
- package/lib/Utils/auth-utils.d.ts +19 -0
- package/lib/Utils/browser-utils.d.ts +4 -0
- package/lib/Utils/business.d.ts +23 -0
- package/lib/Utils/chat-utils.d.ts +70 -0
- package/lib/Utils/crypto.d.ts +41 -0
- package/lib/Utils/decode-wa-message.d.ts +48 -0
- package/lib/Utils/decode-wa-message.js +5 -7
- package/lib/Utils/event-buffer.d.ts +34 -0
- package/lib/Utils/generics.d.ts +90 -0
- package/lib/Utils/history.d.ts +19 -0
- package/lib/Utils/index.d.ts +19 -0
- package/lib/Utils/link-preview.d.ts +21 -0
- package/lib/Utils/logger.d.ts +12 -0
- package/lib/Utils/lt-hash.d.ts +13 -0
- package/lib/Utils/make-mutex.d.ts +8 -0
- package/lib/Utils/message-retry-manager.d.ts +82 -0
- package/lib/Utils/messages-media.d.ts +114 -0
- package/lib/Utils/messages-media.js +69 -33
- package/lib/Utils/messages.d.ts +89 -0
- package/lib/Utils/messages.js +42 -12
- package/lib/Utils/noise-handler.d.ts +20 -0
- package/lib/Utils/pre-key-manager.d.ts +28 -0
- package/lib/Utils/process-message.d.ts +60 -0
- package/lib/Utils/signal.d.ts +34 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts +13 -0
- package/lib/Utils/validate-connection.d.ts +11 -0
- package/lib/WABinary/constants.d.ts +28 -0
- package/lib/WABinary/decode.d.ts +7 -0
- package/lib/WABinary/encode.d.ts +3 -0
- package/lib/WABinary/generic-utils.d.ts +15 -0
- package/lib/WABinary/generic-utils.js +7 -0
- package/lib/WABinary/index.d.ts +6 -0
- package/lib/WABinary/jid-utils.d.ts +48 -0
- package/lib/WABinary/types.d.ts +19 -0
- package/lib/WAM/BinaryInfo.d.ts +9 -0
- package/lib/WAM/constants.d.ts +40 -0
- package/lib/WAM/encode.d.ts +3 -0
- package/lib/WAM/index.d.ts +4 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +10 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +23 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +13 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +13 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +26 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +10 -0
- package/lib/WAUSync/Protocols/index.d.ts +5 -0
- package/lib/WAUSync/USyncQuery.d.ts +29 -0
- package/lib/WAUSync/USyncUser.d.ts +13 -0
- package/lib/WAUSync/index.d.ts +4 -0
- package/lib/index.d.ts +13 -0
- package/package.json +3 -34
package/README.md
CHANGED
|
@@ -1,1555 +1,131 @@
|
|
|
1
|
-
|
|
2
|
-
<div align="center">
|
|
3
|
-
<img src="https://files.catbox.moe/1rjzor.jpeg" alt="WhatsApp Web API" width="600"/>
|
|
4
|
-
|
|
5
|
-
# WhatsApp Web API
|
|
1
|
+
# WhatsApp Web API
|
|
6
2
|
**Advanced Baileys WhatsApp API Wrapper**
|
|
3
|
+
|
|
4
|
+

|
|
7
5
|
|
|
8
|
-
|
|
9
|
-
[](https://www.npmjs.com/package/@kelvdra/baileys)
|
|
10
|
-
[](./LICENSE)
|
|
11
|
-
|
|
12
|
-
---
|
|
13
|
-
A modern and feature-rich WhatsApp Web API built on top of **Baileys** —
|
|
14
|
-
designed for automation, chatbots, and integration with any Node.js project.
|
|
15
|
-
</div>
|
|
16
|
-
|
|
17
|
-
---
|
|
6
|
+
> Contoh implementasi dasar untuk terhubung ke WhatsApp menggunakan pustaka `@kelvdra/baileys`.
|
|
18
7
|
|
|
19
|
-
|
|
20
|
-
- [⚡ Quick Start](#-quick-start)
|
|
21
|
-
- [📦 Installation](#-installation)
|
|
22
|
-
- [🔌 Connecting Account](#-connecting-account)
|
|
23
|
-
- [💡 Important Notes](#-important-notes-about-socket-config)
|
|
24
|
-
- [💾 Saving & Restoring Sessions](#-saving--restoring-sessions)
|
|
25
|
-
- [📡 Handling Events](#-handling-events)
|
|
26
|
-
- [🛠 Implementing a Data Store](#-implementing-a-data-store)
|
|
27
|
-
- [🔑 WhatsApp IDs](#-whatsapp-ids-explain)
|
|
28
|
-
- [✉️ Sending Messages](#-sending-messages)
|
|
29
|
-
- [Non-Media Messages](#non-media-messages)
|
|
30
|
-
- [Text Message](#text-message)
|
|
31
|
-
- [Quote Message](#quote-message-works-with-all-types)
|
|
32
|
-
- [Mention User](#mention-user-works-with-most-types)
|
|
33
|
-
- [Mention Status](#mention-status)
|
|
34
|
-
- [Result Poll From Newsletter](#result-poll-from-newsletter)
|
|
35
|
-
- [SendAlbumMessage](#send-album-message)
|
|
36
|
-
- [SendMessage Product Simple](#SendMessage-Product-Simple)
|
|
37
|
-
- [SendMessage Carousel](#sendMessage-Carousel)
|
|
38
|
-
- [Request Payment](#request-payment)
|
|
39
|
-
- [Event Message](#event-message)
|
|
40
|
-
- [Interactive Message with Native Flow](#Interactive-Message-with-Native-Flow)
|
|
41
|
-
- [Interactive](#interactive)
|
|
42
|
-
- [Forward Messages](#forward-messages)
|
|
43
|
-
- [Location Message](#location-message)
|
|
44
|
-
- [Contact Message](#contact-message)
|
|
45
|
-
- [Reaction Message](#reaction-message)
|
|
46
|
-
- [Pin Message](#pin-message)
|
|
47
|
-
- [Keep Message](#keep-message)
|
|
48
|
-
- [Poll Message](#poll-message)
|
|
49
|
-
- [Sending with Link Preview](#sending-messages-with-link-previews)
|
|
50
|
-
- [🖼 Media Messages](#-media-messages)
|
|
51
|
-
- [Gif Message](#gif-message)
|
|
52
|
-
- [Video Message](#video-message)
|
|
53
|
-
- [Audio Message](#audio-message)
|
|
54
|
-
- [Image Message](#image-message)
|
|
55
|
-
- [ViewOnce Message](#view-once-message)
|
|
56
|
-
- [✏️ Modify Messages](#-modify-messages)
|
|
57
|
-
- [📥 Downloading & Re-uploading Media](#-manipulating-media-messages)
|
|
58
|
-
- [📞 Call & Presence Handling](#-reject-call)
|
|
59
|
-
- [💬 Chat Modifications](#-modifying-chats)
|
|
60
|
-
- [🔍 User Queries](#-user-querys)
|
|
61
|
-
- [👤 Profile Management](#-change-profile)
|
|
62
|
-
- [👥 Group Management](#-groups)
|
|
63
|
-
- [🔒 Privacy Controls](#-privacy)
|
|
64
|
-
- [📢 Broadcast & Stories](#-broadcast-lists--stories)
|
|
65
|
-
- [🧩 Custom Functionality](#-writing-custom-functionality)
|
|
8
|
+
Repositori ini berisi contoh implementasi sederhana untuk membangun koneksi WhatsApp menggunakan pustaka **`@kelvdra/baileys`**, sebuah *wrapper* canggih berbasis Baileys untuk membangun otomasi, chatbot, dan integrasi WhatsApp dalam proyek Node.js.
|
|
66
9
|
|
|
67
10
|
---
|
|
68
11
|
|
|
69
|
-
##
|
|
12
|
+
## 📌 Tentang @kelvdra/baileys
|
|
70
13
|
|
|
71
|
-
|
|
14
|
+
`@kelvdra/baileys` memungkinkan Anda:
|
|
72
15
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
```
|
|
16
|
+
- Membuat WhatsApp bot
|
|
17
|
+
- Mengotomasi pengiriman dan penerimaan pesan
|
|
18
|
+
- Mengelola grup dan kontak
|
|
19
|
+
- Membuat integrasi WhatsApp berbasis WebSocket tanpa browser
|
|
78
20
|
|
|
79
|
-
|
|
21
|
+
Library ini berjalan sebagai **klien WhatsApp Web sekunder (multi-device)**.
|
|
80
22
|
|
|
81
23
|
---
|
|
82
24
|
|
|
83
|
-
##
|
|
25
|
+
## ✨ Fitur Utama
|
|
84
26
|
|
|
85
|
-
**
|
|
86
|
-
|
|
87
|
-
npm install @kelvdra/baileys
|
|
88
|
-
```
|
|
27
|
+
- 🔗 **Koneksi Multi-Device**
|
|
28
|
+
Tetap bisa menggunakan WhatsApp di ponsel saat bot berjalan.
|
|
89
29
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
yarn add @kelvdra/baileys@latest
|
|
93
|
-
```
|
|
30
|
+
- 💾 **Manajemen Sesi Otomatis**
|
|
31
|
+
Menyimpan dan memulihkan sesi tanpa perlu scan QR berulang kali.
|
|
94
32
|
|
|
95
|
-
**
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
33
|
+
- 📡 **Event Handler Lengkap**
|
|
34
|
+
Mendukung monitoring event seperti:
|
|
35
|
+
- Perubahan koneksi
|
|
36
|
+
- Update kredensial
|
|
37
|
+
- Riwayat pesan
|
|
38
|
+
- Perubahan grup
|
|
99
39
|
|
|
100
|
-
|
|
40
|
+
- ⚡ **Ringan & Stabil**
|
|
41
|
+
Menggunakan WebSocket langsung tanpa Selenium atau browser automation.
|
|
101
42
|
|
|
102
43
|
---
|
|
103
44
|
|
|
104
|
-
##
|
|
105
|
-
|
|
106
|
-
WhatsApp supports **multi-device API**, allowing Baileys to act as a secondary WhatsApp Web client.
|
|
107
|
-
You can connect via **QR Code** or **Pairing Code**.
|
|
108
|
-
|
|
109
|
-
# How To Connect To Whatsapp
|
|
110
|
-
## With QR Code
|
|
111
|
-
```javascript
|
|
112
|
-
import makeWASocket from '@kelvdra/baileys'
|
|
113
|
-
|
|
114
|
-
const client = makeWASocket({
|
|
115
|
-
browser: ['Ubuntu', 'Chrome', '20.00.1'],
|
|
116
|
-
printQRInTerminal: true
|
|
117
|
-
})
|
|
118
|
-
```
|
|
119
|
-
|
|
120
|
-
## Connect With Number
|
|
121
|
-
```javascript
|
|
122
|
-
import makeWASocket, { useMultiFileAuthState } from '@kelvdra/baileys'
|
|
123
|
-
|
|
124
|
-
const client = makeWASocket({
|
|
125
|
-
browser: ['Ubuntu', 'Chrome', '20.00.1'],
|
|
126
|
-
printQRInTerminal: false,
|
|
127
|
-
version: fetchLatestWAWebVersion()
|
|
128
|
-
// Other options
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
const number = "628XXXXX";
|
|
132
|
-
const code = await client.requestPairingCode(number.trim) /* Use : (number, "YYYYYYYY") for custom-pairing */
|
|
133
|
-
|
|
134
|
-
console.log("Ur pairing code : " + code)
|
|
135
|
-
```
|
|
45
|
+
## 🛠 1. Instalasi
|
|
136
46
|
|
|
137
|
-
|
|
47
|
+
### Versi Stabil (Direkomendasikan)
|
|
138
48
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
const groupCache = new NodeCache({ stdTTL: 5 * 60, useClones: false });
|
|
142
|
-
|
|
143
|
-
const sock = makeWASocket({
|
|
144
|
-
cachedGroupMetadata: async (jid) => groupCache.get(jid)
|
|
145
|
-
});
|
|
49
|
+
```bash
|
|
50
|
+
npm install @kelvdra/baileys
|
|
146
51
|
```
|
|
147
52
|
|
|
148
|
-
###
|
|
149
|
-
```javascript
|
|
150
|
-
const sock = makeWASocket({
|
|
151
|
-
getMessage: async (key) => await getMessageFromStore(key)
|
|
152
|
-
});
|
|
153
|
-
```
|
|
53
|
+
### Versi Edge (Fitur Terbaru)
|
|
154
54
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
const sock = makeWASocket({
|
|
158
|
-
markOnlineOnConnect: false
|
|
159
|
-
});
|
|
55
|
+
```bash
|
|
56
|
+
npm install @kelvdra/baileys@latest
|
|
160
57
|
```
|
|
161
58
|
|
|
162
59
|
---
|
|
163
60
|
|
|
164
|
-
##
|
|
165
|
-
|
|
166
|
-
Avoid scanning QR every time:
|
|
167
|
-
```javascript
|
|
168
|
-
import makeWASocket from @kelvdra/baileys";
|
|
169
|
-
import { useMultiFileAuthState } from "@kelvdra/baileys"
|
|
170
|
-
|
|
171
|
-
const { state, saveCreds } = await useMultiFileAuthState('auth_info_baileys');
|
|
172
|
-
const sock = makeWASocket({ auth: state });
|
|
61
|
+
## 🚀 2. Penggunaan Dasar
|
|
173
62
|
|
|
174
|
-
|
|
175
|
-
```
|
|
176
|
-
> 💡 Recommended to store auth in a database for production.
|
|
63
|
+
### Inisialisasi & Konfigurasi
|
|
177
64
|
|
|
178
|
-
---
|
|
179
|
-
|
|
180
|
-
## 📡 Handling Events
|
|
181
|
-
|
|
182
|
-
Listen to events using:
|
|
183
65
|
```javascript
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
66
|
+
import makeWASocket, {
|
|
67
|
+
useMultiFileAuthState,
|
|
68
|
+
DisconnectReason,
|
|
69
|
+
fetchLatestWaWebVersion
|
|
70
|
+
} from '@kelvdra/baileys';
|
|
71
|
+
import pino from 'pino';
|
|
72
|
+
import { Boom } from '@hapi/boom';
|
|
190
73
|
|
|
191
|
-
|
|
192
|
-
|
|
74
|
+
async function connectToWhatsApp() {
|
|
75
|
+
const { state, saveCreds } = await useMultiFileAuthState('auth_info_baileys');
|
|
193
76
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
import { DisconnectReason, useMultiFileAuthState } from "@kelvdra/baileys"
|
|
197
|
-
import Boom from '@hapi/boom'
|
|
77
|
+
const { version, isLatest } = await fetchLatestWaWebVersion();
|
|
78
|
+
console.log(`Menggunakan WA v${version.join('.')}, Versi Terbaru: ${isLatest}`);
|
|
198
79
|
|
|
199
|
-
async function connectToWhatsApp () {
|
|
200
|
-
const { state, saveCreds } = await useMultiFileAuthState('auth_info_baileys')
|
|
201
80
|
const sock = makeWASocket({
|
|
202
|
-
|
|
81
|
+
version,
|
|
82
|
+
logger: pino({ level: 'silent' }),
|
|
83
|
+
printQRInTerminal: true,
|
|
203
84
|
auth: state,
|
|
204
|
-
|
|
205
|
-
})
|
|
206
|
-
sock.ev.on('connection.update', (update) => {
|
|
207
|
-
const { connection, lastDisconnect } = update
|
|
208
|
-
if(connection === 'close') {
|
|
209
|
-
const shouldReconnect = (lastDisconnect.error as Boom)?.output?.statusCode !== DisconnectReason.loggedOut
|
|
210
|
-
console.log('connection closed due to ', lastDisconnect.error, ', reconnecting ', shouldReconnect)
|
|
211
|
-
// reconnect if not logged out
|
|
212
|
-
if(shouldReconnect) {
|
|
213
|
-
connectToWhatsApp()
|
|
214
|
-
}
|
|
215
|
-
} else if(connection === 'open') {
|
|
216
|
-
console.log('opened connection')
|
|
217
|
-
}
|
|
218
|
-
})
|
|
219
|
-
sock.ev.on('messages.upsert', event => {
|
|
220
|
-
for (const m of event.messages) {
|
|
221
|
-
console.log(JSON.stringify(m, undefined, 2))
|
|
222
|
-
|
|
223
|
-
console.log('replying to', m.key.remoteJid)
|
|
224
|
-
await sock.sendMessage(m.key.remoteJid!, { text: 'Hello Word' })
|
|
225
|
-
}
|
|
226
|
-
})
|
|
227
|
-
|
|
228
|
-
// to storage creds (session info) when it updates
|
|
229
|
-
sock.ev.on('creds.update', saveCreds)
|
|
230
|
-
}
|
|
231
|
-
// run in main file
|
|
232
|
-
connectToWhatsApp()
|
|
233
|
-
```
|
|
234
|
-
|
|
235
|
-
> [!IMPORTANT]
|
|
236
|
-
> In `messages.upsert` it's recommended to use a loop like `for (const message of event.messages)` to handle all messages in array
|
|
237
|
-
|
|
238
|
-
### Decrypt Poll Votes
|
|
239
|
-
|
|
240
|
-
- By default poll votes are encrypted and handled in `messages.update`
|
|
241
|
-
- That's a simple example
|
|
242
|
-
```javascript
|
|
243
|
-
sock.ev.on('messages.update', event => {
|
|
244
|
-
for(const { key, update } of event) {
|
|
245
|
-
if(update.pollUpdates) {
|
|
246
|
-
const pollCreation = await getMessage(key)
|
|
247
|
-
if(pollCreation) {
|
|
248
|
-
console.log(
|
|
249
|
-
'got poll update, aggregation: ',
|
|
250
|
-
getAggregateVotesInPollMessage({
|
|
251
|
-
message: pollCreation,
|
|
252
|
-
pollUpdates: update.pollUpdates,
|
|
253
|
-
})
|
|
254
|
-
)
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
})
|
|
259
|
-
```
|
|
260
|
-
|
|
261
|
-
- `getMessage` is a [store](#implementing-a-data-store) implementation (in your end)
|
|
262
|
-
|
|
263
|
-
### Summary of Events on First Connection
|
|
264
|
-
|
|
265
|
-
1. When you connect first time, `connection.update` will be fired requesting you to restart sock
|
|
266
|
-
2. Then, history messages will be received in `messaging.history-set`
|
|
267
|
-
|
|
268
|
-
## Implementing a Data Store
|
|
269
|
-
|
|
270
|
-
- 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.
|
|
271
|
-
|
|
272
|
-
> [!IMPORTANT]
|
|
273
|
-
> I highly recommend building your own data store, as storing someone's entire chat history in memory is a terrible waste of RAM.
|
|
274
|
-
|
|
275
|
-
It can be used as follows:
|
|
276
|
-
|
|
277
|
-
```javascript
|
|
278
|
-
import makeWASocket from "@kelvdra/baileys"
|
|
279
|
-
import { makeInMemoryStore } from "@kelvdra/baileys"
|
|
280
|
-
// the store maintains the data of the WA connection in memory
|
|
281
|
-
// can be written out to a file & read from it
|
|
282
|
-
const store = makeInMemoryStore({ })
|
|
283
|
-
// can be read from a file
|
|
284
|
-
store.readFromFile('./baileys_store.json')
|
|
285
|
-
// saves the state to a file every 10s
|
|
286
|
-
setInterval(() => {
|
|
287
|
-
store.writeToFile('./baileys_store.json')
|
|
288
|
-
}, 10_000)
|
|
289
|
-
|
|
290
|
-
const sock = makeWASocket({ })
|
|
291
|
-
// will listen from this socket
|
|
292
|
-
// the store can listen from a new socket once the current socket outlives its lifetime
|
|
293
|
-
store.bind(sock.ev)
|
|
294
|
-
|
|
295
|
-
sock.ev.on('chats.upsert', () => {
|
|
296
|
-
// can use 'store.chats' however you want, even after the socket dies out
|
|
297
|
-
// 'chats' => a KeyedDB instance
|
|
298
|
-
console.log('got chats', store.chats.all())
|
|
299
|
-
})
|
|
300
|
-
|
|
301
|
-
sock.ev.on('contacts.upsert', () => {
|
|
302
|
-
console.log('got contacts', Object.values(store.contacts))
|
|
303
|
-
})
|
|
304
|
-
|
|
305
|
-
```
|
|
306
|
-
|
|
307
|
-
The store also provides some simple functions such as `loadMessages` that utilize the store to speed up data retrieval.
|
|
308
|
-
|
|
309
|
-
## Whatsapp IDs Explain
|
|
310
|
-
|
|
311
|
-
- `id` is the WhatsApp ID, called `jid` too, of the person or group you're sending the message to.
|
|
312
|
-
- It must be in the format ```[country code][phone number]@s.whatsapp.net```
|
|
313
|
-
- Example for people: ```+19999999999@s.whatsapp.net```.
|
|
314
|
-
- For groups, it must be in the format ``` 123456789-123345@g.us ```.
|
|
315
|
-
- For broadcast lists, it's `[timestamp of creation]@broadcast`.
|
|
316
|
-
- For stories, the ID is `status@broadcast`.
|
|
317
|
-
|
|
318
|
-
## Utility Functions
|
|
319
|
-
|
|
320
|
-
- `getContentType`, returns the content type for any message
|
|
321
|
-
- `getDevice`, returns the device from message
|
|
322
|
-
- `makeCacheableSignalKeyStore`, make auth store more fast
|
|
323
|
-
- `downloadContentFromMessage`, download content from any message
|
|
324
|
-
|
|
325
|
-
## Sending Messages
|
|
326
|
-
|
|
327
|
-
- Send all types of messages with a single function
|
|
328
|
-
- **[Here](https://baileys.whiskeysockets.io/types/AnyMessageContent.html) you can see all message contents supported, like text message**
|
|
329
|
-
- **[Here](https://baileys.whiskeysockets.io/types/MiscMessageGenerationOptions.html) you can see all options supported, like quote message**
|
|
330
|
-
|
|
331
|
-
```javascript
|
|
332
|
-
const jid: string
|
|
333
|
-
const content: AnyMessageContent
|
|
334
|
-
const options: MiscMessageGenerationOptions
|
|
335
|
-
|
|
336
|
-
sock.sendMessage(jid, content, options)
|
|
337
|
-
```
|
|
338
|
-
|
|
339
|
-
### Non-Media Messages
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
#### Text Message
|
|
343
|
-
```javascript
|
|
344
|
-
await sock.sendMessage(jid, { text: 'hello word' })
|
|
345
|
-
```
|
|
346
|
-
|
|
347
|
-
#### Quote Message (works with all types)
|
|
348
|
-
```javascript
|
|
349
|
-
await sock.sendMessage(jid, { text: 'hello word' }, { quoted: message })
|
|
350
|
-
```
|
|
351
|
-
|
|
352
|
-
#### Mention User (works with most types)
|
|
353
|
-
- @number is to mention in text, it's optional
|
|
354
|
-
```javascript
|
|
355
|
-
await sock.sendMessage(
|
|
356
|
-
jid,
|
|
357
|
-
{
|
|
358
|
-
text: '@12345678901',
|
|
359
|
-
mentions: ['12345678901@s.whatsapp.net']
|
|
360
|
-
}
|
|
361
|
-
)
|
|
362
|
-
```
|
|
363
|
-
|
|
364
|
-
#### Mention Status
|
|
365
|
-
- [ jid ] If the Jid Group and Jid Private Chat are included in the JID list, try to make the JID group first starting from the Jid Private Chat or Jid Private Chat in the middle between the group Jid
|
|
366
|
-
```javascript
|
|
367
|
-
await sock.sendStatusMentions(
|
|
368
|
-
{
|
|
369
|
-
text: "Hello", // or image / video / audio ( url or buffer )
|
|
370
|
-
},
|
|
371
|
-
[
|
|
372
|
-
"123456789123456789@g.us",
|
|
373
|
-
"123456789@s.whatsapp.net",
|
|
374
|
-
// Enter jid chat here
|
|
375
|
-
]
|
|
376
|
-
)
|
|
377
|
-
```
|
|
378
|
-
|
|
379
|
-
#### Result Poll From Newsletter
|
|
380
|
-
```javascript
|
|
381
|
-
await sock.sendMessage(
|
|
382
|
-
jid,
|
|
383
|
-
{
|
|
384
|
-
pollResult: {
|
|
385
|
-
name: "Text poll",
|
|
386
|
-
votes: [["Options 1", 10], ["Options 2", 10]], // 10 For Fake Polling Count Results
|
|
387
|
-
}
|
|
388
|
-
}, { quoted : message }
|
|
389
|
-
)
|
|
390
|
-
```
|
|
391
|
-
|
|
392
|
-
#### Send Album Message
|
|
393
|
-
- url or buffer ( image or video )
|
|
394
|
-
```javascript
|
|
395
|
-
await sock.sendAlbumMessage(
|
|
396
|
-
jid,
|
|
397
|
-
[
|
|
398
|
-
{
|
|
399
|
-
image: { url: "https://example.jpg" }, // or buffer
|
|
400
|
-
caption: "Hello World",
|
|
401
|
-
},
|
|
402
|
-
{
|
|
403
|
-
video: { url: "https://example.mp4" }, // or buffer
|
|
404
|
-
caption: "Hello World",
|
|
405
|
-
},
|
|
406
|
-
],
|
|
407
|
-
{
|
|
408
|
-
quoted : message,
|
|
409
|
-
delay : 2000 // number in seconds
|
|
410
|
-
}
|
|
411
|
-
)
|
|
412
|
-
|
|
413
|
-
```
|
|
414
|
-
|
|
415
|
-
#### Request Payment
|
|
416
|
-
```javascript
|
|
417
|
-
- Example non media sticker
|
|
418
|
-
await sock.sendMessage(
|
|
419
|
-
jid,
|
|
420
|
-
{
|
|
421
|
-
requestPayment: {
|
|
422
|
-
currency: "IDR",
|
|
423
|
-
amount: "10000000",
|
|
424
|
-
from: "123456@s.whatsapp.net",
|
|
425
|
-
note: "Hai Guys",
|
|
426
|
-
background: { ...background of the message }
|
|
427
|
-
}
|
|
428
|
-
},
|
|
429
|
-
{ quoted : message }
|
|
430
|
-
)
|
|
431
|
-
|
|
432
|
-
- with media sticker buffer
|
|
433
|
-
await sock.sendMessage(
|
|
434
|
-
jid,
|
|
435
|
-
{
|
|
436
|
-
requestPayment: {
|
|
437
|
-
currency: "IDR",
|
|
438
|
-
amount: "10000000",
|
|
439
|
-
from: "123456@s.whatsapp.net",
|
|
440
|
-
sticker: Buffer,
|
|
441
|
-
background: { ...background of the message }
|
|
442
|
-
}
|
|
443
|
-
},
|
|
444
|
-
{ quoted : message }
|
|
445
|
-
)
|
|
446
|
-
|
|
447
|
-
- with media sticker url
|
|
448
|
-
await sock.sendMessage(
|
|
449
|
-
jid,
|
|
450
|
-
{
|
|
451
|
-
requestPayment: {
|
|
452
|
-
currency: "IDR",
|
|
453
|
-
amount: "10000000",
|
|
454
|
-
from: "123456@s.whatsapp.net",
|
|
455
|
-
sticker: { url: Sticker Url },
|
|
456
|
-
background: { ...background of the message }
|
|
457
|
-
}
|
|
458
|
-
},
|
|
459
|
-
{ quoted : message }
|
|
460
|
-
)
|
|
461
|
-
```
|
|
462
|
-
|
|
463
|
-
#### Event Message
|
|
464
|
-
```javascript
|
|
465
|
-
await sock.sendMessage(
|
|
466
|
-
jid,
|
|
467
|
-
{
|
|
468
|
-
event: {
|
|
469
|
-
isCanceled: false, // or true for cancel event
|
|
470
|
-
name: "Name Event",
|
|
471
|
-
description: "Description Event",
|
|
472
|
-
location: {
|
|
473
|
-
degressLatitude: -0,
|
|
474
|
-
degressLongitude: - 0
|
|
475
|
-
},
|
|
476
|
-
link: Call Link,
|
|
477
|
-
startTime: m.messageTimestamp.low,
|
|
478
|
-
endTime: m.messageTimestamp.low + 86400, // 86400 is day in seconds
|
|
479
|
-
extraGuestsAllowed: true // or false
|
|
480
|
-
}
|
|
481
|
-
},
|
|
482
|
-
{ quoted : message }
|
|
483
|
-
)
|
|
484
|
-
```
|
|
485
|
-
|
|
486
|
-
### SendMessage Product Simple
|
|
487
|
-
```javascript
|
|
488
|
-
conn.sendMessage(m.chat, {
|
|
489
|
-
productMessage: {
|
|
490
|
-
title: "tes",
|
|
491
|
-
description: "penis",
|
|
492
|
-
thumbnail: "https://example.png",
|
|
493
|
-
productId: "123456789",
|
|
494
|
-
retailerId: "TOKOKU",
|
|
495
|
-
url: "https://example.png",
|
|
496
|
-
body: "penis",
|
|
497
|
-
footer: "wabot",
|
|
498
|
-
buttons: [
|
|
499
|
-
{
|
|
500
|
-
name: "cta_url",
|
|
501
|
-
buttonParamsJson: JSON.stringify({
|
|
502
|
-
display_text: "K",
|
|
503
|
-
url: "google.com"
|
|
504
|
-
})
|
|
505
|
-
}
|
|
506
|
-
]
|
|
507
|
-
}
|
|
508
|
-
}, { quoted: m });
|
|
509
|
-
```
|
|
510
|
-
### SendMessage Carousel
|
|
511
|
-
```javascript
|
|
512
|
-
await sock.sendMessage(
|
|
513
|
-
jid,
|
|
514
|
-
{
|
|
515
|
-
carouselMessage: {
|
|
516
|
-
caption: "Klik Url",
|
|
517
|
-
footer: "Powered By Hydra",
|
|
518
|
-
cards: [
|
|
519
|
-
// ✅ Card Mode Product
|
|
520
|
-
{
|
|
521
|
-
headerTitle: "`</> Owner Bot </>`",
|
|
522
|
-
imageUrl: logo.thumb,
|
|
523
|
-
productTitle: "Premium Bot",
|
|
524
|
-
productDescription: "Dapatkan akses premium",
|
|
525
|
-
bodyText: "[Hydra]\n- Chat yang penting aja\n- Jangan telpon owner",
|
|
526
|
-
buttons: [
|
|
527
|
-
{
|
|
528
|
-
name: "cta_call",
|
|
529
|
-
params: { display_text: "Contact Owner", phone_number: "+6287784901856" }
|
|
530
|
-
}
|
|
531
|
-
]
|
|
532
|
-
},
|
|
533
|
-
// ✅ Card Mode Gambar Biasa
|
|
534
|
-
{
|
|
535
|
-
headerTitle: "`</> Bot Elaina </>`",
|
|
536
|
-
imageUrl: logo.thumb,
|
|
537
|
-
bodyText: "[Elaina AI]\n- Jangan spam bot\n- Jangan telpon bot",
|
|
538
|
-
buttons: [
|
|
539
|
-
{
|
|
540
|
-
name: "cta_url",
|
|
541
|
-
params: {
|
|
542
|
-
display_text: "Chat Bot",
|
|
543
|
-
url: "https://wa.me/6281918402014",
|
|
544
|
-
merchant_url: "https://wa.me/6281918402014"
|
|
545
|
-
}
|
|
546
|
-
}
|
|
547
|
-
]
|
|
548
|
-
}
|
|
549
|
-
]
|
|
550
|
-
}
|
|
551
|
-
},
|
|
552
|
-
{ quoted: m },
|
|
553
|
-
conn
|
|
554
|
-
);
|
|
555
|
-
```
|
|
556
|
-
|
|
557
|
-
### Interactive Message with Native Flow
|
|
558
|
-
Send interactive messages with buttons, copy actions, and native flow features:
|
|
559
|
-
|
|
560
|
-
```javascript
|
|
561
|
-
await sock.sendMessage(jid, {
|
|
562
|
-
interactiveMessage: {
|
|
563
|
-
title: "Hello World",
|
|
564
|
-
footer: "telegram: @draa82",
|
|
565
|
-
image: { url: "https://example.com/image.jpg" },
|
|
566
|
-
nativeFlowMessage: {
|
|
567
|
-
messageParamsJson: JSON.stringify({
|
|
568
|
-
limited_time_offer: {
|
|
569
|
-
text: "idk hummmm?",
|
|
570
|
-
url: "t.me/draa82",
|
|
571
|
-
copy_code: "kelvdra 1437",
|
|
572
|
-
expiration_time: Date.now() * 999
|
|
573
|
-
},
|
|
574
|
-
bottom_sheet: {
|
|
575
|
-
in_thread_buttons_limit: 2,
|
|
576
|
-
divider_indices: [1, 2, 3, 4, 5, 999],
|
|
577
|
-
list_title: "kelvdra",
|
|
578
|
-
button_title: "kelvdra"
|
|
579
|
-
},
|
|
580
|
-
tap_target_configuration: {
|
|
581
|
-
title: " X ",
|
|
582
|
-
description: "bomboclard",
|
|
583
|
-
canonical_url: "https://t.me/draa82",
|
|
584
|
-
domain: "shop.example.com",
|
|
585
|
-
button_index: 0
|
|
586
|
-
}
|
|
587
|
-
}),
|
|
588
|
-
buttons: [
|
|
589
|
-
{
|
|
590
|
-
name: "single_select",
|
|
591
|
-
buttonParamsJson: JSON.stringify({
|
|
592
|
-
has_multiple_buttons: true
|
|
593
|
-
})
|
|
594
|
-
},
|
|
595
|
-
{
|
|
596
|
-
name: "call_permission_request",
|
|
597
|
-
buttonParamsJson: JSON.stringify({
|
|
598
|
-
has_multiple_buttons: true
|
|
599
|
-
})
|
|
600
|
-
},
|
|
601
|
-
{
|
|
602
|
-
name: "single_select",
|
|
603
|
-
buttonParamsJson: JSON.stringify({
|
|
604
|
-
title: "Hello World",
|
|
605
|
-
sections: [
|
|
606
|
-
{
|
|
607
|
-
title: "title",
|
|
608
|
-
highlight_label: "label",
|
|
609
|
-
rows: [
|
|
610
|
-
{
|
|
611
|
-
title: "@kelvdra",
|
|
612
|
-
description: "love you",
|
|
613
|
-
id: "row_2"
|
|
614
|
-
}
|
|
615
|
-
]
|
|
616
|
-
}
|
|
617
|
-
],
|
|
618
|
-
has_multiple_buttons: true
|
|
619
|
-
})
|
|
620
|
-
},
|
|
621
|
-
{
|
|
622
|
-
name: "cta_copy",
|
|
623
|
-
buttonParamsJson: JSON.stringify({
|
|
624
|
-
display_text: "copy code",
|
|
625
|
-
id: "123456789",
|
|
626
|
-
copy_code: "ABC123XYZ"
|
|
627
|
-
})
|
|
628
|
-
}
|
|
629
|
-
]
|
|
630
|
-
}
|
|
631
|
-
}
|
|
632
|
-
}, { quoted: m });
|
|
633
|
-
```
|
|
634
|
-
|
|
635
|
-
#### Interactive
|
|
636
|
-
```javascript
|
|
637
|
-
- Example non header media
|
|
638
|
-
await sock.sendMessage(
|
|
639
|
-
jid,
|
|
640
|
-
{
|
|
641
|
-
text: "Description Of Messages", //Additional information
|
|
642
|
-
title: "Title Of Messages",
|
|
643
|
-
subtitle: "Subtitle Message",
|
|
644
|
-
footer: "Footer Messages",
|
|
645
|
-
interactiveButtons: [
|
|
646
|
-
{
|
|
647
|
-
name: "quick_reply",
|
|
648
|
-
buttonParamsJson: JSON.stringify({
|
|
649
|
-
display_text: "Display Button",
|
|
650
|
-
id: "ID"
|
|
651
|
-
})
|
|
652
|
-
},
|
|
653
|
-
{
|
|
654
|
-
name: "cta_url",
|
|
655
|
-
buttonParamsJson: JSON.stringify({
|
|
656
|
-
display_text: "Display Button",
|
|
657
|
-
url: "https://www.example.com"
|
|
658
|
-
})
|
|
659
|
-
}
|
|
660
|
-
]
|
|
661
|
-
},
|
|
662
|
-
{ quoted : message }
|
|
663
|
-
)
|
|
664
|
-
|
|
665
|
-
- Example with media
|
|
666
|
-
await sock.sendMessage(
|
|
667
|
-
jid,
|
|
668
|
-
{
|
|
669
|
-
image: { url : "https://example.jpg" }, // Can buffer
|
|
670
|
-
caption: "Description Of Messages", //Additional information
|
|
671
|
-
title: "Title Of Messages",
|
|
672
|
-
subtitle: "Subtile Message",
|
|
673
|
-
footer: "Footer Messages",
|
|
674
|
-
media: true,
|
|
675
|
-
interactiveButtons: [
|
|
676
|
-
{
|
|
677
|
-
name: "quick_reply",
|
|
678
|
-
buttonParamsJson: JSON.stringify({
|
|
679
|
-
display_text: "Display Button",
|
|
680
|
-
id: "ID"
|
|
681
|
-
})
|
|
682
|
-
},
|
|
683
|
-
{
|
|
684
|
-
name: "cta_url",
|
|
685
|
-
buttonParamsJson: JSON.stringify({
|
|
686
|
-
display_text: "Display Button",
|
|
687
|
-
url: "https://www.example.com"
|
|
688
|
-
})
|
|
689
|
-
}
|
|
690
|
-
]
|
|
691
|
-
},
|
|
692
|
-
{ quoted : message }
|
|
693
|
-
)
|
|
694
|
-
|
|
695
|
-
- Example with header product
|
|
696
|
-
await sock.sendMessage(
|
|
697
|
-
jid,
|
|
698
|
-
{
|
|
699
|
-
product: {
|
|
700
|
-
productImage: { url: "https://example.jpg }, //or buffer
|
|
701
|
-
productImageCount: 1,
|
|
702
|
-
title: "Title Product",
|
|
703
|
-
description: "Description Product",
|
|
704
|
-
priceAmount1000: 20000 * 1000,
|
|
705
|
-
currencyCode: "IDR",
|
|
706
|
-
retailerId: "Retail",
|
|
707
|
-
url: "https://example.com",
|
|
708
|
-
},
|
|
709
|
-
businessOwnerJid: "1234@s.whatsapp.net",
|
|
710
|
-
caption: "Description Of Messages", //Additional information
|
|
711
|
-
title: "Title Of Messages",
|
|
712
|
-
footer: "Footer Messages",
|
|
713
|
-
media: true,
|
|
714
|
-
interactiveButtons: [
|
|
715
|
-
{
|
|
716
|
-
name: "quick_reply",
|
|
717
|
-
buttonParamsJson: JSON.stringify({
|
|
718
|
-
display_text: "Display Button",
|
|
719
|
-
id: "ID"
|
|
720
|
-
})
|
|
721
|
-
},
|
|
722
|
-
{
|
|
723
|
-
name: "cta_url",
|
|
724
|
-
buttonParamsJson: JSON.stringify({
|
|
725
|
-
display_text: "Display Button",
|
|
726
|
-
url: "https://www.example.com"
|
|
727
|
-
})
|
|
728
|
-
}
|
|
729
|
-
]
|
|
730
|
-
},
|
|
731
|
-
{ quoted : message }
|
|
732
|
-
)
|
|
733
|
-
```
|
|
734
|
-
|
|
735
|
-
#### Forward Messages
|
|
736
|
-
- You need to have message object, can be retrieved from [store](#implementing-a-data-store) or use a [message](https://baileys.whiskeysockets.io/types/WAMessage.html) object
|
|
737
|
-
```javascript
|
|
738
|
-
const msg = getMessageFromStore() // implement this on your end
|
|
739
|
-
await sock.sendMessage(jid, { forward: msg }) // WA forward the message!
|
|
740
|
-
```
|
|
741
|
-
|
|
742
|
-
#### Location Message
|
|
743
|
-
```javascript
|
|
744
|
-
await sock.sendMessage(
|
|
745
|
-
jid,
|
|
746
|
-
{
|
|
747
|
-
location: {
|
|
748
|
-
degreesLatitude: 24.121231,
|
|
749
|
-
degreesLongitude: 55.1121221
|
|
750
|
-
}
|
|
751
|
-
}
|
|
752
|
-
)
|
|
753
|
-
```
|
|
754
|
-
#### Contact Message
|
|
755
|
-
```javascript
|
|
756
|
-
const vcard = 'BEGIN:VCARD\n' // metadata of the contact card
|
|
757
|
-
+ 'VERSION:3.0\n'
|
|
758
|
-
+ 'FN:Jeff Singh\n' // full name
|
|
759
|
-
+ 'ORG:Ashoka Uni;\n' // the organization of the contact
|
|
760
|
-
+ 'TEL;type=CELL;type=VOICE;waid=911234567890:+91 12345 67890\n' // WhatsApp ID + phone number
|
|
761
|
-
+ 'END:VCARD'
|
|
762
|
-
|
|
763
|
-
await sock.sendMessage(
|
|
764
|
-
id,
|
|
765
|
-
{
|
|
766
|
-
contacts: {
|
|
767
|
-
displayName: 'Jeff',
|
|
768
|
-
contacts: [{ vcard }]
|
|
769
|
-
}
|
|
770
|
-
}
|
|
771
|
-
)
|
|
772
|
-
```
|
|
773
|
-
|
|
774
|
-
#### Reaction Message
|
|
775
|
-
- 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
|
|
776
|
-
```javascript
|
|
777
|
-
await sock.sendMessage(
|
|
778
|
-
jid,
|
|
779
|
-
{
|
|
780
|
-
react: {
|
|
781
|
-
text: '💖', // use an empty string to remove the reaction
|
|
782
|
-
key: message.key
|
|
783
|
-
}
|
|
784
|
-
}
|
|
785
|
-
)
|
|
786
|
-
```
|
|
787
|
-
|
|
788
|
-
#### Pin Message
|
|
789
|
-
- 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
|
|
85
|
+
browser: ['Ubuntu', 'Chrome', '20.0.0'],
|
|
86
|
+
});
|
|
790
87
|
|
|
791
|
-
|
|
88
|
+
sock.ev.on('connection.update', (update) => {
|
|
89
|
+
const { connection, lastDisconnect } = update;
|
|
792
90
|
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
| 7d | 604.800 |
|
|
797
|
-
| 30d | 2.592.000 |
|
|
91
|
+
if (connection === 'close') {
|
|
92
|
+
const shouldReconnect =
|
|
93
|
+
(lastDisconnect.error)?.output?.statusCode !== DisconnectReason.loggedOut;
|
|
798
94
|
|
|
799
|
-
|
|
800
|
-
await sock.sendMessage(
|
|
801
|
-
jid,
|
|
802
|
-
{
|
|
803
|
-
pin: {
|
|
804
|
-
type: 1, // 0 to remove
|
|
805
|
-
time: 86400
|
|
806
|
-
key: message.key
|
|
95
|
+
if (shouldReconnect) connectToWhatsApp();
|
|
807
96
|
}
|
|
808
|
-
}
|
|
809
|
-
)
|
|
810
|
-
```
|
|
811
|
-
|
|
812
|
-
#### Keep Message
|
|
813
|
-
- 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
|
|
814
|
-
|
|
815
|
-
- Time can be:
|
|
816
|
-
|
|
817
|
-
| Time | Seconds |
|
|
818
|
-
|-------|----------------|
|
|
819
|
-
| 24h | 86.400 |
|
|
820
|
-
| 7d | 604.800 |
|
|
821
|
-
| 30d | 2.592.000 |
|
|
822
|
-
|
|
823
|
-
```javascript
|
|
824
|
-
await sock.sendMessage(
|
|
825
|
-
jid,
|
|
826
|
-
{
|
|
827
|
-
keep: message.key,
|
|
828
|
-
type: 1, // 2 to unpin
|
|
829
|
-
time: 86400
|
|
830
|
-
}
|
|
831
|
-
)
|
|
832
|
-
```
|
|
833
97
|
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
await sock.sendMessage(
|
|
837
|
-
jid,
|
|
838
|
-
{
|
|
839
|
-
poll: {
|
|
840
|
-
name: 'My Poll',
|
|
841
|
-
values: ['Option 1', 'Option 2', ...],
|
|
842
|
-
selectableCount: 1,
|
|
843
|
-
toAnnouncementGroup: false // or true
|
|
98
|
+
if (connection === 'open') {
|
|
99
|
+
console.log('✅ Koneksi berhasil tersambung!');
|
|
844
100
|
}
|
|
845
|
-
}
|
|
846
|
-
)
|
|
847
|
-
```
|
|
848
|
-
|
|
849
|
-
### Sending Messages with Link Previews
|
|
850
|
-
|
|
851
|
-
1. By default, wa does not have link generation when sent from the web
|
|
852
|
-
2. Baileys has a function to generate the content for these link previews
|
|
853
|
-
3. To enable this function's usage, add `link-preview-js` as a dependency to your project with `yarn add link-preview-js`
|
|
854
|
-
4. Send a link:
|
|
855
|
-
```javascript
|
|
856
|
-
await sock.sendMessage(
|
|
857
|
-
jid,
|
|
858
|
-
{
|
|
859
|
-
text: 'Hi, this was sent using https://github.com/whiskeysockets/baileys'
|
|
860
|
-
}
|
|
861
|
-
)
|
|
862
|
-
```
|
|
863
|
-
|
|
864
|
-
### Media Messages
|
|
865
|
-
|
|
866
|
-
Sending media (video, stickers, images) is easier & more efficient than ever.
|
|
867
|
-
|
|
868
|
-
> [!NOTE]
|
|
869
|
-
> 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)
|
|
870
|
-
|
|
871
|
-
- When specifying a media url, Baileys never loads the entire buffer into memory; it even encrypts the media as a readable stream.
|
|
872
|
-
|
|
873
|
-
> [!TIP]
|
|
874
|
-
> It's recommended to use Stream or Url to save memory
|
|
875
|
-
|
|
876
|
-
#### Gif Message
|
|
877
|
-
- Whatsapp doesn't support `.gif` files, that's why we send gifs as common `.mp4` video with `gifPlayback` flag
|
|
878
|
-
```javascript
|
|
879
|
-
await sock.sendMessage(
|
|
880
|
-
jid,
|
|
881
|
-
{
|
|
882
|
-
video: fs.readFileSync('Media/ma_gif.mp4'),
|
|
883
|
-
caption: 'hello word',
|
|
884
|
-
gifPlayback: true
|
|
885
|
-
}
|
|
886
|
-
)
|
|
887
|
-
```
|
|
888
|
-
|
|
889
|
-
#### Video Message
|
|
890
|
-
```javascript
|
|
891
|
-
await sock.sendMessage(
|
|
892
|
-
id,
|
|
893
|
-
{
|
|
894
|
-
video: {
|
|
895
|
-
url: './Media/ma_gif.mp4'
|
|
896
|
-
},
|
|
897
|
-
caption: 'hello word',
|
|
898
|
-
ptv: false // if set to true, will send as a `video note`
|
|
899
|
-
}
|
|
900
|
-
)
|
|
901
|
-
```
|
|
902
|
-
|
|
903
|
-
#### Audio Message
|
|
904
|
-
- To audio message work in all devices you need to convert with some tool like `ffmpeg` with this flags:
|
|
905
|
-
```bash
|
|
906
|
-
codec: libopus //ogg file
|
|
907
|
-
ac: 1 //one channel
|
|
908
|
-
avoid_negative_ts
|
|
909
|
-
make_zero
|
|
910
|
-
```
|
|
911
|
-
- Example:
|
|
912
|
-
```bash
|
|
913
|
-
ffmpeg -i input.mp4 -avoid_negative_ts make_zero -ac 1 output.ogg
|
|
914
|
-
```
|
|
915
|
-
```javascript
|
|
916
|
-
await sock.sendMessage(
|
|
917
|
-
jid,
|
|
918
|
-
{
|
|
919
|
-
audio: {
|
|
920
|
-
url: './Media/audio.mp3'
|
|
921
|
-
},
|
|
922
|
-
mimetype: 'audio/mp4'
|
|
923
|
-
}
|
|
924
|
-
)
|
|
925
|
-
```
|
|
926
|
-
|
|
927
|
-
#### Image Message
|
|
928
|
-
```javascript
|
|
929
|
-
await sock.sendMessage(
|
|
930
|
-
id,
|
|
931
|
-
{
|
|
932
|
-
image: {
|
|
933
|
-
url: './Media/ma_img.png'
|
|
934
|
-
},
|
|
935
|
-
caption: 'hello word'
|
|
936
|
-
}
|
|
937
|
-
)
|
|
938
|
-
```
|
|
939
|
-
|
|
940
|
-
#### View Once Message
|
|
941
|
-
|
|
942
|
-
- You can send all messages above as `viewOnce`, you only need to pass `viewOnce: true` in content object
|
|
943
|
-
|
|
944
|
-
```javascript
|
|
945
|
-
await sock.sendMessage(
|
|
946
|
-
id,
|
|
947
|
-
{
|
|
948
|
-
image: {
|
|
949
|
-
url: './Media/ma_img.png'
|
|
950
|
-
},
|
|
951
|
-
viewOnce: true, //works with video, audio too
|
|
952
|
-
caption: 'hello word'
|
|
953
|
-
}
|
|
954
|
-
)
|
|
955
|
-
```
|
|
956
|
-
|
|
957
|
-
## Modify Messages
|
|
958
|
-
|
|
959
|
-
### Deleting Messages (for everyone)
|
|
960
|
-
|
|
961
|
-
```javascript
|
|
962
|
-
const msg = await sock.sendMessage(jid, { text: 'hello word' })
|
|
963
|
-
await sock.sendMessage(jid, { delete: msg.key })
|
|
964
|
-
```
|
|
965
|
-
|
|
966
|
-
**Note:** deleting for oneself is supported via `chatModify`, see in [this section](#modifying-chats)
|
|
967
|
-
|
|
968
|
-
### Editing Messages
|
|
969
|
-
|
|
970
|
-
- You can pass all editable contents here
|
|
971
|
-
```javascript
|
|
972
|
-
await sock.sendMessage(jid, {
|
|
973
|
-
text: 'updated text goes here',
|
|
974
|
-
edit: response.key,
|
|
975
101
|
});
|
|
976
|
-
```
|
|
977
|
-
|
|
978
|
-
## Manipulating Media Messages
|
|
979
|
-
|
|
980
|
-
### Thumbnail in Media Messages
|
|
981
|
-
- 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`.
|
|
982
|
-
- Thumbnails for videos can also be generated automatically, though, you need to have `ffmpeg` installed on your system.
|
|
983
102
|
|
|
984
|
-
|
|
103
|
+
sock.ev.on('creds.update', saveCreds);
|
|
985
104
|
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
sock.ev.on('messages.upsert', async ({ [m] }) => {
|
|
992
|
-
if (!m.message) return // if there is no text or media message
|
|
993
|
-
const messageType = getContentType(m) // get what type of message it is (text, image, video...)
|
|
105
|
+
sock.ev.on('messaging-history.set', (history) => {
|
|
106
|
+
const { chats, messages, contacts } = history;
|
|
107
|
+
console.log(`Menerima ${chats.length} chat, ${messages.length} pesan, ${contacts.length} kontak.`);
|
|
108
|
+
});
|
|
994
109
|
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
const stream = await downloadMediaMessage(
|
|
999
|
-
m,
|
|
1000
|
-
'stream', // can be 'buffer' too
|
|
1001
|
-
{ },
|
|
1002
|
-
{
|
|
1003
|
-
logger,
|
|
1004
|
-
// pass this so that baileys can request a reupload of media
|
|
1005
|
-
// that has been deleted
|
|
1006
|
-
reuploadRequest: sock.updateMediaMessage
|
|
1007
|
-
}
|
|
1008
|
-
)
|
|
1009
|
-
// save to file
|
|
1010
|
-
const writeStream = createWriteStream('./my-download.jpeg')
|
|
1011
|
-
stream.pipe(writeStream)
|
|
1012
|
-
}
|
|
110
|
+
sock.ev.on('groups.update', (updates) => {
|
|
111
|
+
console.log('Update grup:', JSON.stringify(updates, null, 2));
|
|
112
|
+
});
|
|
1013
113
|
}
|
|
1014
|
-
```
|
|
1015
|
-
|
|
1016
|
-
### Re-upload Media Message to Whatsapp
|
|
1017
114
|
|
|
1018
|
-
|
|
1019
|
-
```javascript
|
|
1020
|
-
await sock.updateMediaMessage(msg)
|
|
1021
|
-
```
|
|
1022
|
-
|
|
1023
|
-
## Reject Call
|
|
1024
|
-
|
|
1025
|
-
- You can obtain `callId` and `callFrom` from `call` event
|
|
1026
|
-
|
|
1027
|
-
```javascript
|
|
1028
|
-
await sock.rejectCall(callId, callFrom)
|
|
115
|
+
connectToWhatsApp();
|
|
1029
116
|
```
|
|
1030
117
|
|
|
1031
|
-
##
|
|
1032
|
-
|
|
1033
|
-
### Reading Messages
|
|
1034
|
-
- A set of message [keys](https://baileys.whiskeysockets.io/types/WAMessageKey.html) must be explicitly marked read now.
|
|
1035
|
-
- You cannot mark an entire 'chat' read as it were with Baileys Web.
|
|
1036
|
-
This means you have to keep track of unread messages.
|
|
1037
|
-
|
|
1038
|
-
```javascript
|
|
1039
|
-
const key: WAMessageKey
|
|
1040
|
-
// can pass multiple keys to read multiple messages as well
|
|
1041
|
-
await sock.readMessages([key])
|
|
1042
|
-
```
|
|
1043
|
-
|
|
1044
|
-
The message ID is the unique identifier of the message that you are marking as read.
|
|
1045
|
-
On a `WAMessage`, the `messageID` can be accessed using ```messageID = message.key.id```.
|
|
1046
|
-
|
|
1047
|
-
### Update Presence
|
|
118
|
+
## ⚠️ Penafian
|
|
1048
119
|
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
- This lets the person/group with `jid` know whether you're online, offline, typing etc.
|
|
1052
|
-
|
|
1053
|
-
```javascript
|
|
1054
|
-
await sock.sendPresenceUpdate('available', jid)
|
|
1055
|
-
```
|
|
1056
|
-
|
|
1057
|
-
> [!NOTE]
|
|
1058
|
-
> 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')`
|
|
1059
|
-
|
|
1060
|
-
## Modifying Chats
|
|
1061
|
-
|
|
1062
|
-
WA uses an encrypted form of communication to send chat/app updates. This has been implemented mostly and you can send the following updates:
|
|
1063
|
-
|
|
1064
|
-
> [!IMPORTANT]
|
|
1065
|
-
> 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.
|
|
1066
|
-
|
|
1067
|
-
### Archive a Chat
|
|
1068
|
-
```javascript
|
|
1069
|
-
const lastMsgInChat = await getLastMessageInChat(jid) // implement this on your end
|
|
1070
|
-
await sock.chatModify({ archive: true, lastMessages: [lastMsgInChat] }, jid)
|
|
1071
|
-
```
|
|
1072
|
-
### Mute/Unmute a Chat
|
|
1073
|
-
|
|
1074
|
-
- Supported times:
|
|
1075
|
-
|
|
1076
|
-
| Time | Miliseconds |
|
|
1077
|
-
|-------|-----------------|
|
|
1078
|
-
| Remove | null |
|
|
1079
|
-
| 8h | 86.400.000 |
|
|
1080
|
-
| 7d | 604.800.000 |
|
|
1081
|
-
|
|
1082
|
-
```javascript
|
|
1083
|
-
// mute for 8 hours
|
|
1084
|
-
await sock.chatModify({ mute: 8 * 60 * 60 * 1000 }, jid)
|
|
1085
|
-
// unmute
|
|
1086
|
-
await sock.chatModify({ mute: null }, jid)
|
|
1087
|
-
```
|
|
1088
|
-
### Mark a Chat Read/Unread
|
|
1089
|
-
```javascript
|
|
1090
|
-
const lastMsgInChat = await getLastMessageInChat(jid) // implement this on your end
|
|
1091
|
-
// mark it unread
|
|
1092
|
-
await sock.chatModify({ markRead: false, lastMessages: [lastMsgInChat] }, jid)
|
|
1093
|
-
```
|
|
1094
|
-
|
|
1095
|
-
### Delete a Message for Me
|
|
1096
|
-
```javascript
|
|
1097
|
-
await sock.chatModify(
|
|
1098
|
-
{
|
|
1099
|
-
clear: {
|
|
1100
|
-
messages: [
|
|
1101
|
-
{
|
|
1102
|
-
id: 'ATWYHDNNWU81732J',
|
|
1103
|
-
fromMe: true,
|
|
1104
|
-
timestamp: '1654823909'
|
|
1105
|
-
}
|
|
1106
|
-
]
|
|
1107
|
-
}
|
|
1108
|
-
},
|
|
1109
|
-
jid
|
|
1110
|
-
)
|
|
1111
|
-
|
|
1112
|
-
```
|
|
1113
|
-
### Delete a Chat
|
|
1114
|
-
```javascript
|
|
1115
|
-
const lastMsgInChat = await getLastMessageInChat(jid) // implement this on your end
|
|
1116
|
-
await sock.chatModify({
|
|
1117
|
-
delete: true,
|
|
1118
|
-
lastMessages: [
|
|
1119
|
-
{
|
|
1120
|
-
key: lastMsgInChat.key,
|
|
1121
|
-
messageTimestamp: lastMsgInChat.messageTimestamp
|
|
1122
|
-
}
|
|
1123
|
-
]
|
|
1124
|
-
},
|
|
1125
|
-
jid
|
|
1126
|
-
)
|
|
1127
|
-
```
|
|
1128
|
-
### Pin/Unpin a Chat
|
|
1129
|
-
```javascript
|
|
1130
|
-
await sock.chatModify({
|
|
1131
|
-
pin: true // or `false` to unpin
|
|
1132
|
-
},
|
|
1133
|
-
jid
|
|
1134
|
-
)
|
|
1135
|
-
```
|
|
1136
|
-
### Star/Unstar a Message
|
|
1137
|
-
```javascript
|
|
1138
|
-
await sock.chatModify({
|
|
1139
|
-
star: {
|
|
1140
|
-
messages: [
|
|
1141
|
-
{
|
|
1142
|
-
id: 'messageID',
|
|
1143
|
-
fromMe: true // or `false`
|
|
1144
|
-
}
|
|
1145
|
-
],
|
|
1146
|
-
star: true // - true: Star Message; false: Unstar Message
|
|
1147
|
-
}
|
|
1148
|
-
},
|
|
1149
|
-
jid
|
|
1150
|
-
)
|
|
1151
|
-
```
|
|
1152
|
-
|
|
1153
|
-
### Disappearing Messages
|
|
1154
|
-
|
|
1155
|
-
- Ephemeral can be:
|
|
1156
|
-
|
|
1157
|
-
| Time | Seconds |
|
|
1158
|
-
|-------|----------------|
|
|
1159
|
-
| Remove | 0 |
|
|
1160
|
-
| 24h | 86.400 |
|
|
1161
|
-
| 7d | 604.800 |
|
|
1162
|
-
| 90d | 7.776.000 |
|
|
1163
|
-
|
|
1164
|
-
- You need to pass in **Seconds**, default is 7 days
|
|
1165
|
-
|
|
1166
|
-
```javascript
|
|
1167
|
-
// turn on disappearing messages
|
|
1168
|
-
await sock.sendMessage(
|
|
1169
|
-
jid,
|
|
1170
|
-
// this is 1 week in seconds -- how long you want messages to appear for
|
|
1171
|
-
{ disappearingMessagesInChat: WA_DEFAULT_EPHEMERAL }
|
|
1172
|
-
)
|
|
1173
|
-
|
|
1174
|
-
// will send as a disappearing message
|
|
1175
|
-
await sock.sendMessage(jid, { text: 'hello' }, { ephemeralExpiration: WA_DEFAULT_EPHEMERAL })
|
|
1176
|
-
|
|
1177
|
-
// turn off disappearing messages
|
|
1178
|
-
await sock.sendMessage(
|
|
1179
|
-
jid,
|
|
1180
|
-
{ disappearingMessagesInChat: false }
|
|
1181
|
-
)
|
|
1182
|
-
```
|
|
1183
|
-
|
|
1184
|
-
## User Querys
|
|
1185
|
-
|
|
1186
|
-
### Check If ID Exists in Whatsapp
|
|
1187
|
-
```javascript
|
|
1188
|
-
const [result] = await sock.onWhatsApp(jid)
|
|
1189
|
-
if (result.exists) console.log (`${jid} exists on WhatsApp, as jid: ${result.jid}`)
|
|
1190
|
-
```
|
|
1191
|
-
|
|
1192
|
-
### Query Chat History (groups too)
|
|
1193
|
-
|
|
1194
|
-
- You need to have oldest message in chat
|
|
1195
|
-
```javascript
|
|
1196
|
-
const msg = await getOldestMessageInChat(jid)
|
|
1197
|
-
await sock.fetchMessageHistory(
|
|
1198
|
-
50, //quantity (max: 50 per query)
|
|
1199
|
-
msg.key,
|
|
1200
|
-
msg.messageTimestamp
|
|
1201
|
-
)
|
|
1202
|
-
```
|
|
1203
|
-
- Messages will be received in `messaging.history-set` event
|
|
1204
|
-
|
|
1205
|
-
### Fetch User Lid
|
|
1206
|
-
```javascript
|
|
1207
|
-
const jid = "123456789@s.whatsapp.net"
|
|
1208
|
-
const lid = await sock.fetchUserLid(jid)
|
|
1209
|
-
console.log('user lid: ' + lid)
|
|
1210
|
-
```
|
|
1211
|
-
|
|
1212
|
-
### Fetch Status
|
|
1213
|
-
```javascript
|
|
1214
|
-
const status = await sock.fetchStatus(jid)
|
|
1215
|
-
console.log('status: ' + status)
|
|
1216
|
-
```
|
|
1217
|
-
|
|
1218
|
-
### Fetch Profile Picture (groups too)
|
|
1219
|
-
- To get the display picture of some person/group/newsletter
|
|
1220
|
-
```javascript
|
|
1221
|
-
// for low res picture
|
|
1222
|
-
const ppUrl = await sock.profilePictureUrl(jid)
|
|
1223
|
-
console.log(ppUrl)
|
|
1224
|
-
|
|
1225
|
-
// for high res picture
|
|
1226
|
-
const ppUrl = await sock.profilePictureUrl(jid, 'image')
|
|
1227
|
-
```
|
|
1228
|
-
|
|
1229
|
-
### Fetch Bussines Profile (such as description or category)
|
|
1230
|
-
```javascript
|
|
1231
|
-
const profile = await sock.getBusinessProfile(jid)
|
|
1232
|
-
console.log('business description: ' + profile.description + ', category: ' + profile.category)
|
|
1233
|
-
```
|
|
1234
|
-
|
|
1235
|
-
### Fetch Someone's Presence (if they're typing or online)
|
|
1236
|
-
```javascript
|
|
1237
|
-
// the presence update is fetched and called here
|
|
1238
|
-
sock.ev.on('presence.update', console.log)
|
|
1239
|
-
|
|
1240
|
-
// request updates for a chat
|
|
1241
|
-
await sock.presenceSubscribe(jid)
|
|
1242
|
-
```
|
|
1243
|
-
|
|
1244
|
-
## Change Profile
|
|
1245
|
-
|
|
1246
|
-
### Change Profile Status
|
|
1247
|
-
```javascript
|
|
1248
|
-
await sock.updateProfileStatus('Hello World!')
|
|
1249
|
-
```
|
|
1250
|
-
### Change Profile Name
|
|
1251
|
-
```javascript
|
|
1252
|
-
await sock.updateProfileName('My name')
|
|
1253
|
-
```
|
|
1254
|
-
### Change Display Picture (groups too)
|
|
1255
|
-
- To change your display picture or a group's
|
|
120
|
+
Proyek ini tidak berafiliasi atau didukung secara resmi oleh WhatsApp atau Meta.
|
|
121
|
+
Gunakan dengan tanggung jawab dan patuhi Ketentuan Layanan WhatsApp.
|
|
1256
122
|
|
|
1257
|
-
|
|
1258
|
-
> 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)
|
|
1259
|
-
|
|
1260
|
-
```javascript
|
|
1261
|
-
await sock.updateProfilePicture(jid, { url: './new-profile-picture.jpeg' })
|
|
1262
|
-
```
|
|
1263
|
-
### Remove display picture (groups too)
|
|
1264
|
-
```javascript
|
|
1265
|
-
await sock.removeProfilePicture(jid)
|
|
1266
|
-
```
|
|
1267
|
-
|
|
1268
|
-
## Groups
|
|
1269
|
-
|
|
1270
|
-
- To change group properties you need to be admin
|
|
1271
|
-
|
|
1272
|
-
### Create a Group
|
|
1273
|
-
```javascript
|
|
1274
|
-
// title & participants
|
|
1275
|
-
const group = await sock.groupCreate('My Fab Group', ['1234@s.whatsapp.net', '4564@s.whatsapp.net'])
|
|
1276
|
-
console.log('created group with id: ' + group.gid)
|
|
1277
|
-
await sock.sendMessage(group.id, { text: 'hello there' }) // say hello to everyone on the group
|
|
1278
|
-
```
|
|
1279
|
-
### Add/Remove or Demote/Promote
|
|
1280
|
-
```javascript
|
|
1281
|
-
// id & people to add to the group (will throw error if it fails)
|
|
1282
|
-
await sock.groupParticipantsUpdate(
|
|
1283
|
-
jid,
|
|
1284
|
-
['abcd@s.whatsapp.net', 'efgh@s.whatsapp.net'],
|
|
1285
|
-
'add' // replace this parameter with 'remove' or 'demote' or 'promote'
|
|
1286
|
-
)
|
|
1287
|
-
```
|
|
1288
|
-
### Change Subject (name)
|
|
1289
|
-
```javascript
|
|
1290
|
-
await sock.groupUpdateSubject(jid, 'New Subject!')
|
|
1291
|
-
```
|
|
1292
|
-
### Change Description
|
|
1293
|
-
```javascript
|
|
1294
|
-
await sock.groupUpdateDescription(jid, 'New Description!')
|
|
1295
|
-
```
|
|
1296
|
-
### Change Settings
|
|
1297
|
-
```javascript
|
|
1298
|
-
// only allow admins to send messages
|
|
1299
|
-
await sock.groupSettingUpdate(jid, 'announcement')
|
|
1300
|
-
// allow everyone to send messages
|
|
1301
|
-
await sock.groupSettingUpdate(jid, 'not_announcement')
|
|
1302
|
-
// allow everyone to modify the group's settings -- like display picture etc.
|
|
1303
|
-
await sock.groupSettingUpdate(jid, 'unlocked')
|
|
1304
|
-
// only allow admins to modify the group's settings
|
|
1305
|
-
await sock.groupSettingUpdate(jid, 'locked')
|
|
1306
|
-
```
|
|
1307
|
-
### Leave a Group
|
|
1308
|
-
```javascript
|
|
1309
|
-
// will throw error if it fails
|
|
1310
|
-
await sock.groupLeave(jid)
|
|
1311
|
-
```
|
|
1312
|
-
### Get Invite Code
|
|
1313
|
-
- To create link with code use `'https://chat.whatsapp.com/' + code`
|
|
1314
|
-
```javascript
|
|
1315
|
-
const code = await sock.groupInviteCode(jid)
|
|
1316
|
-
console.log('group code: ' + code)
|
|
1317
|
-
```
|
|
1318
|
-
### Revoke Invite Code
|
|
1319
|
-
```javascript
|
|
1320
|
-
const code = await sock.groupRevokeInvite(jid)
|
|
1321
|
-
console.log('New group code: ' + code)
|
|
1322
|
-
```
|
|
1323
|
-
### Join Using Invitation Code
|
|
1324
|
-
- Code can't have `https://chat.whatsapp.com/`, only code
|
|
1325
|
-
```javascript
|
|
1326
|
-
const response = await sock.groupAcceptInvite(code)
|
|
1327
|
-
console.log('joined to: ' + response)
|
|
1328
|
-
```
|
|
1329
|
-
### Get Group Info by Invite Code
|
|
1330
|
-
```javascript
|
|
1331
|
-
const response = await sock.groupGetInviteInfo(code)
|
|
1332
|
-
console.log('group information: ' + response)
|
|
1333
|
-
```
|
|
1334
|
-
### Query Metadata (participants, name, description...)
|
|
1335
|
-
```javascript
|
|
1336
|
-
const metadata = await sock.groupMetadata(jid)
|
|
1337
|
-
console.log(metadata.id + ', title: ' + metadata.subject + ', description: ' + metadata.desc)
|
|
1338
|
-
```
|
|
1339
|
-
### Join using `groupInviteMessage`
|
|
1340
|
-
```javascript
|
|
1341
|
-
const response = await sock.groupAcceptInviteV4(jid, groupInviteMessage)
|
|
1342
|
-
console.log('joined to: ' + response)
|
|
1343
|
-
```
|
|
1344
|
-
### Get Request Join List
|
|
1345
|
-
```javascript
|
|
1346
|
-
const response = await sock.groupRequestParticipantsList(jid)
|
|
1347
|
-
console.log(response)
|
|
1348
|
-
```
|
|
1349
|
-
### Approve/Reject Request Join
|
|
1350
|
-
```javascript
|
|
1351
|
-
const response = await sock.groupRequestParticipantsUpdate(
|
|
1352
|
-
jid, // group id
|
|
1353
|
-
['abcd@s.whatsapp.net', 'efgh@s.whatsapp.net'],
|
|
1354
|
-
'approve' // or 'reject'
|
|
1355
|
-
)
|
|
1356
|
-
console.log(response)
|
|
1357
|
-
```
|
|
1358
|
-
### Get All Participating Groups Metadata
|
|
1359
|
-
```javascript
|
|
1360
|
-
const response = await sock.groupFetchAllParticipating()
|
|
1361
|
-
console.log(response)
|
|
1362
|
-
```
|
|
1363
|
-
### Toggle Ephemeral
|
|
1364
|
-
|
|
1365
|
-
- Ephemeral can be:
|
|
1366
|
-
|
|
1367
|
-
| Time | Seconds |
|
|
1368
|
-
|-------|----------------|
|
|
1369
|
-
| Remove | 0 |
|
|
1370
|
-
| 24h | 86.400 |
|
|
1371
|
-
| 7d | 604.800 |
|
|
1372
|
-
| 90d | 7.776.000 |
|
|
1373
|
-
|
|
1374
|
-
```javascript
|
|
1375
|
-
await sock.groupToggleEphemeral(jid, 86400)
|
|
1376
|
-
```
|
|
1377
|
-
|
|
1378
|
-
### Change Add Mode
|
|
1379
|
-
```javascript
|
|
1380
|
-
await sock.groupMemberAddMode(
|
|
1381
|
-
jid,
|
|
1382
|
-
'all_member_add' // or 'admin_add'
|
|
1383
|
-
)
|
|
1384
|
-
```
|
|
1385
|
-
|
|
1386
|
-
## Privacy
|
|
1387
|
-
|
|
1388
|
-
### Block/Unblock User
|
|
1389
|
-
```javascript
|
|
1390
|
-
await sock.updateBlockStatus(jid, 'block') // Block user
|
|
1391
|
-
await sock.updateBlockStatus(jid, 'unblock') // Unblock user
|
|
1392
|
-
```
|
|
1393
|
-
### Get Privacy Settings
|
|
1394
|
-
```javascript
|
|
1395
|
-
const privacySettings = await sock.fetchPrivacySettings(true)
|
|
1396
|
-
console.log('privacy settings: ' + privacySettings)
|
|
1397
|
-
```
|
|
1398
|
-
### Get BlockList
|
|
1399
|
-
```javascript
|
|
1400
|
-
const response = await sock.fetchBlocklist()
|
|
1401
|
-
console.log(response)
|
|
1402
|
-
```
|
|
1403
|
-
### Update LastSeen Privacy
|
|
1404
|
-
```javascript
|
|
1405
|
-
const value = 'all' // 'contacts' | 'contact_blacklist' | 'none'
|
|
1406
|
-
await sock.updateLastSeenPrivacy(value)
|
|
1407
|
-
```
|
|
1408
|
-
### Update Online Privacy
|
|
1409
|
-
```javascript
|
|
1410
|
-
const value = 'all' // 'match_last_seen'
|
|
1411
|
-
await sock.updateOnlinePrivacy(value)
|
|
1412
|
-
```
|
|
1413
|
-
### Update Profile Picture Privacy
|
|
1414
|
-
```javascript
|
|
1415
|
-
const value = 'all' // 'contacts' | 'contact_blacklist' | 'none'
|
|
1416
|
-
await sock.updateProfilePicturePrivacy(value)
|
|
1417
|
-
```
|
|
1418
|
-
### Update Status Privacy
|
|
1419
|
-
```javascript
|
|
1420
|
-
const value = 'all' // 'contacts' | 'contact_blacklist' | 'none'
|
|
1421
|
-
await sock.updateStatusPrivacy(value)
|
|
1422
|
-
```
|
|
1423
|
-
### Update Read Receipts Privacy
|
|
1424
|
-
```javascript
|
|
1425
|
-
const value = 'all' // 'none'
|
|
1426
|
-
await sock.updateReadReceiptsPrivacy(value)
|
|
1427
|
-
```
|
|
1428
|
-
### Update Groups Add Privacy
|
|
1429
|
-
```javascript
|
|
1430
|
-
const value = 'all' // 'contacts' | 'contact_blacklist'
|
|
1431
|
-
await sock.updateGroupsAddPrivacy(value)
|
|
1432
|
-
```
|
|
1433
|
-
### Update Default Disappearing Mode
|
|
1434
|
-
|
|
1435
|
-
- Like [this](#disappearing-messages), ephemeral can be:
|
|
1436
|
-
|
|
1437
|
-
| Time | Seconds |
|
|
1438
|
-
|-------|----------------|
|
|
1439
|
-
| Remove | 0 |
|
|
1440
|
-
| 24h | 86.400 |
|
|
1441
|
-
| 7d | 604.800 |
|
|
1442
|
-
| 90d | 7.776.000 |
|
|
1443
|
-
|
|
1444
|
-
```javascript
|
|
1445
|
-
const ephemeral = 86400
|
|
1446
|
-
await sock.updateDefaultDisappearingMode(ephemeral)
|
|
1447
|
-
```
|
|
1448
|
-
|
|
1449
|
-
## Broadcast Lists & Stories
|
|
1450
|
-
|
|
1451
|
-
### Send Broadcast & Stories
|
|
1452
|
-
- Messages can be sent to broadcasts & stories. You need to add the following message options in sendMessage, like this:
|
|
1453
|
-
```javascript
|
|
1454
|
-
await sock.sendMessage(
|
|
1455
|
-
jid,
|
|
1456
|
-
{
|
|
1457
|
-
image: {
|
|
1458
|
-
url: url
|
|
1459
|
-
},
|
|
1460
|
-
caption: caption
|
|
1461
|
-
},
|
|
1462
|
-
{
|
|
1463
|
-
backgroundColor: backgroundColor,
|
|
1464
|
-
font: font,
|
|
1465
|
-
statusJidList: statusJidList,
|
|
1466
|
-
broadcast: true
|
|
1467
|
-
}
|
|
1468
|
-
)
|
|
1469
|
-
```
|
|
1470
|
-
- Message body can be a `extendedTextMessage` or `imageMessage` or `videoMessage` or `voiceMessage`, see [here](https://baileys.whiskeysockets.io/types/AnyRegularMessageContent.html)
|
|
1471
|
-
- You can add `backgroundColor` and other options in the message options, see [here](https://baileys.whiskeysockets.io/types/MiscMessageGenerationOptions.html)
|
|
1472
|
-
- `broadcast: true` enables broadcast mode
|
|
1473
|
-
- `statusJidList`: a list of people that you can get which you need to provide, which are the people who will get this status message.
|
|
1474
|
-
|
|
1475
|
-
- You can send messages to broadcast lists the same way you send messages to groups & individual chats.
|
|
1476
|
-
- Right now, WA Web does not support creating broadcast lists, but you can still delete them.
|
|
1477
|
-
- Broadcast IDs are in the format `12345678@broadcast`
|
|
1478
|
-
### Query a Broadcast List's Recipients & Name
|
|
1479
|
-
```javascript
|
|
1480
|
-
const bList = await sock.getBroadcastListInfo('1234@broadcast')
|
|
1481
|
-
console.log (`list name: ${bList.name}, recps: ${bList.recipients}`)
|
|
1482
|
-
```
|
|
1483
|
-
|
|
1484
|
-
## Writing Custom Functionality
|
|
1485
|
-
Baileys is written with custom functionality in mind. Instead of forking the project & re-writing the internals, you can simply write your own extensions.
|
|
1486
|
-
|
|
1487
|
-
### Enabling Debug Level in Baileys Logs
|
|
1488
|
-
First, enable the logging of unhandled messages from WhatsApp by setting:
|
|
1489
|
-
```javascript
|
|
1490
|
-
const sock = makeWASocket({
|
|
1491
|
-
logger: P({ level: 'debug' }),
|
|
1492
|
-
})
|
|
1493
|
-
```
|
|
1494
|
-
This will enable you to see all sorts of messages WhatsApp sends in the console.
|
|
1495
|
-
|
|
1496
|
-
### How Whatsapp Communicate With Us
|
|
1497
|
-
|
|
1498
|
-
> [!TIP]
|
|
1499
|
-
> If you want to learn whatsapp protocol, we recommend to study about Libsignal Protocol and Noise Protocol
|
|
1500
|
-
|
|
1501
|
-
- **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:
|
|
1502
|
-
```
|
|
1503
|
-
{
|
|
1504
|
-
"level": 10,
|
|
1505
|
-
"fromMe": false,
|
|
1506
|
-
"frame": {
|
|
1507
|
-
"tag": "ib",
|
|
1508
|
-
"attrs": {
|
|
1509
|
-
"from": "@s.whatsapp.net"
|
|
1510
|
-
},
|
|
1511
|
-
"content": [
|
|
1512
|
-
{
|
|
1513
|
-
"tag": "edge_routing",
|
|
1514
|
-
"attrs": {},
|
|
1515
|
-
"content": [
|
|
1516
|
-
{
|
|
1517
|
-
"tag": "routing_info",
|
|
1518
|
-
"attrs": {},
|
|
1519
|
-
"content": {
|
|
1520
|
-
"type": "Buffer",
|
|
1521
|
-
"data": [8,2,8,5]
|
|
1522
|
-
}
|
|
1523
|
-
}
|
|
1524
|
-
]
|
|
1525
|
-
}
|
|
1526
|
-
]
|
|
1527
|
-
},
|
|
1528
|
-
"msg":"communication"
|
|
1529
|
-
}
|
|
1530
|
-
```
|
|
1531
|
-
|
|
1532
|
-
The `'frame'` is what the message received is, it has three components:
|
|
1533
|
-
- `tag` -- what this frame is about (eg. message will have 'message')
|
|
1534
|
-
- `attrs` -- a string key-value pair with some metadata (contains ID of the message usually)
|
|
1535
|
-
- `content` -- the actual data (eg. a message node will have the actual message content in it)
|
|
1536
|
-
- read more about this format [here](/src/WABinary/readme.md)
|
|
1537
|
-
|
|
1538
|
-
### Register a Callback for Websocket Events
|
|
123
|
+
---
|
|
1539
124
|
|
|
1540
|
-
|
|
1541
|
-
> Recommended to see `onMessageReceived` function in `socket.ts` file to understand how websockets events are fired
|
|
125
|
+
## 📞 Kontak & Dukungan
|
|
1542
126
|
|
|
1543
|
-
|
|
1544
|
-
// for any message with tag 'edge_routing'
|
|
1545
|
-
sock.ws.on('CB:edge_routing', (node: BinaryNode) => { })
|
|
127
|
+
Jika Anda memiliki pertanyaan atau ingin berdiskusi, silakan bergabung ke Channel Telegram:
|
|
1546
128
|
|
|
1547
|
-
|
|
1548
|
-
sock.ws.on('CB:edge_routing,id:abcd', (node: BinaryNode) => { })
|
|
129
|
+
👉 **[Gabung Channel Telegram](https://t.me/kelvdraa)**
|
|
1549
130
|
|
|
1550
|
-
|
|
1551
|
-
sock.ws.on('CB:edge_routing,id:abcd,routing_info', (node: BinaryNode) => { })
|
|
1552
|
-
```
|
|
1553
|
-
|
|
1554
|
-
> [!NOTE]
|
|
1555
|
-
> Also, this repo is now licenced under GPL 3 since it uses [libsignal-node](https://git.questbook.io/backend/service-coderunner/-/merge_requests/1)
|
|
131
|
+
---
|