@vanzxy/baileys 1.5.0 → 1.5.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.
@@ -2679,26 +2679,107 @@ class AIRich extends BaseBuilder {
2679
2679
  // the two calls expect different option shapes, so the fallback now only forwards `quoted`
2680
2680
  // (the one option that clearly applies to both) instead of blindly spreading everything.
2681
2681
  /** Build and send this AI-rich message. @param {string} jid Destination chat/group jid. @param {boolean} [skipImageFallback] Skip auto-resending inline images as a plain imageMessage. */
2682
- async send(jid, { forwarded, notification, includesUnifiedResponse, includesSubmessages, skipImageFallback = false, quoted, ...options } = {}) {
2683
- const msg = await this.build({ forwarded, notification, includesUnifiedResponse, includesSubmessages, quoted, ...options });
2684
-
2685
- if (!skipImageFallback && this._mediaFallbacks.length) {
2686
- const fallbacks = await waitAllPromises(this._mediaFallbacks);
2687
- for (const item of fallbacks) {
2688
- try {
2689
- const media = Buffer.isBuffer(item.url) ? item.url : { url: item.url };
2690
- const content = { [item.type]: media };
2691
- if (item.caption) content.caption = item.caption;
2692
- if (item.mimetype) content.mimetype = item.mimetype;
2693
- if (item.fileName) content.fileName = item.fileName;
2694
- await this.#client.sendMessage(jid, content, quoted ? { quoted } : {});
2695
- } catch (err) {
2696
- this.#client.logger?.warn?.({ err, url: item.url, type: item.type }, 'AIRich media fallback failed, continuing with rich card');
2697
- }
2698
- }
2699
- }
2700
- return await this.#client.relayMessage(jid, msg, { ...options });
2701
- }
2682
+ \tasync send(jid, {
2683
+ \t\tforwarded,
2684
+ \t\tnotification,
2685
+ \t\tincludesUnifiedResponse,
2686
+ \t\tincludesSubmessages,
2687
+ \t\tskipImageFallback = false,
2688
+ \t\tnativeFallback = true,
2689
+ \t\tquoted,
2690
+ \t\t...options
2691
+ \t} = {}) {
2692
+ \t\tconst msg = await this.build({ forwarded, notification, includesUnifiedResponse, includesSubmessages, quoted, ...options });
2693
+ \t\tconst sendOptions = quoted ? { quoted } : {};
2694
+
2695
+ \t\t// Native fallback is enabled by default because stock/third-party WhatsApp clients
2696
+ \t\t// do not reliably render botForwardedMessage.richResponseMessage. The rich payload
2697
+ \t\t// remains available through build()/relayMessage(), while send() uses ordinary WA
2698
+ \t\t// message types that are known to render immediately.
2699
+ \t\tif (nativeFallback) {
2700
+ \t\t\tconst sent = [];
2701
+
2702
+ \t\t\t// 1) Send real WhatsApp media first. addImage()/addVideo()/addInlineImage()
2703
+ \t\t\t// already populate this queue with resolved URLs/buffers.
2704
+ \t\t\tif (!skipImageFallback && this._mediaFallbacks.length) {
2705
+ \t\t\t\tconst fallbacks = await waitAllPromises(this._mediaFallbacks);
2706
+ \t\t\t\tfor (const item of fallbacks) {
2707
+ \t\t\t\t\ttry {
2708
+ \t\t\t\t\t\tconst media = Buffer.isBuffer(item.url) ? item.url : { url: item.url };
2709
+ \t\t\t\t\t\tconst content = { [item.type]: media };
2710
+ \t\t\t\t\t\tif (item.caption) content.caption = item.caption;
2711
+ \t\t\t\t\t\tif (item.mimetype) content.mimetype = item.mimetype;
2712
+ \t\t\t\t\t\tif (item.fileName) content.fileName = item.fileName;
2713
+ \t\t\t\t\t\tsent.push(await this.#client.sendMessage(jid, content, sendOptions));
2714
+ \t\t\t\t\t} catch (err) {
2715
+ \t\t\t\t\t\tthis.#client.logger?.warn?.(
2716
+ \t\t\t\t\t\t\t{ err, url: item.url, type: item.type },
2717
+ \t\t\t\t\t\t\t'AIRich native media fallback failed'
2718
+ \t\t\t\t\t\t);
2719
+ \t\t\t\t\t}
2720
+ \t\t\t\t}
2721
+ \t\t\t}
2722
+
2723
+ \t\t\t// 2) Convert AIRich submessages into ordinary WhatsApp text. This preserves
2724
+ \t\t\t// every primitive's readable content even when the AI-only rich renderer is absent.
2725
+ \t\t\tconst lines = [];
2726
+ \t\t\tfor (const sub of await waitAllPromises(this._submessages)) {
2727
+ \t\t\t\tif (!sub) continue;
2728
+
2729
+ \t\t\t\tif (typeof sub.messageText === 'string' && sub.messageText.trim()) {
2730
+ \t\t\t\t\tconst t = sub.messageText.trim();
2731
+
2732
+ \t\t\t\t\t// Media primitives already have a native media message above; don't emit
2733
+ \t\t\t\t\t// their internal placeholder text as a duplicate.
2734
+ \t\t\t\t\tif (
2735
+ \t\t\t\t\t\tt === '[ Video tidak dapat dimuat ]' ||
2736
+ \t\t\t\t\t\tt === '[ Postingan tidak dapat dimuat ]' ||
2737
+ \t\t\t\t\t\tt === '[ Produk tidak dapat dimuat ]' ||
2738
+ \t\t\t\t\t\tt === '[ Sedang diproses... ]'
2739
+ \t\t\t\t\t) continue;
2740
+
2741
+ \t\t\t\t\tlines.push(t);
2742
+ \t\t\t\t\tcontinue;
2743
+ \t\t\t\t}
2744
+
2745
+ \t\t\t\tif (sub.codeMetadata) {
2746
+ \t\t\t\t\tconst blocks = sub.codeMetadata.codeBlocks ?? [];
2747
+ \t\t\t\t\tconst code = Array.isArray(blocks)
2748
+ \t\t\t\t\t\t? blocks.map((b) => typeof b === 'string' ? b : (b?.value ?? '')).join('')
2749
+ \t\t\t\t\t\t: String(blocks);
2750
+ \t\t\t\t\tlines.push('```' + (sub.codeMetadata.codeLanguage || '') + '\\n' + code + '\\n```');
2751
+ \t\t\t\t\tcontinue;
2752
+ \t\t\t\t}
2753
+
2754
+ \t\t\t\tif (sub.tableMetadata?.rows) {
2755
+ \t\t\t\t\tconst rows = sub.tableMetadata.rows;
2756
+ \t\t\t\t\tif (Array.isArray(rows)) {
2757
+ \t\t\t\t\t\tlines.push(rows.map((row) => {
2758
+ \t\t\t\t\t\t\tconst cells = Array.isArray(row) ? row : row?.cells;
2759
+ \t\t\t\t\t\t\treturn Array.isArray(cells)
2760
+ \t\t\t\t\t\t\t\t? cells.map((c) => typeof c === 'string' ? c : (c?.text ?? c?.value ?? '')).join(' | ')
2761
+ \t\t\t\t\t\t\t\t: String(row);
2762
+ \t\t\t\t\t\t}).join('\\n'));
2763
+ \t\t\t\t\t}
2764
+ \t\t\t\t\tcontinue;
2765
+ \t\t\t\t}
2766
+
2767
+ \t\t\t\tif (sub.latexMetadata?.text) {
2768
+ \t\t\t\t\tlines.push(sub.latexMetadata.text);
2769
+ \t\t\t\t}
2770
+ \t\t\t}
2771
+
2772
+ \t\t\tconst text = lines.join('\\n\\n').trim();
2773
+ \t\t\tif (text) {
2774
+ \t\t\t\tsent.push(await this.#client.sendMessage(jid, { text }, sendOptions));
2775
+ \t\t\t}
2776
+
2777
+ \t\t\tif (sent.length) return sent.length === 1 ? sent[0] : sent;
2778
+ \t\t}
2779
+
2780
+ \t\t// Explicit compatibility mode: preserve the original AIRich rich payload.
2781
+ \t\treturn await this.#client.relayMessage(jid, msg, { ...options });
2782
+ \t}
2702
2783
 
2703
2784
  /** Tokenize `code` into `{ type, value }` spans for syntax highlighting. Covers JS/TS/Python/Java and more; unsupported languages fall back to a single plain-text token. */
2704
2785
  static tokenizer(code, lang = 'javascript') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vanzxy/baileys",
3
- "version": "1.5.0",
3
+ "version": "1.5.1",
4
4
  "description": "Enhanced Baileys fork by Vanzxy — based on @itsliaaa/baileys + @whiskeysockets/baileys with fixes for audio group status and clean media without newsletter button.",
5
5
  "type": "module",
6
6
  "module": "./lib/index.js",