whalibmob 5.40.34 → 5.40.37

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
@@ -20,7 +20,7 @@ code, and bring the account into being. Both transports, one API.
20
20
  ### Start here
21
21
 
22
22
  [![Register a number](https://img.shields.io/badge/Register_a_number-SMS,_voice_or_email-25D366?style=for-the-badge)](https://github.com/Kunboruto20/whalibmob/blob/main/docs/registration.md#register-a-new-number)
23
- [![Link an account](https://img.shields.io/badge/Link_an_account-QR_or_pairing_code-128C7E?style=for-the-badge)](https://github.com/Kunboruto20/whalibmob/blob/main/docs/linking.md#linking-to-an-existing-account-pairing-code-or-qr)
23
+ [![Link an account](https://img.shields.io/badge/Link_an_account-QR,_pairing_code_or_passkey-128C7E?style=for-the-badge)](https://github.com/Kunboruto20/whalibmob/blob/main/docs/linking.md#linking-to-an-existing-account-pairing-code-or-qr)
24
24
  [![Use the CLI](https://img.shields.io/badge/Use_the_CLI-no_code_needed-075E54?style=for-the-badge)](https://github.com/Kunboruto20/whalibmob/blob/main/docs/cli-getting-started.md#cli--getting-started)
25
25
 
26
26
  [![Library API](https://img.shields.io/badge/Library_API-Node.js-34B7F1?style=for-the-badge)](https://github.com/Kunboruto20/whalibmob/blob/main/docs/registration.md#library-api)
@@ -76,7 +76,7 @@ code, and bring the account into being. Both transports, one API.
76
76
  > This project is not affiliated, associated, authorized, endorsed by, or in any way officially connected with WhatsApp or any of its subsidiaries or affiliates. "WhatsApp" and related names are registered trademarks of their respective owners. Use at your own discretion.
77
77
 
78
78
  - **It registers numbers.** Give it a phone number that has never been on WhatsApp, request the code over SMS, voice call, flash call or an old WhatsApp account, confirm it, and the account exists — as an **Android or iOS device**, on the Mobile API. No phone, no scanning, no existing account to borrow. See [Register a New Number](https://github.com/Kunboruto20/whalibmob/blob/main/docs/registration.md#register-a-new-number).
79
- - **It also speaks WhatsApp Web**, over a WebSocket. When a number cannot receive an SMS, or is already live on a phone, whalibmob links itself to that account by **QR code** or an **8-character pairing code** and runs as one of its linked devices — with the full message history and the account's address book. See [Linking to an Existing Account](https://github.com/Kunboruto20/whalibmob/blob/main/docs/linking.md#linking-to-an-existing-account-pairing-code-or-qr).
79
+ - **It also speaks WhatsApp Web**, over a WebSocket. When a number cannot receive an SMS, or is already live on a phone, whalibmob links itself to that account by **QR code**, an **8-character pairing code** or, where the account has one, its **passkey**, and runs as one of its linked devices — with the full message history and the account's address book. See [Linking to an Existing Account](https://github.com/Kunboruto20/whalibmob/blob/main/docs/linking.md#linking-to-an-existing-account-pairing-code-or-qr).
80
80
  - **The API is identical in both modes.** Everything below — sending, media, groups, events — reads the same whichever way the session was created.
81
81
  - No browser, no Selenium, no external runtime. It talks to WhatsApp directly over a **TCP socket** with the **Noise Protocol** handshake.
82
82
  - Signal Protocol encryption is **fully inlined** in pure JavaScript — no native binaries, no node-gyp, runs anywhere Node.js runs.
@@ -109,8 +109,8 @@ const os = require('os')
109
109
  const path = require('path')
110
110
  const readline = require('readline/promises')
111
111
 
112
- const PHONE = '447533640016' // your number: country code + number, no '+'
113
- const TO = 'number for message' // who to message
112
+ const PHONE = '40712345678' // your number: country code + number, no '+'
113
+ const TO = '40798765432' // who to message
114
114
  const BASE_DIR = path.join(os.homedir(), '.waSession')
115
115
 
116
116
  async function register(phone) {
@@ -241,6 +241,7 @@ Every command of the interactive shell: messages, presence, profile, chats, grou
241
241
  ### [Linking, Companion Mode & Approving Devices](https://github.com/Kunboruto20/whalibmob/blob/main/docs/linking.md)
242
242
 
243
243
  - [Linking to an Existing Account (Pairing Code or QR)](https://github.com/Kunboruto20/whalibmob/blob/main/docs/linking.md#linking-to-an-existing-account-pairing-code-or-qr)
244
+ - [Linking with a Passkey](https://github.com/Kunboruto20/whalibmob/blob/main/docs/linking.md#linking-with-a-passkey)
244
245
  - [Companion Mode — Node.js API](https://github.com/Kunboruto20/whalibmob/blob/main/docs/linking.md#companion-mode--nodejs-api)
245
246
  - [Approving a Companion Device (Primary Role)](https://github.com/Kunboruto20/whalibmob/blob/main/docs/linking.md#approving-a-companion-device-primary-role)
246
247
 
@@ -274,6 +275,7 @@ Where a session is kept, saving and restoring it, database backends, and the Sig
274
275
  ### [Handling Events & History Sync](https://github.com/Kunboruto20/whalibmob/blob/main/docs/events-history.md)
275
276
 
276
277
  - [Handling Events](https://github.com/Kunboruto20/whalibmob/blob/main/docs/events-history.md#handling-events)
278
+ - [Connection Health, Sync and Account Events](https://github.com/Kunboruto20/whalibmob/blob/main/docs/events-history.md#connection-health-sync-and-account-events)
277
279
  - [History Sync](https://github.com/Kunboruto20/whalibmob/blob/main/docs/events-history.md#history-sync)
278
280
 
279
281
  ### [Sending & Receiving Messages](https://github.com/Kunboruto20/whalibmob/blob/main/docs/messaging.md)
@@ -284,6 +286,9 @@ Where a session is kept, saving and restoring it, database backends, and the Sig
284
286
  - [Status / Stories](https://github.com/Kunboruto20/whalibmob/blob/main/docs/messaging.md#status--stories)
285
287
  - [Send States in Chat](https://github.com/Kunboruto20/whalibmob/blob/main/docs/messaging.md#send-states-in-chat)
286
288
  - [Modifying Chats](https://github.com/Kunboruto20/whalibmob/blob/main/docs/messaging.md#modifying-chats)
289
+ - [Vote on a Poll](https://github.com/Kunboruto20/whalibmob/blob/main/docs/messaging.md#vote-on-a-poll) · [Pin a Message](https://github.com/Kunboruto20/whalibmob/blob/main/docs/messaging.md#pin-a-message) · [Send a Message You Encoded](https://github.com/Kunboruto20/whalibmob/blob/main/docs/messaging.md#send-a-message-you-encoded)
290
+ - [Encrypted Reactions, Comments, Event Responses and Edits](https://github.com/Kunboruto20/whalibmob/blob/main/docs/messaging.md#encrypted-reactions-comments-event-responses-and-edits)
291
+ - [Labels](https://github.com/Kunboruto20/whalibmob/blob/main/docs/messaging.md#labels) · [Delete a Message for Me](https://github.com/Kunboruto20/whalibmob/blob/main/docs/messaging.md#delete-a-message-for-me)
287
292
 
288
293
  ### [User Queries, Profile, Privacy & Account State](https://github.com/Kunboruto20/whalibmob/blob/main/docs/profile-privacy.md)
289
294
 
@@ -297,7 +302,9 @@ Where a session is kept, saving and restoring it, database backends, and the Sig
297
302
  - [Groups](https://github.com/Kunboruto20/whalibmob/blob/main/docs/groups-channels.md#groups)
298
303
  - [Communities](https://github.com/Kunboruto20/whalibmob/blob/main/docs/groups-channels.md#communities)
299
304
  - [Newsletters (Channels)](https://github.com/Kunboruto20/whalibmob/blob/main/docs/groups-channels.md#newsletters-channels)
305
+ - [Read a Channel's Posts](https://github.com/Kunboruto20/whalibmob/blob/main/docs/groups-channels.md#read-a-channels-posts) · [Live Updates, Views and Reactions](https://github.com/Kunboruto20/whalibmob/blob/main/docs/groups-channels.md#live-updates-views-and-reactions)
300
306
  - [Business Profile](https://github.com/Kunboruto20/whalibmob/blob/main/docs/groups-channels.md#business-profile)
307
+ - [Links, Bots, Sticker Packs and Web Push](https://github.com/Kunboruto20/whalibmob/blob/main/docs/groups-channels.md#links-bots-sticker-packs-and-web-push)
301
308
  - [WhatsApp IDs](https://github.com/Kunboruto20/whalibmob/blob/main/docs/groups-channels.md#whatsapp-ids)
302
309
 
303
310
  ### [IDs, Transport, Media Encryption & Device Emulation](https://github.com/Kunboruto20/whalibmob/blob/main/docs/internals.md)
package/cli.js CHANGED
@@ -1330,6 +1330,13 @@ async function doConnectWebQr(phone) {
1330
1330
  out(' the QR set expired — run /qrcode ' + phone + ' again for a fresh one');
1331
1331
  });
1332
1332
 
1333
+ // WhatsApp can offer a passkey link to an account that has a passkey. A
1334
+ // terminal has no authenticator to answer with, so say what is happening and
1335
+ // that the QR, drawn again just above, still works.
1336
+ client.on('passkey_request', () => {
1337
+ out(' this account offered a passkey link, which the shell cannot answer; scan the QR above instead');
1338
+ });
1339
+
1333
1340
  client.once('paired', (pp) => {
1334
1341
  out('');
1335
1342
  out(' scanned — linked as ' + pp.jid + (pp.lid ? ' (' + pp.lid + ')' : ''));
@@ -165,6 +165,35 @@ The `decoded` object shape per message type:
165
165
  { type: 'protocol', subtype: string }
166
166
  ```
167
167
 
168
+ ### Connection Health, Sync and Account Events
169
+
170
+ | Event | Payload | Description |
171
+ |---|---|---|
172
+ | `keepalive_timeout` | `{ errorCount, lastSuccess }` | A keepalive ping went unanswered for 10 seconds. `errorCount` is how many in a row, `lastSuccess` when the last answer came (ms). The connection is not closed for you: decide whether to `disconnect({ reconnect: true })` |
173
+ | `keepalive_restored` | `{ missed }` | The first ping answered after one or more were missed |
174
+ | `offline_sync_preview` | `{ total, appDataChanges, messages, notifications, receipts }` | What the server is about to replay from while you were away |
175
+ | `offline_sync_completed` | `{ count }` | The replay is done; what arrives from here on is live |
176
+ | `temporary_ban` | `{ code, expireSecs, expiresAt }` | The account is temporarily banned. The session survives; the server refuses it until the ban runs out |
177
+ | `qr_scanned_without_multidevice` | `{}` | The QR was scanned by a phone with multi-device off. The same QR still works once it is on |
178
+ | `picture_update` | `{ jid, author, removed, pictureId, ts }` | A contact or group changed or removed its picture |
179
+ | `about_update` | `{ jid, about, ts }` | A contact changed its "about" text |
180
+ | `newsletter_live_update` | `{ jid, ts, messages }` | Count changes on a channel you subscribed to with `subscribeNewsletterLiveUpdates` |
181
+ | `label_edit` | `{ labelId, name, color, deleted }` | A label was created, changed or deleted |
182
+ | `label_association` | `{ labelId, jid, msgId, labeled }` | A label was put on, or taken off, a chat (`msgId` null) or a message |
183
+ | `message_deleted_for_me` | `{ jid, msgId, fromMe, deleteMedia }` | A message was deleted on this account's devices only |
184
+ | `status_muted` | `{ jid, muted }` | A contact's status updates were muted or unmuted |
185
+ | `unarchive_chats_setting` | `{ unarchiveChats }` | Whether archived chats come back when a message arrives |
186
+
187
+ The app-state events carry `remote: true` when the change was made on another device and `synced: true` when this client made it.
188
+
189
+ A keepalive example — drop a connection that has gone silent:
190
+
191
+ ```js
192
+ client.on('keepalive_timeout', ({ errorCount }) => {
193
+ if (errorCount >= 3) client.disconnect({ reconnect: true })
194
+ })
195
+ ```
196
+
168
197
  ---
169
198
 
170
199
  ## History Sync
@@ -261,6 +290,18 @@ Sync type values:
261
290
  | `NON_BLOCKING_DATA` | Background low-priority data |
262
291
  | `ON_DEMAND` | Explicitly requested by the client |
263
292
 
293
+ ### When a History Blob Cannot Be Fetched
294
+
295
+ A large history chunk is not sent inline: the phone uploads it and sends a notice with where it is and the key to open it. If that file is gone by the time you fetch it, tell the phone, and it uploads the chunk again:
296
+
297
+ ```js
298
+ // msgId: the id of the message that carried the history notice
299
+ // mediaKey: the key from that notice
300
+ await client.sendHistorySyncServerErrorReceipt(msgId, mediaKey)
301
+ ```
302
+
303
+ The receipt goes to your own account as a peer message, the same way a media re-upload request does.
304
+
264
305
  ### Persistent Files Written to Disk
265
306
 
266
307
  The library automatically writes these files to `sessionDir` per account. You do not need to create or manage them.
@@ -403,6 +403,17 @@ await client.unlinkGroupFromCommunity(
403
403
  )
404
404
  ```
405
405
 
406
+ ### Sub Groups and Community Participants
407
+
408
+ ```js
409
+ const groups = await client.getSubGroups('120363000000000001@g.us')
410
+ // [{ jid, subject, subjectTime, size, isDefaultSubGroup }]
411
+
412
+ // everyone in any group of the community — admins of the community only
413
+ const people = await client.getLinkedGroupsParticipants('120363000000000001@g.us')
414
+ // [{ jid, phoneNumber, lid }]
415
+ ```
416
+
406
417
  ## Newsletters (Channels)
407
418
 
408
419
  Newsletters are one-to-many broadcast channels. Only the owner can post; anyone can subscribe.
@@ -440,6 +451,59 @@ await client.changeNewsletterDescription('120363000000000004@newsletter', 'New d
440
451
  await client.sendNewsletterText('120363000000000004@newsletter', 'Breaking: WhatsApp adds polls!')
441
452
  ```
442
453
 
454
+ ### Read a Channel's Posts
455
+
456
+ Channel posts are not end-to-end encrypted, so they can be read for any channel, followed or not.
457
+
458
+ ```js
459
+ const posts = await client.getNewsletterMessages('120363000000000004@newsletter', { count: 20 })
460
+ for (const p of posts) {
461
+ console.log(p.serverId, p.decoded?.text, p.viewsCount, p.reactionCounts) // { '❤️': 3 } or null
462
+ }
463
+
464
+ // page back from the oldest one you have
465
+ const older = await client.getNewsletterMessages(jid, { count: 20, before: posts[0].serverId })
466
+
467
+ // what changed since: view and reaction counts, edits
468
+ const updates = await client.getNewsletterMessageUpdates(jid, { since: 1700000000, count: 50 })
469
+ ```
470
+
471
+ Each post is `{ serverId, id, type, ts, viewsCount, forwardsCount, reactionCounts, decoded, raw }`. `serverId` is the post's number in the channel and is what the calls below take; `raw` is the encoded `Message`.
472
+
473
+ Posts from channels you follow also arrive live, on the ordinary `message` event with `newsletter: true` and `serverId` set.
474
+
475
+ ### Live Updates, Views and Reactions
476
+
477
+ ```js
478
+ // ask for count changes to be pushed; lasts durationSecs, then ask again
479
+ const { durationSecs } = await client.subscribeNewsletterLiveUpdates(jid)
480
+ client.on('newsletter_live_update', ({ jid, messages }) => {
481
+ for (const m of messages) console.log(m.serverId, m.viewsCount, m.reactionCounts)
482
+ })
483
+
484
+ await client.markNewsletterViewed(jid, [posts[0].serverId, posts[1].serverId])
485
+ await client.sendNewsletterReaction(jid, posts[0].serverId, '🔥')
486
+ await client.sendNewsletterReaction(jid, posts[0].serverId, '') // take it back
487
+ ```
488
+
489
+ ### Mute, List and Look Up Channels
490
+
491
+ ```js
492
+ await client.muteNewsletter(jid)
493
+ await client.unmuteNewsletter(jid)
494
+
495
+ const mine = await client.getSubscribedNewsletters() // as the server describes them
496
+ const info = await client.getNewsletterInfoWithInvite('https://whatsapp.com/channel/0029VaABC')
497
+ ```
498
+
499
+ ### Post a Message You Encoded
500
+
501
+ `sendNewsletterText` covers text. For anything else, encode the `Message` yourself:
502
+
503
+ ```js
504
+ await client.sendNewsletterMessage(jid, messageBytes, { type: 'media', mediaType: 'image', mediaId })
505
+ ```
506
+
443
507
  ## Business Profile
444
508
 
445
509
  Query the public business profile of any WhatsApp Business account:
@@ -458,6 +522,28 @@ if (bp) {
458
522
 
459
523
  ---
460
524
 
525
+ ## Links, Bots, Sticker Packs and Web Push
526
+
527
+ ```js
528
+ // where a wa.me/message/… business link points, and the text it prefills
529
+ const biz = await client.resolveBusinessMessageLink('https://wa.me/message/ABCDEF')
530
+ // { jid, pushName, message, isSigned, verifiedName, verifiedLevel }
531
+
532
+ // your own contact link; pass true to revoke it and get a new one
533
+ const { link } = await client.getContactQrLink() // https://wa.me/qr/…
534
+ const who = await client.resolveContactQrLink(link) // { jid, pushName, type }
535
+
536
+ // the Meta AI bots the server lists
537
+ const bots = await client.getBotList() // [{ jid, personaId }]
538
+
539
+ // a sticker pack's listing from WhatsApp's store
540
+ const pack = await client.fetchStickerPack('PACK_ID')
541
+
542
+ // Web Push: let the server wake this client through a browser push service
543
+ await client.registerWebPush({ endpoint, auth, p256dh }) // from a PushSubscription
544
+ const settings = await client.getPushConfig()
545
+ ```
546
+
461
547
  ## WhatsApp IDs
462
548
 
463
549
  - Individual contacts: `[countrycode][number]@s.whatsapp.net`
package/docs/linking.md CHANGED
@@ -8,12 +8,13 @@
8
8
 
9
9
  Registering a number over SMS makes whalibmob that number's **own device**. Sometimes that is not what you want — the number is already in use on a phone, or the verification SMS never arrives. For those cases whalibmob can instead connect over a **WebSocket** and link itself to an account that already exists, exactly the way the WhatsApp Web and desktop clients do.
10
10
 
11
- There are two ways to link, and they reach the same place:
11
+ There are three ways to link, and they reach the same place:
12
12
 
13
13
  - **Pairing code** — whalibmob gives you an 8-character code, the owner types it into their phone.
14
14
  - **QR code** — whalibmob draws a QR, the owner scans it with the phone's camera.
15
+ - **Passkey** — the account's passkey signs a challenge, and the owner confirms a short code. Only offered by WhatsApp for accounts that have a passkey; see [Linking with a Passkey](#linking-with-a-passkey).
15
16
 
16
- Both link the number as a companion device, both leave the whole library working the same afterwards — same client, same methods, same events. The only difference is what the owner does: type a code, or scan a square.
17
+ All of them link the number as a companion device, and all leave the whole library working the same afterwards — same client, same methods, same events. The only difference is what the owner does: type a code, scan a square, or approve with a passkey.
17
18
 
18
19
  > [!IMPORTANT]
19
20
  > The two modes are independent. SMS registration is unchanged and still the default; nothing about it is affected by linking. A single number can even have both a registered session and a linked session — they are stored in separate files and never share state.
@@ -43,7 +44,8 @@ client.on('connected', () => {
43
44
  // open the WebSocket connection as a companion
44
45
  await client.connectWeb('919634847671', { syncFullHistory: true })
45
46
 
46
- // ask for the code — returns immediately, the link completes later
47
+ // ask for the code — resolves once the server has accepted the request;
48
+ // the link completes later, when the owner types it in
47
49
  const code = await client.requestPairingCode('919634847671')
48
50
  console.log('enter this on the phone:', code) // e.g. "K7M2QX4B"
49
51
  ```
@@ -52,6 +54,14 @@ On the phone that owns the number:
52
54
 
53
55
  **WhatsApp → Settings → Linked Devices → Link a device → Link with phone number instead**, then type the code.
54
56
 
57
+ `requestPairingCode()` waits for the server's answer before it hands the code out, so a code you are given is one the server is holding. If the server refuses the request, the call throws instead of returning a code that could never work:
58
+
59
+ | `err.code` | Meaning |
60
+ |---|---|
61
+ | `PAIRING_CODE_REFUSED` | The server answered with an error. `err.serverCode` is its code: `400` means the request was not accepted (usually the number, or a `browser` name it does not recognise), `429` that too many codes were asked for and you should wait. |
62
+ | `PAIRING_CODE_NO_RESPONSE` | No answer within 15 seconds, or the connection closed first. |
63
+ | `PAIRING_CODE_NO_REF` | The answer did not carry the reference a code is tied to. |
64
+
55
65
  ### Linking by QR Code
56
66
 
57
67
  The QR path is the scan-to-connect alternative. You **do not** request a pairing code — you just connect and listen for the `qr` event. Because no code is asked for, the server volunteers a QR instead, and whalibmob turns it into a ready-to-render string:
@@ -84,13 +94,52 @@ On the phone that owns the number:
84
94
 
85
95
  **WhatsApp → Settings → Linked Devices → Link a device**, then point the camera at the QR.
86
96
 
87
- The `qr` string is what a WhatsApp camera reads: `ref,noise,identity,advSecret,platformId` — a one-time ref plus this client's public keys, comma-joined, the same fields WhatsApp Web itself renders. It rotates on its own (about a minute for the first, then shorter) until the account is scanned or the refs run out. `qrcode-terminal` is optional — without it you get the raw string on `qr` and can render it however you like (a PNG, a web page, an image in a chat). To emit the QR as a `wa.me/settings/linked_devices#…` link instead of the bare fields, pass `{ qrWrapUrl: true }` to `connectWeb`.
97
+ The `qr` string is what a WhatsApp camera reads: `ref,noise,identity,advSecret,platformId` — a one-time ref plus this client's public keys, comma-joined, the same fields WhatsApp Web itself renders. The server can ask for the secret in it to be replaced while a QR is on screen; when it does, `qr` fires again for the same ref with the new string and the time it has left, so always draw the latest one. It rotates on its own (about a minute for the first, then shorter) until the account is scanned or the refs run out. `qrcode-terminal` is optional — without it you get the raw string on `qr` and can render it however you like (a PNG, a web page, an image in a chat). To emit the QR as a `wa.me/settings/linked_devices#…` link instead of the bare fields, pass `{ qrWrapUrl: true }` to `connectWeb`.
88
98
 
89
99
  Everything after the scan is identical to the pairing-code path: `paired`, a stream restart, then `connected`.
90
100
 
91
- ### After the link — same for both paths
101
+ ### Linking with a Passkey
102
+
103
+ An account that has a passkey can be linked with it. This is not something you ask for: WhatsApp offers it, to an unlinked companion, by sending a WebAuthn challenge. whalibmob surfaces that as `passkey_request`, and from there you supply the one thing it cannot do itself — getting an authenticator to sign.
104
+
105
+ ```js
106
+ client.on('passkey_request', async ({ publicKey }) => {
107
+ // publicKey is a WebAuthn request in its JSON form: challenge, rpId,
108
+ // allowCredentials..., binary members as base64url. Hand it to whatever
109
+ // holds the account's passkey. In a browser that is:
110
+ //
111
+ // const options = PublicKeyCredential.parseRequestOptionsFromJSON(publicKey)
112
+ // const credential = await navigator.credentials.get({ publicKey: options })
113
+ // const assertion = credential.toJSON()
114
+ const assertion = await askMyAuthenticator(publicKey)
115
+ await client.sendPasskeyResponse(assertion)
116
+ })
117
+
118
+ client.on('passkey_confirmation', async ({ code, skipHandoffUx, autoConfirmed }) => {
119
+ if (autoConfirmed) return // nothing to compare, already sent
120
+ console.log('check that the phone shows', code) // e.g. "K7M2-QX4B"
121
+ if (await ownerSaysItMatches()) await client.sendPasskeyConfirmation()
122
+ })
123
+
124
+ client.on('passkey_error', ({ err, continuation }) => console.error('passkey:', err.message))
125
+ client.on('paired', (p) => console.log('linked as', p.jid))
126
+
127
+ await client.connectWeb('919634847671')
128
+ ```
129
+
130
+ `sendPasskeyResponse()` takes a WebAuthn assertion: `{ id, rawId, type, response: { clientDataJSON, authenticatorData, signature, userHandle } }`. The binary members may be bytes (`Buffer`, `Uint8Array`, `ArrayBuffer`) or base64url or base64 text, so the object `credential.toJSON()` returns in a browser can be passed as it is.
131
+
132
+ The code in `passkey_confirmation` is the safeguard. Each side commits to a random value before it sees the other's, and the code is derived from both, so the same eight characters on both screens mean the two devices talked to each other and not to something in between. When the phone had this client's QR in front of it moments before, that comparison is unnecessary: `skipHandoffUx` is `true`, whalibmob sends the confirmation itself and `autoConfirmed` says so. Pass `{ passkeyAutoConfirm: false }` to `connectWeb` to always confirm yourself.
133
+
134
+ A passkey offer does not take the QR away. The secret inside it is replaced when the offer arrives, so `qr` fires again with a fresh string just before `passkey_request`, and scanning that one still links. An offer you do not answer can simply be ignored.
135
+
136
+ The passkey belongs to the account and stays with whoever holds it: whalibmob never sees it, only the signed answer you pass in. There is no authenticator in the library, and none in the CLI.
92
137
 
93
- A few seconds after the code is accepted (or the QR is scanned) you will see `paired`, the server restarts the stream, and `connected` fires on the new connection. From that point on everything else in this document applies unchanged:
138
+ A step that fails raises `passkey_error` (for the server's pushes) or throws from the call you made, with an `err.code`: `PASSKEY_REFUSED` (the server said no; `err.serverCode` and `err.serverText` say why), `PASSKEY_NO_RESPONSE`, `PASSKEY_NO_REF`, `PASSKEY_NOT_PENDING`, `PASSKEY_NOT_READY` (confirmation asked before `passkey_confirmation`), `PASSKEY_BAD_CONTINUATION`, `PASSKEY_ALREADY_LINKED`, `PASSKEY_NOT_CONNECTED`, `PASSKEY_WRONG_MODE`.
139
+
140
+ ### After the link — same for every path
141
+
142
+ A few seconds after the code is accepted (the QR is scanned, or the passkey link is confirmed) you will see `paired`, the server restarts the stream, and `connected` fires on the new connection. From that point on everything else in this document applies unchanged:
94
143
 
95
144
  ```js
96
145
  await client.sendText('919876543210', 'sent from a linked device')
@@ -123,10 +172,13 @@ const code = await client.requestPairingCode('919634847671', 'MYCODE12')
123
172
  ```js
124
173
  await client.connectWeb(phone, {
125
174
  syncFullHistory: true, // ask the phone for full history (default true)
126
- browser: ['Ubuntu', 'Chrome', '120.0.0.0'] // what the owner sees in Linked Devices
175
+ browser: ['Ubuntu', 'Chrome', '120.0.0.0'], // what the owner sees in Linked Devices
176
+ prePair: ({ jid, platform }) => jid.startsWith('919634847671') // last word on a link
127
177
  })
128
178
  ```
129
179
 
180
+ `prePair` is called once the phone has authorised this device and its proof has been verified, just before the link is confirmed. It receives `{ jid, lid, platform, businessName }`; return `false` (or a promise of it) and the link is refused, the server is told, and nothing is saved. Use it when the number that ends up linked matters, since the owner of *any* account can scan a QR you show.
181
+
130
182
  `browser` is `[os, client, version]`. The second element decides the device icon shown on the phone — `Chrome`, `Firefox`, `Safari`, `Edge`, `Opera`, `Desktop` are all recognised.
131
183
 
132
184
  ### Events Specific to Linking
@@ -137,6 +189,10 @@ await client.connectWeb(phone, {
137
189
  | `qr` | a QR is ready to render — `{ qr, ref, ttlMs, remaining }`; fires again on each rotation |
138
190
  | `qr_timeout` | the QR refs ran out — reconnect for a fresh set |
139
191
  | `paired` | the owner accepted the code or scanned the QR — `{ jid, lid, deviceIndex, platform }` |
192
+ | `pair_error` | the phone authorised a link and it was turned down here — `{ jid, lid, platform, err }`; `error` fires too |
193
+ | `passkey_request` | the account can be linked with a passkey — `{ publicKey }` |
194
+ | `passkey_confirmation` | the code to compare with the phone — `{ code, skipHandoffUx, autoConfirmed }` |
195
+ | `passkey_error` | a passkey step failed — `{ err, continuation }` |
140
196
  | `restart_required` | the server is restarting the stream after pairing (normal; the reconnect is automatic) |
141
197
  | `pair_device` | the raw QR reference strings, before they are turned into `qr` — `{ refs }` |
142
198
  | `history_sync` | a chunk of history arrived from the phone |
@@ -210,7 +266,11 @@ whalibmob attaches it automatically whenever a `pkmsg` is in the stanza, in dire
210
266
 
211
267
  The pairing code is a password, not an identifier. It is never sent to the server in the clear. Both sides run it through PBKDF2-SHA256 (131,072 iterations) to derive a key that wraps the ephemeral public keys they exchange, then combine two Diffie-Hellman results into `adv_secret` — the key every later proof of account membership is authenticated under.
212
268
 
213
- whalibmob verifies three things before accepting a link, and refuses it outright if any fails: the HMAC over the signed device identity, the account signature over its own identity key, and the device slot it was issued. A wrong code cannot produce a working link, and a tampered response cannot either.
269
+ whalibmob verifies three things before accepting a link, and refuses it outright if any fails: the HMAC over the signed device identity, the account signature over its own identity key, and the device slot it was issued. A wrong code cannot produce a working link, and a tampered response cannot either. A refusal is also sent to the server, with the reason (`hmac-mismatch`, `signature-mismatch` or `internal-error`), so the phone stops waiting rather than timing out.
270
+
271
+ The notification that completes a code has to name the reference the server issued for that code. One that names another is ignored: it belongs to an earlier request, and acting on it would replace the secret the pending code is tied to.
272
+
273
+ Once a link is accepted, the key that signed it — the phone's own identity key — is recorded as the identity of the account's device 0. The first encrypted session the phone opens with this device is then checked against the key that authorised the link.
214
274
 
215
275
  ## Companion Mode — Node.js API
216
276
 
@@ -290,7 +350,9 @@ Run it once, type the code into the phone, and it is linked. Run it again and it
290
350
  | Method | Description |
291
351
  |---|---|
292
352
  | `client.connectWeb(phone, opts?)` | Open the companion connection. Resolves as soon as the encrypted channel is up when unlinked, or after `<success>` when already linked. |
293
- | `client.requestPairingCode(phone?, customCode?)` | Ask for an 8-character code. Returns it immediately; the link completes later. Throws if the session is already linked. |
353
+ | `client.requestPairingCode(phone?, customCode?)` | Ask for an 8-character code. Resolves once the server has accepted the request; the link completes later. Throws if the server refuses it, or if the session is already linked. |
354
+ | `client.sendPasskeyResponse(assertion)` | Answer a `passkey_request` with the assertion an authenticator produced. Resolves once the server has taken it. |
355
+ | `client.sendPasskeyConfirmation()` | Finish a passkey link once the owner has confirmed the code. Not needed when `passkey_confirmation` says `autoConfirmed`. |
294
356
  | `client.disconnect()` | Close the connection. The link survives — reconnect with `connectWeb()`. |
295
357
  | `client.logout()` | Unlink this device from the account, the way the Linked Devices screen does, then disconnect. The link does **not** survive — the next `connectWeb()` pairs afresh. Nothing on disk is deleted; remove the session directory yourself if you want the keys gone. |
296
358
 
@@ -302,6 +364,10 @@ Run it once, type the code into the phone, and it is linked. Run it again and it
302
364
  | `browser` | `['Ubuntu', 'Chrome', '120.0.0.0']` | `[os, client, version]`. The second element picks the icon shown under Linked Devices: `Chrome`, `Firefox`, `Safari`, `Edge`, `Opera`, `Desktop`. |
303
365
  | `version` | fetched live | Web client revision to announce, e.g. `[2, 3000, 1035194821]`. Set it to pin one. |
304
366
  | `fetchVersion` | `true` | Set `false` to skip the live lookup and use the pinned fallback. |
367
+ | `qrWrapUrl` | `false` | Emit the QR as a `wa.me/settings/linked_devices#…` link instead of the bare fields. |
368
+ | `prePair` | none | `({ jid, lid, platform, businessName }) => boolean`. Called before a link is confirmed; `false` refuses it. |
369
+ | `passkeyAutoConfirm` | `true` | Send the passkey confirmation without asking when the phone needs no code comparison. |
370
+ | `lidDbMigrated` | `true` | Announce at login that chats are stored by LID, as current WhatsApp clients do. Set `false` if your own storage is still keyed by phone number. |
305
371
 
306
372
  #### The Announced Version
307
373
 
@@ -337,6 +403,10 @@ Every event from the SMS primary API fires here too — `message`, `receipt`, `p
337
403
  |---|---|---|
338
404
  | `pairing_code` | `{ code, phoneNumber }` | a code was requested |
339
405
  | `paired` | `{ jid, lid, deviceIndex, platform }` | the owner accepted the code |
406
+ | `pair_error` | `{ jid, lid, platform, err }` | the phone authorised a link and it was turned down here: a proof that did not verify, or `prePair` returning `false`. `error` fires too |
407
+ | `passkey_request` | `{ publicKey }` | the account can be linked with a passkey; `publicKey` is the WebAuthn request, as JSON |
408
+ | `passkey_confirmation` | `{ code, skipHandoffUx, autoConfirmed }` | the passkey exchange produced the code to compare with the phone |
409
+ | `passkey_error` | `{ err, continuation }` | a passkey step failed. `continuation` is `false` for the request itself, `true` for the step after your response |
340
410
  | `restart_required` | `{ reason }` | the server is restarting the stream after pairing — the reconnect is automatic |
341
411
  | `pair_device` | `{ refs }` | the QR path produced reference strings |
342
412
  | `history_sync` | `{ syncTypeName, chats, contacts, pushNames, merged }` | a chunk of history arrived |
package/docs/messaging.md CHANGED
@@ -309,6 +309,88 @@ The key is derived from the poll id, the poll's sender and the voter, so a vote
309
309
  on someone else's poll needs their `encKey`, which only arrives if they sent the
310
310
  poll to you: read it off `msg.decoded.encKey` on the poll message itself.
311
311
 
312
+ ### Vote on a Poll
313
+
314
+ ```js
315
+ // poll: a poll message you received (or one you sent with sendPoll)
316
+ client.on('message', async (msg) => {
317
+ if (msg.decoded?.type !== 'poll') return
318
+ await client.sendPollVote(msg.chat, {
319
+ id: msg.id,
320
+ sender: msg.participant || msg.from, // who sent the poll
321
+ encKey: msg.decoded.encKey // the poll's message secret
322
+ }, ['Rust']) // option texts; [] clears your vote
323
+ })
324
+
325
+ // a poll you sent yourself
326
+ const poll = await client.sendPoll(jid, 'Language?', ['Rust', 'Go'], 1)
327
+ await client.sendPollVote(jid, { id: poll.id, fromMe: true, encKey: poll.encKey }, ['Go'])
328
+ ```
329
+
330
+ The vote is encrypted under the poll's secret, so `encKey` is required: there is no way to vote on a poll whose message you never received. In a group the vote names the poll's author, which is why `sender` is needed for somebody else's poll.
331
+
332
+ ### Pin a Message
333
+
334
+ ```js
335
+ // pin for everyone, for 7 days (the default); 86400 and 2592000 are the other choices
336
+ await client.pinMessage(jid, { id: 'MSGID123', fromMe: true }, { durationSecs: 604800 })
337
+
338
+ // in a group, somebody else's message needs its sender
339
+ await client.pinMessage(groupJid, { id: 'MSGID456', fromMe: false, participant: '919634847671@s.whatsapp.net' })
340
+
341
+ await client.unpinMessage(jid, { id: 'MSGID123', fromMe: true })
342
+ ```
343
+
344
+ An incoming pin decodes as `{ type: 'pinInChat', pinned, targetKey }`, and a "keep in chat" on a disappearing message as `{ type: 'keepInChat', kept, targetKey }`.
345
+
346
+ ### Encrypted Reactions, Comments, Event Responses and Edits
347
+
348
+ Some messages act on another message and are encrypted under *that* message's secret rather than sent in the clear: a reaction or a comment in a community announcement group, a response to an event, an encrypted edit. They decode as `encReaction`, `encComment`, `encEventResponse` and `secretEncrypted`, each with a `targetKey` naming the message it belongs to.
349
+
350
+ To read one you need the target message's secret. It is on the target when it arrives, as `decoded.messageSecret`, so keep it by message id:
351
+
352
+ ```js
353
+ const secrets = new Map() // message id -> 32-byte secret
354
+
355
+ client.on('message', (msg) => {
356
+ const d = msg.decoded
357
+ if (!d) return
358
+ if (d.messageSecret) secrets.set(msg.id, d.messageSecret)
359
+
360
+ const secret = d.targetKey && secrets.get(d.targetKey.id)
361
+ if (!secret) return
362
+
363
+ if (d.type === 'encReaction') {
364
+ const r = client.decryptReaction(msg, { messageSecret: secret })
365
+ console.log(msg.participant, 'reacted', r.text) // '' means the reaction was removed
366
+ } else if (d.type === 'encComment') {
367
+ const c = client.decryptComment(msg, { messageSecret: secret })
368
+ console.log('comment:', c.decoded?.text)
369
+ } else if (d.type === 'encEventResponse') {
370
+ const e = client.decryptEventResponse(msg, { messageSecret: secret })
371
+ console.log(e.response) // 'going' | 'not_going' | 'maybe'
372
+ } else if (d.type === 'secretEncrypted') {
373
+ const e = client.decryptSecretMessage(msg, { messageSecret: secret })
374
+ console.log(e.secretType, e.decoded?.text) // 'Message Edit', the new text
375
+ }
376
+ })
377
+ ```
378
+
379
+ Every result also carries `plaintext`, the protobuf that was inside, for anything the built-in decoder does not name. The key depends on who sent the target and who sent the add-on; both are read off the message, and `opts.targetSender` / `opts.sender` override them when you know better. A wrong secret or a wrong sender throws rather than returning garbage.
380
+
381
+ ### Send a Message You Encoded
382
+
383
+ For a message type this library has no method for, encode the `Message` protobuf yourself and hand over the bytes. It is encrypted and delivered exactly like the built-in sends.
384
+
385
+ ```js
386
+ // messageBytes: an encoded WhatsApp `Message`, from your own protobuf tooling
387
+ await client.sendRawMessage(jid, messageBytes) // a text-like message
388
+ await client.sendRawMessage(jid, messageBytes, { type: 'media', mediaType: 'image' })
389
+ await client.sendRawMessage(jid, messageBytes, { type: 'poll', pollType: 'creation' })
390
+ ```
391
+
392
+ The options describe what the stanza says in the clear, which the server reads without decrypting anything: `type` (`text`, `media`, `poll`, `reaction`), `mediaType` for media (`image`, `video`, `audio`, `ptt`, `document`, `sticker`, `gif`, `vcard`…), `pollType`, `edit` (`'1'` edit, `'2'` pin, `'7'` revoke, `'8'` admin revoke) and `hide` (show nothing if it cannot be decrypted). A message that says one thing in the stanza and another inside may be dropped by the recipient, so set them to match.
393
+
312
394
  ### Quoted Reply
313
395
 
314
396
  Send a text message that quotes (replies to) a specific earlier message. The recipient sees the original message highlighted above your reply.
@@ -606,6 +688,31 @@ await client.starMessage('MSGID123', '919634847671', true) // yours
606
688
  await client.unstarMessage('MSGID123', '919634847671', false) // theirs
607
689
  ```
608
690
 
691
+ ### Labels
692
+
693
+ Labels are the coloured tags a WhatsApp Business account files chats under. A label is identified by an id you choose; create or change it, then put it on a chat or on one message.
694
+
695
+ ```js
696
+ await client.editLabel('5', { name: 'VIP', color: 3 }) // create, rename or recolour
697
+ await client.labelChat('919634847671', '5') // tag a chat
698
+ await client.labelMessage('919634847671', '5', 'MSGID123') // tag one message
699
+ await client.labelChat('919634847671', '5', false) // remove the tag
700
+ await client.editLabel('5', { deleted: true }) // delete the label
701
+ ```
702
+
703
+ ### Delete a Message for Me
704
+
705
+ Removes one message from this account's devices only; nobody else's copy changes. This is not `deleteMessage(..., true)`, which revokes it for everyone.
706
+
707
+ ```js
708
+ await client.deleteMessageForMe('919634847671', 'MSGID123', true, {
709
+ timestamp: 1700000000, // the message's time, unix seconds
710
+ deleteMedia: true
711
+ })
712
+ ```
713
+
714
+ Both of these are app-state changes, so they need a session that can sync app state (`client.canSyncAppState()`), and they throw when it cannot. Changes made on the phone arrive as `label_edit`, `label_association`, `message_deleted_for_me`, `status_muted` and `unarchive_chats_setting` — see [All Events](events-history.md#connection-health-sync-and-account-events).
715
+
609
716
  <a id="app-state-sync"></a>
610
717
 
611
718
  ### Reading Changes Made Elsewhere