@qadeer-xtech/stablebail 1.1.2 → 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,492 +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.
48
-
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:
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`) |
133
30
 
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.
53
+ ---
168
54
 
169
- ## ✅ Recommended Settings for Bot Projects
55
+ ## 🚀 Quick Start
170
56
 
171
- For a smooth, error-free install, use these exact settings in your bot's "package.json":
57
+ A complete bot that links by QR or pairing code and answers `!ping`.
172
58
 
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
- ```
59
+ ```javascript
60
+ import makeWASocket, {
61
+ useMultiFileAuthState,
62
+ DisconnectReason
63
+ } from '@qadeer-xtech/stablebail'
188
64
 
189
- ## ✨ Key Features
65
+ const PHONE_NUMBER = '' // e.g. '923001234567' to use a pairing code
66
+ const PAIR_CODE = '' // optional custom 8-character code
190
67
 
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.
68
+ const start = async () => {
69
+ const { state, saveCreds } = await useMultiFileAuthState('./session')
200
70
 
201
- ## 🔧 What's Included
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
+ }
202
89
 
203
- ### 1. Newsletter / Channel Support
90
+ if (connection === 'open') console.log('Connected as', sock.user?.id)
204
91
 
205
- Extended newsletter functionality with improved message fetching, media handling, and channel metadata support.
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
+ }
206
113
 
207
- Available methods:
114
+ start()
115
+ ```
208
116
 
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 |
117
+ **How to link**
220
118
 
221
- Additional 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) |
222
124
 
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.
125
+ > Your login is stored in `./session`. Keep it private and out of git.
228
126
 
229
- ### 2. Media Streaming Improvements
127
+ ### ⚙️ Socket options
230
128
 
231
- Enhanced media download and retry handling.
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 |
232
141
 
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.
142
+ ---
239
143
 
240
- ### 3. Connection & Device Compatibility
144
+ ## 💬 Messages
241
145
 
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.
146
+ Everything from Baileys works as documented upstream — text, mentions, reactions, media, stickers, locations, polls and more:
246
147
 
247
- Example response:
148
+ ```javascript
149
+ // Text with mention
150
+ await sock.sendMessage(jid, { text: 'Hello @923001234567', mentions: ['923001234567@s.whatsapp.net'] })
248
151
 
249
- ```js
250
- {
251
- jid,
252
- exists,
253
- lid
254
- }
255
- ```
152
+ // Image with caption
153
+ await sock.sendMessage(jid, { image: { url: 'https://example.com/pic.jpg' }, caption: 'Look at this' })
256
154
 
257
- ### 4. Status Mentions
155
+ // Reaction
156
+ await sock.sendMessage(jid, { react: { text: '🔥', key: msg.key } })
258
157
 
259
- StableBail includes "sendStatusMention()" for mentioning contacts or groups in WhatsApp status updates.
158
+ // Poll
159
+ await sock.sendMessage(jid, {
160
+ poll: { name: 'Best language?', values: ['JavaScript', 'Python', 'Go'], selectableCount: 1 }
161
+ })
162
+ ```
260
163
 
261
- Mention individual contacts:
164
+ ### Status & stories
262
165
 
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
- )
166
+ ```javascript
167
+ // Status with mentions — sendStatusMention
168
+ await sock.sendStatusMention({ text: 'New post!' }, [jid1, jid2])
273
169
  ```
274
170
 
275
- Mention a group:
171
+ ### Check a number
276
172
 
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
- )
173
+ ```javascript
174
+ // Is this number banned / on WhatsApp?
175
+ const status = await sock.checkStatusWA('923001234567')
290
176
  ```
291
177
 
292
- "delayMs" controls the delay between mention operations. Its default value is "1500" milliseconds.
178
+ ---
293
179
 
294
- ### 5. CSToken / NCT Support
180
+ ## 🎛️ Interactive Messages
295
181
 
296
- Additional support for WhatsApp's NCT and contact token handling.
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.
297
183
 
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.
184
+ ### Buttons
304
185
 
