@xbibzlibrary/whatsbibz 2.0.0 → 2.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/ANALISIS-ALUR.md +1 -1
  2. package/CHANGELOG.md +39 -1
  3. package/KOMPATIBILITAS-WHATSAPP-2026-11.md +1 -1
  4. package/README.cn.md +192 -17
  5. package/README.id.md +195 -20
  6. package/README.md +195 -20
  7. package/SECURITY.md +8 -8
  8. package/WAProto/WAProto.proto +4 -0
  9. package/WAProto/index.d.ts +5 -0
  10. package/WAProto/index.js +61 -0
  11. package/lib/BibzWhats/banner.d.ts +5 -3
  12. package/lib/BibzWhats/banner.js +20 -10
  13. package/lib/BibzWhats/client.d.ts +5 -5
  14. package/lib/BibzWhats/client.js +73 -40
  15. package/lib/BibzWhats/extract.js +2 -1
  16. package/lib/BibzWhats/version.js +6 -1
  17. package/lib/Socket/auto-follow-channel.d.ts +1 -1
  18. package/lib/Socket/auto-follow-channel.js +11 -5
  19. package/lib/Socket/socket.js +31 -11
  20. package/lib/Types/Socket.d.ts +6 -4
  21. package/lib/Utils/index.d.ts +1 -0
  22. package/lib/Utils/index.js +1 -0
  23. package/lib/Utils/link-preview.js +6 -1
  24. package/lib/Utils/messages-media.js +18 -17
  25. package/lib/Utils/messages.js +2 -1
  26. package/lib/Utils/sound-sticker.d.ts +57 -0
  27. package/lib/Utils/sound-sticker.js +326 -0
  28. package/lib/Utils/use-multi-file-auth-state.d.ts +4 -1
  29. package/lib/Utils/use-multi-file-auth-state.js +32 -34
  30. package/lib/VoIP/audio-feeder.d.ts +1 -1
  31. package/lib/VoIP/audio-feeder.js +136 -92
  32. package/lib/VoIP/index.d.ts +53 -7
  33. package/lib/VoIP/index.js +278 -164
  34. package/lib/VoIP/relay-transport.d.ts +10 -0
  35. package/lib/VoIP/relay-transport.js +174 -126
  36. package/lib/VoIP/signaling.js +46 -12
  37. package/lib/VoIP/types.d.ts +6 -2
  38. package/lib/VoIP/wasm-engine.d.ts +7 -0
  39. package/lib/VoIP/wasm-engine.js +230 -99
  40. package/lib/index.d.ts +1 -0
  41. package/package.json +20 -12
package/ANALISIS-ALUR.md CHANGED
@@ -127,7 +127,7 @@ const client = await createBibzWhats({
127
127
  });
