@vanzxy/baileys 1.4.6 → 1.4.8

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.
@@ -61,7 +61,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
61
61
  var _a, _Button_client, _Button_validateAgainstSchema, _ButtonV2_client, _Carousel_client, _Poll_client, _AIRich_client;
62
62
  Object.defineProperty(exports, "__esModule", { value: true });
63
63
  exports.Toolkit = exports.VanzxyRich = exports.VanzxyAI = exports.LeafRich = exports.AIVanzxy = exports.AIRich = exports.Poll = exports.Carousel = exports.ButtonV2 = exports.Button = exports.MESSAGE_BUILDER_VERSION = void 0;
64
- const MESSAGE_BUILDER_VERSION = '4.8';
64
+ const MESSAGE_BUILDER_VERSION = '4.9';
65
65
  exports.MESSAGE_BUILDER_VERSION = MESSAGE_BUILDER_VERSION;
66
66
  const messages_js_1 = require("./messages.js");
67
67
  const rich_message_utils_js_1 = require("./rich-message-utils.js");
@@ -1378,7 +1378,7 @@ class AIRich extends BaseBuilder {
1378
1378
  }))));
1379
1379
  return this;
1380
1380
  }
1381
- addImage(imageUrl, { resolveUrl = false } = {}) {
1381
+ addImage(imageUrl, { resolveUrl = false, instant = false } = {}) {
1382
1382
  if (!(typeof imageUrl === 'string' || Buffer.isBuffer(imageUrl) || (Array.isArray(imageUrl) && imageUrl.every((v) => typeof v === 'string' || Buffer.isBuffer(v))))) {
1383
1383
  throw new TypeError('imageUrl must be string | buffer | array of string/buffer');
1384
1384
  }
@@ -1420,6 +1420,9 @@ class AIRich extends BaseBuilder {
1420
1420
  status: { status: 'READY' },
1421
1421
  __typename: 'GenAIImaginePrimitive',
1422
1422
  }));
1423
+ if (instant) {
1424
+ this._inlineImages.push({ url: imagePreviewUrl, caption: undefined });
1425
+ }
1423
1426
  });
1424
1427
  return this;
1425
1428
  }
@@ -44,7 +44,7 @@
44
44
 
45
45
  'use strict';
46
46
 
47
- const MESSAGE_BUILDER_VERSION = '4.8';
47
+ const MESSAGE_BUILDER_VERSION = '4.9';
48
48
 
49
49
  import { generateWAMessageFromContent, prepareWAMessageMedia } from './messages.js';
50
50
  import { botMetadataSignature, botMetadataCertificate } from './rich-message-utils.js';