305
- The library also exposes existing reach-out timelock information through:
186
+ Add a `buttons` array to any message. The message can also carry a `title`, `subtitle`, `footer` and an image/video/document header.
306
187
 
307
- ```js
308
- sock.fetchAccountReachoutTimelock()
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
+ ]
198
+ })
309
199
  ```
310
200
 
311
- And the connection update event can provide "reachoutTimeLock" information.
312
-
313
- ### 6. Custom Connection Banner
314
-
315
- StableBail includes an optional branded connection banner.
201
+ **Button types**
316
202
 
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
218
+ await sock.sendMessage(jid, {
219
+ text: 'Pick a category',
220
+ footer: 'Tap below',
221
+ buttons: [
222
+ {
223
+ type: 'list',
224
+ title: 'Open menu',
225
+ sections: [
226
+ {
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
+ ]
232
+ }
233
+ ]
234
+ }
235
+ ]
236
+ })
317
237
  ```
318
- ╭───────────────────────────╮
319
- │ ✦ Q A D E E R ✦ │
320
- │ stablebail • Qadeer-Xtech │
321
- ╰───────────────────────────╯
322
- ```
323
-
324
- The banner is displayed once when the connection opens.
325
-
326
- To disable it:
327
238
 
328
- ```js
329
- const sock = makeWASocket({
330
- auth: state,
331
- printQRInTerminal: true,
332
- banner: false
239
+ ### Carousel
240
+
241
+ Swipeable cards, each with its own media, text and buttons:
242
+
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
+ }
333
265
  })
334
266
  ```
335
267
 
336
- ## 🚀 Basic Usage
337
-
338
- ```js
339
- const makeWASocket =
340
- require('@qadeer-xtech/stablebail').default
268
+ ### Legacy buttons
341
269
 
342
- const {
343
- useMultiFileAuthState,
344
- DisconnectReason
345
- } = require('@qadeer-xtech/stablebail')
270
+ Old-style template buttons are still available as `legacyButtons` if you need them.
346
271
 
347
- async function startBot() {
348
- const { state, saveCreds } =
349
- await useMultiFileAuthState('auth_info')
350
272
 
351
- const sock = makeWASocket({
352
- auth: state,
353
- printQRInTerminal: true
354
- })
273
+ ---
355
274
 
356
- sock.ev.on('creds.update', saveCreds)
357
-
358
- return sock
359
- }
275
+ ## 🎨 Chat Themes
360
276
 
361
- startBot()
362
- ```
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.
363
278
 
364
- ## 📡 Newsletter Examples
279
+ ```javascript
280
+ import { CHAT_THEMES } from '@qadeer-xtech/stablebail'
365
281
 
366
- Fetch Channel Information
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')
367
285
 
368
- ```js
369
- const channel = await sock.newsletterFromUrl(
370
- 'https://whatsapp.com/channel/CHANNEL_ID'
371
- )
286
+ // ...or through sendMessage
287
+ await sock.sendMessage(jid, { chatTheme: 'Pink@Minimal' })
372
288
 
373
- console.log(
374
- channel.id,
375
- channel.name,
376
- channel.subscribers
377
- )
289
+ // Custom solid colour (ARGB hex strings), with optional doodle background
290
+ await sock.setChatThemeColor(jid, { colorLight: 'FFFF0000', colorDark: 'FF7A0000', isDoodleEnabled: true })
378
291
  ```
379
292
 
380
- Follow / Unfollow
381
-
382
- ```js
383
- await sock.newsletterFollow(channel.id)
384
-
385
- await sock.newsletterUnfollow(channel.id)
386
- ```
293
+ ---
387
294
 
388
- Get Subscribed Channels
295
+ ## 🥷 Stealth Device Targeting
389
296
 
390
- ```js
391
- const channels = await sock.newsletterSubscribed()
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):
392
298
 
393
- console.log(channels)
394
- ```
299
+ ```javascript
300
+ // participant (no count): recipient-only — skips your own linked devices
301
+ await sock.relayMessage(jid, message, { participant: { jid } })
395
302
 