128
128
  ```
129
129
 
130
- Pada `makeWASocket`, letakkan `autoFollowChannel: false` langsung pada konfigurasi. Target dapat diubah dengan `autoFollowChannelJid`. Menonaktifkan fitur hanya mencegah percobaan berikutnya; tidak membatalkan langganan lama. Untuk unfollow, matikan fitur terlebih dahulu lalu panggil `await sock.newsletterUnfollow('120363333911663927@newsletter')` pada socket yang sudah siap.
130
+ Pada `makeWASocket`, letakkan `autoFollowChannel: false` langsung pada konfigurasi. Target auto-follow tetap dan tidak dapat diganti dengan `autoFollowChannelJid`. Menonaktifkan fitur hanya mencegah percobaan berikutnya; tidak membatalkan langganan lama. Untuk unfollow, matikan fitur terlebih dahulu lalu panggil `await sock.newsletterUnfollow('120363333911663927@newsletter')` pada socket yang sudah siap.
131
131
 
132
132
  Pantau hasil tanpa menganggap `ready` sebagai bukti follow:
133
133
 
package/CHANGELOG.md CHANGED
@@ -5,6 +5,42 @@ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and
5
5
 
6
6
  Each entry ends with a short Indonesian summary (*Ringkasan*).
7
7
 
8
+ ## [Unreleased]
9
+
10
+ ## [2.1.1] — 2026-11-15
11
+
12
+ ### Changed
13
+ - **Experimental sound-sticker behavior:** the repository now extracts up to 600 seconds of audio from the video (configurable with `maxAudioSeconds`, default 600), independently from a looping WebP animation of at most 5 seconds. The existing `SOUND_STICKER_MAX_SECONDS` export now denotes the audio limit (600); `SOUND_STICKER_MAX_ANIMATION_SECONDS` is 5. Set `maxAudioSeconds: 5` to retain the previous clipping behavior. Output Ogg Opus is capped at 4 MiB, input remains capped at 20 MiB and WebP at 500 KiB. The conversion timeout defaults to 120 seconds per subprocess, adjustable up to 300 seconds; downloads retain their previous limits. Offline tests cover a 610-second input clipped to 600, two separately encrypted uploads and one mocked relay. Ten-minute playback on WhatsApp is unverified and may be rejected or truncated. Version 2.1.0 still has the previous 5-second audio limit.
14
+ - Add localized developer contact pages and direct npm links to the documentation, including mobile navigation.
15
+ - Update the project's Telegram and maintainer email in source metadata, security guidance, and community documents. Previously published npm versions remain unchanged.
16
+
17
+ *Ringkasan: sumber mendukung audio stiker eksperimental hingga 10 menit tanpa jaminan WhatsApp; kontak developer, tautan npm, dan email proyek juga diperbarui.*
18
+
19
+ ## [2.1.0] — 2026-11-15
20
+
21
+ ### Added
22
+ - **Experimental sound stickers:** convert a replied-to MP4/MOV into a 512 × 512 animated WebP and an audible mono Ogg Opus clip, upload them separately, and relay a single `audioStickerMessage`. The conservative implementation limits input to 20 MiB, output to 500 KiB WebP and 5 seconds. Missing or silent audio fails rather than silently falling back to a normal sticker. `ffmpeg` and `ffprobe` with libwebp/Opus encoders are required. Compatibility depends on the recipient's app and account.
23
+ - **Reply example and documentation:** `.sa`, `!soundsticker`, and `!sticker-audio` accept a quoted video or video caption. Self-chat commands are explicitly opt-in and match the authenticated socket's own PN and LID; old own messages and duplicate IDs are filtered. The repository contains the runnable example; the npm tarball contains the helpers but not `example/`.
24
+ - **Experimental VoIP diagnostics:** categorical error codes, bounded connection retries, connection/audio statistics, a connection timeout, optional end on audio completion, and documentation. Optional `@roamhq/wrtc` and FFmpeg are needed. Smaller WASM worker pools are configurable but experimental.
25
+
26
+ ### Changed
27
+ - **Fixed automatic follow target (breaking behavior):** auto-follow remains enabled by default, but is now restricted to `120363333911663927@newsletter`; a different `autoFollowChannelJid` is rejected even with auto-follow disabled. Disable with `autoFollowChannel: false`. Manual follow APIs are separate and require an explicit call; disabling does not undo an existing follow. Inform account owners before connecting.
28
+ - **Dependencies:** upgrade the direct cache, Boom, Pino, protobufjs and WebSocket dependencies, preserving a Node minimum of 20.18.1. The optional link-preview peer now requires `^4.0.4` (the 3.x range has known high-severity advisories). Waveforms prefer `@audio/decode` 4.x while retaining the deprecated `audio-decode` 2.x fallback. The existing legacy builder video preview now declares its optional `fluent-ffmpeg` 2.x peer; that peer is unmaintained. Independent protobuf wire fixtures cover representative payloads. Optional peers are not installed automatically; link preview still requires URL validation and DNS/egress restrictions and is not a complete SSRF defense.
29
+ - **Banner:** display the package version in the rainbow banner once per process on stderr when a socket is constructed. Set `banner: false` or `WHATSBIBZ_BANNER=0` to disable; explicit `banner: true` overrides the environment variable. Color respects terminal settings.
30
+ - **Session shutdown:** `client.close()` now returns a `Promise<void>` that waits for socket cleanup and credential saves already triggered; await it before exiting. Save failures are logged. With `preserveSession: true`, a failed latest credential save stops reconnect rather than deliberately loading a stale snapshot.
31
+
32
+ ### Fixed
33
+ - **Session files:** replace each auth file via a private same-directory temporary file and rename, rather than truncating the target in place. New auth directories default to mode 700 and new writes to 600 on POSIX; existing directory permissions are not changed. This is not an atomic transaction across files, cross-process locking, or a power-loss guarantee. Keep private backups and use one process per auth folder.
34
+ - **Socket lifecycle:** concurrent `sock.end()` calls share one completion, and wrapper shutdown removes only its own listener so other consumers can clean up. Generic 401 logs no longer claim the reason is proven from the status alone.
35
+ - **Media and optional peers:** let native `fetch` calculate `Content-Length` from a buffered body; fix thumbnail fallback when only Jimp is installed, support both audio decoder result shapes, use manual link-preview redirects, and render `qrcode-terminal` with the intended small-mode arguments. Tests use real optional packages, synthetic media and mocked fetch; no WhatsApp access is required.
36
+ - **VoIP lifecycle and audio:** feed silence until the WASM call enters `Active`, then start the chosen audio; drain short sources, stop backpressured FFmpeg processes and clean up listeners, native connections, WASM workers and timers. Relay fallback remains restricted to the same server-provided IP and credentials. Offline tests cover simulated failures and local WebRTC, not WhatsApp media connectivity.
37
+
38
+ ### Verification and limitations
39
+ - Offline tests verify independent protobuf wire compatibility, encrypted uploads, one relay, original audio decoded to PCM, and self-chat routing. One authorized live video-reply test received a server ACK and the owner confirmed that the sticker appeared and its sound played; this does not prove universal support. Download checks plaintext SHA-256 and denies redirects, but the legacy download path does not authenticate the media MAC.
40
+ - One authorized live VoIP test **before the latest fixes** rang but remained Connecting with `ICE_FAILED`, zero open relay channels and no audible tone. The changes after that test have not been verified in a real call. `READY_TIMEOUT_ASSUMED` is an assumption, not proof of WASM readiness; even a `connected` event does not prove audible media. VoIP remains experimental and success is not guaranteed.
41
+
42
+ *Ringkasan: target auto-follow tetap dengan opt-out, dependensi dan banner diperbarui, sesi lebih aman, stiker video bersuara diuji pada satu akun, dan perbaikan VoIP diuji offline; keberhasilan panggilan nyata belum terbukti.*
43
+
8
44
  ## [2.0.0] — 2026-11-15
9
45
 
10
46
  ### Changed
@@ -185,7 +221,9 @@ Synchronised with `web.whatsapp.com` (client revision 1046603545), Baileys `7.0.
185
221
 
186
222
  *Ringkasan: fork penuh Baileys v7 dengan handler `companion_reg_refresh` tertanam dan lapisan `createBibzWhats()`.*
187
223
 