@@ -1587,6 +1587,79 @@ class AIRich extends BaseBuilder {
1587
1587
  // mediaKey still doesn't render, so it's a trust-chain gate, not a domain/encoding issue).
1588
1588
  // Track every addInlineImage() call here so send() can fall back to a normal imageMessage.
1589
1589
  this._inlineImages = [];
1590
+
1591
+ // Vanz@Add (v4.9.1) --- { id, insertAt } support for every add*()/set*() call, without
1592
+ // touching each method's own body/signature. Every add*() call ends up pushing 0-N items
1593
+ // onto _submessages and 0-N onto _sections (some push to both, some to just one — e.g.
1594
+ // addSuggest only touches _submessages, addSection only touches _sections). A Proxy wraps
1595
+ // every add*/set* call: it snapshots array lengths before calling the real method, lets the
1596
+ // method push onto the tail as it always has, then — if the caller passed { insertAt } —
1597
+ // peels those freshly-pushed items back off the tail and re-splices them right after the
1598
+ // last item that belongs to the block named by insertAt. Blocks are tracked by *object
1599
+ // reference*, not saved numeric index, so earlier insertions shifting the array around never
1600
+ // invalidates a later insertAt lookup (indexOf on the reference always finds the live position).
1601
+ this._blocks = new Map(); // id -> { subItems: object[], secItems: object[] }
1602
+ return new Proxy(this, {
1603
+ get(target, prop, receiver) {
1604
+ const orig = Reflect.get(target, prop, receiver);
1605
+ if (typeof orig !== 'function' || !/^(add|set)/.test(String(prop))) return orig;
1606
+
1607
+ return (...args) => {
1608
+ const opts = args.find((a) => a && typeof a === 'object' && !Array.isArray(a) && !Buffer.isBuffer(a) && ('id' in a || 'insertAt' in a));
1609
+ const id = opts?.id;
1610
+ const insertAt = opts?.insertAt;
1611
+
1612
+ const subBefore = target._submessages.length;
1613
+ const secBefore = target._sections.length;
1614
+
1615
+ // Vanz@Fix 23-08-26 --- was orig.apply(receiver, args): calling the real method bound to
1616
+ // the Proxy itself (`receiver`) makes any `this.#client` access inside throw
1617
+ // "Cannot read private member #client from an object whose class did not declare it",
1618
+ // because a Proxy is never the branded instance a private field was declared on —
1619
+ // this hit every add*() that touches #client via Toolkit.resolveMedia(this.#client, ...)
1620
+ // (addProduct/addPost/addReels/addSource, and would eventually hit addImage/addVideo
1621
+ // too once JIT/engine specifics changed). Binding to `target` (the real instance) instead
1622
+ // fixes it for good; `target._submessages`/`target._sections` below are unaffected since
1623
+ // they're plain properties, and `result === target ? receiver : result` still converts a
1624
+ // `this`-return back to the Proxy so chaining (`.addX().addY()`) keeps working.
1625
+ const result = orig.apply(target, args);
1626
+
1627
+
1628
+ const subItems = target._submessages.splice(subBefore);
1629
+ const secItems = target._sections.splice(secBefore);
1630
+
1631
+ if (insertAt) {
1632
+ const anchor = target._blocks.get(insertAt);
1633
+ if (!anchor) throw new Error(`insertAt: no block registered with id "${insertAt}" (register it by passing { id: "${insertAt}" } on an earlier add*() call)`);
1634
+
1635
+ const lastSub = anchor.subItems[anchor.subItems.length - 1];
1636
+ const subIdx = lastSub ? target._submessages.indexOf(lastSub) + 1 : target._submessages.length;
1637
+ target._submessages.splice(subIdx, 0, ...subItems);
1638
+
1639
+ const lastSec = anchor.secItems[anchor.secItems.length - 1];
1640
+ const secIdx = lastSec ? target._sections.indexOf(lastSec) + 1 : target._sections.length;
1641
+ target._sections.splice(secIdx, 0, ...secItems);
1642
+ } else {
1643
+ target._submessages.push(...subItems);
1644
+ target._sections.push(...secItems);
1645
+ }
1646
+
1647
+ if (id) target._blocks.set(id, { subItems, secItems });
1648
+
1649
+ return result === target ? receiver : result;
1650
+ };
1651
+ },
1652
+ });
1653
+ }
1654
+
1655
+ /** Flatten every primitive pushed into `_sections` so far into one array — lets you build a
1656
+ * card set in one AIRich instance and re-embed it into another via addSection(AIRich.newLayout(...)). */
1657
+ get items() {
1658
+ return this._sections.flatMap((s) => {
1659
+ const vm = s?.view_model;
1660
+ if (!vm) return [];
1661
+ return vm.primitives ?? (vm.primitive !== undefined ? [vm.primitive] : []);
1662
+ });
1590
1663
  }
1591
1664
 
1592
1665
  /** Push a raw pre-built submessage block (escape hatch for shapes not covered by the add*() helpers). */
@@ -1703,7 +1776,7 @@ class AIRich extends BaseBuilder {
1703
1776
  }
1704
1777
 
1705
1778
  /** Add a "Sources" strip. @param {string[]|string[][]} sources Flat list of urls, or `[title, url]` pairs. */
