@lordmega/baileys 0.3.24 โ†’ 0.3.26

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.
Files changed (2) hide show
  1. package/README.md +20 -1530
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -31,77 +31,6 @@
31
31
  - [๐Ÿ› ๏ธ Internal Adjustments](#%EF%B8%8F-internal-adjustments)
32
32
  - [๐Ÿ“จ Messages Handling & Compatibility](#-messages-handling--compatibility)
33
33
  - [๐Ÿงฉ Additional Message Options](#-additional-message-options)
34
- - [๐Ÿ“ฅ Installation](#-installation)
35
- - [๐Ÿงฉ Import (ESM & CJS)](#-import-esm--cjs)
36
- - [๐Ÿš€ Quick Start](#-quick-start)
37
- - [๐ŸŒ Connect to WhatsApp (Quick Step)](#-connect-to-whatsapp-quick-step)
38
- - [๐Ÿ” Auth State](#-auth-state)
39
- - [๐Ÿ—„๏ธ Implementing Data Store](#%EF%B8%8F-implementing-data-store)
40
- - [๐Ÿชช WhatsApp IDs Explain](#-whatsapp-ids-explain)
41
- - [โœ‰๏ธ Sending Messages](#%EF%B8%8F-sending-messages)
42
- - [๐Ÿ”  Text](#-text)
43
- - [๐Ÿ”” Mention](#-mention)
44
- - [๐Ÿ˜ Reaction](#-reaction)
45
- - [๐Ÿ“Œ Pin Message](#-pin-message)
46
- - [๐Ÿ”– Keep Chat](#-keep-chat)
47
- - [โžก๏ธ Forward Message](#%EF%B8%8F-forward-message)
48
- - [๐Ÿ‘ค Contact](#-contact)
49
- - [๐Ÿ“ Location](#-location)
50
- - [๐Ÿ—“๏ธ Event](#%EF%B8%8F-event)
51
- - [๐Ÿ‘ฅ Group Invite](#-group-invite)
52
- - [๐Ÿ›๏ธ Product](#%EF%B8%8F-product)
53
- - [๐Ÿ“Š Poll](#-poll)
54
- - [๐Ÿ’ญ Button Response](#-button-response)
55
- - [โœจ Rich Response](#-rich-response)
56
- - [๐Ÿงพ Message with Code Block](#-message-with-code-block)
57
- - [๐ŸŒ Message with Inline Entities](#-message-with-inline-entities)
58
- - [๐Ÿ“‹ Message with Table](#-message-with-table)
59
- - [๐ŸŽž๏ธ Status Mention](#%EF%B8%8F-status-mention)
60
- - [๐Ÿ“ Sending Media Messages](#-sending-media-messages)
61
- - [๐Ÿ–ผ๏ธ Image](#%EF%B8%8F-image)
62
- - [๐ŸŽฅ Video](#-video)
63
- - [๐Ÿ“ƒ Sticker](#-sticker)
64
- - [๐Ÿ’ฝ Audio](#-audio)
65
- - [๐Ÿ—‚๏ธ Document](#%EF%B8%8F-document)
66
- - [๐Ÿ–ผ๏ธ Album (Image & Video)](#%EF%B8%8F-album-image--video)
67
- - [๐Ÿ“ฆ Sticker Pack](#-sticker-pack)
68
- - [๐Ÿ‘๏ธ Reveal View-Once](#%EF%B8%8F-reveal-view-once)
69
- - [๐Ÿ‘‰๐Ÿป Sending Interactive Messages](#-sending-interactive-messages)
70
- - [๐Ÿ”˜ Buttons](#-buttons)
71
- - [๐Ÿ“‹ List](#-list)
72
- - [๐Ÿ—„๏ธ Interactive](#%EF%B8%8F-interactive)
73
- - [๐Ÿซ™ Hydrated Template](#-hydrated-template)
74
- - [๐Ÿ’ณ Sending Payment Messages](#-sending-payment-messages)
75
- - [โž• Invite Payment](#-invite-payment)
76
- - [๐Ÿงพ Invoice](#-invoice)
77
- - [๐Ÿ›๏ธ Order](#%EF%B8%8F-order)
78
- - [๐Ÿ’ณ Request Payment](#-request-payment)
79
- - [๐Ÿ‘๏ธ Other Message Options](#%EF%B8%8F-other-message-options)
80
- - [๐Ÿค– AI Icon](#-ai-icon)
81
- - [๐Ÿ•’ Ephemeral](#-ephemeral)
82
- - [๐Ÿ“ฐ External Ad Reply](#-external-ad-reply)
83
- - [๐Ÿง‘โ€๐Ÿง‘โ€๐Ÿง’ Group Status](#%E2%80%8D%E2%80%8D-group-status)
84
- - [๐Ÿฑ Lottie Sticker](#-lottie-sticker)
85
- - [๐Ÿงฉ Raw](#-raw)
86
- - [๐Ÿท๏ธ Secure Meta Service Label](#%EF%B8%8F-secure-meta-service-label)
87
- - [๐Ÿ“‘ Spoiler](#-spoiler)
88
- - [๐Ÿ‘๏ธ View Once](#%EF%B8%8F-view-once)
89
- - [๐Ÿ‘๏ธ View Once V2](#%EF%B8%8F-view-once-v2)
90
- - [๐Ÿ‘๏ธ View Once V2 Extension](#%EF%B8%8F-view-once-v2-extension)
91
- - [โ™ป๏ธ Modify Messages](#%EF%B8%8F-modify-messages)
92
- - [๐Ÿ—‘๏ธ Delete Messages](#%EF%B8%8F-delete-messages)
93
- - [โœ๏ธ Edit Messages](#%EF%B8%8F-edit-messages)
94
- - [๐Ÿงฐ Additional Contents](#-additional-contents)
95
- - [๐Ÿท๏ธ Find User ID (JID|PN/LID)](#%EF%B8%8F-find-user-id-jidpnlid)
96
- - [๐Ÿ”‘ Request Custom Pairing Code](#-request-custom-pairing-code)
97
- - [๐Ÿ–ผ๏ธ Image Processing](#%EF%B8%8F-image-processing)
98
- - [๐Ÿ“ฃ Newsletter Management](#-newsletter-management)
99
- - [๐Ÿ‘ฅ Group Management](#-group-management)
100
- - [๐Ÿ‘ฅ Community Management](#-community-management)
101
- - [๐Ÿ‘ค Profile Management](#-profile-management)
102
- - [๐Ÿ›’ Business Management](#-business-management)
103
- - [๐Ÿ” Privacy Management](#-privacy-management)
104
- - [๐Ÿ“ก Events](#-events)
105
34
  - [๐Ÿš€ Try the Bot](#-try-the-bot)
106
35
  - [๐Ÿ“ฆ Fork Base](#-fork-base)
107
36
 
@@ -123,1483 +52,44 @@ Built for production with an emphasis on readability and reliability:
123
52
  - ๐Ÿ–ผ๏ธ Fixed newsletter media upload failures caused by an upstream bug.
124
53
  - ๐Ÿ“ Restored `makeInMemoryStore` with a lightweight ESM adaptation and minor compatibility tweaks for Baileys v7.
125
54
  - ๐Ÿ“ฆ Replaced FFmpeg `exec` calls with `spawn` for more reliable process management.
126
- - ๐Ÿ—ƒ๏ธ Added [`@napi-rs/image`](https://www.npmjs.com/package/@napi-rs/image) as a supported backend in [`getImageProcessingLibrary()`](#%EF%B8%8F-image-processing), providing a solid balance between speed and compatibility.
55
+ - ๐Ÿ—ƒ๏ธ Added [`@napi-rs/image`](https://www.npmjs.com/package/@napi-rs/image) as a supported backend in `getImageProcessingLibrary()`, providing a solid balance between speed and compatibility.
127
56
  - ๐Ÿ”’ Spoofing guards on self-only protocol messages.
128
57
 
129
58
  ### ๐Ÿ“จ Messages Handling & Compatibility
130
59
 
131
60
  - ๐Ÿ“ฉ Extended message type support for:
132
- - ๐Ÿ–ผ๏ธ [Album Message](#%EF%B8%8F-album-image--video)
133
- - ๐Ÿ‘ค [Group Status Message](#%E2%80%8D%E2%80%8D-group-status)
134
- - ๐Ÿ‘‰๐Ÿป [Interactive Message](#-sending-interactive-messages) (buttons, lists, native flows, templates, carousels)
135
- - ๐ŸŽž๏ธ [Status Mention Message](#%EF%B8%8F-status-mention)
136
- - ๐Ÿ“ฆ [Sticker Pack Message](#-sticker-pack)
137
- - โœจ [Rich Response Message](#-rich-response) **[NEW]**
138
- - ๐Ÿงพ [Message with Code Blocks](#-message-with-code-block) **[NEW]**
139
- - ๐ŸŒ [Message with Inline Entities](#-message-with-inline-entities) **[NEW]**
140
- - ๐Ÿ“‹ [Message with Table](#-message-with-table) **[NEW]**
141
- - ๐Ÿ’ณ [Payment-related Messages](#-sending-payment-messages) (requests, invites, orders, invoices)
142
- - ๐Ÿ“ฐ Simplified ad thumbnail sending via [`externalAdReply`](#-external-ad-reply) โ€” no manual `contextInfo` required.
61
+ - ๐Ÿ–ผ๏ธ Album Message
62
+ - ๐Ÿ‘ค Group Status Message
63
+ - ๐Ÿ‘‰๐Ÿป Interactive Message (buttons, lists, native flows, templates, carousels)
64
+ - ๐ŸŽž๏ธ Status Mention Message
65
+ - ๐Ÿ“ฆ Sticker Pack Message
66
+ - โœจ Rich Response Message **[NEW]**
67
+ - ๐Ÿงพ Message with Code Blocks **[NEW]**
68
+ - ๐ŸŒ Message with Inline Entities **[NEW]**
69
+ - ๐Ÿ“‹ Message with Table **[NEW]**
70
+ - ๐Ÿ’ณ Payment-related Messages (requests, invites, orders, invoices)
71
+ - ๐Ÿ“ฐ Simplified ad thumbnail sending via `externalAdReply` โ€” no manual `contextInfo` required.
143
72
  - ๐Ÿ’ญ Added support for quoting messages inside newsletters. **[NEW]**
144
- - ๐ŸŽ€ Added support for [custom button icons](#%EF%B8%8F-interactive). **[NEW]**
145
- - ๐Ÿ‘๏ธ Reveal view-once messages and resend as normal media via [`sock.rvo()`](#%EF%B8%8F-reveal-view-once). **[NEW]**
73
+ - ๐ŸŽ€ Added support for custom button icons. **[NEW]**
74
+ - ๐Ÿ‘๏ธ Reveal view-once messages and resend as normal media via `sock.rvo()`. **[NEW]**
146
75
 
147
76
  ### ๐Ÿงฉ Additional Message Options
148
77
 
149
78
  - ๐Ÿ‘๏ธ Optional boolean flags for message behavior:
150
- - ๐Ÿค– [`ai`](#-ai-icon) โ€” AI icon on message
151
- - ๐Ÿ“ฃ [`mentionAll`](#-mention) โ€” Mention all group participants without specifying individual JIDs **[NEW]**
152
- - ๐Ÿ”ง [`ephemeral`](#-ephemeral), [`groupStatus`](#%E2%80%8D%E2%80%8D-group-status), [`isLottie`](#-lottie-sticker), [`spoiler`](#-spoiler), [`viewOnce`](#%EF%B8%8F-view-once), [`viewOnceV2`](#%EF%B8%8F-view-once-v2), [`viewOnceV2Extension`](#%EF%B8%8F-view-once-v2-extension), [`interactiveAsTemplate`](#%EF%B8%8F-interactive) โ€” Message wrappers
153
- - ๐Ÿ”’ [`secureMetaServiceLabel`](#%EF%B8%8F-secure-meta-service-label) โ€” Secure meta service label **[NEW]**
154
- - ๐Ÿ“„ [`raw`](#-raw) โ€” Build message proto manually **(DO NOT USE FOR EXPLOITATION)**
79
+ - ๐Ÿค– `ai` โ€” AI icon on message
80
+ - ๐Ÿ“ฃ `mentionAll` โ€” Mention all group participants without specifying individual JIDs **[NEW]**
81
+ - ๐Ÿ”ง `ephemeral`, `groupStatus`, `isLottie`, `spoiler`, `viewOnce`, `viewOnceV2`, `viewOnceV2Extension`, `interactiveAsTemplate` โ€” Message wrappers
82
+ - ๐Ÿ”’ `secureMetaServiceLabel` โ€” Secure meta service label **[NEW]**
83
+ - ๐Ÿ“„ `raw` โ€” Build message proto manually **(DO NOT USE FOR EXPLOITATION)**
155
84
  - ๐Ÿ”‘ Pass a custom 32-byte `messageSecret` on any message type via send options.
156
85
 
157
86
  ---
158
87
 
159
- ### ๐Ÿ“ฅ Installation
160
-
161
- - ๐Ÿ“„ Via `package.json`
162
-
163
- ```json
164
- # NPM
165
- "dependencies": {
166
- "@lordmega/baileys": "latest"
167
- }
168
-
169
- # GitHub
170
- "dependencies": {
171
- "@lordmega/baileys": "github:lordmega/baileys"
172
- }
173
- ```
174
-
175
- - โŒจ๏ธ Via terminal
176
-
177
- ```bash
178
- # NPM
179
- npm i @lordmega/baileys@latest
180
-
181
- # GitHub
182
- npm i github:lordmega/baileys
183
- ```
184
-
185
- #### ๐Ÿงฉ Import (ESM & CJS)
186
-
187
- ```javascript
188
- // --- ESM
189
- import { makeWASocket } from '@lordmega/baileys'
190
-
191
- // --- CJS (tested and working on Node.js 24 โœ…)
192
- const { makeWASocket } = require('@lordmega/baileys')
193
- ```
194
-
195
- ---
196
-
197
- ### ๐Ÿš€ Quick Start
198
-
199
- ```javascript
200
- import { makeWASocket, useMultiFileAuthState, DisconnectReason } from '@lordmega/baileys'
201
- import { Boom } from '@hapi/boom'
202
-
203
- const { state, saveCreds } = await useMultiFileAuthState('auth')
204
-
205
- const sock = makeWASocket({ auth: state, printQRInTerminal: true })
206
-
207
- sock.ev.on('creds.update', saveCreds)
208
-
209
- sock.ev.on('connection.update', ({ connection, lastDisconnect }) => {
210
- if (connection === 'close') {
211
- const reconnect = lastDisconnect?.error?.output?.statusCode !== DisconnectReason.loggedOut
212
- if (reconnect) makeWASocket({ auth: state })
213
- }
214
- })
215
-
216
- sock.ev.on('messages.upsert', async ({ messages }) => {
217
- const msg = messages[0]
218
- if (!msg.key.fromMe && msg.message?.conversation) {
219
- await sock.sendMessage(msg.key.remoteJid, { text: 'pong' })
220
- }
221
- })
222
- ```
223
-
224
- ---
225
-
226
- ### ๐ŸŒ Connect to WhatsApp (Quick Step)
227
-
228
- ```javascript
229
- import { makeWASocket, delay, DisconnectReason, useMultiFileAuthState } from '@lordmega/baileys'
230
- import { Boom } from '@hapi/boom'
231
- import pino from 'pino'
232
-
233
- const myPhoneNumber = '2560000000'
234
-
235
- const logger = pino({ level: 'silent' })
236
-
237
- const connectToWhatsApp = async () => {
238
- const { state, saveCreds } = await useMultiFileAuthState('session')
239
-
240
- const sock = makeWASocket({
241
- logger,
242
- auth: state
243
- })
244
-
245
- sock.ev.on('creds.update', saveCreds)
246
-
247
- sock.ev.on('connection.update', (update) => {
248
- const { connection, lastDisconnect } = update
249
- if (connection === 'connecting' && !sock.authState.creds.registered) {
250
- await delay(1500)
251
- const code = await sock.requestPairingCode(myPhoneNumber)
252
- console.log('๐Ÿ”— Pairing code', ':', code)
253
- }
254
- else if (connection === 'close') {
255
- const shouldReconnect = new Boom(connection?.lastDisconnect?.error)?.output?.statusCode !== DisconnectReason.loggedOut
256
- console.log('โš ๏ธ Connection closed because', lastDisconnect.error, ', reconnecting ', shouldReconnect)
257
- if (shouldReconnect) {
258
- connectToWhatsApp()
259
- }
260
- }
261
- else if (connection === 'open') {
262
- console.log('โœ… Successfully connected to WhatsApp')
263
- }
264
- })
265
-
266
- sock.ev.on('messages.upsert', async ({ messages }) => {
267
- for (const message of messages) {
268
- if (!message.message) continue
269
-
270
- console.log('๐Ÿ”” Got new message', ':', message)
271
- await sock.sendMessage(message.key.remoteJid, {
272
- text: '๐Ÿ‘‹๐Ÿป Hello world'
273
- })
274
- }
275
- })
276
- }
277
-
278
- connectToWhatsApp()
279
- ```
280
-
281
- #### ๐Ÿ” Auth State
282
-
283
- > [!NOTE]
284
- > You can use the experimental `useSingleFileAuthState` and `useSqliteAuthState` as alternatives to `useMultiFileAuthState`. Note that `useSingleFileAuthState` has built-in caching, so wrapping `state.keys` with `makeCacheableSignalKeyStore` is unnecessary.
285
-
286
- #### ๐Ÿ“ฑ Android Browser (receive view-once)
287
-
288
- Connect as an Android client to receive view-once messages natively:
289
-
290
- ```javascript
291
- import { makeWASocket, Browsers } from '@lordmega/baileys'
292
-
293
- const sock = makeWASocket({ auth: state, browser: Browsers.android('Chrome') })
294
- ```
295
-
296
- ---
297
-
298
- ### ๐Ÿ—„๏ธ Implementing Data Store
299
-
300
- > [!CAUTION]
301
- > Building your own data store is strongly recommended โ€” keeping full chat history in memory can cause excessive RAM usage.
302
-
303
- ```javascript
304
- import { makeWASocket, makeInMemoryStore, delay, DisconnectReason, useMultiFileAuthState } from '@lordmega/baileys'
305
- import { Boom } from '@hapi/boom'
306
- import pino from 'pino'
307
-
308
- const myPhoneNumber = '6288888888888'
309
- const storePath = './store.json'
310
- const logger = pino({ level: 'silent' })
311
-
312
- const connectToWhatsApp = async () => {
313
- const { state, saveCreds } = await useMultiFileAuthState('session')
314
-
315
- const sock = makeWASocket({
316
- logger,
317
- auth: state
318
- })
319
-
320
- const store = makeInMemoryStore({
321
- logger,
322
- socket: sock
323
- })
324
-
325
- store.bind(sock.ev)
326
-
327
- sock.ev.on('creds.update', saveCreds)
328
-
329
- sock.ev.on('connection.update', (update) => {
330
- const { connection, lastDisconnect } = update
331
- if (connection === 'connecting' && !sock.authState.creds.registered) {
332
- await delay(1500)
333
- const code = await sock.requestPairingCode(myPhoneNumber)
334
- console.log('๐Ÿ”— Pairing code', ':', code)
335
- }
336
- else if (connection === 'close') {
337
- const shouldReconnect = new Boom(connection?.lastDisconnect?.error)?.output?.statusCode !== DisconnectReason.loggedOut
338
- console.log('โš ๏ธ Connection closed because', lastDisconnect.error, ', reconnecting ', shouldReconnect)
339
- if (shouldReconnect) {
340
- connectToWhatsApp()
341
- }
342
- }
343
- else if (connection === 'open') {
344
- console.log('โœ… Successfully connected to WhatsApp')
345
- }
346
- })
347
-
348
- sock.ev.on('chats.upsert', () => {
349
- console.log('โœ‰๏ธ Got chats', store.chats.all())
350
- })
351
-
352
- sock.ev.on('contacts.upsert', () => {
353
- console.log('๐Ÿ‘ฅ Got contacts', Object.values(store.contacts))
354
- })
355
-
356
- store.readFromFile(storePath)
357
-
358
- setInterval(() => {
359
- store.writeToFile(storePath)
360
- }, 180000)
361
- }
362
-
363
- connectToWhatsApp()
364
- ```
365
-
366
- ---
367
-
368
- ### ๐Ÿชช WhatsApp IDs Explain
369
-
370
- `id` is the WhatsApp ID (also referred to as `jid` or `lid`) of the person or group you're messaging.
371
- - Format: `[country code][phone number]@s.whatsapp.net`
372
- - Individual: `19999999999@s.whatsapp.net` or `12699999999@lid`
373
- - Group: `123456789-123345@g.us`
374
- - Meta AI: `11111111111@bot`
375
- - Broadcast lists: `[timestamp]@broadcast`
376
- - Stories: `status@broadcast`
377
-
378
- ---
379
-
380
- ### โœ‰๏ธ Sending Messages
381
-
382
- #### ๐Ÿ”  Text
383
-
384
- ```javascript
385
- // --- Regular text
386
- sock.sendMessage(jid, {
387
- text: '๐Ÿ‘‹๐Ÿป Hello'
388
- }, {
389
- quoted: message
390
- })
391
-
392
- // --- With link preview
393
- const urlA = 'https://www.npmjs.com/package/@lordmega/baileys'
394
-
395
- sock.sendMessage(jid, {
396
- text: urlA + ' ๐Ÿ‘†๐Ÿป Check it out!',
397
- linkPreview: {
398
- 'matched-text': urlA,
399
- title: '๐ŸŒฑ @lordmega/baileys',
400
- description: 'Underrated Baileys Fork',
401
- previewType: 0,
402
- jpegThumbnail: fs.readFileSync('./path/to/image.jpg')
403
- }
404
- })
405
-
406
- // --- Large link preview with favicon
407
- import { prepareWAMessageMedia } from '@lordmega/baileys'
408
-
409
- const urlB = 'https://www.npmjs.com/package/@lordmega/baileys#readme'
410
-
411
- const { imageMessage: image } = await prepareWAMessageMedia({
412
- image: { url: './path/to/image.jpg' }
413
- }, {
414
- upload: sock.waUploadToServer,
415
- mediaTypeOverride: 'thumbnail-link'
416
- })
417
-
418
- image.height = 720
419
- image.width = 480
420
-
421
- sock.sendMessage(jid, {
422
- text: urlB + ' ๐Ÿ‘†๐Ÿป Check it out!',
423
- linkPreview: {
424
- 'matched-text': urlB,
425
- title: '๐ŸŒฑ @lordmega/baileys',
426
- description: 'Underrated Baileys Fork',
427
- previewType: 0,
428
- jpegThumbnail: fs.readFileSync('./path/to/image.jpg'),
429
- highQualityThumbnail: image,
430
- linkPreviewMetadata: {
431
- linkMediaDuration: 0,
432
- socialMediaPostType: 1,
433
- }
434
- },
435
- favicon: { url: './path/to/tiny-image.ico' }
436
- })
437
- ```
438
-
439
- #### ๐Ÿ”” Mention
440
-
441
- ```javascript
442
- // --- Specific mention
443
- sock.sendMessage(jid, {
444
- text: '๐Ÿ‘‹๐Ÿป Hello @628123456789',
445
- mentions: ['628123456789@s.whatsapp.net']
446
- }, {
447
- quoted: message
448
- })
449
-
450
- // --- Mention all
451
- sock.sendMessage(jid, {
452
- text: '๐Ÿ‘‹๐Ÿป Hello @all',
453
- mentionAll: true
454
- }, {
455
- quoted: message
456
- })
457
- ```
458
-
459
- #### ๐Ÿ˜ Reaction
460
-
461
- ```javascript
462
- sock.sendMessage(jid, {
463
- react: {
464
- key: message.key,
465
- text: 'โœจ'
466
- }
467
- })
468
- ```
469
-
470
- #### ๐Ÿ“Œ Pin Message
471
-
472
- ```javascript
473
- sock.sendMessage(jid, {
474
- pin: message.key,
475
- time: 86400, // 86400 (1d), 604800 (7d), 2592000 (30d)
476
- type: 1 // 2 to unpin
477
- })
478
- ```
479
-
480
- #### ๐Ÿ”– Keep Chat
481
-
482
- > [!NOTE]
483
- > Only works in chats or groups with disappearing messages enabled.
484
-
485
- ```javascript
486
- sock.sendMessage(jid, {
487
- keep: message.key,
488
- type: 1 // 2 to remove
489
- })
490
- ```
491
-
492
- #### โžก๏ธ Forward Message
493
-
494
- ```javascript
495
- sock.sendMessage(jid, {
496
- forward: message,
497
- force: true // Optional
498
- })
499
- ```
500
-
501
- #### ๐Ÿ‘ค Contact
502
-
503
- ```javascript
504
- const vcard = 'BEGIN:VCARD\n'
505
- + 'VERSION:3.0\n'
506
- + 'FN:John Doe\n'
507
- + 'ORG:Example;\n'
508
- + 'TEL;type=CELL;type=VOICE;waid=628123456789:+62 8123 4567 89\n'
509
- + 'END:VCARD'
510
-
511
- sock.sendMessage(jid, {
512
- contacts: {
513
- displayName: 'John Doe',
514
- contacts: [{ vcard }]
515
- }
516
- }, {
517
- quoted: message
518
- })
519
- ```
520
-
521
- #### ๐Ÿ“ Location
522
-
523
- ```javascript
524
- sock.sendMessage(jid, {
525
- location: {
526
- degreesLatitude: 24.121231,
527
- degreesLongitude: 55.1121221,
528
- name: '๐Ÿ‘‹๐Ÿป I am here'
529
- }
530
- }, {
531
- quoted: message
532
- })
533
- ```
534
-
535
- #### ๐Ÿ—“๏ธ Event
536
-
537
- ```javascript
538
- sock.sendMessage(jid, {
539
- event: {
540
- name: '๐ŸŽถ Meet & Mingle Party',
541
- description: 'A casual gathering to connect and build new relationships.',
542
- call: 'audio', // or "video", optional
543
- startDate: new Date(Date.now() + 3600000),
544
- endDate: new Date(Date.now() + 28800000),
545
- isCancelled: false,
546
- isScheduleCall: false,
547
- extraGuestsAllowed: false,
548
- location: {
549
- name: 'Jakarta',
550
- degreesLatitude: -6.2,
551
- degreesLongitude: 106.8
552
- }
553
- }
554
- }, {
555
- quoted: message
556
- })
557
- ```
558
-
559
- #### ๐Ÿ‘ฅ Group Invite
560
-
561
- ```javascript
562
- const inviteCode = groupUrl
563
- .split('chat.whatsapp.com/')[1]
564
- ?.split('?')[0]
565
-
566
- sock.sendMessage(jid, {
567
- groupInvite: {
568
- inviteCode,
569
- inviteExpiration: Date.now() + 86400000,
570
- text: '๐Ÿ‘‹๐Ÿป You are invited to join our group.',
571
- jid: '1201111111111@g.us',
572
- subject: 'Group Name',
573
- }
574
- }, {
575
- quoted: message
576
- })
577
- ```
578
-
579
- #### ๐Ÿ›๏ธ Product
580
-
581
- ```javascript
582
- import { randomUUID } from 'crypto'
583
-
584
- sock.sendMessage(jid, {
585
- image: { url: './path/to/image.jpg' },
586
- body: '๐Ÿ‘‹๐Ÿป Check this out!',
587
- footer: 'MegaBot',
588
- product: {
589
- currencyCode: 'IDR',
590
- description: '๐Ÿ›๏ธ Great product!',
591
- priceAmount1000: 70_000_000,
592
- productId: randomUUID(),
593
- productImageCount: 1,
594
- salePriceAmount1000: 65_000_000,
595
- signedUrl: 'https://example.com',
596
- title: '๐Ÿ“ฆ Product Name',
597
- url: 'https://example.com'
598
- },
599
- businessOwnerJid: '0@s.whatsapp.net'
600
- })
601
- ```
602
-
603
- #### ๐Ÿ“Š Poll
604
-
605
- ```javascript
606
- // --- Standard poll
607
- sock.sendMessage(jid, {
608
- poll: {
609
- name: '๐Ÿ”ฅ Quick vote',
610
- values: ['Yes', 'No'],
611
- selectableCount: 1,
612
- toAnnouncementGroup: false,
613
- endDate: new Date(Date.now() + 28800000),
614
- hideVoter: false,
615
- canAddOption: false
616
- }
617
- }, {
618
- quoted: message
619
- })
620
-
621
- // --- Quiz (newsletters only)
622
- sock.sendMessage('1211111111111@newsletter', {
623
- poll: {
624
- name: '๐Ÿ”ฅ Quiz',
625
- values: ['Yes', 'No'],
626
- correctAnswer: 'Yes',
627
- pollType: 1
628
- }
629
- })
630
-
631
- // --- Poll result
632
- sock.sendMessage(jid, {
633
- pollResult: {
634
- name: '๐Ÿ“ Poll Result',
635
- votes: [{
636
- name: 'Nice',
637
- voteCount: 10
638
- }, {
639
- name: 'Nah',
640
- voteCount: 2
641
- }],
642
- pollType: 0
643
- }
644
- })
645
-
646
- // --- Poll update
647
- sock.sendMessage(jid, {
648
- pollUpdate: {
649
- metadata: {},
650
- key: message.key,
651
- vote: {
652
- enclv: /* <Buffer> */,
653
- encPayload: /* <Buffer> */
654
- }
655
- }
656
- })
657
- ```
658
-
659
- #### ๐Ÿ’ญ Button Response
660
-
661
- ```javascript
662
- // --- buttonsResponseMessage
663
- sock.sendMessage(jid, {
664
- type: 'plain',
665
- buttonReply: {
666
- id: '#Menu',
667
- displayText: 'โœจ Menu'
668
- }
669
- }, { quoted: message })
670
-
671
- // --- interactiveResponseMessage
672
- sock.sendMessage(jid, {
673
- flowReply: {
674
- format: 0,
675
- text: '๐Ÿ’ญ Response',
676
- name: 'menu_options',
677
- paramsJson: JSON.stringify({
678
- id: '#Menu',
679
- description: 'โœจ Menu'
680
- })
681
- }
682
- }, { quoted: message })
683
-
684
- // --- listResponseMessage
685
- sock.sendMessage(jid, {
686
- listReply: {
687
- title: '๐Ÿ“„ See More',
688
- description: 'โœจ Menu',
689
- id: '#Menu'
690
- }
691
- }, { quoted: message })
692
-
693
- // --- templateButtonReplyMessage
694
- sock.sendMessage(jid, {
695
- type: 'template',
696
- buttonReply: {
697
- id: '#Menu',
698
- displayText: 'โœจ Menu',
699
- index: 1
700
- }
701
- }, { quoted: message })
702
- ```
703
-
704
- #### โœจ Rich Response
705
-
706
- > [!NOTE]
707
- > `richResponse[]` maps to `submessages[]` inside `richResponseMessage`.
708
-
709
- ```javascript
710
- sock.sendMessage(jid, {
711
- disclaimerText: 'RAW submessages structure example',
712
- richResponse: [{
713
- text: 'Example Usage',
714
- }, {
715
- language: 'javascript',
716
- code: [{
717
- highlightType: 0,
718
- codeContent: 'console.log("Hello, World!")'
719
- }]
720
- }, {
721
- text: 'Pretty simple, right?\n'
722
- }, {
723
- text: 'Runtime Comparison',
724
- }, {
725
- title: 'Runtime Comparison',
726
- table: [{
727
- isHeading: true,
728
- items: ['', 'Node.js', 'Bun', 'Deno']
729
- }, {
730
- isHeading: false,
731
- items: ['Engine', 'V8 (C++)', 'JavaScriptCore (C++)', 'V8 (C++)']
732
- }, {
733
- isHeading: false,
734
- items: ['Performance', '4/5', '5/5', '4/5']
735
- }]
736
- }, {
737
- text: 'Does this help clarify the differences?'
738
- }]
739
- })
740
- ```
741
-
742
- > [!TIP]
743
- > Use `tokenizeCode` for syntax highlighting:
744
-
745
- ```javascript
746
- import { tokenizeCode } from '@lordmega/baileys'
747
-
748
- const language = 'javascript'
749
- const code = 'console.log("Hello, World!")'
750
-
751
- sock.sendMessage(jid, {
752
- disclaimerText: 'Tokenized Code Block',
753
- richResponse: [{
754
- text: 'Example',
755
- }, {
756
- language,
757
- code: tokenizeCode(code, language)
758
- }, {
759
- text: 'Clean and simple.'
760
- }]
761
- })
762
- ```
763
-
764
- > ๐Ÿ’ก Supported languages: `css`, `html`, `javascript`, `typescript`, `python`, `golang`, `rust`, `c`, `c#`, `c++`, `bash`, `bat`, `powershell`
765
-
766
- #### ๐Ÿงพ Message with Code Block
767
-
768
- ```javascript
769
- sock.sendMessage(jid, {
770
- disclaimerText: 'Code Block',
771
- headerText: '## Example Usage',
772
- contentText: '---',
773
- code: 'console.log("Hello, World!")',
774
- language: 'javascript',
775
- footerText: 'Pretty simple, right?'
776
- })
777
- ```
778
-
779
- #### ๐ŸŒ Message with Inline Entities
780
-
781
- ```javascript
782
- sock.sendMessage(jid, {
783
- disclaimerText: 'Inline Entities',
784
- headerText: '## Check Out!',
785
- contentText: '---',
786
- links: [{
787
- text: '1. Google',
788
- title: 'Popular Search Engine',
789
- url: 'https://www.google.com/'
790
- }, {
791
- text: '2. YouTube',
792
- title: 'Popular Streaming Platform',
793
- url: 'https://www.youtube.com/'
794
- }],
795
- footerText: '---'
796
- })
797
- ```
798
-
799
- #### ๐Ÿ“‹ Message with Table
800
-
801
- ```javascript
802
- sock.sendMessage(jid, {
803
- disclaimerText: 'Table',
804
- headerText: '## Runtime Comparison',
805
- contentText: '---',
806
- title: 'Node.js vs Bun vs Deno',
807
- table: [
808
- ['', 'Node.js', 'Bun', 'Deno'],
809
- ['Engine', 'V8 (C++)', 'JavaScriptCore (C++)', 'V8 (C++)'],
810
- ['Performance', '4/5', '5/5', '4/5']
811
- ],
812
- noHeading: false,
813
- footerText: 'Does this help clarify things?'
814
- })
815
- ```
816
-
817
- #### ๐ŸŽž๏ธ Status Mention
818
-
819
- ```javascript
820
- sock.sendMessage([jidA, jidB, jidC], {
821
- text: 'Hello! ๐Ÿ‘‹๐Ÿป'
822
- })
823
- ```
824
-
825
- ---
826
-
827
- ### ๐Ÿ“ Sending Media Messages
828
-
829
- > [!NOTE]
830
- > Media can be passed as a `Buffer`, `{ stream: Readable }`, or `{ url: string }` (local path or HTTP/HTTPS URL).
831
-
832
- #### ๐Ÿ–ผ๏ธ Image
833
-
834
- ```javascript
835
- sock.sendMessage(jid, {
836
- image: { url: './path/to/image.jpg' },
837
- caption: '๐Ÿ”ฅ Check this out'
838
- }, { quoted: message })
839
- ```
840
-
841
- #### ๐ŸŽฅ Video
842
-
843
- ```javascript
844
- sock.sendMessage(jid, {
845
- video: { url: './path/to/video.mp4' },
846
- gifPlayback: false,
847
- ptv: false,
848
- caption: '๐Ÿ”ฅ Check this out'
849
- }, { quoted: message })
850
- ```
851
-
852
- #### ๐Ÿ“ƒ Sticker
853
-
854
- ```javascript
855
- sock.sendMessage(jid, {
856
- sticker: { url: './path/to/sticker.webp' }
857
- }, { quoted: message })
858
- ```
859
-
860
- #### ๐Ÿ’ฝ Audio
861
-
862
- ```javascript
863
- sock.sendMessage(jid, {
864
- audio: { url: './path/to/audio.mp3' },
865
- ptt: false // true for voice note
866
- }, { quoted: message })
867
- ```
868
-
869
- #### ๐Ÿ—‚๏ธ Document
870
-
871
- ```javascript
872
- sock.sendMessage(jid, {
873
- document: { url: './path/to/document.pdf' },
874
- mimetype: 'application/pdf',
875
- caption: 'โœจ Document'
876
- }, { quoted: message })
877
- ```
878
-
879
- #### ๐Ÿ–ผ๏ธ Album (Image & Video)
880
-
881
- ```javascript
882
- sock.sendMessage(jid, {
883
- album: [{
884
- image: { url: './path/to/image.jpg' },
885
- caption: '1st image'
886
- }, {
887
- video: { url: './path/to/video.mp4' },
888
- caption: '1st video'
889
- }, {
890
- image: { url: './path/to/image.jpg' },
891
- caption: '2nd image'
892
- }, {
893
- video: { url: './path/to/video.mp4' },
894
- caption: '2nd video'
895
- }]
896
- }, { quoted: message })
897
- ```
898
-
899
- #### ๐Ÿ“ฆ Sticker Pack
900
-
901
- > [!IMPORTANT]
902
- > Without `sharp` or `@napi-rs/image` installed, all sticker files must already be in WebP format.
903
-
904
- ```javascript
905
- sock.sendMessage(jid, {
906
- cover: { url: './path/to/image.webp' },
907
- stickers: [{
908
- data: { url: './path/to/image.webp' }
909
- }, {
910
- data: { url: './path/to/image.webp' }
911
- }],
912
- name: '๐Ÿ“ฆ My Sticker Pack',
913
- publisher: 'MegaBot',
914
- description: 'Custom sticker pack'
915
- }, { quoted: message })
916
- ```
917
-
918
- ---
919
-
920
- ### ๐Ÿ‘๏ธ Reveal View-Once
921
-
922
- Download a view-once message and resend it as normal media. Works for image, video, audio, document, and sticker. Downloads and re-uploads so it stays valid even after the original was opened.
923
-
924
- ```javascript
925
- sock.ev.on('messages.upsert', async ({ messages }) => {
926
- for (const m of messages) {
927
- const vo = m.message?.viewOnceMessage
928
- || m.message?.viewOnceMessageV2
929
- || m.message?.viewOnceMessageV2Extension
930
- if (vo) {
931
- await sock.rvo(m) // resend to the original chat
932
- // await sock.rvo(m, jid) // or to a specific jid
933
- }
934
- }
935
- })
936
- ```
937
-
938
- ---
939
-
940
- ### ๐Ÿ‘‰๐Ÿป Sending Interactive Messages
941
-
942
- #### ๐Ÿ”˜ Buttons
943
-
944
- ```javascript
945
- // --- Basic buttons
946
- sock.sendMessage(jid, {
947
- text: '๐Ÿ‘†๐Ÿป Buttons!',
948
- footer: 'MegaBot',
949
- buttons: [{
950
- text: '๐Ÿ‘‹๐Ÿป Sign Up',
951
- id: '#SignUp'
952
- }]
953
- }, { quoted: message })
954
-
955
- // --- Buttons with media and native flow
956
- sock.sendMessage(jid, {
957
- image: { url: './path/to/image.jpg' },
958
- caption: '๐Ÿ‘†๐Ÿป Buttons with Native Flow!',
959
- footer: 'MegaBot',
960
- buttons: [{
961
- text: '๐Ÿ‘‹๐Ÿป Rating',
962
- id: '#Rating'
963
- }, {
964
- text: '๐Ÿ“‹ Select',
965
- sections: [{
966
- title: 'โœจ Section 1',
967
- rows: [{
968
- header: '',
969
- title: '๐Ÿ’ญ Secret Ingredient',
970
- description: '',
971
- id: '#SecretIngredient'
972
- }]
973
- }]
974
- }]
975
- }, { quoted: message })
976
- ```
977
-
978
- #### ๐Ÿ“‹ List
979
-
980
- > [!NOTE]
981
- > Only works in private chats (`@s.whatsapp.net`).
982
-
983
- ```javascript
984
- sock.sendMessage(jid, {
985
- text: '๐Ÿ“‹ Pick an option',
986
- footer: 'MegaBot',
987
- buttonText: '๐Ÿ“‹ Select',
988
- title: '๐Ÿ‘‹๐Ÿป Hello',
989
- sections: [{
990
- title: '๐Ÿš€ Menu 1',
991
- rows: [{
992
- title: 'โœจ AI',
993
- description: '',
994
- rowId: '#AI'
995
- }]
996
- }, {
997
- title: '๐ŸŒฑ Menu 2',
998
- rows: [{
999
- title: '๐Ÿ” Search',
1000
- description: '',
1001
- rowId: '#Search'
1002
- }]
1003
- }]
1004
- }, { quoted: message })
1005
- ```
1006
-
1007
- #### ๐Ÿ—„๏ธ Interactive
1008
-
1009
- ```javascript
1010
- // --- Native flow
1011
- sock.sendMessage(jid, {
1012
- image: { url: './path/to/image.jpg' },
1013
- caption: '๐Ÿ—„๏ธ Interactive!',
1014
- footer: 'MegaBot',
1015
- optionText: '๐Ÿ‘‰๐Ÿป Select Options',
1016
- optionTitle: '๐Ÿ“„ Options',
1017
- offerText: '๐Ÿท๏ธ Latest Deal!',
1018
- offerCode: 'MEGA2024',
1019
- offerUrl: 'https://example.com',
1020
- offerExpiration: Date.now() + 3_600_000,
1021
- nativeFlow: [{
1022
- text: '๐Ÿ‘‹๐Ÿป Greeting',
1023
- id: '#Greeting',
1024
- icon: 'review'
1025
- }, {
1026
- text: '๐Ÿ“ž Call',
1027
- call: '628123456789'
1028
- }, {
1029
- text: '๐Ÿ“‹ Copy',
1030
- copy: 'some-text'
1031
- }, {
1032
- text: '๐ŸŒ Visit',
1033
- url: 'https://example.com',
1034
- useWebview: true
1035
- }, {
1036
- text: '๐Ÿ“‹ Select',
1037
- sections: [{
1038
- title: 'โœจ Section 1',
1039
- rows: [{
1040
- header: '',
1041
- title: '๐Ÿท๏ธ Option A',
1042
- description: '',
1043
- id: '#OptionA'
1044
- }]
1045
- }],
1046
- icon: 'default'
1047
- }],
1048
- interactiveAsTemplate: false // Optional, wrap into templateMessage
1049
- }, { quoted: message })
1050
-
1051
- // --- Carousel with native flow
1052
- sock.sendMessage(jid, {
1053
- text: '๐Ÿ—‚๏ธ Carousel!',
1054
- footer: 'MegaBot',
1055
- cards: [{
1056
- image: { url: './path/to/image.jpg' },
1057
- caption: '๐Ÿ–ผ๏ธ Slide 1',
1058
- footer: '๐Ÿท๏ธ Tag',
1059
- nativeFlow: [{
1060
- text: '๐ŸŒ Visit',
1061
- url: 'https://example.com',
1062
- useWebview: true
1063
- }]
1064
- }, {
1065
- image: { url: './path/to/image.jpg' },
1066
- caption: '๐Ÿ–ผ๏ธ Slide 2',
1067
- footer: '๐Ÿท๏ธ Tag',
1068
- nativeFlow: [{
1069
- text: '๐ŸŒ Visit',
1070
- url: 'https://example.com'
1071
- }]
1072
- }]
1073
- }, { quoted: message })
1074
-
1075
- // --- Native flow with audio footer
1076
- sock.sendMessage(jid, {
1077
- text: '๐Ÿ”ˆ Audio in footer!',
1078
- audioFooter: { url: './path/to/audio.mp3' },
1079
- nativeFlow: [{
1080
- text: '๐Ÿ‘๐Ÿป Next',
1081
- id: '#Next',
1082
- icon: 'review'
1083
- }, {
1084
- text: '๐Ÿ‘Ž๐Ÿป Skip',
1085
- id: '#Skip',
1086
- icon: 'default'
1087
- }]
1088
- }, { quoted: message })
1089
- ```
1090
-
1091
- #### ๐Ÿซ™ Hydrated Template
1092
-
1093
- ```javascript
1094
- sock.sendMessage(jid, {
1095
- title: '๐Ÿ‘‹๐Ÿป Hello',
1096
- image: { url: './path/to/image.jpg' },
1097
- caption: '๐Ÿซ™ Template!',
1098
- footer: 'MegaBot',
1099
- templateButtons: [{
1100
- text: '๐Ÿ‘‰๐Ÿป Tap Here',
1101
- id: '#Order'
1102
- }, {
1103
- text: '๐ŸŒ Visit',
1104
- url: 'https://example.com'
1105
- }, {
1106
- text: '๐Ÿ“ž Call',
1107
- call: '628123456789'
1108
- }]
1109
- }, { quoted: message })
1110
- ```
1111
-
1112
- ---
1113
-
1114
- ### ๐Ÿ’ณ Sending Payment Messages
1115
-
1116
- #### โž• Invite Payment
1117
-
1118
- ```javascript
1119
- sock.sendMessage(jid, {
1120
- paymentInviteServiceType: 3 // 1, 2, or 3
1121
- })
1122
- ```
1123
-
1124
- #### ๐Ÿงพ Invoice
1125
-
1126
- > [!NOTE]
1127
- > Invoice messages are not fully supported yet.
1128
-
1129
- ```javascript
1130
- sock.sendMessage(jid, {
1131
- image: { url: './path/to/image.jpg' },
1132
- invoiceNote: '๐Ÿท๏ธ Invoice'
1133
- })
1134
- ```
1135
-
1136
- #### ๐Ÿ›๏ธ Order
1137
-
1138
- ```javascript
1139
- sock.sendMessage(jid, {
1140
- orderText: '๐Ÿ›๏ธ Your Order',
1141
- thumbnail: fs.readFileSync('./path/to/image.jpg') // Must be a Buffer
1142
- }, { quoted: message })
1143
- ```
1144
-
1145
- #### ๐Ÿ’ณ Request Payment
1146
-
1147
- ```javascript
1148
- sock.sendMessage(jid, {
1149
- text: '๐Ÿ’ณ Payment Request',
1150
- requestPaymentFrom: '0@s.whatsapp.net'
1151
- })
1152
- ```
1153
-
1154
- ---
1155
-
1156
- ### ๐Ÿ‘๏ธ Other Message Options
1157
-
1158
- #### ๐Ÿค– AI Icon
1159
-
1160
- > [!NOTE]
1161
- > Only works in private chats (`@s.whatsapp.net`).
1162
-
1163
- ```javascript
1164
- sock.sendMessage(jid, {
1165
- image: { url: './path/to/image.jpg' },
1166
- caption: '๐Ÿค– AI-tagged message',
1167
- ai: true
1168
- }, { quoted: message })
1169
- ```
1170
-
1171
- #### ๐Ÿ•’ Ephemeral
1172
-
1173
- ```javascript
1174
- sock.sendMessage(jid, {
1175
- image: { url: './path/to/image.jpg' },
1176
- caption: '๐Ÿ‘๏ธ Ephemeral',
1177
- ephemeral: true
1178
- })
1179
- ```
1180
-
1181
- #### ๐Ÿ“ฐ External Ad Reply
1182
-
1183
- ```javascript
1184
- sock.sendMessage(jid, {
1185
- text: '๐Ÿ“ฐ Ad Reply',
1186
- externalAdReply: {
1187
- title: '๐Ÿ“ Did you know?',
1188
- body: 'โ“ Interesting fact',
1189
- thumbnail: fs.readFileSync('./path/to/image.jpg'),
1190
- largeThumbnail: false,
1191
- url: 'https://example.com'
1192
- }
1193
- }, { quoted: message })
1194
- ```
1195
-
1196
- #### ๐Ÿง‘โ€๐Ÿง‘โ€๐Ÿง’ Group Status
1197
-
1198
- > [!NOTE]
1199
- > Only works in group chats (`@g.us`).
1200
-
1201
- ```javascript
1202
- sock.sendMessage(jid, {
1203
- image: { url: './path/to/image.jpg' },
1204
- caption: '๐Ÿ‘ฅ Group Status',
1205
- groupStatus: true
1206
- })
1207
- ```
1208
-
1209
- #### ๐Ÿฑ Lottie Sticker
1210
-
1211
- ```javascript
1212
- sock.sendMessage(jid, {
1213
- sticker: { url: './path/to/sticker.webp' },
1214
- isLottie: true
1215
- })
1216
- ```
1217
-
1218
- #### ๐Ÿงฉ Raw
1219
-
1220
- ```javascript
1221
- sock.sendMessage(jid, {
1222
- extendedTextMessage: {
1223
- text: '๐Ÿ“ƒ Manually constructed proto message',
1224
- contextInfo: {
1225
- externalAdReply: {
1226
- title: 'MegaBot',
1227
- thumbnail: fs.readFileSync('./path/to/image.jpg'),
1228
- sourceApp: 'whatsapp',
1229
- showAdAttribution: true,
1230
- mediaType: 1
1231
- }
1232
- }
1233
- },
1234
- raw: true
1235
- }, { quoted: message })
1236
- ```
1237
-
1238
- #### ๐Ÿท๏ธ Secure Meta Service Label
1239
-
1240
- ```javascript
1241
- sock.sendMessage(jid, {
1242
- text: '๐Ÿท๏ธ Labeled message',
1243
- secureMetaServiceLabel: true
1244
- })
1245
- ```
1246
-
1247
- #### ๐Ÿ“‘ Spoiler
1248
-
1249
- ```javascript
1250
- sock.sendMessage(jid, {
1251
- image: { url: './path/to/image.jpg' },
1252
- caption: 'โ” Spoiler',
1253
- spoiler: true
1254
- })
1255
- ```
1256
-
1257
- #### ๐Ÿ‘๏ธ View Once
1258
-
1259
- ```javascript
1260
- sock.sendMessage(jid, {
1261
- image: { url: './path/to/image.jpg' },
1262
- caption: '๐Ÿ‘๏ธ View Once',
1263
- viewOnce: true
1264
- })
1265
- ```
1266
-
1267
- #### ๐Ÿ‘๏ธ View Once V2
1268
-
1269
- ```javascript
1270
- sock.sendMessage(jid, {
1271
- image: { url: './path/to/image.jpg' },
1272
- caption: '๐Ÿ‘๏ธ View Once V2',
1273
- viewOnceV2: true
1274
- })
1275
- ```
1276
-
1277
- #### ๐Ÿ‘๏ธ View Once V2 Extension
1278
-
1279
- ```javascript
1280
- sock.sendMessage(jid, {
1281
- image: { url: './path/to/image.jpg' },
1282
- caption: '๐Ÿ‘๏ธ View Once V2 Extension',
1283
- viewOnceV2Extension: true
1284
- })
1285
- ```
1286
-
1287
- #### ๐Ÿ”‘ Caller-Supplied messageSecret
1288
-
1289
- Pass your own 32-byte `messageSecret` on any message type:
1290
-
1291
- ```javascript
1292
- import { randomBytes } from 'crypto'
1293
-
1294
- await sock.sendMessage(jid, { text: 'hi' }, { messageSecret: randomBytes(32) })
1295
- ```
1296
-
1297
- ---
1298
-
1299
- ### โ™ป๏ธ Modify Messages
1300
-
1301
- #### ๐Ÿ—‘๏ธ Delete Messages
1302
-
1303
- ```javascript
1304
- sock.sendMessage(jid, {
1305
- delete: message.key
1306
- })
1307
- ```
1308
-
1309
- #### โœ๏ธ Edit Messages
1310
-
1311
- ```javascript
1312
- // --- Edit text
1313
- sock.sendMessage(jid, {
1314
- text: 'โœจ Corrected message',
1315
- edit: message.key
1316
- })
1317
-
1318
- // --- Edit media caption
1319
- sock.sendMessage(jid, {
1320
- caption: 'โœจ Updated caption',
1321
- edit: message.key
1322
- })
1323
- ```
1324
-
1325
- > [!NOTE]
1326
- > Encrypted E2EE message edits (May 2026+) are automatically decrypted โ€” edited messages arrive via the normal `protocolMessage.editedMessage` path.
1327
-
1328
- ---
1329
-
1330
- ### ๐Ÿงฐ Additional Contents
1331
-
1332
- #### ๐Ÿท๏ธ Find User ID (JID|PN/LID)
1333
-
1334
- > [!NOTE]
1335
- > Numbers only โ€” no `+`, `()`, or `-`. Must include country code.
1336
-
1337
- ```javascript
1338
- const ids = await sock.findUserId('6281111111111@s.whatsapp.net')
1339
- console.log('๐Ÿท๏ธ User ID:', ids)
1340
-
1341
- // Output:
1342
- // { phoneNumber: '6281111111111@s.whatsapp.net', lid: '43411111111111@lid' }
1343
- // On failure:
1344
- // { phoneNumber: '6281111111111@s.whatsapp.net', lid: undefined }
1345
- ```
1346
-
1347
- #### ๐Ÿ”‘ Request Custom Pairing Code
1348
-
1349
- ```javascript
1350
- await sock.requestPairingCode('6281111111111', 'MYCODE')
1351
- console.log('๐Ÿ”— Pairing code: MYCODE')
1352
- ```
1353
-
1354
- #### ๐Ÿ–ผ๏ธ Image Processing
1355
-
1356
- ```javascript
1357
- import { getImageProcessingLibrary } from '@lordmega/baileys'
1358
- import { readFile } from 'fs/promises'
1359
-
1360
- const lib = await getImageProcessingLibrary()
1361
- const input = './path/to/image.jpg'
1362
- const width = 512
1363
- let output
1364
-
1365
- if (lib.sharp?.default) {
1366
- output = await lib.sharp.default(input)
1367
- .resize(width)
1368
- .jpeg({ quality: 80 })
1369
- .toBuffer()
1370
- }
1371
- else if (lib.image?.Transformer) {
1372
- const buf = Buffer.isBuffer(input) ? input : await readFile(input)
1373
- output = await new lib.image.Transformer(buf)
1374
- .resize(width, undefined, 0)
1375
- .jpeg(50)
1376
- }
1377
- else if (lib.jimp?.Jimp) {
1378
- output = await (await lib.jimp.Jimp.read(input))
1379
- .resize({ w: width, mode: lib.jimp.ResizeStrategy.BILINEAR })
1380
- .getBuffer('image/jpeg', { quality: 50 })
1381
- }
1382
- else {
1383
- throw new Error('No image processing library available')
1384
- }
1385
- ```
1386
-
1387
- #### ๐Ÿ“ฃ Newsletter Management
1388
-
1389
- ```javascript
1390
- sock.newsletterCreate('Name', 'Description')
1391
- const metadata = sock.newsletterMetadata('1231111111111@newsletter')
1392
- const subscribers = await sock.newsletterSubscribers('1231111111111@newsletter')
1393
- sock.newsletterFollow('1231111111111@newsletter')
1394
- sock.newsletterUnfollow('1231111111111@newsletter')
1395
- sock.newsletterMute('1231111111111@newsletter')
1396
- sock.newsletterUnmute('1231111111111@newsletter')
1397
- sock.newsletterDemote('1231111111111@newsletter', '628...@s.whatsapp.net')
1398
- sock.newsletterChangeOwner('1231111111111@newsletter', '628...@s.whatsapp.net')
1399
- sock.newsletterUpdate('1231111111111@newsletter', { name: 'New Name' })
1400
- sock.newsletterUpdateName('1231111111111@newsletter', 'New Name')
1401
- sock.newsletterUpdateDescription('1231111111111@newsletter', 'New description')
1402
- sock.newsletterUpdatePicture('1231111111111@newsletter', { url: 'path/to/image.jpg' })
1403
- sock.newsletterRemovePicture('1231111111111@newsletter')
1404
- sock.newsletterReactMessage('1231111111111@newsletter', '100', '๐Ÿ’›')
1405
- const count = await sock.newsletterAdminCount('1231111111111@newsletter')
1406
- const newsletters = await sock.newsletterSubscribed()
1407
- const messages = sock.newsletterFetchMessages('jid', '1231111111111@newsletter', 50, 0, 0)
1408
- sock.newsletterDelete('1231111111111@newsletter')
1409
- ```
1410
-
1411
- #### ๐Ÿ‘ฅ Group Management
1412
-
1413
- ```javascript
1414
- const group = sock.groupCreate('Group Name', ['628...@s.whatsapp.net'])
1415
- const metadata = await sock.groupMetadata(jid)
1416
- const inviteCode = await sock.groupInviteCode(jid)
1417
- sock.groupRevokeInvite(jid)
1418
- sock.groupAcceptInvite(inviteCode)
1419
- sock.groupLeave(jid)
1420
- sock.groupParticipantsUpdate(jid, ['628...@s.whatsapp.net'], 'add')
1421
- sock.groupParticipantsUpdate(jid, ['628...@s.whatsapp.net'], 'remove')
1422
- sock.groupParticipantsUpdate(jid, ['628...@s.whatsapp.net'], 'promote')
1423
- sock.groupParticipantsUpdate(jid, ['628...@s.whatsapp.net'], 'demote')
1424
- sock.groupRequestParticipantsUpdate(jid, ['628...@s.whatsapp.net'], 'approve')
1425
- sock.groupUpdateSubject(jid, 'New Name')
1426
- sock.groupUpdateDescription(jid, 'New description')
1427
- sock.updateProfilePicture(jid, { url: 'path/to/image.jpg' })
1428
- sock.removeProfilePicture(jid)
1429
- sock.groupSettingUpdate(jid, 'announcement') // admin-only chat
1430
- sock.groupSettingUpdate(jid, 'not_announcement') // open chat
1431
- sock.groupSettingUpdate(jid, 'locked') // admin-only edits
1432
- sock.groupSettingUpdate(jid, 'unlocked') // open edits
1433
- sock.groupMemberAddMode(jid, 'admin_add')
1434
- sock.groupMemberAddMode(jid, 'all_member_add')
1435
- sock.groupToggleEphemeral(jid, 86400)
1436
- sock.groupToggleEphemeral(jid, 0) // disable
1437
- sock.groupJoinApprovalMode(jid, 'on')
1438
- sock.groupJoinApprovalMode(jid, 'off')
1439
- const groups = await sock.groupFetchAllParticipating()
1440
- const requests = await sock.groupRequestParticipantsList(jid)
1441
- const groupInfo = await sock.groupGetInviteInfo('ABC123456789')
1442
- sock.updateMemberLabel(jid, 'label')
1443
- ```
1444
-
1445
- #### ๐Ÿ‘ฅ Community Management
1446
-
1447
- ```javascript
1448
- const community = await sock.communityCreate('Name', 'Description')
1449
- const group = await sock.communityCreateGroup('Announcements', ['628...@s.whatsapp.net'], communityJid)
1450
- sock.communityLinkGroup(groupJid, communityJid)
1451
- sock.communityUnlinkGroup(groupJid, communityJid)
1452
- const metadata = await sock.communityMetadata(jid)
1453
- const inviteCode = await sock.communityInviteCode(jid)
1454
- sock.communityRevokeInvite(jid)
1455
- sock.communityAcceptInvite(inviteCode)
1456
- sock.communityLeave(jid)
1457
- sock.communityRequestParticipantsUpdate(jid, ['628...@s.whatsapp.net'], 'approve')
1458
- sock.communityUpdateSubject(jid, 'New Name')
1459
- sock.communityUpdateDescription(jid, 'New description')
1460
- sock.communitySettingUpdate(jid, 'announcement')
1461
- sock.communitySettingUpdate(jid, 'locked')
1462
- sock.communityMemberAddMode(jid, 'admin_add')
1463
- sock.communityToggleEphemeral(jid, 86400)
1464
- sock.communityJoinApprovalMode(jid, 'on')
1465
- const communities = await sock.communityFetchAllParticipating()
1466
- const linked = await sock.communityFetchLinkedGroups(jid)
1467
- const requests = await sock.communityRequestParticipantsList(jid)
1468
- const info = await sock.communityGetInviteInfo('ABC123456789')
1469
- ```
1470
-
1471
- #### ๐Ÿ‘ค Profile Management
1472
-
1473
- ```javascript
1474
- const url = await sock.profilePictureUrl(jid, 'image')
1475
- sock.updateProfilePicture(jid, buffer)
1476
- sock.removeProfilePicture(jid)
1477
- sock.updateProfileName('My Name')
1478
- sock.updateProfileStatus('Available')
1479
- sock.sendPresenceUpdate('available', jid)
1480
- sock.presenceSubscribe(jid)
1481
- sock.readMessages([message.key])
1482
- sock.sendReceipt(jid, participant, [messageId], 'read')
1483
- sock.updateBlockStatus(jid, 'block')
1484
- sock.updateBlockStatus(jid, 'unblock')
1485
- const blocked = await sock.fetchBlocklist()
1486
- sock.chatModify({ archive: true, lastMessageOrig: message, lastMessage: message }, jid)
1487
- sock.star(jid, [{ id: messageId, fromMe: true }], true)
1488
- sock.addOrEditContact(jid, { displayName: 'Name' })
1489
- sock.removeContact(jid)
1490
- sock.addChatLabel(jid, labelId)
1491
- sock.removeChatLabel(jid, labelId)
1492
- sock.addMessageLabel(jid, messageId, labelId)
1493
- sock.resyncAppState(['regular', 'critical_block'], true)
1494
- const profile = await sock.getBusinessProfile(jid)
1495
- ```
1496
-
1497
- #### ๐Ÿ›’ Business Management
1498
-
1499
- ```javascript
1500
- const product = await sock.productCreate({
1501
- name: 'Product Name',
1502
- description: 'Description',
1503
- price: 100000,
1504
- currency: 'IDR',
1505
- originCountryCode: 'ID',
1506
- images: [bufferImage, { url: './path/to/image.jpg' }]
1507
- })
1508
-
1509
- await sock.productUpdate(productId, {
1510
- name: 'Updated Name',
1511
- price: 75000,
1512
- currency: 'IDR',
1513
- images: [{ url: './path/to/image.jpg' }]
1514
- })
1515
-
1516
- sock.productDelete([productId])
1517
-
1518
- const { products, nextPageCursor } = await sock.getCatalog({
1519
- jid: '628...@s.whatsapp.net',
1520
- limit: 10
1521
- })
1522
-
1523
- const collections = await sock.getCollections('628...@s.whatsapp.net', 10)
1524
- const order = await sock.getOrderDetails(orderId, tokenBase64)
1525
-
1526
- await sock.updateBusinessProfile({
1527
- address: 'Jakarta, Indonesia',
1528
- description: 'Official Store',
1529
- websites: ['https://example.com'],
1530
- email: 'contact@example.com',
1531
- hours: {
1532
- timezone: 'Asia/Jakarta',
1533
- days: [{ day: 'mon', mode: 'open_24h' }]
1534
- }
1535
- })
1536
-
1537
- sock.updateCoverPhoto({ url: './path/to/image.jpg' })
1538
- sock.removeCoverPhoto(coverId)
1539
- sock.addOrEditQuickReply({ shortcut: 'hello', message: 'Hello!' })
1540
- sock.removeQuickReply(timestamp)
1541
- ```
1542
-
1543
- #### ๐Ÿ” Privacy Management
1544
-
1545
- ```javascript
1546
- sock.updateLastSeenPrivacy('all' | 'contacts' | 'contact_blacklist' | 'nobody')
1547
- sock.updateOnlinePrivacy('all' | 'match_last_seen')
1548
- sock.updateProfilePicturePrivacy('contacts')
1549
- sock.updateStatusPrivacy('contacts')
1550
- sock.updateReadReceiptsPrivacy('all' | 'none')
1551
- sock.updateGroupsAddPrivacy('all' | 'contacts')
1552
- sock.updateMessagesPrivacy('all' | 'contacts' | 'nobody')
1553
- sock.updateCallPrivacy('everyone')
1554
- sock.updateDefaultDisappearingMode(86400)
1555
- sock.updateDisableLinkPreviewsPrivacy(true)
1556
- ```
1557
-
1558
- #### ๐Ÿ“ก Events
1559
-
1560
- ```javascript
1561
- sock.ev.on('connection.update', (update) => {})
1562
- sock.ev.on('creds.update', (update) => {})
1563
- sock.ev.on('messaging-history.set', (update) => {})
1564
- sock.ev.on('messaging-history.status', (update) => {})
1565
- sock.ev.on('chats.upsert', (update) => {})
1566
- sock.ev.on('chats.update', (update) => {})
1567
- sock.ev.on('chats.delete', (update) => {})
1568
- sock.ev.on('chats.lock', (update) => {})
1569
- sock.ev.on('lid-mapping.update', (update) => {})
1570
- sock.ev.on('presence.update', (update) => {})
1571
- sock.ev.on('contacts.upsert', (update) => {})
1572
- sock.ev.on('contacts.update', (update) => {})
1573
- sock.ev.on('messages.delete', (update) => {})
1574
- sock.ev.on('messages.update', (update) => {})
1575
- sock.ev.on('messages.media-update', (update) => {})
1576
- sock.ev.on('messages.upsert', (update) => {})
1577
- sock.ev.on('messages.reaction', (update) => {})
1578
- sock.ev.on('message-receipt.update', (update) => {})
1579
- sock.ev.on('groups.upsert', (update) => {})
1580
- sock.ev.on('groups.update', (update) => {})
1581
- sock.ev.on('group-participants.update', (update) => {})
1582
- sock.ev.on('group.join-request', (update) => {})
1583
- sock.ev.on('group.member-tag.update', (update) => {})
1584
- sock.ev.on('blocklist.set', (update) => {})
1585
- sock.ev.on('blocklist.update', (update) => {})
1586
- sock.ev.on('call', (update) => {})
1587
- sock.ev.on('labels.edit', (update) => {})
1588
- sock.ev.on('labels.association', (update) => {})
1589
- sock.ev.on('newsletter.reaction', (update) => {})
1590
- sock.ev.on('newsletter.view', (update) => {})
1591
- sock.ev.on('newsletter-participants.update', (update) => {})
1592
- sock.ev.on('newsletter-settings.update', (update) => {})
1593
- sock.ev.on('settings.update', (update) => {})
1594
- ```
1595
-
1596
- ---
1597
-
1598
88
  ### ๐Ÿš€ Try the Bot
1599
89
 
1600
90
  A lightweight, modular WhatsApp bot built on this library โ€” includes group management, moderation, quiz games, and utility tools.
1601
91
 
1602
- ๐Ÿ‘‰๐Ÿป [MegaBot MD](https://github.com/LORDMEGA-MD/MegaBot)
92
+ ๐Ÿ‘‰๐Ÿป [MegaBot MD](https://github.com/LORDMEGA-MD/MEGABOT5)
1603
93
 
1604
94
  ---
1605
95