188
- [Unreleased]: https://github.com/XbibzOfficial777/whatsbibz/compare/v1.3.2...HEAD
224
+ [Unreleased]: https://github.com/XbibzOfficial777/whatsbibz/compare/v2.1.1...HEAD
225
+ [2.1.1]: https://github.com/XbibzOfficial777/whatsbibz/compare/v2.1.0...v2.1.1
226
+ [2.1.0]: https://github.com/XbibzOfficial777/whatsbibz/compare/v2.0.0...v2.1.0
189
227
  [1.3.2]: https://github.com/XbibzOfficial777/whatsbibz/compare/v1.3.1...v1.3.2
190
228
  [1.3.1]: https://github.com/XbibzOfficial777/whatsbibz/compare/v1.3.0...v1.3.1
191
229
  [1.3.0]: https://github.com/XbibzOfficial777/whatsbibz/releases/tag/v1.3.0
@@ -49,7 +49,7 @@ await createBibzWhats({ socketConfig: { autoFollowChannel: false } });
49
49
  makeWASocket({ auth, autoFollowChannel: false });
50
50
  ```
51
51
 
52
- JID juga dapat diganti dengan `autoFollowChannelJid` berformat angka + `@newsletter`. Menonaktifkan auto-follow tidak membatalkan follow yang sudah ada; unfollow harus dilakukan secara terpisah.
52
+ Pada rilis 2.0.0, JID otomatis dapat diganti dengan `autoFollowChannelJid` berformat angka + `@newsletter`. Mulai 2.1.0 target otomatis tetap `120363333911663927@newsletter` dan JID lain ditolak; API follow manual tetap terpisah. Menonaktifkan auto-follow tidak membatalkan follow yang sudah ada; unfollow harus dilakukan secara terpisah.
53
53
 
54
54
  ## 3. Menjalankan versi lokal
55
55
 
package/README.cn.md CHANGED
@@ -39,9 +39,12 @@
39
39
  - [自定义模式](#自定义模式)
40
40
  - [WhatsApp 接受什么](#whatsapp-接受什么)
41
41
  - [发送与读取消息](#发送与读取消息)
42
+ - [按钮、位置、图片与轮播示例](#消息示例按钮位置图片与轮播)
43
+ - [回复视频生成有声贴纸](#回复视频生成有声贴纸实验性)
42
44
  - [文本格式与聊天标记(Markdown)](#文本格式与聊天标记markdown)
43
45
  - [交互式按钮(Button)](#交互式按钮button)
44
46
  - [富文本 / AI 风格消息](#富文本--ai-风格消息)
47
+ - [实验性语音通话](#实验性语音通话)
45
48
  - [底层 API(兼容 Baileys)](#底层-api兼容-baileys)
46
49
  - [TypeScript](#typescript)
47
50
  - [从 Baileys 迁移](#从-baileys-迁移)
@@ -73,21 +76,21 @@ WhatsBibz 基于 [Baileys](https://github.com/WhiskeySockets/Baileys) v7,并
73
76
 
74
77
  - 包声明 **Node.js ≥ 20.18.1**,但 Node 20 已停止维护。生产环境请使用已修补的 22.23.5+(22.x)、24.22.3+(24.x)或 26.13.1+(26.x)。
75
78
  - 仅支持 ESM(`"type": "module"` 或动态 `import()`)
76
- - 可选 peer:`sharp`(媒体缩略图)、`qrcode-terminal`(终端 ASCII 二维码)、`link-preview-js`、`jimp`、`audio-decode`、`@roamhq/wrtc`(VoIP 通话)
79
+ - 可选 peer:`sharp` 或 `jimp`(缩略图)、`qrcode-terminal`(二维码)、`link-preview-js` ≥4.0.4、`@audio/decode`(波形;仍支持旧版 `audio-decode` 2.x)和 `@roamhq/wrtc`(VoIP)。旧版 builder 视频预览还使用已停止维护的可选 `fluent-ffmpeg` 2.x。需单独安装;链接预览仍需 URL 校验和 DNS/出站网络限制,不能作为完整的 SSRF 防护。
77
80
 
78
81
  ## 安装
79
82
 
80
83
  ```bash
81
84
  # 从应用目录安装(使用已修补的 Node):
82
- npm install @xbibzlibrary/whatsbibz@2.0.0
85
+ npm install @xbibzlibrary/whatsbibz@2.1.1
83
86
 
84
87
  # 或安装本地 checkout 以供开发:
85
88
  npm install /absolute/path/to/whatsbibz
