@hiroosy/baileys-lite 0.0.3 → 0.3.0

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 (116) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +660 -12
  3. package/WAProto/index.js +2 -2558
  4. package/engine-requirements.js +3 -4
  5. package/package.json +8 -3
  6. package/src/binary/wa-binary.js +3 -25
  7. package/src/constants.js +7 -15
  8. package/src/defaults.js +2 -5
  9. package/src/foundation/ai-rich.js +530 -0
  10. package/src/foundation/audio-duration.js +43 -103
  11. package/src/foundation/audio-samples.js +19 -37
  12. package/src/foundation/boom.js +0 -7
  13. package/src/foundation/cache.js +4 -26
  14. package/src/foundation/concurrency.js +1 -19
  15. package/src/foundation/curve25519.js +7 -39
  16. package/src/foundation/link-preview.js +15 -57
  17. package/src/foundation/logger.js +0 -11
  18. package/src/foundation/long.js +4 -14
  19. package/src/foundation/protobuf-minimal.js +21 -53
  20. package/src/foundation/qrcode-terminal.js +273 -0
  21. package/src/foundation/sql-database.js +702 -0
  22. package/src/foundation/wa-crypto.js +2 -31
  23. package/src/foundation/zip.js +25 -41
  24. package/src/index.js +8 -18
  25. package/src/signal/libsignal.js +23 -78
  26. package/src/signal/signal-group.js +0 -35
  27. package/src/signal/signal-repository.js +10 -29
  28. package/src/socket/business-communities.js +12 -31
  29. package/src/socket/chats.js +5 -8
  30. package/src/socket/groups-newsletter.js +18 -17
  31. package/src/socket/messages-recv.js +81 -127
  32. package/src/socket/messages-send.js +372 -139
  33. package/src/socket/socket-core.js +227 -157
  34. package/src/socket/usync.js +2 -6
  35. package/src/socket-client/native-websocket.js +344 -0
  36. package/src/socket-client/websocket-client.js +84 -38
  37. package/src/utils/auth-state-core.js +14 -56
  38. package/src/utils/auth-state-storage.js +7 -42
  39. package/src/utils/chat-sync.js +4 -26
  40. package/src/utils/media.js +15 -71
  41. package/src/utils/message-compose.js +208 -85
  42. package/src/utils/message-processing.js +10 -65
  43. package/src/utils/username.js +19 -0
  44. package/src/utils/wa-protocol-core.js +71 -127
  45. package/src/vendor/jpeg-js/decoder.js +75 -136
  46. package/src/vendor/jpeg-js/encoder.js +179 -264
  47. package/src/vendor/pngjs/bitmapper.js +5 -27
  48. package/src/vendor/pngjs/bitpacker.js +4 -12
  49. package/src/vendor/pngjs/constants.js +3 -11
  50. package/src/vendor/pngjs/crc.js +0 -6
  51. package/src/vendor/pngjs/filter-pack.js +1 -7
  52. package/src/vendor/pngjs/filter-parse-sync.js +0 -6
  53. package/src/vendor/pngjs/filter-parse.js +1 -11
  54. package/src/vendor/pngjs/format-normaliser.js +5 -11
  55. package/src/vendor/pngjs/interlace.js +7 -24
  56. package/src/vendor/pngjs/packer-sync.js +0 -11
  57. package/src/vendor/pngjs/packer.js +7 -15
  58. package/src/vendor/pngjs/paeth-predictor.js +0 -6
  59. package/src/vendor/pngjs/parser-sync.js +0 -8
  60. package/src/vendor/pngjs/parser.js +5 -29
  61. package/src/vendor/pngjs/png-sync.js +0 -7
  62. package/src/vendor/pngjs/sync-inflate.js +7 -16
  63. package/src/vendor/pngjs/sync-reader.js +4 -11
  64. package/src/voip/WaVoipCoordinator.js +158 -0
  65. package/src/voip/app-data/WaAppDataStream.js +193 -0
  66. package/src/voip/app-data/protocol.js +172 -0
  67. package/src/voip/bytes.js +63 -0
  68. package/src/voip/call/WaCallManager.js +442 -0
  69. package/src/voip/call/WaCallMediaSession.js +1705 -0
  70. package/src/voip/call/call-state.js +203 -0
  71. package/src/voip/crypto/encryption.js +13 -0
  72. package/src/voip/crypto/primitives.js +21 -0
  73. package/src/voip/crypto/rtcp.js +66 -0
  74. package/src/voip/crypto/srtp.js +180 -0
  75. package/src/voip/crypto/ssrc.js +15 -0
  76. package/src/voip/index.js +628 -0
  77. package/src/voip/media/WaAudioEngine.js +486 -0
  78. package/src/voip/media/WaVideoEngine.js +275 -0
  79. package/src/voip/media/audio-codec.js +0 -0
  80. package/src/voip/media/audio-reorder.js +107 -0
  81. package/src/voip/media/h264.js +246 -0
  82. package/src/voip/media/mlow-codec.js +465 -0
  83. package/src/voip/media/rtcp.js +68 -0
  84. package/src/voip/media/rtp.js +242 -0
  85. package/src/voip/protobuf.js +30 -0
  86. package/src/voip/relay/WaManualRelay.js +609 -0
  87. package/src/voip/relay/datachannel/pre-negotiated.js +25 -0
  88. package/src/voip/relay/dtls/aead.js +46 -0
  89. package/src/voip/relay/dtls/cert-builder.js +102 -0
  90. package/src/voip/relay/dtls/der.js +98 -0
  91. package/src/voip/relay/dtls/ecdhe.js +37 -0
  92. package/src/voip/relay/dtls/handshake-framing.js +100 -0
  93. package/src/voip/relay/dtls/handshake-messages.js +158 -0
  94. package/src/voip/relay/dtls/handshake.js +582 -0
  95. package/src/voip/relay/dtls/prf.js +39 -0
  96. package/src/voip/relay/dtls/record.js +56 -0
  97. package/src/voip/relay/relay-ack.js +141 -0
  98. package/src/voip/relay/sctp/association.js +434 -0
  99. package/src/voip/relay/sctp/crc32c.js +21 -0
  100. package/src/voip/relay/sctp/wire.js +226 -0
  101. package/src/voip/relay/stun.js +463 -0
  102. package/src/voip/shim/baileys-resolve.js +7 -0
  103. package/src/voip/shim/core.js +66 -0
  104. package/src/voip/shim/crypto.js +6 -0
  105. package/src/voip/shim/proto.js +10 -0
  106. package/src/voip/shim/protocol.js +130 -0
  107. package/src/voip/shim/transport.js +82 -0
  108. package/src/voip/shim/util.js +207 -0
  109. package/src/voip/signaling/bridge.js +102 -0
  110. package/src/voip/signaling/screen-share.js +60 -0
  111. package/src/voip/signaling/signaling.js +491 -0
  112. package/src/voip/types.js +69 -0
  113. package/src/voip/voip-deps.js +243 -0
  114. package/src/voip/voipClient.js +314 -0
  115. package/src/wam/wam-constants.js +0 -1
  116. package/src/wam/wam.js +2 -7