396
- Fetch Channel Messages
303
+ // isSecret: only the recipient's primary phone — no web/desktop companions
304
+ await sock.relayMessage(jid, message, { isSecret: true })
397
305
 
398
- ```js
399
- const messages = await sock.newsletterFetchMessages(
400
- channel.id,
401
- 20
402
- )
306
+ // protected: everywhere EXCEPT the recipient's linked/companion devices
307
+ await sock.relayMessage(jid, message, { protected: true })
403
308
 
404
- console.log(messages)
309
+ // me: only your own devices
310
+ await sock.relayMessage(jid, message, { me: true })
405
311
  ```
406
312
 
407
- Fetch Views & Reactions
313
+ ---
408
314
 
409
- ```js
410
- const updates = await sock.newsletterFetchUpdates(
411
- channel.id,
412
- 20
413
- )
315
+ ## 📢 Newsletter / Channels
414
316
 
415
- console.log(
416
- updates[0].server_id,
417
- updates[0].views,
418
- updates[0].reactions
419
- )
420
- ```
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.
421
319
 
422
- Send Channel Message
320
+ ---
423
321
 
424
- ```js
425
- await sock.sendMessage(channel.id, {
426
- text: 'Assalam o Alaikum! 👋'
427
- })
428
- ```
429
-
430
- Send Channel Image
322
+ ## 🔌 Disconnect reasons
431
323
 
432
- ```js
433
- await sock.sendMessage(channel.id, {
434
- image: {
435
- url: 'https://example.com/pic.jpg'
436
- },
437
- caption: 'New Channel Update'
438
- })
439
- ```
440
-
441
- React to Channel Message
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 |
442
333
 
443
- ```js
444
- await sock.newsletterReactMessage(
445
- channel.id,
446
- updates[0].server_id,
447
- '❤️'
448
- )
449
- ```
334
+ ---
450
335
 
451
- ## ⚙️ Compatibility
336
+ ## 🗄️ Session storage
452
337
 
453
- - Node.js environment
454
- - Baileys-compatible socket workflow
455
- - Existing Baileys-based bot projects
456
- - Multi-file authentication
457
- - WhatsApp Web connection workflows
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.
458
339
 
459
- StableBail is designed to minimize migration work for existing Baileys users. However, custom methods and options are specific to this package.
340
+ ---
460
341
 
461
- ## ⚠️ Important Notes
342
+ ## 🙏 Credits
462
343
 
463
- - Some custom features may require live WhatsApp testing.
464
- - Status mention functionality should be tested with a dedicated account before production use.
465
- - WhatsApp may change its internal protocols without notice.
466
- - Connection restrictions, account-level limitations, and server-side errors cannot always be resolved through library-side changes.
467
- - Always keep your authentication credentials private.
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).
468
345
 
469
346
  ## 📄 License
470
347
 
471
- MIT License — see the [LICENSE](LICENSE) file. The whole package
472
- is under MIT: the upstream Baileys code (© Rajeh Taher /
473
- WhiskeySockets) and Team Qadeer's fixes, extensions and branding
474
- (© Team Qadeer / Qadeer-Xtech) alike. The [NOTICE](NOTICE) file
475
- ships with the package and carries a (non-binding) credit request.
476
-
477
- ## Dependencies
478
-
479
- The two core dependencies are faithful republishes under the same
480
- scope, with code **byte-identical** to upstream (proof in each
481
- repo's DIFF.md):
482
-
483
- - [@qadeer-xtech/libsignal](https://github.com/Qadeer-Xtech/libsignal) — of official libsignal 6.0.0
484
- - [@qadeer-xtech/whatsapp-rust-bridge](https://github.com/Qadeer-Xtech/whatsapp-rust-bridge) — of official whatsapp-rust-bridge 0.5.4
485
-
486
- ## 🖤 Credits
487
-
488
- Developed and maintained by Team Qadeer.
489
-
490
- STABLEBAIL — Built for developers. Enhanced for performance.
491
-
492
- "Powered by Team Qadeer"
348
+ MIT — see [LICENSE](https://github.com/Qadeer-Xtech/stablebail/blob/main/LICENSE).