@qadeer-xtech/stablebail 1.1.3 → 1.2.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.
package/README.md CHANGED
@@ -1,524 +1,348 @@
1
- @qadeer-xtech/stablebail
1
+ <div align="center">
2
2
 
3
- <p align="center">
4
- **STABLEBAIL — POWERED BY TEAM QADEER**
5
- </p>
3
+ # @qadeer-xtech/stablebail
6
4
 
7
- A powerful WhatsApp Web API library built on the Baileys architecture, enhanced with custom fixes, improved media handling, advanced newsletter support, and additional WhatsApp features.
5
+ **A stable, fixed WhatsApp Web API for Node.js — with interactive buttons, lists and carousels built right into `sendMessage`.**
8
6
 
9
- Based on **@whiskeysockets/baileys 7.0.0-rc14** (MIT). Source, issues and changelog: https://github.com/Qadeer-Xtech/stablebail
7
+ [![npm](https://img.shields.io/npm/v/@qadeer-xtech/stablebail?style=flat-square&color=black&label=npm)](https://npmjs.com/package/@qadeer-xtech/stablebail)
8
+ [![version](https://img.shields.io/badge/version-v1.1.3-black?style=flat-square)](https://npmjs.com/package/@qadeer-xtech/stablebail)
9
+ [![downloads](https://img.shields.io/npm/dm/@qadeer-xtech/stablebail?style=flat-square&color=black)](https://npmjs.com/package/@qadeer-xtech/stablebail)
10
+ [![node](https://img.shields.io/badge/node-%E2%89%A518-black?style=flat-square&logo=node.js)](https://nodejs.org)
11
+ [![license](https://img.shields.io/badge/license-MIT-black?style=flat-square)](https://opensource.org/licenses/MIT)
10
12
 
11
- [![CI](https://github.com/Qadeer-Xtech/stablebail/actions/workflows/ci.yml/badge.svg)](https://github.com/Qadeer-Xtech/stablebail/actions/workflows/ci.yml)
13
+ [Install](#-install) · [Quick Start](#-quick-start) · [Messages](#-messages) · [Interactive](#-interactive-messages) · [Themes](#-chat-themes) · [Newsletter](#-newsletter--channels) · [Disconnect reasons](#-disconnect-reasons) · [Credits](#-credits)
12
14
 
13
- ## Browser identity setup (in your `index.js`)
15
+ </div>
14
16
 
15
- The `browser` option in `makeWASocket` decides how your bot appears to
16
- WhatsApp. It changes what WhatsApp sends your bot, so pick carefully —
17
- nothing else in your bot code changes, and your existing session keeps
18
- working; the identity simply applies on the next connect.
17
+ ---
19
18
 
20
- **1. Ubuntu / web identity** — the bot looks like a browser on Ubuntu.
19
+ ## ✨ Highlights
21
20
 
22
- ```js
23
- browser: Browsers.ubuntu('Chrome')
24
- ```
25
-
26
- - **Who it is for:** simple bots — commands, groups, chats — that do
27
- not need phone-class media.
28
- - **How it behaves:** pairing works the normal way and channel
29
- (newsletter) data arrives as plain JSON. But WhatsApp treats
30
- browsers as web companions: **view-once photos/videos can arrive as
31
- empty stubs** with no media inside. If your bot needs view-once,
32
- use setup 2 or 3.
33
-
34
- **2. Android phone identity** — the bot presents itself as an Android
35
- phone.
36
-
37
- ```js
38
- browser: Browsers.androidPhone('Chrome')
39
- ```
40
-
41
- - **Who it is for:** bots that need full media, above all view-once.
42
- - **What changes in the bot after this setup:** WhatsApp treats the
43
- bot as a phone-class device, so **view-once media actually arrives**
44
- instead of empty stubs. One side effect: on Android sessions,
45
- channel data can arrive in a compact **binary format** instead of
46
- JSON — StableBail decodes that format fully, so your channel
47
- features (name, followers, description, picture) keep working.
21
+ | | |
22
+ |---|---|
23
+ | 🛡️ **Stable base** | Faithful Baileys **7.0.0-rc14** core — same API you already know, plus reviewed fixes upstream has not released yet |
24
+ | 🎛️ **Interactive built-in** | Buttons, lists and carousels with plain `sendMessage` — **no** `relayMessage` hacks, no extra helper library |
25
+ | 🔧 **Real fixes** | Media re-upload on 403/404/410, pairing-code 515 failures, stream drops, retry double-encryption — all fixed |
26
+ | 💾 **Safe sessions** | Atomic `creds.json` writes — a crash mid-write can no longer corrupt your login |
27
+ | 📢 **Newsletters** | Channel media paths fixed — posts and media show up the way they should |
28
+ | 👁️ **View once** | Works out of the box, including on Android companion devices |
29
+ | 🔢 **Custom pairing codes** | Link with your own 8-character code (e.g. `TEAMQD11`) |
48
30
 
49
- **3. Dynamic identity (recommended)** — pair easily, run as Android.
50
-
51
- ```js
52
- const getBrowserIdentity = (registered) =>
53
- registered ? Browsers.androidPhone('Chrome') : Browsers.macOS('Safari')
54
-
55
- // inside makeWASocket:
56
- browser: getBrowserIdentity(state.creds.registered)
57
- ```
58
-
59
- - **Who it is for:** most bots — this is the setup we recommend.
60
- - **How it works:** while the session is fresh (not yet registered),
61
- the Safari/Mac identity pairs the fastest and most reliably. As
62
- soon as the session is registered, the identity switches to the
63
- Android phone identity by itself on the next connect — **no
64
- re-pairing, no code change** — and the bot gets the full Android
65
- behaviour from setup 2, including view-once media.
66
-
67
- **In short:** Ubuntu = simple web bot, no view-once. Android =
68
- phone-class bot, view-once works. Dynamic = easy pairing first,
69
- Android powers after — the best of both.
70
-
71
- ## View-once — the fix, and the bot code for it
72
-
73
- **The problem:** on browser/web identities, WhatsApp delivers
74
- view-once photos and videos to companion devices as *empty stubs* —
75
- the message arrives, but there is no media inside it. No bot code can
76
- recover media that never arrived.
77
-
78
- **The fix in StableBail:** when the bot runs on the Android phone
79
- identity, StableBail presents a real Android device in the connection
80
- user-agent (device = `Android`, not `Desktop`). WhatsApp then treats
81
- the bot as a phone-class device and delivers view-once media
82
- normally — it works out of the box, nothing to configure in the
83
- library.
84
-
85
- **The code you add in your bot (`index.js`):** just run the bot on
86
- the Android identity — or use the dynamic setup so pairing stays
87
- easy and Android takes over right after:
88
-
89
- ```js
90
- const {
91
- default: makeWASocket,
92
- Browsers,
93
- useMultiFileAuthState
94
- } = require('@whiskeysockets/baileys')
95
-
96
- const getBrowserIdentity = (registered) =>
97
- registered ? Browsers.androidPhone('Chrome') : Browsers.macOS('Safari')
98
-
99
- const { state, saveCreds } = await useMultiFileAuthState('auth')
100
-
101
- const sock = makeWASocket({
102
- auth: state,
103
- browser: getBrowserIdentity(state.creds.registered)
104
- })
105
- ```
106
-
107
- That is all. Pair once (Safari identity), and from the next connect
108
- onward the bot runs as Android and view-once media arrives — your
109
- view-once commands can then download the quoted message as usual.
110
-
111
- ## Why StableBail instead of stock Baileys?
112
-
113
- Same API — StableBail is Baileys 7.0.0-rc14 plus reviewed fixes that
114
- upstream has not released yet:
115
-
116
- | Area | Stock rc14 | StableBail |
117
- |---|---|---|
118
- | Media reupload on 403/404/410 | broken | fixed (1.0.3) |
119
- | Stream drops ~50 min (status ack) | broken | fixed (1.0.7) |
120
- | Pairing code 515 failures | broken | fixed (1.0.7) |
121
- | creds.json corruption on crash | possible | atomic writes (1.0.7) |
122
- | Channel (newsletter) media | often invisible | fixed paths (1.0.2 + 1.0.7) |
123
- | Status mentions | not available | `sendStatusMention` (1.0.5) |
124
- | Retry double-encryption | present | fixed (1.0.7) |
125
- | View-once on Android companions | unavailable stubs | works out of the box (1.0.12) |
126
- | Ban / number status checker | not available | `checkStatusWA` (1.0.12) |
127
-
128
- Full per-version list: [CHANGELOG.md](CHANGELOG.md) · Plans: [ROADMAP.md](ROADMAP.md) · Runnable samples: [examples/](examples/)
129
-
130
- ## Switching from official Baileys (1 minute)
131
-
132
- Change only the dependency line — your code stays the same:
133
-
134
- ```json
135
- "@whiskeysockets/baileys": "npm:@qadeer-xtech/stablebail@latest"
136
- ```
31
+ Made by **Team Qadeer** · Package: [npmjs.com/package/@qadeer-xtech/stablebail](https://npmjs.com/package/@qadeer-xtech/stablebail) · Source: [github.com/Qadeer-Xtech/stablebail](https://github.com/Qadeer-Xtech/stablebail)
137
32
 
138
- Designed for developers who need a familiar Baileys-compatible API with extra functionality and a smoother development experience.
33
+ > **Why StableBail instead of stock Baileys?** Stock rc14 breaks in places every serious bot hits: media re-uploads fail, pairing dies on 515, streams drop, creds corrupt on crash. StableBail keeps the exact same API and fixes those — verified by a full test suite (**437/437 passing**) and by production bots running on it every day.
139
34
 
140
- ## TypeScript source
35
+ ---
141
36
 
142
- The full TypeScript source of this package is in
143
- [`src/`](src/). It is **build-verified**: compiling it with the
144
- included tsconfig reproduces the shipped `lib/` JavaScript
145
- exactly — what you read here is what runs. (The published
146
- tarball omits the build's sourcemap files, and a few type
147
- declarations were completed so the types match the shipped JS.)
37
+ ## 📥 Install
148
38
 
149
- ## 📦 Installation
39
+ Requires **Node.js 18+**.
150
40
 
151
41
  ```bash
152
42
  npm install @qadeer-xtech/stablebail
153
43
  ```
154
44
 
155
- ## Use as Official Baileys Replacement
156
-
157
- To use StableBail without changing your existing import paths, add this alias to your "package.json":
158
-
159
45
  ```json
160
46
  {
161
47
  "dependencies": {
162
- "@whiskeysockets/baileys": "npm:@qadeer-xtech/stablebail@latest"
48
+ "@qadeer-xtech/stablebail": "^1.1.3"
163
49
  }
164
50
  }
165
51
  ```
166
52
 
167
- This allows existing Baileys-based projects to use StableBail while keeping their original package imports.
168
-
169
- ## ✅ Recommended Settings for Bot Projects
53
+ ---
170
54
 
171
- For a smooth, error-free install, use these exact settings in your bot's "package.json":
172
-
173
- ```json
174
- {
175
- "dependencies": {
176
- "@whiskeysockets/baileys": "npm:@qadeer-xtech/stablebail@1.0.13",
177
- "sharp": "0.35.5",
178
- "wa-sticker-formatter": "4.4.4"
179
- },
180
- "overrides": {
181
- "sharp": "$sharp"
182
- },
183
- "engines": {
184
- "node": "20.x"
185
- }
186
- }
187
- ```
55
+ ## 🚀 Quick Start
188
56
 
189
- ## ✨ Key Features
57
+ A complete bot that links by QR or pairing code and answers `!ping`.
190
58
 
191
- - Baileys-Compatible API — Familiar socket methods and existing Baileys workflow.
192
- - Newsletter Enhancements — Improved channel messaging, media uploads, subscriptions, and metadata fetching.
193
- - Media Stream Fixes — Improved download error handling, media retries, and expired-link recovery.
194
- - Windows Hybrid Support — Updated device identification for modern WhatsApp connections.
195
- - LID Compatibility — Improved "onWhatsApp()" support for LID-based addresses.
196
- - Status Mentions — Mention contacts and groups in WhatsApp status updates.
197
- - CSToken / NCT Support — Additional token handling for LID-addressed messaging.
198
- - Connection Banner — Optional branded startup banner.
199
- - Improved Stability — Additional fixes for connection handling and media operations.
59
+ ```javascript
60
+ import makeWASocket, {
61
+ useMultiFileAuthState,
62
+ DisconnectReason
63
+ } from '@qadeer-xtech/stablebail'
200
64
 
201
- ## 🔧 What's Included
65
+ const PHONE_NUMBER = '' // e.g. '923001234567' to use a pairing code
66
+ const PAIR_CODE = '' // optional custom 8-character code
202
67
 
203
- ### 1. Newsletter / Channel Support
68
+ const start = async () => {
69
+ const { state, saveCreds } = await useMultiFileAuthState('./session')
204
70
 
205
- Extended newsletter functionality with improved message fetching, media handling, and channel metadata support.
71
+ const sock = makeWASocket({
72
+ auth: state,
73
+ printQRInTerminal: !PHONE_NUMBER,
74
+ syncFullHistory: false
75
+ })
76
+
77
+ sock.ev.on('creds.update', saveCreds)
78
+
79
+ let pairingRequested = false
80
+ sock.ev.on('connection.update', async ({ connection, lastDisconnect, qr }) => {
81
+ if (qr && PHONE_NUMBER && !pairingRequested) {
82
+ pairingRequested = true
83
+ try {
84
+ console.log('Pairing code:', await sock.requestPairingCode(PHONE_NUMBER, PAIR_CODE || undefined))
85
+ } catch (err) {
86
+ console.error('Could not request a pairing code:', err.message)
87
+ }
88
+ }
206
89
 
207
- Available methods:
90
+ if (connection === 'open') console.log('Connected as', sock.user?.id)
208
91
 
209
- | Method | Description |
210
- | --- | --- |
211
- | "newsletterFromUrl()" | Fetch channel information from an invite link |
212
- | "newsletterSubscribed()" | Get subscribed channels |
213
- | "newsletterFetchAllSubscribe()" | Fetch all subscribed channels |
214
- | "newsletterFetchMessages()" | Retrieve channel messages |
215
- | "newsletterFetchUpdates()" | Fetch views and reactions |
216
- | "newsletterReactionMode()" | Change channel reaction settings |
217
- | "newsletterFollow()" | Follow a channel |
218
- | "newsletterUnfollow()" | Unfollow a channel |
219
- | "newsletterReactMessage()" | React to channel messages |
92
+ if (connection === 'close') {
93
+ const code = lastDisconnect?.error?.output?.statusCode
94
+ if (code === DisconnectReason.loggedOut) {
95
+ return console.log('Logged out. Delete ./session and run again to link a new device.')
96
+ }
97
+ console.log(`Connection closed (${code}), reconnecting...`)
98
+ setTimeout(start, 1000)
99
+ }
100
+ })
101
+
102
+ sock.ev.on('messages.upsert', async ({ messages, type }) => {
103
+ if (type !== 'notify') return
104
+ for (const m of messages) {
105
+ if (m.key.fromMe || !m.message) continue
106
+ const text = m.message.conversation || m.message.extendedTextMessage?.text
107
+ if (text === '!ping') {
108
+ await sock.sendMessage(m.key.remoteJid, { text: 'pong' }, { quoted: m }).catch(console.error)
109
+ }
110
+ }
111
+ })
112
+ }
220
113
 
221
- Additional improvements:
114
+ start()
115
+ ```
222
116
 
223
- - Dedicated newsletter media upload handling.
224
- - Improved channel message decoding.
225
- - Better thumbnail handling.
226
- - Protection against missing channel profile pictures.
227
- - Support for legacy message-fetching arguments.
117
+ **How to link**
228
118
 
229
- ### 2. Media Streaming Improvements
119
+ | Method | Steps |
120
+ |---|---|
121
+ | QR code | Leave `PHONE_NUMBER` empty, then scan from *Linked devices → Link a device* |
122
+ | Pairing code | Set `PHONE_NUMBER`, choose *Link with phone number instead*, enter the code |
123
+ | Custom code | Set `PAIR_CODE` to any 8 characters (empty = random) |
230
124
 
231
- Enhanced media download and retry handling.
125
+ > Your login is stored in `./session`. Keep it private and out of git.
232
126
 
233
- - Proper stream error propagation.
234
- - Prevents downloads from remaining stuck after stream failures.
235
- - Improved recovery for expired media links.
236
- - Handles CDN "403", "404", and "410" responses.
237
- - Improved phone-based media reupload handling.
238
- - Automatically converts Base64 media keys into usable byte data when required.
127
+ ### ⚙️ Socket options
239
128
 
240
- ### 3. Connection & Device Compatibility
129
+ | Option | Default | What it does |
130
+ |---|---|---|
131
+ | `auth` | – | **Required.** The `state` from an auth helper |
132
+ | `browser` | — | Device name shown in *Linked devices* |
133
+ | `printQRInTerminal` | `false` | Print each QR in the terminal (`qr` is always emitted on `connection.update`) |
134
+ | `syncFullHistory` | `true` | Set `false` for lighter bots |
135
+ | `markOnlineOnConnect` | `true` | Set `false` to keep notifications on your phone |
136
+ | `connectTimeoutMs` | `60000` | Opening handshake timeout |
137
+ | `keepAliveIntervalMs` | `25000` | Ping interval |
138
+ | `defaultQueryTimeoutMs` | `60000` | Server request timeout |
139
+ | `getMessage` | `undefined` | Return a stored message by key so retries and poll votes can be decrypted |
140
+ | `logger` | built-in | Any pino-style logger |
241
141
 
242
- - Updated Windows device identification using "WIN_HYBRID".
243
- - Updated default WhatsApp Web version configuration.
244
- - Improved LID address handling in "onWhatsApp()".
245
- - Returns LID information alongside standard WhatsApp lookup results when available.
142
+ ---
246
143
 
247
- Example response:
144
+ ## 💬 Messages
248
145
 
249
- ```js
250
- {
251
- jid,
252
- exists,
253
- lid
254
- }
255
- ```
146
+ Everything from Baileys works as documented upstream — text, mentions, reactions, media, stickers, locations, polls and more:
256
147
 
257
- ### 4. Status Mentions
148
+ ```javascript
149
+ // Text with mention
150
+ await sock.sendMessage(jid, { text: 'Hello @923001234567', mentions: ['923001234567@s.whatsapp.net'] })
258
151
 
259
- StableBail includes "sendStatusMention()" for mentioning contacts or groups in WhatsApp status updates.
152
+ // Image with caption
153
+ await sock.sendMessage(jid, { image: { url: 'https://example.com/pic.jpg' }, caption: 'Look at this' })
260
154
 
261
- Mention individual contacts:
155
+ // Reaction
156
+ await sock.sendMessage(jid, { react: { text: '🔥', key: msg.key } })
262
157
 
263
- ```js
264
- await sock.sendStatusMention(
265
- [
266
- '923001234567@s.whatsapp.net',
267
- '923009876543@s.whatsapp.net'
268
- ],
269
- {
270
- text: 'Eid Mubarak! 🌙'
271
- }
272
- )
158
+ // Poll
159
+ await sock.sendMessage(jid, {
160
+ poll: { name: 'Best language?', values: ['JavaScript', 'Python', 'Go'], selectableCount: 1 }
161
+ })
273
162
  ```
274
163
 
275
- Mention a group:
164
+ ### Status & stories
276
165
 
277
- ```js
278
- await sock.sendStatusMention(
279
- ['120363000000000000@g.us'],
280
- {
281
- image: {
282
- url: 'https://example.com/pic.jpg'
283
- },
284
- caption: 'Team Qadeer'
285
- },
286
- {
287
- delayMs: 1500
288
- }
289
- )
166
+ ```javascript
167
+ // Status with mentions — sendStatusMention
168
+ await sock.sendStatusMention({ text: 'New post!' }, [jid1, jid2])
290
169
  ```
291
170
 
292
- "delayMs" controls the delay between mention operations. Its default value is "1500" milliseconds.
293
-
294
- ### 5. CSToken / NCT Support
295
-
296
- Additional support for WhatsApp's NCT and contact token handling.
171
+ ### Check a number
297
172
 
298
- - Collects NCT salt through history and app-state synchronization.
299
- - Stores available NCT salt in authentication credentials.
300
- - Supports regular-high synchronization when history synchronization is disabled.
301
- - Computes CSToken using HMAC-SHA256 when a required token is unavailable.
302
- - Prioritizes existing TCToken data when available.
303
- - Adds additional token handling for LID-addressed messaging.
304
-
305
- The library also exposes existing reach-out timelock information through:
306
-
307
- ```js
308
- sock.fetchAccountReachoutTimelock()
173
+ ```javascript
174
+ // Is this number banned / on WhatsApp?
175
+ const status = await sock.checkStatusWA('923001234567')
309
176
  ```
310
177
 
311
- And the connection update event can provide "reachoutTimeLock" information.
312
-
313
- ### 6. Custom Connection Banner
178
+ ---
314
179
 
315
- StableBail includes an optional branded connection banner.
180
+ ## 🎛️ Interactive Messages
316
181
 
317
- ```
318
- ╭───────────────────────────╮
319
- │ ✦ Q A D E E R ✦ │
320
- │ stablebail • Qadeer-Xtech │
321
- ╰───────────────────────────╯
322
- ```
182
+ This is where StableBail goes beyond stock Baileys: **buttons, lists and carousels are part of `sendMessage` itself.** No manual proto building, no `relayMessage`, no external button library.
323
183
 
324
- The banner is displayed once when the connection opens.
184
+ ### Buttons
325
185
 
326
- To disable it:
186
+ Add a `buttons` array to any message. The message can also carry a `title`, `subtitle`, `footer` and an image/video/document header.
327
187
 
328
- ```js
329
- const sock = makeWASocket({
330
- auth: state,
331
- printQRInTerminal: true,
332
- banner: false
188
+ ```javascript
189
+ await sock.sendMessage(jid, {
190
+ title: 'QADEER AI',
191
+ text: 'Choose an option:',
192
+ footer: 'Powered by My Bot',
193
+ buttons: [
194
+ { type: 'reply', displayText: '📋 Menu', id: '.menu' },
195
+ { type: 'url', displayText: '🌐 Website', url: 'https://example.com' },
196
+ { type: 'copy', displayText: '📑 Copy JID', copyCode: jid }
197
+ ]
333
198
  })
334
199
  ```
335
200
 
336
- ### 7. Buttons & Lists (new in 1.1.3)
337
-
338
- Buttons and lists are built into the library — no extra helper
339
- files or packages. Just pass `buttons` to `sendMessage`:
201
+ **Button types**
340
202
 
341
- ```js
203
+ | Type | Fields | What it does |
204
+ |---|---|---|
205
+ | `reply` | `displayText`, `id` | Quick-reply button — tapping sends `id` back as a message |
206
+ | `url` | `displayText`, `url` | Opens a link |
207
+ | `call` | `displayText`, `phoneNumber` | Starts a call to the number |
208
+ | `copy` | `displayText`, `copyCode` | Copies the code/text to the clipboard |
209
+ | `list` | `title`, `sections` | Opens a selection list (see below) |
210
+ | `reminder` | `displayText`, `id` | Creates a reminder |
211
+ | `cancelReminder` | `displayText`, `id` | Cancels a reminder |
212
+ | `address` | `displayText`, `id` | Address message button |
213
+ | `location` | — | Asks for / sends location |
214
+
215
+ ### Lists
216
+
217
+ ```javascript
342
218
  await sock.sendMessage(jid, {
343
- text: 'Choose an option',
344
- footer: 'Powered by Team Qadeer',
345
- buttons: [
346
- { type: 'reply', displayText: 'Yes', id: 'yes' },
347
- { type: 'url', displayText: 'Website', url: 'https://example.com' },
348
- { type: 'call', displayText: 'Call us', phoneNumber: '+923001234567' },
349
- { type: 'copy', displayText: 'Copy code', copyCode: 'PROMO10' },
219
+ text: 'Pick a category',
220
+ footer: 'Tap below',
221
+ buttons: [
222
+ {
223
+ type: 'list',
224
+ title: 'Open menu',
225
+ sections: [
350
226
  {
351
- type: 'list',
352
- title: 'Open menu',
353
- sections: [
354
- {
355
- title: 'Main',
356
- rows: [{ title: 'First item', description: 'Details', id: 'item_1' }]
357
- }
358
- ]
227
+ title: 'Main',
228
+ rows: [
229
+ { title: 'Downloads', description: 'Songs, videos, apps', id: '.menu download' },
230
+ { title: 'Games', description: 'Play in chat', id: '.menu games' }
231
+ ]
359
232
  }
360
- ]
233
+ ]
234
+ }
235
+ ]
361
236
  })
362
237
  ```
363
238
 
364
- Also supported: image/video/document headers, carousels
365
- (`carousel: { cards: [...] }`), legacy buttons (`legacyButtons`),
366
- reminder buttons, and raw native-flow passthrough.
367
-
368
- ## 🚀 Basic Usage
369
-
370
- ```js
371
- const makeWASocket =
372
- require('@qadeer-xtech/stablebail').default
373
-
374
- const {
375
- useMultiFileAuthState,
376
- DisconnectReason
377
- } = require('@qadeer-xtech/stablebail')
378
-
379
- async function startBot() {
380
- const { state, saveCreds } =
381
- await useMultiFileAuthState('auth_info')
382
-
383
- const sock = makeWASocket({
384
- auth: state,
385
- printQRInTerminal: true
386
- })
239
+ ### Carousel
387
240
 
388
- sock.ev.on('creds.update', saveCreds)
241
+ Swipeable cards, each with its own media, text and buttons:
389
242
 
390
- return sock
391
- }
392
-
393
- startBot()
243
+ ```javascript
244
+ await sock.sendMessage(jid, {
245
+ text: 'Featured',
246
+ footer: 'Swipe →',
247
+ carousel: {
248
+ cards: [
249
+ {
250
+ title: 'Card One',
251
+ text: 'First card body',
252
+ footer: 'My Bot',
253
+ image: { url: 'https://example.com/one.jpg' },
254
+ buttons: [{ type: 'reply', displayText: 'Open', id: '.open 1' }]
255
+ },
256
+ {
257
+ title: 'Card Two',
258
+ text: 'Second card body',
259
+ footer: 'My Bot',
260
+ image: { url: 'https://example.com/two.jpg' },
261
+ buttons: [{ type: 'url', displayText: 'Visit', url: 'https://example.com' }]
262
+ }
263
+ ]
264
+ }
265
+ })
394
266
  ```
395
267
 
396
- ## 📡 Newsletter Examples
268
+ ### Legacy buttons
397
269
 
398
- Fetch Channel Information
270
+ Old-style template buttons are still available as `legacyButtons` if you need them.
399
271
 
400
- ```js
401
- const channel = await sock.newsletterFromUrl(
402
- 'https://whatsapp.com/channel/CHANNEL_ID'
403
- )
404
272
 
405
- console.log(
406
- channel.id,
407
- channel.name,
408
- channel.subscribers
409
- )
410
- ```
411
-
412
- Follow / Unfollow
413
-
414
- ```js
415
- await sock.newsletterFollow(channel.id)
416
-
417
- await sock.newsletterUnfollow(channel.id)
418
- ```
273
+ ---
419
274
 
420
- Get Subscribed Channels
275
+ ## 🎨 Chat Themes
421
276
 
422
- ```js
423
- const channels = await sock.newsletterSubscribed()
277
+ Set the official WhatsApp chat theme for any chat or group — preset colour schemes or your own solid colour. This uses WhatsApp's own `CHAT_THEME_SETTING` protocol message.
424
278
 
425
- console.log(channels)
426
- ```
279
+ ```javascript
280
+ import { CHAT_THEMES } from '@qadeer-xtech/stablebail'
427
281
 
428
- Fetch Channel Messages
282
+ // Preset themes: 'Default-Blue@Minimal', 'Emerald@Minimal', 'Pink@Minimal',
283
+ // 'Red@Minimal', 'Royal-Blue@Minimal', 'Tyrian-Purple@Minimal', 'WhatsApp-Green@Minimal', ...
284
+ await sock.setChatTheme(jid, 'Emerald@Minimal')
429
285
 
430
- ```js
431
- const messages = await sock.newsletterFetchMessages(
432
- channel.id,
433
- 20
434
- )
286
+ // ...or through sendMessage
287
+ await sock.sendMessage(jid, { chatTheme: 'Pink@Minimal' })
435
288
 
436
- console.log(messages)
289
+ // Custom solid colour (ARGB hex strings), with optional doodle background
290
+ await sock.setChatThemeColor(jid, { colorLight: 'FFFF0000', colorDark: 'FF7A0000', isDoodleEnabled: true })
437
291
  ```
438
292
 
439
- Fetch Views & Reactions
293
+ ---
440
294
 
441
- ```js
442
- const updates = await sock.newsletterFetchUpdates(
443
- channel.id,
444
- 20
445
- )
295
+ ## 🥷 Stealth Device Targeting
446
296
 
447
- console.log(
448
- updates[0].server_id,
449
- updates[0].views,
450
- updates[0].reactions
451
- )
452
- ```
297
+ Control exactly **which devices** a direct message is delivered to. Pass these options to `relayMessage` (they apply to 1-to-1 chats only — not groups or status):
453
298
 
454
- Send Channel Message
299
+ ```javascript
300
+ // participant (no count): recipient-only — skips your own linked devices
301
+ await sock.relayMessage(jid, message, { participant: { jid } })
455
302
 
456
- ```js
457
- await sock.sendMessage(channel.id, {
458
- text: 'Assalam o Alaikum! 👋'
459
- })
460
- ```
303
+ // isSecret: only the recipient's primary phone — no web/desktop companions
304
+ await sock.relayMessage(jid, message, { isSecret: true })
461
305
 
462
- Send Channel Image
306
+ // protected: everywhere EXCEPT the recipient's linked/companion devices
307
+ await sock.relayMessage(jid, message, { protected: true })
463
308
 
464
- ```js
465
- await sock.sendMessage(channel.id, {
466
- image: {
467
- url: 'https://example.com/pic.jpg'
468
- },
469
- caption: 'New Channel Update'
470
- })
309
+ // me: only your own devices
310
+ await sock.relayMessage(jid, message, { me: true })
471
311
  ```
472
312
 
473
- React to Channel Message
313
+ ---
474
314
 
475
- ```js
476
- await sock.newsletterReactMessage(
477
- channel.id,
478
- updates[0].server_id,
479
- '❤️'
480
- )
481
- ```
315
+ ## 📢 Newsletter / Channels
482
316
 
483
- ## ⚙️ Compatibility
317
+ - Channel (newsletter) media paths are fixed — media posts render correctly for followers.
318
+ - Follow, unfollow, react and manage newsletters with the standard socket methods.
484
319
 
485
- - Node.js environment
486
- - Baileys-compatible socket workflow
487
- - Existing Baileys-based bot projects
488
- - Multi-file authentication
489
- - WhatsApp Web connection workflows
320
+ ---
490
321
 
491
- StableBail is designed to minimize migration work for existing Baileys users. However, custom methods and options are specific to this package.
322
+ ## 🔌 Disconnect reasons
492
323
 
493
- ## ⚠️ Important Notes
494
-
495
- - Some custom features may require live WhatsApp testing.
496
- - Status mention functionality should be tested with a dedicated account before production use.
497
- - WhatsApp may change its internal protocols without notice.
498
- - Connection restrictions, account-level limitations, and server-side errors cannot always be resolved through library-side changes.
499
- - Always keep your authentication credentials private.
500
-
501
- ## 📄 License
324
+ | Code | Meaning | What to do |
325
+ |---|---|---|
326
+ | `401` | Logged out | Session is dead — delete it and pair again |
327
+ | `403` | Forbidden | Number/account restricted by WhatsApp |
328
+ | `408` | Timed out | Reconnect |
329
+ | `428` | Connection closed | Reconnect |
330
+ | `440` | Connection replaced | The same session opened somewhere else — do not fight it, find the other instance |
331
+ | `500` | Bad session | Reconnect; if it repeats, re-pair |
332
+ | `515` | Restart required | Normal right after pairing — just reconnect |
502
333
 
503
- MIT License — see the [LICENSE](LICENSE) file. The whole package
504
- is under MIT: the upstream Baileys code (© Rajeh Taher /
505
- WhiskeySockets) and Team Qadeer's fixes, extensions and branding
506
- (© Team Qadeer / Qadeer-Xtech) alike. The [NOTICE](NOTICE) file
507
- ships with the package and carries a (non-binding) credit request.
334
+ ---
508
335
 
509
- ## Dependencies
336
+ ## 🗄️ Session storage
510
337
 
511
- The two core dependencies are faithful republishes under the same
512
- scope, with code **byte-identical** to upstream (proof in each
513
- repo's DIFF.md):
338
+ `useMultiFileAuthState('./session')` stores credentials and keys as files in a folder. Back the folder up if the session matters — on hosts with ephemeral disks (Heroku, containers), persist it to a database or external storage on `creds.update` and on a timer, and restore it before starting the socket.
514
339
 
515
- - [@qadeer-xtech/libsignal](https://github.com/Qadeer-Xtech/libsignal) — of official libsignal 6.0.0
516
- - [@qadeer-xtech/whatsapp-rust-bridge](https://github.com/Qadeer-Xtech/whatsapp-rust-bridge) — of official whatsapp-rust-bridge 0.5.4
340
+ ---
517
341
 
518
- ## 🖤 Credits
342
+ ## 🙏 Credits
519
343
 
520
- Developed and maintained by Team Qadeer.
344
+ Built on [**@whiskeysockets/baileys**](https://github.com/WhiskeySockets/Baileys) 7.0.0-rc14 (MIT). Full upstream attribution is kept in [NOTICE](https://github.com/Qadeer-Xtech/stablebail/blob/main/NOTICE).
521
345
 
522
- STABLEBAIL — Built for developers. Enhanced for performance.
346
+ ## 📄 License
523
347
 
524
- "Powered by Team Qadeer"
348
+ MIT — see [LICENSE](https://github.com/Qadeer-Xtech/stablebail/blob/main/LICENSE).