package/README.md CHANGED
@@ -1,25 +1,673 @@
1
1
  <div align=center><img src="https://files.catbox.moe/bzw1x3.png"/></div>
2
2
 
3
3
  <p align="center">
4
- <a href="https://www.npmjs.com/package/@hiroosy/baileys-lite"><img height="25" alt="npm version" src="https://img.shields.io/npm/v/@hiroosy/baileys?color=CB3837&style=for-the-badge&logo=npm" /></a>
5
- <a href="https://www.npmjs.com/package/@hiroosy/baileys-lite"><img height="25" alt="npm package size" src="https://img.shields.io/npm/unpacked-size/@hiroosy/baileys?label=size&color=2F855A&style=for-the-badge&logo=npm" /></a>
6
- <img height="25" alt="node version" src="https://img.shields.io/badge/NodeJS_22+-000000.svg?&style=for-the-badge&logo=node.js&logoColor=green" />
4
+ <a href="https://www.npmjs.com/package/@hiroosy/baileys-lite"><img height="25" alt="npm version" src="https://img.shields.io/npm/v/@hiroosy/baileys-lite?color=CB3837&style=for-the-badge&logo=npm" /></a>
5
+ <a href="https://www.npmjs.com/package/@hiroosy/baileys-lite"><img height="25" alt="npm package size" src="https://img.shields.io/npm/unpacked-size/@hiroosy/baileys-lite?label=size&color=2F855A&style=for-the-badge&logo=npm" /></a>
6
+ <img height="25" alt="node version" src="https://img.shields.io/badge/NodeJS_>=18-000000.svg?&style=for-the-badge&logo=node.js&logoColor=green" />
7
7
  </p>
8
8
 