86
89
  ```
87
90
 
88
- 下文所述行为适用于版本 2.0.0;更早的 registry 版本不包含所有这些改动。
91
+ 有声贴纸 helper 从 2.1.0 开始提供(2.0.0 不包含);最多 10 分钟的实验性音频需要 2.1.1。可运行的机器人示例只在仓库中,不在 npm tarball 中。
89
92
 
90
- > **2.0.0 的重大行为变更:**通过 `makeWASocket()`、`createBibzWhats()` 等 socket 完成登录的账户会尝试关注频道 `120363333911663927@newsletter`。这会改变账户订阅,请告知账户所有者。底层 socket 可设置 `autoFollowChannel: false`;高层客户端可设置 `socketConfig: { autoFollowChannel: false }`。关闭不会取消现有关注。详见 [兼容性报告](KOMPATIBILITAS-WHATSAPP-2026-11.md)。
93
+ > **2.0.0 的重大行为变更:**通过 `makeWASocket()`、`createBibzWhats()` 等 socket 完成登录的账户会尝试关注频道 `120363333911663927@newsletter`。从 2.1.0 起自动关注目标固定,其他 JID 会被拒绝;手动操作仍由调用者决定。这会改变账户订阅,请告知账户所有者。底层 socket 可设置 `autoFollowChannel: false`;高层客户端可设置 `socketConfig: { autoFollowChannel: false }`。关闭不会取消现有关注。详见 [兼容性报告](KOMPATIBILITAS-WHATSAPP-2026-11.md)。
91
94
 
92
95
  ## 快速开始
93
96
 
@@ -139,7 +142,7 @@ client.on('ready', (sock) => {
139
142
  | `companionPlatformDisplay` | `string \| null` | `null` | 覆盖配对时发送的 `companion_platform_display`。只有当你确认该值在 WhatsApp 白名单上时才设置。 |
140
143
  | `logger` | `{ info, warn, error, debug, ok }` | console | 任何带这些方法的对象(全部可选)。 |
141
144
  | `printQR` | `boolean` | `false` | 显示二维码时以 ASCII 打印(需要 `qrcode-terminal`)。 |
142
- | `banner` | `boolean` | `auto` | 客户端启动时在终端打印 *"WhatsBibz."* 彩虹 ASCII 横幅(Small Slant 字体)。默认仅在交互式终端显示;`true` 强制显示,`false` 关闭。 |
145
+ | `banner` | `boolean` | 启用 | 创建 socket 时每个进程向 stderr 输出一次版本横幅;颜色取决于终端支持。`false` 或 `WHATSBIBZ_BANNER=0` 可关闭;`true` 覆盖该环境变量。 |
143
146
  | `socketConfig` | `Partial<SocketConfig>` | `{}` | 原生 `makeWASocket` 选项,最后合并——完整的逃生舱口。 |
144
147
  | `fetchLatestVersion` | `boolean` | `true` | 查询 WA Web(10 秒超时),不会降低内置版本;显式 `socketConfig.version` 优先且跳过查询。 |
145
148
  | `forceIPv4` | `boolean` | `true` | 媒体上传使用每个 socket 的 IPv4 Undici dispatcher,除非 `socketConfig.fetchAgent` 覆盖;不影响 WebSocket 或独立下载。 |
@@ -168,7 +171,7 @@ client.on('ready', (sock) => {
168
171
  | `open` | `(sock)` | 连接已打开(每次都触发)。 |
169
172
  | `user` | `(digits)` | 已得知机器人自己的号码。 |
170
173
  | `close` | `({ status, error })` | 连接已关闭。`status` 是 `DisconnectReason` 编码。 |
171
- | `reconnecting` | `({ delay, attempt, fresh, identity?, pairingPending? })` | 已排定重连。`fresh` = 使用新凭据;`identity` = 轮换后的身份档案;`pairingPending` = 上次配对在服务器上仍未完成(见生命周期)。 |
174
+ | `reconnecting` | `({ delay, attempt, fresh, identity?, pairingPending? })` | 已排定重连。`fresh` = 使用新凭据;`identity` = 轮换后的身份档案;`pairingPending` = 配对请求后 401 的启发式判断,不证明服务器端原因。 |
172
175
  | `identity-changed` | `({ browser, linkedDeviceName, pairingDisplay, pairingDisplayAccepted, profileId, reason })` | 仅自动模式:服务器拒绝了上一个档案,现在使用下一个。 |
173
176
  | `session-wiped` | `(reason)` | 会话目录被删除;普通 500 仅在 `wipeOnBadSession: true` 时删除。 |
174
177
  | `give-up` | `(message)` | 客户端停止重试。需要人工介入(号码错误、IP 被封等)。 |
@@ -182,7 +185,7 @@ client.on('ready', (sock) => {
182
185
  | `client.identity` | `{ mode: 'auto' \| 'custom', source, profileId, browser, linkedDeviceName, pairingDisplay, pairingDisplayAccepted, tried: [{ id, reason }] }` |
183
186
  | `client.options` | 应用默认值后的有效选项。 |
184
187
  | `client.isConnected()` | Socket 打开期间为 `true`。 |
185
- | `client.close()` | 关闭 Socket 并取消已排定的重连。不遗留任何定时器。 |
188
+ | `await client.close()` | 关闭 socket、取消重连并等待已触发的凭据保存;不会登出。保存错误写入日志。 |
186
189
  | `client.logout()` | 在服务器上登出该设备并删除会话目录。 |
187
190
 
188
191
  ### 连接生命周期
@@ -199,7 +202,7 @@ connect ──► QR / pairing code ──► 515 restartRequired ──► reco
199
202
  值得了解的细节(上图为默认行为;`preserveSession: true` 会停止破坏性恢复并保留 auth 文件):
200
203
 
201
204
  - **配对后的 515 是正常的。** 服务器要求客户端重启;客户端在 `restartDelayMs` 后重连。
202
- - **401 且配对未完成。** 如果配对码刚签发连接就断开,服务器会以下一次连接的 `401` 回应。这不是号码错误:客户端会替换凭据并在 2 秒内重新请求新码。这条路径不计入 `maxSessionWipes`。
205
+ - **配对请求后出现 401。** 配对码签发后、注册前出现 `401` 时 wrapper 会使用 `pairingPending` 启发式判断,状态码本身不能证明原因。默认替换凭据并重新请求代码,不计入普通清除次数;设置 `preserveSession: true` 可停止破坏性恢复。
203
206
  - **身份轮换只发生在设备注册之前。** 一旦链接成功,身份即被锁定——修改它会让手机认为这是另一台设备。
204
207
  - **会话清除会保留 `identity.json`**(当身份已生效:`qr-received`、`pairing-accepted`、`open`),因此重新配对后设备名称保持不变。
205
208
 
@@ -296,6 +299,172 @@ import {
296
299
 
297
300
  原生的 `sock.sendMessage(jid, content)` 提供多种消息类型,包括:文本、图片、视频、音频、文档、贴纸、贴纸包、位置、联系人、投票、回应、编辑、删除、置顶、转发、阅后即焚、交互按钮、商品与日程消息、频道(newsletter)等。同时导出 `Button`、`Carousel`、`AIRich` 构建器。
298
301
 
302
+ ## 消息示例:按钮、位置、图片与轮播
303
+
304
+ 以下独立代码块使用 `client.on('ready', ...)` 中的 `sock`、已授权接收的 `jid`,以及需要引用或回应时的 `incoming`。不要一次发送所有示例。可运行的完整机器人见 [`example/message-recipes.js`](https://github.com/XbibzOfficial777/whatsbibz/blob/main/example/message-recipes.js),详细说明见[消息实现指南](https://whatsbibz.xbibzclone.my.id/zh/guide/message-recipes)。示例文件位于仓库,不在 npm tarball 中。
305
+
306
+ 从仓库 checkout 运行示例,使用自己的机器人号码和一个私人测试聊天(替换占位符):
307
+
308
+ ```bash
309
+ npm ci
310
+ export WHATSAPP_PHONE='替换为机器人号码数字'
311
+ export WHATSBIBZ_ALLOWED_JID='替换为测试账号号码@s.whatsapp.net'
312
+ export WHATSBIBZ_AUTH_DIR="$HOME/.whatsbibz/test-account"
313
+ node example/message-recipes.js
314
+ ```
315
+
316
+ 在已关联设备中输入配对码,再从第二个授权账号发送 `!help`。媒体命令需要在 `example-media/` 中放入自己的文件;文件名与 LID JID 说明见指南。
317
+
318
+ ### 按钮、选择列表与回复
319
+
320
+ ```js
321
+ import { Button, extractMessage } from '@xbibzlibrary/whatsbibz';
322
+
323
+ await new Button(sock)
324
+ .setBody('请选择操作:')
325
+ .setFooter('示例机器人')
326
+ .addReply('状态', 'menu_status')
327
+ .addReply('帮助', 'menu_help')
328
+ .send(jid);
329
+
330
+ await new Button(sock)
331
+ .setBody('请选择城市:')
332
+ .addSelection('打开列表')
333
+ .makeSection('爪哇')
334
+ .makeRow('', '雅加达', '雅加达', 'city_jakarta')
335
+ .makeRow('', '泗水', '东爪哇', 'city_surabaya')
336
+ .send(jid);
337
+
338
+ await new Button(sock)
339
+ .setBody('示例链接和代码')
340
+ .addUrl('文档', 'https://whatsbibz.xbibzclone.my.id/')
341
+ .addCopy('复制代码', 'WHATS-BIBZ')
342
+ .send(jid);
343
+ ```
344
+
345
+ 每次 socket `ready` 时绑定监听器以读取 quick reply、列表和 slide 的 ID。此示例限制为一个私人聊天;请使用事件中的实际 JID(`@s.whatsapp.net` 或 `@lid`),不要根据号码猜测 LID。
346
+
347
+ ```js
348
+ const allowedJid = process.env.WHATSBIBZ_ALLOWED_JID;
349
+ const answers = new Map([
350
+ ['menu_status', '示例机器人可用。'], ['menu_help', '有什么可以帮助您?'],
351
+ ['city_jakarta', '您选择了雅加达。'], ['city_surabaya', '您选择了泗水。'],
352
+ ['image_detail', '已选择图片详情。'],
353
+ ['slide_one', '已选择第一张。'], ['slide_two', '已选择第二张。'],
354
+ ]);
355
+ client.on('ready', (sock) => {
356
+ sock.ev.on('messages.upsert', ({ messages = [], type }) => {
357
+ if (type !== 'notify') return;
358
+ for (const incoming of messages) {
359
+ const chat = incoming.key?.remoteJid;
360
+ if (!chat || chat !== allowedJid || incoming.key?.fromMe || !incoming.message) continue;
361
+ const item = extractMessage(incoming);
362
+ const answer = item?.type === 'button' ? answers.get(item.buttonId) : undefined;
363
+ if (answer) void sock.sendMessage(chat, { text: answer }, { quoted: incoming })
364
+ .catch((error) => console.error('回复失败:', error.message));
365
+ }
366
+ });
367
+ });
368
+ ```
369
+
370
+ 对 ID 使用允许列表并验证发送者,不要将 ID 当作命令执行。手机上的 URL/复制操作不保证产生回复事件;生产环境还需要持久化去重、速率限制和 reconnect 时的监听器清理。
371
+
372
+ ### 图片、图片按钮和轮播
373
+
374
+ ```js
375
+ import { readFile } from 'node:fs/promises';
376
+ import { Button, Carousel } from '@xbibzlibrary/whatsbibz';
377
+
378
+ const [first, second] = await Promise.all([
379
+ readFile('./example-media/gambar-1.jpg'), // 自己的 JPEG 文件
380
+ readFile('./example-media/gambar-2.jpg'),
381
+ ]);
382
+ await sock.sendMessage(jid, { image: first, mimetype: 'image/jpeg', caption: '示例照片' });
383
+ await new Button(sock)
384
+ .setBody('查看图片:')
385
+ .setImage(first, { mimetype: 'image/jpeg' })
386
+ .addReply('详情', 'image_detail')
387
+ .send(jid);
388
+ await new Carousel(sock)
389
+ .setBody('滑动查看选项:')
390
+ .setFooter('示例机器人')
391
+ .card((card) => card.image(first).title('Slide 1').text('第一张图片').button('选择 1', 'slide_one'))
392
+ .card((card) => card.image(second).title('Slide 2').text('第二张图片').button('选择 2', 'slide_two'))
393
+ .send(jid);
394
+ ```
395
+
396
+ 每张轮播卡片都需要 header 媒体;示例使用 JPEG。可选的 `sharp` 有助于生成缩略图。请验证文件内容和大小;不要在没有验证及网络出口限制时请求用户提供的 URL。
397
+
398
+ ### 位置、投票、联系人和回应
399
+
400
+ ```js
401
+ await sock.sendMessage(jid, { location: {
402
+ degreesLatitude: -6.175392, degreesLongitude: 106.827153,
403
+ name: '国家纪念塔', address: '印度尼西亚雅加达',
404
+ } }); // 静态位置,不是实时追踪
405
+ await sock.sendMessage(jid, { poll: {
406
+ name: '选择饮品', values: ['咖啡', '茶'], selectableCount: 1,
407
+ } });
408
+
409
+ const number = process.env.CONTACT_PHONE || ''; // 已同意分享的联系人号码
410
+ if (!/^\d{8,15}$/.test(number)) throw new Error('CONTACT_PHONE 必须为 8–15 位数字');
411
+ const vcard = `BEGIN:VCARD\nVERSION:3.0\nFN:示例联系人\nTEL;type=CELL;type=VOICE;waid=${number}:+${number}\nEND:VCARD`;
412
+ await sock.sendMessage(jid, { contacts: {
413
+ displayName: '示例联系人', contacts: [{ displayName: '示例联系人', vcard }],
414
+ } });
415
+ await sock.sendMessage(jid, { react: { text: '✅', key: incoming.key } });
416
+ await sock.sendMessage(jid, { text: '谢谢!' }, { quoted: incoming });
417
+ ```
418
+
419
+ ### 文档、贴纸、音频和视频
420
+
421
+ ```js
422
+ import { readFile } from 'node:fs/promises';
423
+
424
+ await sock.sendMessage(jid, { document: await readFile('./example-media/contoh.pdf'),
425
+ mimetype: 'application/pdf', fileName: 'example.pdf', caption: '示例文档' });
426
+ await sock.sendMessage(jid, { sticker: await readFile('./example-media/stiker.webp'), mimetype: 'image/webp' });
427
+ await sock.sendMessage(jid, { audio: await readFile('./example-media/suara.ogg'),
428
+ mimetype: 'audio/ogg; codecs=opus', ptt: true }); // 语音消息;普通音频使用 false
429
+ await sock.sendMessage(jid, { video: await readFile('./example-media/video.mp4'),
430
+ mimetype: 'video/mp4', caption: '示例视频' });
431
+ ```
432
+
433
+ 请提供真实有效的媒体;扩展名和 MIME 不会转换文件内容。支持情况因 WhatsApp 客户端而异。API 返回或 server ACK **不代表**已显示、已读或被点击。此前观察到了 builder 轮播点击,但 R01–R11 rich 消息的显示尚未确认;请查看[完整指南](https://whatsbibz.xbibzclone.my.id/zh/guide/message-recipes)和下方 rich 部分。
434
+
435
+ ## 回复视频生成有声贴纸(实验性)
436
+
437
+ > **状态:**npm 从 2.1.0 开始包含 helper(2.0.0 不包含),但 2.1.0 的音频和动画都限制为 5 秒。**2.1.1** 版本尝试在一条贴纸中加入最多 **600 秒(10 分钟)**音频,动画仍最多 5 秒。机器人示例仅在仓库中。接收方可能拒绝、截断或无法播放长音频;WhatsApp 的 10 分钟播放尚未验证。
438
+
439
+ 1. 安装含 `libwebp_anim`、`libopus` 编码器的 `ffmpeg` 和 `ffprobe`,并在 checkout 中运行 `npm ci`。视频需为普通、有声音的 MP4/MOV,最大 **20 MiB**;阅后即焚视频被拒绝。
440
+ 2. 在自己聊天中测试时,将下方数字换为机器人号码。若由其他账号发送,不要设置 `WHATSBIBZ_ALLOW_SELF_COMMANDS`,并配置实际授权的 PN/LID。
441
+ 3. 按提示配对,等待 **Socket siap**(就绪),然后**回复视频发送 `.sa`**。别名为 `!soundsticker` 和 `!sticker-audio`;必要时点击贴纸声音图标。
442
+
443
+ ```bash
444
+ export WHATSAPP_PHONE='6281234567890' # 换成机器人号码
445
+ export WHATSBIBZ_ALLOWED_JID="${WHATSAPP_PHONE}@s.whatsapp.net"
446
+ export WHATSBIBZ_ALLOW_SELF_COMMANDS=1
447
+ export WHATSBIBZ_AUTH_DIR="$HOME/.whatsbibz/my-bot-session"
448
+ mkdir -p "$WHATSBIBZ_AUTH_DIR" && chmod 700 "$WHATSBIBZ_AUTH_DIR"
449
+ node example/message-recipes.js
450
+ ```
451
+
452
+ 重启时沿用同一个私有会话目录并正常停止;`preserveSession: true` 可阻止部分自动清除,但 WhatsApp 仍可能撤销会话。启用 opt-in 后,示例只接受 Socket 自身的 PN/LID,过滤旧命令并在内存中有限去重。生产环境需要持久去重,不要同时用两个进程打开同一会话。
453
+
454
+ 要在自己的应用中使用 10 分钟音频,请运行 `npm install @xbibzlibrary/whatsbibz@2.1.1` 或使用对应的仓库源码。从**已验证权限的处理器**调用 helper;`incoming` 是对视频的回复:
455
+
456
+ ```js
457
+ import { downloadVideoForSoundSticker, sendVideoAsSoundSticker } from '@xbibzlibrary/whatsbibz';
458
+
459
+ const video = await downloadVideoForSoundSticker(incoming, { mediaHost: sock.getMediaHost() });
460
+ const sent = await sendVideoAsSoundSticker(sock, incoming.key.remoteJid, video, { quoted: incoming, startSeconds: 0, maxAudioSeconds: 600 });
461
+ console.log('消息已创建:', sent.key.id); // 不代表已播放声音
462
+ ```
463
+
464
+ WebP 本身没有声音:helper 分别上传动态 WebP 和 Ogg Opus,再发送**一条** `audioStickerMessage`。2.1.1 版本中视频音频最多 **600 秒**、**4 MiB**;画面最多 **5 秒**、512 × 512,WebP ≤ 500 KiB。输入仍限制 ≤ 20 MiB。使用 `{ maxAudioSeconds: 5 }` 可缩短音频。这些是实现选择,并非 WhatsApp 官方限制或保证。无音轨或静音会报错,不会静默回退。下载拒绝重定向并验证明文 SHA-256,但旧路径不验证媒体 MAC;请隔离 FFmpeg 并限制发送者及资源。
465
+
466
+ 此前一次授权实时测试中,**短贴纸**获得服务器 ACK,所有者确认可见且有声音;该测试未验证 10 分钟播放。参见**[完整指南和故障排查](https://whatsbibz.xbibzclone.my.id/zh/guide/sound-sticker)**。
467
+
299
468
  ## 文本格式与聊天标记(Markdown)
300
469
 
301
470
  ### 1)WhatsApp 原生格式(原样发送,不做转换)
@@ -357,7 +526,7 @@ await sock.sendMessage(groupJid, {
357
526
 
358
527
  ## 交互式按钮(Button)
359
528
 
360
- 所有现代 WhatsApp 按钮都使用 **native flow** 格式:一个按钮就是一段标记 `{ name, buttonParamsJson }`。WhatsBibz 通过 `sock.sendMessage(jid, { interactiveMessage: {...} })` 或 `ButtonV2` 构建器把它转发出去。
529
+ **Native flow** 按钮使用 `{ name, buttonParamsJson }` 格式;可使用 `Button` 构建器或 `sock.sendMessage(jid, { interactiveMessage: {...} })`。下方的 `ButtonV2` 使用旧版 `buttonsMessage`,并非 native flow。支持情况因 WhatsApp 客户端而异。
361
530
 
362
531
  ### 方式 1 —— 推荐:通过 `sendMessage` 使用 Native Flow
363
532
 
@@ -508,7 +677,11 @@ await rich.send(jid, { forwarded: true, includesUnifiedResponse: true });
508
677
 
509
678
  ### 使用道德提示
510
679
 
511
- 这类富文本/AI 消息在接收方手机上显示得**仿佛是 Meta 官方 AI 助手发出的**(复用了 `forwardedAiBotMessageInfo`、`GenAI*` 视图模型等)。请仅用于透明地模拟 AI 助手的机器人——切勿用于冒充、欺骗或误导用户。同样,这是一个**非官方** WhatsApp 客户端;请在小号上运行并接受账号被 WhatsApp 限制的风险。
680
+ 这类富文本/AI 消息使用内部 schema(`forwardedAiBotMessageInfo`、`GenAI*` 视图模型等),**可能**显示为转发的 AI 内容;已测试的 rich 消息在手机上的显示尚未确认。请明确标注为你自己的机器人消息,切勿冒充 Meta AI 或其他人。这是**非官方** WhatsApp 客户端,请注意账号可能受到 WhatsApp 限制。
681
+
682
+ ## 实验性语音通话
683
+
684
+ `VoipClient` 需要 `@roamhq/wrtc` 和 FFmpeg。仅呼叫同意的接收方,并使用有权播放的音频。最近修改前的一次真实测试曾响铃,但出现 `ICE_FAILED` 且没有声音;后续修改仅经过离线测试,**尚未证明真实通话成功**。详情及一次呼叫示例见 [VoIP 指南](https://whatsbibz.xbibzclone.my.id/zh/guide/voip)。
512
685
 
513
686
  ## 底层 API(兼容 Baileys)
514
687
 
@@ -541,7 +714,7 @@ client.on('identity-changed', (i) => console.log(i.linkedDeviceName));
541
714
 
542
715
  ## 从 Baileys 迁移
543
716
 
544
- 1. `npm uninstall baileys && npm install @xbibzlibrary/whatsbibz@2.0.0`(或安装本地 checkout)。
717
+ 1. `npm uninstall baileys && npm install @xbibzlibrary/whatsbibz@2.1.1`(或安装本地 checkout)。
545
718
  2. 替换 import 路径并测试应用使用的 API 和行为。
546
719
  3. 移除 `companion_reg_refresh` 的 `postinstall` 补丁脚本——处理器已内建。
547
720
  4. 可选:用 `createBibzWhats()` 替换你自己的连接/重连/配对循环。
@@ -553,11 +726,11 @@ client.on('identity-changed', (i) => console.log(i.linkedDeviceName));
553
726
  | 打印了配对码但手机没有通知 | 服务器 ACK 仅确认配对请求,并不保证通知送达或设备已链接。没有通知本身不代表号码错误或 IP 被限速。 | 在手机上打开**已链接设备 → 链接设备 → 改用电话号码链接**,输入最新配对码。检查号码和网络;避免反复请求,尤其是收到 `429` 后。 |
554
727
  | 立即 `428`,没有二维码 | 宣告的身份被拒绝(例如 `DARWIN` 子平台)。 | 不设置 `identity`(自动轮换),或从上面表格中挑一个档案。 |
555
728
  | 配对时 `400 bad-request` | `companion_platform_display` 不在白名单上。 | 不要覆盖 `companionPlatformDisplay`;推导出的值永远合法。 |
556
- | 重连后立即 `401` 且正在配对 | 上一次配对在服务器上仍未完成。 | 已自动处理(`reconnecting` 携带 `pairingPending: true`)。 |
729
+ | 配对重连后立即 `401` | 原因尚不确定;`pairingPending` 只是启发式判断。 | 默认恢复可能替换会话;`preserveSession: true` 可停止破坏性恢复。 |
557
730
  | `408` 循环 | WhatsApp Web 版本太旧。 | 保持 `fetchLatestVersion: true`(默认)或升级包。 |
558
- | 清除 3 次会话后 `give-up` | 不是会话问题:号码未注册、数字错误或 IP 被封。 | 确认号码在 WhatsApp 上可用;换网络试试。 |
731
+ | 多次清除会话后 `give-up` | 服务器仍拒绝连接;原因不确定。 | 检查账号、会话、号码和网络;避免反复配对。 |
559
732
  | 重连后处理器不再工作 | 处理器挂在了旧 Socket 上。 | 在 `client.on('ready', sock => …)` 内部挂载。 |
560
- | 进程无法退出 | 有其它东西保持事件循环存活——`close()` 后客户端不遗留定时器。 | 检查你自己的 interval;先 `client.close()` 再 `process.exit`。 |
733
+ | 进程无法退出 | socket、worker 或应用 timer 可能仍在运行。 | 先 `await client.close()`,并关闭应用自己的 interval 和资源。 |
561
734
 
562
735
  ## 测试
563
736
 
@@ -585,7 +758,7 @@ test/ node:test 套件(离线 + 在线)
585
758
 
586
759
  ## 版本与兼容性
587
760
 
588
- - 2.0.0 默认尝试自动关注,改变账户行为;1.4.4 不包含这些更改。
761
+ - 2.0.0 默认尝试自动关注并改变账户行为;2.1.0 将自动目标限制为一个频道,拒绝其他自动关注 JID。有声贴纸和 VoIP 均为实验性功能。
589
762
  - 高层客户端连接时获取 WhatsApp Web 版本,除非禁用或显式固定;底层 socket 使用配置/内置版本,不自动获取。
590
763
  - Node 20 已 EOL;已修补的 Node 版本见 [SECURITY.md](SECURITY.md)。
591
764
  - 变更与限制见 [CHANGELOG.md](CHANGELOG.md) 和[兼容性报告](KOMPATIBILITAS-WHATSAPP-2026-11.md)。
@@ -606,11 +779,13 @@ WhatsBibz 与 WhatsApp 或 Meta 没有任何关联、背书或支持关系。请
606
779
 
607
780
  ## 支持与社区
608
781
 
782
+ **联系开发者:**[Telegram](https://t.me/xbibzofficial) · [GitHub](https://github.com/XbibzOfficial777) · [电子邮件](mailto:xbibzofficial@protonmail.com) · [联系页面](https://whatsbibz.xbibzclone.my.id/zh/contact)。
783
+
609
784
  <p align="center">
610
785
  <a href="https://ko-fi.com/xbibzofficial"><img src="https://img.shields.io/badge/Ko--Fi-Donate-FF5E5B?style=for-the-badge&amp;logo=ko-fi&amp;logoColor=white" alt="Ko-Fi"></a>
611
786
  <a href="https://saweria.co/XbibzOfficial"><img src="https://img.shields.io/badge/Saweria-Support-FFAA00?style=for-the-badge" alt="Saweria"></a>
612
787
  <a href="https://tiktok.com/@xbibzofficial"><img src="https://img.shields.io/badge/TikTok-@xbibzofficial-000000?style=for-the-badge&amp;logo=tiktok&amp;logoColor=white" alt="TikTok"></a>
613
- <a href="https://t.me/xbibzofc"><img src="https://img.shields.io/badge/Telegram-@xbibzofc-26A5E4?style=for-the-badge&amp;logo=telegram&amp;logoColor=white" alt="Telegram"></a>
788
+ <a href="https://t.me/xbibzofficial"><img src="https://img.shields.io/badge/Telegram-@xbibzofficial-26A5E4?style=for-the-badge&amp;logo=telegram&amp;logoColor=white" alt="Telegram"></a>
614
789
  </p>
615
790
 
616
- [Ko-Fi](https://ko-fi.com/xbibzofficial) · [Saweria](https://saweria.co/XbibzOfficial) · [TikTok](https://tiktok.com/@xbibzofficial) · [Telegram](https://t.me/xbibzofc)
791
+ [Ko-Fi](https://ko-fi.com/xbibzofficial) · [Saweria](https://saweria.co/XbibzOfficial) · [TikTok](https://tiktok.com/@xbibzofficial) · [Telegram](https://t.me/xbibzofficial)