1706
- addSource(sources = []) {
1779
+ addSource(sources = [], { resolveUrl = false } = {}) {
1707
1780
  if (!(Array.isArray(sources) && (sources.every((item) => typeof item === 'string') || sources.every((item) => Array.isArray(item) && item.every((v) => typeof v === 'string'))))) {
1708
1781
  throw new TypeError('Sources must be a string array or an array of string arrays');
1709
1782
  }
@@ -1718,7 +1791,7 @@ class AIRich extends BaseBuilder {
1718
1791
  source_subtitle: 'AI',
1719
1792
  source_url: url ?? '',
1720
1793
  favicon: {
1721
- url: Toolkit.resolveMedia(this.#client, icon ?? '', 'image'),
1794
+ url: Toolkit.resolveMedia(this.#client, icon ?? '', 'image', { resolveUrl }),
1722
1795
  mime_type: 'image/jpeg',
1723
1796
  width: 16,
1724
1797
  height: 16,
@@ -1736,7 +1809,7 @@ class AIRich extends BaseBuilder {
1736
1809
  }
1737
1810
 
1738
1811
  /** Add a horizontally-scrollable reel of image/video items. */
1739
- addReels(reelsItems = []) {
1812
+ addReels(reelsItems = [], { resolveUrl = false } = {}) {
1740
1813
  if (
1741
1814
  !(
1742
1815
  (reelsItems && typeof reelsItems === 'object' && !Array.isArray(reelsItems)) ||
@@ -1752,8 +1825,8 @@ class AIRich extends BaseBuilder {
1752
1825
 
1753
1826
  const reels = reelsItems.map((item) => ({
1754
1827
  ...item,
1755
- _avatar: Toolkit.resolveMedia(this.#client, item.profileIconUrl ?? item.profile_url ?? item.profile ?? '', 'image'),
1756
- _thumbnail: Toolkit.resolveMedia(this.#client, item.thumbnailUrl ?? item.thumbnail ?? '', 'image'),
1828
+ _avatar: Toolkit.resolveMedia(this.#client, item.profileIconUrl ?? item.profile_url ?? item.profile ?? '', 'image', { resolveUrl }),
1829
+ _thumbnail: Toolkit.resolveMedia(this.#client, item.thumbnailUrl ?? item.thumbnail ?? '', 'image', { resolveUrl }),
1757
1830
  }));
1758
1831
 
1759
1832
  this._submessages.push({
@@ -1806,10 +1879,24 @@ class AIRich extends BaseBuilder {
1806
1879
  }
1807
1880
 
1808
1881
  /** Add a full-width image (or grid of images if `imageUrl` is an array). */
1809
- addImage(imageUrl, { resolveUrl = false } = {}) {
1882
+ /**
1883
+ * @param {{ resolveUrl?: boolean, instant?: boolean|'only' }} [options]
1884
+ * `instant: true` — sends BOTH: the GRID_IMAGE card (still shows WA's "can't verify"
1885
+ * forwarded-download prompt, unavoidable per-design of botForwardedMessage) AND a plain
1886
+ * (non-forwarded) imageMessage via send()'s inline-image fallback queue (`_inlineImages`,
1887
+ * shared with addInlineImage()) that renders instantly with no prompt. Two images, by design.
1888
+ * `instant: 'only'` — Vanz@Add (v4.9.2): skips building the GRID_IMAGE card entirely (no
1889
+ * submessage, no GenAIImaginePrimitive section) and queues ONLY the plain imageMessage.
1890
+ * One image, no prompt, nothing to download — use this when you don't need the rich card,
1891
+ * just the picture to show up immediately.
1892
+ */
1893
+ addImage(imageUrl, { resolveUrl = false, instant = false } = {}) {
1810
1894
  if (!(typeof imageUrl === 'string' || Buffer.isBuffer(imageUrl) || (Array.isArray(imageUrl) && imageUrl.every((v) => typeof v === 'string' || Buffer.isBuffer(v))))) {
1811
1895
  throw new TypeError('imageUrl must be string | buffer | array of string/buffer');
1812
1896
  }
1897
+ if (instant !== false && instant !== true && instant !== 'only') {
1898
+ throw new TypeError(`instant must be false, true, or 'only' — got ${JSON.stringify(instant)}`);
1899
+ }
1813
1900
 
1814
1901
  const list = Array.isArray(imageUrl)
1815
1902
  ? imageUrl.map((v) => {
@@ -1831,28 +1918,38 @@ class AIRich extends BaseBuilder {
1831
1918
  ];
1832
1919
  })();
1833
1920
 
1834
- this._submessages.push({
1835
- messageType: 1,
1836
- gridImageMetadata: {
1837
- gridImageUrl: {
1838
- imagePreviewUrl: list[0]?.imagePreviewUrl,
1921
+ const buildCard = instant !== 'only';
1922
+
1923
+ if (buildCard) {
1924
+ this._submessages.push({
1925
+ messageType: 1,
1926
+ gridImageMetadata: {
1927
+ gridImageUrl: {
1928
+ imagePreviewUrl: list[0]?.imagePreviewUrl,
1929
+ },
1930
+ imageUrls: list,
1839
1931
  },
1840
- imageUrls: list,
1841
- },
1842
- });
1932
+ });
1933
+ }
1843
1934
 
1844
1935
  list.forEach(({ imagePreviewUrl }) => {
1845
- this._sections.push(
1846
- AIRich.newLayout('Single', {
1847
- media: {
1848
- url: imagePreviewUrl,
1849
- mime_type: 'image/png',
1850
- },
1851
- imagine_type: 'IMAGE',
1852
- status: { status: 'READY' },
1853
- __typename: 'GenAIImaginePrimitive',
1854
- })
1855
- );
1936
+ if (buildCard) {
1937
+ this._sections.push(
1938
+ AIRich.newLayout('Single', {
1939
+ media: {
1940
+ url: imagePreviewUrl,
1941
+ mime_type: 'image/png',
1942
+ },
1943
+ imagine_type: 'IMAGE',
1944
+ status: { status: 'READY' },
1945
+ __typename: 'GenAIImaginePrimitive',
1946
+ })
1947
+ );
1948
+ }
1949
+
1950
+ if (instant) {
1951
+ this._inlineImages.push({ url: imagePreviewUrl, caption: undefined });
1952
+ }
1856
1953
  });
1857
1954
 
1858
1955
  return this;
@@ -1923,8 +2020,12 @@ class AIRich extends BaseBuilder {
1923
2020
  // fetch-full-video + ffmpeg-frame-extraction + duration-parse round trip per video, which
1924
2021
  // was the main source of blurose's slower response time. Pass { autoFill: true } to opt
1925
2022
  // back into the complete/slow path (real thumbnail + duration + file_length).
2023
+ // Vanz@Fix 23-08-26 --- addVideo() had no resolveUrl option at all (unlike addImage()), so the
2024
+ // video url always stayed a raw external link, which stock WA clients show a "download" state
2025
+ // for before rendering. Mirrors addImage()'s { resolveUrl } — when true, the url is uploaded to
2026
+ // WA's own media server first via Toolkit.toUrl() so it renders instantly like WA-native media.
1926
2027
  /** Add a video block. */
1927
- addVideo(videoUrl, { autoFill = false } = {}) {
2028
+ addVideo(videoUrl, { autoFill = false, resolveUrl = false } = {}) {
1928
2029
  const isObjectVideo = (v) => v && typeof v === 'object' && v.url;
1929
2030
 
1930
2031
  const isValidPrimitive =
@@ -1947,7 +2048,9 @@ class AIRich extends BaseBuilder {
1947
2048
  items.forEach((item) => {
1948
2049
  const isObject = isObjectVideo(item);
1949
2050
 
1950
- const url = isObject ? Toolkit.resolveMedia(this.#client, item.url ?? '', 'video') : Toolkit.resolveMedia(this.#client, item, 'video');
2051
+ const url = isObject
2052
+ ? Toolkit.resolveMedia(this.#client, item.url ?? '', 'video', { resolveUrl })
2053
+ : Toolkit.resolveMedia(this.#client, item, 'video', { resolveUrl });
1951
2054
 
1952
2055
  const bufferPromise = autoFill ? Promise.resolve(url).then((u) => Toolkit.fetchBuffer(u)) : null;
1953
2056
 
@@ -2005,7 +2108,7 @@ class AIRich extends BaseBuilder {
2005
2108
  }
2006
2109
 
2007
2110
  /** Add an inline product card (or array of cards). Each item needs at least a `title`. */
2008
- addProduct(data = {}) {
2111
+ addProduct(data = {}, { resolveUrl = false } = {}) {
2009
2112
  if (!((data && typeof data === 'object' && !Array.isArray(data)) || (Array.isArray(data) && data.every((item) => item && typeof item === 'object' && !Array.isArray(item))))) {
2010
2113
  throw new TypeError('Product items must be an object or an array of objects');
2011
2114
  }
@@ -2030,11 +2133,11 @@ class AIRich extends BaseBuilder {
2030
2133
  sale_price: item.sale_price,
2031
2134
  product_url: item.product_url ?? item.url,
2032
2135
  image: {
2033
- url: Toolkit.resolveMedia(this.#client, item.image_url ?? item.image, 'image'),
2136
+ url: Toolkit.resolveMedia(this.#client, item.image_url ?? item.image, 'image', { resolveUrl }),
2034
2137
  },
2035
2138
  additional_images: [
2036
2139
  {
2037
- url: Toolkit.resolveMedia(this.#client, item.icon_url ?? item.icon, 'image'),
2140
+ url: Toolkit.resolveMedia(this.#client, item.icon_url ?? item.icon, 'image', { resolveUrl }),
2038
2141
  },
2039
2142
  ],
2040
2143
  __typename: 'GenAIProductItemCardPrimitive',
@@ -2046,7 +2149,7 @@ class AIRich extends BaseBuilder {
2046
2149
  }
2047
2150
 
2048
2151
  /** Add an inline social-post style card (or array of cards). */
2049
- addPost(data = {}) {
2152
+ addPost(data = {}, { resolveUrl = false } = {}) {
2050
2153
  if (!((data && typeof data === 'object' && !Array.isArray(data)) || (Array.isArray(data) && data.every((item) => item && typeof item === 'object' && !Array.isArray(item))))) {
2051
2154
  throw new TypeError('Post items must be an object or an array of objects');
2052
2155
  }
@@ -2062,9 +2165,9 @@ class AIRich extends BaseBuilder {
2062
2165
  title: p.title ?? '',
2063
2166
  subtitle: p.subtitle ?? '',
2064
2167
  username: p.username ?? '',
2065
- profile_picture_url: Toolkit.resolveMedia(this.#client, p.profile_picture_url ?? p.profile_url ?? p.profile ?? '', 'image'),
2168
+ profile_picture_url: Toolkit.resolveMedia(this.#client, p.profile_picture_url ?? p.profile_url ?? p.profile ?? '', 'image', { resolveUrl }),
2066
2169
  is_verified: !!(p.is_verified || p.verified),
2067
- thumbnail_url: Toolkit.resolveMedia(this.#client, p.thumbnail_url ?? p.thumbnail ?? '', 'image'),
2170
+ thumbnail_url: Toolkit.resolveMedia(this.#client, p.thumbnail_url ?? p.thumbnail ?? '', 'image', { resolveUrl }),
2068
2171
  post_caption: p.post_caption ?? p.caption ?? '',
2069
2172
  likes_count: p.likes_count ?? p.like ?? 0,
2070
2173
  comments_count: p.comments_count ?? p.comment ?? 0,
@@ -2073,7 +2176,7 @@ class AIRich extends BaseBuilder {
2073
2176
  post_deeplink: p.post_deeplink ?? p.deeplink ?? '',
2074
2177
  source_app: p.source_app || p.source || 'INSTAGRAM',
2075
2178
  footer_label: p.footer_label ?? p.footer ?? '',
2076
- footer_icon: Toolkit.resolveMedia(this.#client, p.footer_icon ?? p.icon ?? '', 'image'),
2179
+ footer_icon: Toolkit.resolveMedia(this.#client, p.footer_icon ?? p.icon ?? '', 'image', { resolveUrl }),
2077
2180
  is_carousel: posts.length > 1,
2078
2181
  orientation: p.orientation ?? 'LANDSCAPE',
2079
2182
  post_type: p.post_type ?? 'VIDEO',
@@ -147,13 +147,13 @@ export class AIRich extends BaseBuilder {
147
147
  addText(text: string, options?: AddTextOptions): this;
148
148
  addCode(language: string, code: string): this;
149
149
  addTable(table: string[][], options?: AddTextOptions): this;
150
- addSource(sources?: Record<string, any>[]): this;
151
- addReels(reelsItems?: Record<string, any>[]): this;
150
+ addSource(sources?: Record<string, any>[], options?: { resolveUrl?: boolean }): this;
151
+ addReels(reelsItems?: Record<string, any>[], options?: { resolveUrl?: boolean }): this;
152
152
  addImage(imageUrl: string, options?: { resolveUrl?: boolean }): this;
153
153
  addInlineImage(imageUrl: string, options?: AddInlineImageOptions): this;
154
- addVideo(videoUrl: string, options?: { autoFill?: boolean }): this;
155
- addProduct(data?: Record<string, any>): this;
156
- addPost(data?: Record<string, any>): this;
154
+ addVideo(videoUrl: string, options?: { autoFill?: boolean; resolveUrl?: boolean }): this;
155
+ addProduct(data?: Record<string, any>, options?: { resolveUrl?: boolean }): this;
156
+ addPost(data?: Record<string, any>, options?: { resolveUrl?: boolean }): this;
157
157
  addTip(text: string): this;
158
158
  /** FOATextPrimitive — large heading text, distinct from addText()'s paragraph text. */
159
159
  addHeading(text: string): this;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vanzxy/baileys",
3
- "version": "1.4.6",
3
+ "version": "1.4.8",
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
  "main": "./cjs/lib/index.js",