9
- A lightweight, dependency-free recode of [Baileys](https://github.com/WhiskeySockets/Baileys) — the
10
- WhatsApp Web API library. Same public API and event model as upstream Baileys, rebuilt on Node.js
11
- built-ins instead of third-party packages.
9
+ **High-Performance Javascript Baileys**, built for high-scalability workloads, multi-session operation, and full user configurability.
12
10
 
13
- ## Requirements
11
+ - [x] Support LID/PN/Username.
12
+ - [x] High performance for multi sessions.
13
+ - [x] Zero dependency.
14
+ - [x] Low memory & CPU consumption.
15
+ - [x] Calls: Video & Audio.
14
16
 
15
- - Node.js **22 or newer** (the library uses the native global `WebSocket` and other modern built-ins).
16
- - FFMPEG
17
+ ---
17
18
 
18
19
  ## Install
19
20
 
21
+ Needs **Node.js 18+** and FFmpeg. Calls also need `ffprobe` in `PATH`. No native or WebRTC dependencies are required.
22
+
20
23
  ```bash
21
- npm install @hiroosy/baileys
24
+ npm install @hiroosy/baileys-lite
25
+ ```
26
+
27
+ ## Quick Start
28
+
29
+ ```javascript
30
+ import makeWASocket, {
31
+ useMultiFileAuthState,
32
+ DisconnectReason,
33
+ extractMessageContent
34
+ } from '@hiroosy/baileys-lite'
35
+
36
+ const PHONE_NUMBER = '' // '628123456789' = pairing code
37
+ const PAIR_CODE = '' // optional custom 8-char code
38
+
39
+ const start = async () => {
40
+ const { state, saveCreds } = await useMultiFileAuthState('./session')
41
+
42
+ const sock = makeWASocket({
43
+ auth: state,
44
+ printQRInTerminal: !PHONE_NUMBER,
45
+ syncFullHistory: false
46
+ })
47
+
48
+ sock.ev.on('creds.update', saveCreds)
49
+
50
+ let pairingRequested = false
51
+ sock.ev.on('connection.update', async ({ connection, lastDisconnect, qr }) => {
52
+ if (qr && PHONE_NUMBER && !pairingRequested) {
53
+ pairingRequested = true
54
+ try {
55
+ console.log('Pairing code:', await sock.requestPairingCode(PHONE_NUMBER, PAIR_CODE || undefined))
56
+ } catch (err) {
57
+ console.error('Could not request a pairing code:', err.message)
58
+ }
59
+ }
60
+
61
+ if (connection === 'open') console.log('Connected as', sock.user?.id)
62
+
63
+ if (connection === 'close') {
64
+ const code = lastDisconnect?.error?.output?.statusCode
65
+ if (code === DisconnectReason.loggedOut) {
66
+ return console.log('Logged out. Delete ./session and run again to link a new device.')
67
+ }
68
+ if (code === DisconnectReason.connectionReplaced) {
69
+ return console.log('This session was opened somewhere else. Not reconnecting.')
70
+ }
71
+ console.log(`Connection closed (${code}), reconnecting...`)
72
+ setTimeout(start, 1000)
73
+ }
74
+ })
75
+
76
+ sock.ev.on('messages.upsert', async ({ messages, type }) => {
77
+ if (type !== 'notify') return
78
+ for (const m of messages) {
79
+ if (m.key.fromMe || !m.message) continue
80
+ const content = extractMessageContent(m.message)
81
+ const text = content?.conversation || content?.extendedTextMessage?.text
82
+ if (text === '!ping') {
83
+ await sock.sendMessage(m.key.remoteJid, { text: 'pong' }, { quoted: m }).catch(console.error)
84
+ }
85
+ }
86
+ })
87
+ }
88
+
89
+ start()
90
+ ```
91
+
92
+ - **QR:** leave `PHONE_NUMBER` empty and scan it from *Linked devices* → *Link a device*.
93
+ - **Pairing code:** set `PHONE_NUMBER`, choose *Link with phone number instead*, type the code.
94
+ - **Custom pairing code:** set `PAIR_CODE` to any 8 characters. Empty gives a random one.
95
+
96
+ Send `!ping` from another number and the bot answers `pong`. The login is saved in `./session`, so keep it private and out of git.
97
+
98
+ <details> <summary>Common options</summary>
99
+
100
+ | Option | Default | Notes |
101
+ |---|---|---|
102
+ | `auth` | – | Required. `state` from an auth helper. |
103
+ | `browser` | `Browsers.macOS('Chrome')` | Device name in *Linked devices*. Also `Browsers.ubuntu()`, `.windows()`, `.appropriate()`. |
104
+ | `printQRInTerminal` | `false` | Print every QR in the terminal. `qr` is always emitted in `connection.update`. |
105
+ | `qrTimeout` | `60000`, then `20000` | How long each QR stays valid. |
106
+ | `syncFullHistory` | `true` | `false` is lighter for bots. |
107
+ | `markOnlineOnConnect` | `true` | `false` keeps notifications on your phone. |
108
+ | `connectTimeoutMs` | `20000` | Timeout of the opening handshake. |
109
+ | `keepAliveIntervalMs` | `30000` | Ping interval. |
110
+ | `defaultQueryTimeoutMs` | `60000` | Timeout of a server request. |
111
+ | `getMessage` | returns `undefined` | Return the stored message for a key so retries and poll votes can be decrypted. |
112
+ | `disableStickyRouting` | `false` | `true` stops sending `ED` in the URL and the `sticky_routing` cookie. |
113
+ | `waWebSocketUrl` | `wss://web.whatsapp.com/ws/chat` | Custom endpoint only. |
114
+ | `logger` | built-in | A pino-style logger. |
115
+
116
+ </details>
117
+
118
+ <details> <summary>Session Type Choices </summary>
119
+
120
+ All helpers return `{ state, saveCreds }`, so they are interchangeable.
121
+
122
+ ```javascript
123
+ import { useMultiFileAuthState, useSingleFileAuthState, useSqliteAuthState } from '@hiroosy/baileys-lite'
124
+
125
+ const a = await useMultiFileAuthState('./session') // one file per key
126
+ const b = await useSingleFileAuthState('./session.json') // one file, flushed in batches
127
+ const c = await useSqliteAuthState({ dbPath: './session.db' }) // native SQL store, best for many sessions
128
+ ```
129
+
130
+ </details>
131
+
132
+ <details> <summary>Disconnect Status</summary>
133
+
134
+ `lastDisconnect.error.output.statusCode` matches `DisconnectReason`:
135
+
136
+ | Code | `DisconnectReason` | Meaning |
137
+ |---|---|---|
138
+ | `401` | `loggedOut` | Device removed or session invalid. Delete the session and link again. |
139
+ | `440` | `connectionReplaced` | Opened somewhere else. Do not reconnect. |
140
+ | `515` | `restartRequired` | Normal after pairing. Reconnect. |
141
+ | `428` / `408` | `connectionClosed` / `connectionLost` / `timedOut` | Network drop. Reconnect. |
142
+ | `500` | `badSession` | Server rejected the stream. Reconnect. |
143
+
144
+ When the server closes the socket, `lastDisconnect.error.data` has `wsCode` and `wsReason`.
145
+
146
+ </details>
147
+
148
+ ---
149
+
150
+ ## SendMessage
151
+
152
+ <details> <summary>Basic</summary>
153
+
154
+ ```javascript
155
+ await sock.sendMessage(jid, { text: 'Hello there!' })
156
+
157
+ await sock.sendMessage(jid, { text: 'Hi @6281234567890', mentions: ['6281234567890@s.whatsapp.net'] }, {
158
+ quoted: m,
159
+ ephemeralExpiration: 86400
160
+ })
161
+
162
+ await sock.sendMessage(jid, { react: { text: '👍', key: m.key } })
163
+
164
+ await sock.sendMessage(jid, {
165
+ contacts: { contacts: [{ displayName: 'HirooSy', vcard: 'BEGIN:VCARD\nVERSION:3.0\nFN:HirooSy\nTEL;type=CELL:+6281234567890\nEND:VCARD' }] }
166
+ })
167
+ ```
168
+
169
+ </details>
170
+
171
+ <details> <summary>Media</summary>
172
+
173
+ ```javascript
174
+ await sock.sendMessage(jid, { image: { url: './photo.jpg' }, caption: 'Nice view' })
175
+ await sock.sendMessage(jid, { video: { url: './clip.mp4' }, caption: 'Clip', gifPlayback: false })
176
+ await sock.sendMessage(jid, { audio: { url: './voice.ogg' }, ptt: true })
177
+ await sock.sendMessage(jid, { document: { url: './file.pdf' }, mimetype: 'application/pdf', fileName: 'file.pdf' })
178
+ await sock.sendMessage(jid, { sticker: { url: './sticker.webp' } })
179
+
180
+ // viewOnce (image/video/audio), video note, spoiler
181
+ await sock.sendMessage(jid, { image: { url: './photo.jpg' }, viewOnce: true })
182
+ await sock.sendMessage(jid, { video: { url: './clip.mp4' }, ptv: true })
183
+ await sock.sendMessage(jid, { image: { url: './surprise.jpg' }, caption: 'Peekaboo', spoiler: true })
184
+
185
+ // album
186
+ await sock.sendMessage(jid, {
187
+ album: [
188
+ { image: { url: './1.jpg' } },
189
+ { image: { url: './2.jpg' } },
190
+ { video: { url: './clip.mp4' } }
191
+ ]
192
+ })
193
+ ```
194
+
195
+ </details>
196
+
197
+ <details> <summary>Location</summary>
198
+
199
+ ```javascript
200
+ await sock.sendMessage(jid, { location: { degreesLatitude: -6.2088, degreesLongitude: 106.8456, name: 'Monas' } })
201
+ ```
202
+
203
+ </details>
204
+
205
+ <details> <summary>Product</summary>
206
+
207
+ ```javascript
208
+ await sock.sendMessage(jid, {
209
+ businessOwnerJid: '1234567890@s.whatsapp.net',
210
+ image: { url: './mouse.png' },
211
+ product: {
212
+ title: 'Wireless Mouse',
213
+ description: 'Ergonomic, 2.4GHz',
214
+ currencyCode: 'USD',
215
+ priceAmount1000: 19990, // $19.99
216
+ retailerId: 'sku-001'
217
+ }
218
+ })
219
+ ```
220
+
221
+ </details>
222
+
223
+ <details> <summary>Carousel</summary>
224
+
225
+ ```javascript
226
+ // card header: image, video or product only
227
+ await sock.sendMessage(jid, {
228
+ text: 'Check out our new arrivals:',
229
+ footer: 'HirooSy',
230
+ cards: [
231
+ { image: { url: './item-a.jpg' }, title: 'Item A', caption: 'New in stock', nativeFlow: [{ text: 'View', id: 'view_a' }] },
232
+ { video: { url: './item-b.mp4' }, title: 'Item B', caption: 'Limited edition', nativeFlow: [{ text: 'View', id: 'view_b' }] },
233
+ {
234
+ businessOwnerJid: '1234567890@s.whatsapp.net',
235
+ product: { title: 'Wireless Mouse', productImage: { url: './mouse.png' } },
236
+ title: 'Wireless Mouse',
237
+ caption: '$19.99',
238
+ nativeFlow: [{ text: 'Buy Now', id: 'buy_mouse' }]
239
+ }
240
+ ]
241
+ })
242
+ ```
243
+
244
+ </details>
245
+
246
+ <details> <summary>NativeFlow Button</summary>
247
+
248
+ ```javascript
249
+ await sock.sendMessage(jid, {
250
+ text: 'Choose one:',
251
+ footer: 'HirooSy',
252
+ nativeFlow: [
253
+ { text: '👋🏻 Yes', id: 'yes_1' },
254
+ { text: '📞 Call', call: '628123456789' },
255
+ { text: '📋 Copy', copy: 'PROMO123' },
256
+ { text: '🌐 Source', url: 'https://example.com' },
257
+ {
258
+ text: '📋 Select',
259
+ sections: [{ title: '✨ Section 1', rows: [{ title: '🏷️ Coupon', id: 'coupon_code' }] }]
260
+ }
261
+ ]
262
+ })
263
+
264
+ // media header: use caption instead of text (image, video, document, location, product)
265
+ await sock.sendMessage(jid, {
266
+ image: { url: './promo.jpg' },
267
+ title: 'Flash Sale',
268
+ caption: 'Up to 50% off today only',
269
+ footer: 'HirooSy',
270
+ nativeFlow: [
271
+ { text: 'Shop Now', url: 'https://shop.example.com' },
272
+ { text: 'Copy Code', copy: 'SALE50' }
273
+ ]
274
+ })
275
+
276
+ // widget (A2UI): can be combined with buttons, or use nativeFlow: [] for none
277
+ await sock.sendMessage(jid, {
278
+ text: 'Widget demo',
279
+ footer: 'A2UI Showcase',
280
+ nativeFlow: [{ text: '🌐 Source', url: 'https://example.com' }],
281
+ widget: {
282
+ align: 'center',
283
+ fallback: 'Widget cannot be loaded on this device', // optional
284
+ items: [
285
+ { text: 'Welcome to the Widget Demo', variant: 'title' }, // title | body | caption
286
+ { text: 'This is a longer description.', variant: 'body' },
287
+
288
+ { icon: 'info' },
289
+ { icon: 'warning', style: 'symbol' },
290
+ { icon: 'favorite', native: true },
291
+
292
+ { image: 'https://example.com/banner.jpg', variant: 'header', fit: 'cover', description: 'Promo banner' },
293
+ { video: 'https://example.com/preview.mp4' },
294
+ { audio: 'https://example.com/audio.mp3', description: 'Listen to this audio' },
295
+
296
+ { divider: 'horizontal' }, // or 'vertical'
297
+ { button: 'Open Website', url: 'https://example.com', variant: 'primary' },
298
+
299
+ { input: 'name', label: 'Enter your name', value: '', variant: 'shortText' }, // or 'longText'
300
+ { input: 'email', label: 'Email', validationRegexp: '^[^@]+@[^@]+\\.[^@]+$' },
301
+ { checkbox: 'I agree to the terms & conditions', value: false },
302
+ { choice: ['Red', 'Green', 'Blue'], label: 'Favorite color', variant: 'mutuallyExclusive', displayStyle: 'chips', filterable: true },
303
+ { choice: [{ label: 'Option A', value: 'a' }, { label: 'Option B', value: 'b' }], label: 'Multi-select', variant: 'multipleSelection', value: ['a'] },
304
+ { slider: 100, min: 0, value: 50, label: 'Volume' }, // slider = max value
305
+ { datetime: true, label: 'Pick a date', enableDate: true, enableTime: false },
306
+
307
+ { row: [{ text: 'Left' }, { text: 'Center' }, { text: 'Right' }], justify: 'space-between', align: 'center' },
308
+ { column: [{ text: 'Row 1' }, { text: 'Row 2' }], justify: 'start', align: 'stretch' },
309
+ { list: [{ text: '• First item' }, { text: '• Second item' }], direction: 'vertical' }
310
+ ]
311
+ }
312
+ })
313
+ ```
314
+
315
+ </details>
316
+
317
+ <details> <summary>Legacy Button</summary>
318
+
319
+ ```javascript
320
+ // old format, prefer nativeFlow
321
+ await sock.sendMessage(jid, {
322
+ text: 'Choose one:',
323
+ footer: 'HirooSy',
324
+ templateButtons: [
325
+ { text: 'Reply', id: 'r1' },
326
+ { text: 'Visit', url: 'https://example.com' },
327
+ { text: 'Call', call: '+6281234567890' }
328
+ ]
329
+ })
330
+ ```
331
+
332
+ </details>
333
+
334
+ <details> <summary>Button/List Replies</summary>
335
+
336
+ ```javascript
337
+ // send a reply as if a user tapped a button
338
+ await sock.sendMessage(jid, { buttonReply: { id: 'yes_1', displayText: 'Yes' }, type: 'plain' })
339
+ await sock.sendMessage(jid, { listReply: { id: 'row1', title: 'Row 1', description: 'desc' } })
340
+ await sock.sendMessage(jid, { flowReply: { name: 'single_select', paramsJson: JSON.stringify({ id: 'row1' }) } })
341
+ ```
342
+
343
+ </details>
344
+
345
+ <details> <summary>Poll</summary>
346
+
347
+ ```javascript
348
+ await sock.sendMessage(jid, {
349
+ poll: { name: 'Favorite language?', values: ['JavaScript', 'Python', 'Rust'], selectableCount: 1 }
350
+ })
351
+
352
+ // quiz polls: newsletter only, need correctAnswer
353
+ await sock.sendMessage(newsletterJid, {
354
+ poll: { name: 'Capital of Japan?', values: ['Tokyo', 'Osaka'], pollType: 1, correctAnswer: 'Tokyo' }
355
+ })
356
+
357
+ // final tally of a poll you created
358
+ await sock.sendMessage(jid, {
359
+ pollResult: { name: 'Favorite language?', votes: [{ name: 'JavaScript', voteCount: 12 }, { name: 'Python', voteCount: 9 }] }
360
+ })
361
+ ```
362
+
363
+ </details>
364
+
365
+ <details> <summary>AI Rich</summary>
366
+
367
+ ```javascript
368
+ await sock.aiRich()
369
+ .setTitle('Ai Rich Message')
370
+ .addText('[HyperLink](https://example.com)\nCitation [](https://example.com)')
371
+ .addImage('https://example.com/image.png')
372
+ .addCode('javascript', `console.log('Hello World')`)
373
+ .addHtml(['<html>Hello world</html>', 'Tab 1'], ['<html>Hi twin</html>', 'Tab 2'])
374
+ .addTable([
375
+ ['Name', 'HirooSy'],
376
+ ['Bio', 'Im developer'],
377
+ ['Age', '67']
378
+ ])
379
+ .addSource([['https://example.com/favicon.ico', 'https://example.com', 'Source']])
380
+ .addTip('Tip Text')
381
+ .addSuggest(['Continue', 'Cancel'])
382
+ .send(jid, { quoted: m })
383
+
384
+ // animated progress
385
+ await sock.aiRich()
386
+ .addProcess('Loading...')
387
+ .send(jid)
388
+
389
+ // shorthand without the builder
390
+ await sock.sendMessage(jid, {
391
+ aiRich: { title: 'Assistant', text: 'Here is what I found:', table: [['Name', 'Score'], ['Alice', '90']] }
392
+ })
393
+ ```
394
+
395
+ **Bypass download:** `send()` edits its own message right after sending, so the client renders the rich response without having to download it first. It only runs for messages that carry a rich response. If the edit fails, the error is thrown with `error.relayedKey` set to the key of the message that was already sent.
396
+
397
+ <details> <summary align=center>All AiRich Methods</summary>
398
+
399
+ | Method | Purpose |
400
+ | --- | --- |
401
+ | `setTitle(title)` | Disclaimer label shown on the message |
402
+ | `setFooter(footer)` | Trailing metadata text block |
403
+ | `setContextInfo(obj)` | Merges extra fields into `contextInfo` |
404
+ | `addText(text, opts?)` | Markdown text. Extracts `[text](url)` links, `[](url)` citations, `[text\|w\|h](<url>)` LaTeX |
405
+ | `addCode(language, code)` | Syntax-highlighted code block |
406
+ | `addTable(rows, opts?)` | `[[header...], [row...], ...]` array of strings |
407
+ | `addImage(image)` | `string \| Buffer \| array`, shown as a grid |
408
+ | `addVideo(video)` | `string \| Buffer \| { url, mimeType?, duration? } \| array` |
409
+ | `addSource(sources)` | `[icon, url, text][]` source cards |
410
+ | `addProduct(data)` | Product card, or an array for a carousel |
411
+ | `addPost(data)` | Social-post card, or an array for a carousel |
412
+ | `addReels(data)` | Reel card, or an array |
413
+ | `addTip(text)` | Small tip line |
414
+ | `addSuggest(suggestion, opts?)` | Follow-up suggestion pill |
415
+ | `addProcess(title)` | In-progress status indicator |
416
+ | `addHtml(...)` | One inline HTML block, or `[html, title]` tab pairs |
417
+ | `build(opts?)` | Build the raw content without sending |
418
+ | `buildEdit(jid, key, message)` | Builds the edit payload used by bypass download |
419
+ | `send(jid, opts?)` | Sends the message. `opts.bypassDownload` (default `true`) sends the follow-up edit. Other options go to `sendMessage` |
420
+
421
+ </details>
422
+
423
+ </details>
424
+
425
+ <details> <summary>Sticker</summary>
426
+
427
+ ```javascript
428
+ await sock.sendMessage(jid, { sticker: { url: './sticker.webp' } })
429
+
430
+ // sticker pack: needs sharp or @napi-rs/image, max 60, cover required
431
+ await sock.sendMessage(jid, {
432
+ stickers: [{ data: { url: './s1.webp' } }, { data: { url: './s2.webp' } }],
433
+ cover: { url: './cover.webp' },
434
+ name: 'My Sticker Pack',
435
+ publisher: 'HirooSy'
436
+ })
437
+ ```
438
+
439
+ </details>
440
+
441
+ <details> <summary>Message Actions</summary>
442
+
443
+ ```javascript
444
+ await sock.sendMessage(jid, { pin: m.key, type: 1, time: 86400 }) // type: 0 unpin, 1 pin
445
+ await sock.sendMessage(jid, { keep: m.key, type: 1 }) // type: 0 remove, 1 keep
446
+ await sock.sendMessage(jid, { text: 'Updated text', edit: m.key })
447
+ await sock.sendMessage(jid, { delete: m.key })
448
+
449
+ // group only: disappearing messages
450
+ await sock.sendMessage(groupJid, { disappearingMessagesInChat: true }) // 7 days
451
+ await sock.sendMessage(groupJid, { disappearingMessagesInChat: 86400 }) // custom seconds
452
+ await sock.sendMessage(groupJid, { disappearingMessagesInChat: false }) // off
453
+ ```
454
+
455
+ </details>
456
+
457
+ <details> <summary>Event</summary>
458
+
459
+ ```javascript
460
+ await sock.sendMessage(jid, {
461
+ event: { name: 'Team Sync', description: 'Discuss the Q1 roadmap', startDate: new Date(Date.now() + 3600_000) }
462
+ })
22
463
  ```
23
464
 
24
- > [!IMPORTANT]
25
- > This library is **ESM-only** (`"type": "module"`). Use `import`, not `require`.
465
+ </details>
466
+
467
+ <details> <summary>Payments & Business</summary>
468
+
469
+ ```javascript
470
+ await sock.sendMessage(jid, { requestPaymentFrom: recipientJid, text: 'Payment for order #123' })
471
+ await sock.sendMessage(jid, { paymentInviteServiceType: 1 })
472
+ await sock.sendMessage(jid, { orderText: 'Your order summary', thumbnail: fs.readFileSync('./order-thumb.jpg') })
473
+ await sock.sendMessage(jid, { document: { url: './invoice.pdf' }, mimetype: 'application/pdf', invoiceNote: 'Invoice #1024' })
474
+
475
+ // sponsored ad card on any message
476
+ await sock.sendMessage(jid, {
477
+ text: 'Check this deal!',
478
+ externalAdReply: { title: 'Big Sale', body: '50% off', thumbnail: fs.readFileSync('./thumb.jpg'), mediaType: 1, url: 'https://example.com' }
479
+ })
480
+
481
+ await sock.sendMessage(jid, { requestPhoneNumber: true })
482
+ await sock.sendMessage(jid, { sharePhoneNumber: true })
483
+
484
+ await sock.sendMessage(jid, {
485
+ groupInvite: { jid: groupJid, inviteCode: code, inviteExpiration: Date.now() + 3600_000, subject: 'My Group', text: 'Join us!' }
486
+ })
487
+
488
+ // disable forwarding
489
+ await sock.sendMessage(jid, { limitSharing: true })
490
+ ```
491
+
492
+ </details>
493
+
494
+ <details> <summary>Status</summary>
495
+
496
+ ```javascript
497
+ // jid can be an array to choose who sees the status
498
+ await sock.sendMessage([contactJid1, contactJid2], { text: 'Status update text' })
499
+ ```
500
+
501
+ </details>
502
+
503
+ ---
504
+
505
+ ## Call
506
+
507
+ Calls need `ffmpeg` and `ffprobe` in `PATH`. Create one `Voip` per socket once it is open. After a reconnect there is a new socket, so create a new `Voip`.
508
+
509
+ <details> <summary>Quick start</summary>
510
+
511
+ ```javascript
512
+ import Voip from '@hiroosy/baileys-lite/voip'
513
+
514
+ const voip = new Voip(sock, {
515
+ ffprobePath: 'ffprobe',
516
+ voipLogLevel: 'warn', // trace | debug | info | warn | error
517
+ tmpDir: './tmp', // temp folder for downloads
518
+ maxConcurrentCalls: 1 // see Multi Call
519
+ })
520
+
521
+ const call = await voip.call('628123456789', './song.mp3')
522
+
523
+ await call.hangup() // or call.end()
524
+
525
+ // ring only, no media
526
+ await voip.call('628123456789')
527
+ ```
528
+
529
+ </details>
530
+
531
+ <details> <summary>Media & Playlist</summary>
532
+
533
+ ```javascript
534
+ await voip.call(jid, './song.mp3') // local file
535
+ await voip.call(jid, 'https://example.com/song.mp3') // url, downloaded first (audio max 20MB, video max 50MB)
536
+ await voip.call(jid, { audio: './voice.ogg' })
537
+ await voip.call(jid, './clip.mp4', '720p') // video call
538
+
539
+ // audio: mp3 ogg opus wav m4a aac flac weba
540
+ // video: mp4 mov webm mkv avi m4v 3gp
541
+
542
+ // resolution (third argument): '240p' | '360p' | '480p' | '720p' | '1080p'
543
+ // or { width, height, frameRate }. Default is 480p, portrait sources are rotated automatically.
544
+
545
+ // playlist, items play in order and can mix audio and video
546
+ const list = await voip.call(
547
+ jid,
548
+ ['./intro.mp3', './clip.mp4', 'https://example.com/outro.mp3'],
549
+ '480p',
550
+ {
551
+ loop: false, // repeat the playlist
552
+ autoEndCall: true, // hang up when the playlist ends
553
+ autoDowngrade: true // drop to audio when the peer turns every camera off
554
+ }
555
+ )
556
+ ```
557
+
558
+ `jid` can be a number or a jid, non-digits are removed.
559
+
560
+ </details>
561
+
562
+ <details> <summary>Controls</summary>
563
+
564
+ ```javascript
565
+ await call.silent(true) // silence audio
566
+ await call.silent(false) // resume
567
+ await call.silent() // toggle
568
+ console.log(call.isSilenced)
569
+
570
+ call.mute(true) // mic only
571
+ call.raiseHand(true)
572
+ call.react('👍') // false if not connected yet
573
+ await call.shareScreen(true) // needs video, 1:1 only
574
+ await call.shareScreen(false)
575
+
576
+ const result = await call.upgradeToVideo()
577
+ // 'accepted' | 'rejected' | 'rejected_by_timeout' | 'error' | 'timeout' | 'cancelled'
578
+ ```
579
+
580
+ `shareScreen` only tells the peer a screen is shared. The picture is whatever you feed to `voip.coordinator.feedLiveVideo()`.
581
+
582
+ </details>
583
+
584
+ <details> <summary>Events</summary>
585
+
586
+ ```javascript
587
+ call.on('ringing', () => {})
588
+ call.on('connected', () => {})
589
+ call.on('ended', reason => {}) // 'connection_closed' if the socket drops
590
+ call.on('error', err => {})
591
+
592
+ call.on('item', ({ index, kind, source }) => {})
593
+ call.on('playlist_looped', () => {})
594
+ call.on('playlist_ended', () => {})
595
+ call.on('downgraded', () => {}) // video dropped to audio
596
+ call.on('silent', state => {})
597
+
598
+ call.on('peer_mute', muted => {})
599
+ call.on('hand_raise', ({ jid, raised }) => {})
600
+ call.on('reaction', reaction => {})
601
+ call.on('screen_share', share => {})
602
+ call.on('peer_video', change => {})
603
+ call.on('inbound_audio', pcm => {}) // Float32Array, 16 kHz mono, 60 ms
604
+ call.on('inbound_video', frame => {}) // decoded H.264 frame
605
+ call.on('audio_finished', () => {}) // current audio item reached its end
606
+ ```
607
+
608
+ </details>
609
+
610
+ <details> <summary>Incoming Calls</summary>
611
+
612
+ ```javascript
613
+ await voip.listen() // register the call handlers, safe to call twice
614
+
615
+ voip.on('call_incoming', async call => {
616
+ console.log('incoming from', call.peerJid, call.callId)
617
+ await voip.acceptCall(call.callId)
618
+ })
619
+
620
+ voip.on('call_inbound_audio', ({ call, pcm }) => {})
621
+ voip.on('call_ended', call => console.log('ended', call.callId))
622
+
623
+ await voip.rejectCall(callId)
624
+ await voip.hangup(callId)
625
+
626
+ // events: call_incoming, call_state, call_ended, call_peer_mute, call_inbound_audio,
627
+ // call_inbound_video, call_hand_raise, call_reaction, call_screen_share,
628
+ // call_peer_video_state, call_outbound_audio_finished, call_error
629
+ ```
630
+
631
+ `voip.coordinator` is the raw engine (`feedLiveAudio`, `feedLiveVideo`, `setExternalAudioMode`, ...).
632
+
633
+ </details>
634
+
635
+ <details> <summary>Multi Call</summary>
636
+
637
+ ```javascript
638
+ const voip = new Voip(sock, { maxConcurrentCalls: 3 })
639
+
640
+ // one by one
641
+ const a = await voip.call('628111111111', './song.mp3')
642
+ const b = await voip.call('628222222222', './song.mp3')
643
+
644
+ // many numbers at once
645
+ const results = await voip.callMany(
646
+ ['628111111111', '628222222222', '628333333333'],
647
+ './song.mp3'
648
+ )
649
+
650
+ for (const { jid, call, error } of results) {
651
+ if (error) {
652
+ console.log(jid, 'failed:', error.message)
653
+ continue
654
+ }
655
+ call.on('ended', reason => console.log(jid, 'ended:', reason))
656
+ call.on('error', err => console.error(jid, err))
657
+ }
658
+
659
+ voip.calls // active calls
660
+ voip.calls[0].callId
661
+ voip.calls[0].target // dialed number
662
+ await voip.hangup(callId) // end one call
663
+ await voip.end() // end all calls
664
+ await voip.end(true) // only release the slots
665
+ ```
666
+
667
+ - `maxConcurrentCalls` defaults to `1`. Each call gets its own relay, codec and audio.
668
+ - Incoming calls count toward the limit too.
669
+ - A call over the limit throws `Maximum concurrent calls reached`. In `callMany()` it is returned as `error` for that number and the rest still go through.
670
+ - `callMany()` takes the same media and options as `call()` and calls duplicate numbers once.
671
+ - A safety timeout emits `error` if a call never ends (starts at 105s).
672
+
673
+ </details>