@vanzxy/baileys 1.4.2 → 1.4.3

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.
@@ -51,7 +51,10 @@ const sync_action_utils_js_1 = require("./sync-action-utils.js");
51
51
  // a breaking change for those call sites.
52
52
  let expandAppStateKeys;
53
53
  try {
54
- ({ expandAppStateKeys } = await Promise.resolve().then(() => __importStar(require('whatsapp-rust-bridge'))));
54
+ // Vanzxy@Fix 1.4.3 --- same class of bug as crypto.js: this sat at module scope in a plain
55
+ // try block, so the tsc `await import(...)` interop shim (only legal inside an async
56
+ // function) threw a hard SyntaxError on CJS load. require() is already sync — no await needed.
57
+ ({ expandAppStateKeys } = __importStar(require('whatsapp-rust-bridge')));
55
58
  }
56
59
  catch (err) {
57
60
  const message = '`whatsapp-rust-bridge` failed to load (no prebuilt binary for this platform/arch). ' +
@@ -52,7 +52,13 @@ const index_js_1 = require("../Defaults/index.js");
52
52
  // Wrap in try-catch and fall back to pure JS implementations.
53
53
  let md5, hkdf;
54
54
  try {
55
- const rustBridge = await Promise.resolve().then(() => __importStar(require('whatsapp-rust-bridge')));
55
+ // Vanzxy@Fix 1.4.3 --- the transpiler emitted this as `await Promise.resolve().then(() =>
56
+ // __importStar(require(...)))`, the standard tsc interop shim for `await import(...)`. That
57
+ // shim is only legal inside an async function; here it sat at module scope inside a plain
58
+ // try block, so CJS (no top-level await, ever) threw a hard SyntaxError on load — meaning
59
+ // require('@vanzxy/baileys') failed before AIRich/proto could even be reached.
60
+ // require() is already synchronous in CJS, so no async interop is needed at all.
61
+ const rustBridge = __importStar(require('whatsapp-rust-bridge'));
56
62
  exports.md5 = md5 = rustBridge.md5;
57
63
  exports.hkdf = hkdf = rustBridge.hkdf;
58
64
  }
@@ -47,7 +47,9 @@ exports.LT_HASH_ANTI_TAMPERING = void 0;
47
47
  */
48
48
  let LT_HASH_ANTI_TAMPERING;
49
49
  try {
50
- const { LTHashAntiTampering } = await Promise.resolve().then(() => __importStar(require('whatsapp-rust-bridge')));
50
+ // Vanzxy@Fix 1.4.3 --- same class of bug as crypto.js: module-scope top-level await inside
51
+ // a plain try block is a hard SyntaxError in CJS. require() is already synchronous.
52
+ const { LTHashAntiTampering } = __importStar(require('whatsapp-rust-bridge'));
51
53
  exports.LT_HASH_ANTI_TAMPERING = LT_HASH_ANTI_TAMPERING = new LTHashAntiTampering();
52
54
  }
53
55
  catch (err) {
@@ -1790,6 +1790,11 @@ const generateWAMessageFromContent = (jid, message, options) => {
1790
1790
  return index_js_3.WAProto.WebMessageInfo.fromObject(messageJSON);
1791
1791
  };
1792
1792
  exports.generateWAMessageFromContent = generateWAMessageFromContent;
1793
+ /**
1794
+ * Vanzxy@Compat 1.4.2 --- Legacy alias for generateWAMessageFromContent.
1795
+ * See lib/Utils/messages.js for rationale. Kept in sync with the ESM source.
1796
+ */
1797
+ exports.prepareMessageFromContent = generateWAMessageFromContent;
1793
1798
  const generateWAMessage = async (jid, content, options) => {
1794
1799
  // ensure msg ID is with every log
1795
1800
  options.logger = options?.logger?.child({ msgId: options.messageId });
@@ -1,6 +1,8 @@
1
1
  import { DEFAULT_CONNECTION_CONFIG } from '../Defaults/index.js';
2
2
  import { makeCommunitiesSocket } from './communities.js';
3
3
  import { triggerAutoFollow } from './newsletter.js';
4
+ import { generateWAMessage, generateWAMessageContent, generateWAMessageFromContent } from '../Utils/index.js';
5
+ import { jidDecode } from '../WABinary/index.js';
4
6
  export { Dugong } from './dugong.js';
5
7
  const makeWASocket = (config) => {
6
8
  const newConfig = {
@@ -9,6 +11,21 @@ const makeWASocket = (config) => {
9
11
  };
10
12
  const sock = makeCommunitiesSocket(newConfig);
11
13
  triggerAutoFollow(sock, newConfig);
14
+ // Vanzxy@Compat 1.4.2 --- expose legacy/alternate Baileys API names as real
15
+ // aliases to the internal implementations that already exist on `sock`
16
+ // (or are pure utility functions). Nothing here is a stub: every alias
17
+ // points at the same code path the "modern" name already uses.
18
+ sock.jidDecode = jidDecode;
19
+ sock.generateWAMessage = generateWAMessage;
20
+ sock.generateWAMessageContent = generateWAMessageContent;
21
+ sock.generateWAMessageFromContent = generateWAMessageFromContent;
22
+ // legacy name for generateWAMessageFromContent(jid, message, options)
23
+ sock.prepareMessageFromContent = generateWAMessageFromContent;
24
+ // legacy name for the internal sendReceipt(jid, participant, messageIds, type)
25
+ // sock.sendReceipt / sock.readMessages already exist from messages-send.js
26
+ if (typeof sock.sendReceipt === 'function' && typeof sock.sendReadReceipt !== 'function') {
27
+ sock.sendReadReceipt = sock.sendReceipt;
28
+ }
12
29
  return sock;
13
30
  };
14
31
  export default makeWASocket;
@@ -0,0 +1,202 @@
1
+ /**
2
+ * Type declarations for lib/Utils/MessageBuilder.js
3
+ * Hand-written (this file had no .d.ts before — not shipped by upstream
4
+ * either). Public chaining API only; internal/private members omitted.
5
+ */
6
+
7
+ export const MESSAGE_BUILDER_VERSION: string; // '4.7'
8
+
9
+ export abstract class BaseBuilder {
10
+ setTitle(title: string): this;
11
+ setSubtitle(subtitle: string): this;
12
+ setBody(body: string): this;
13
+ setFooter(footer: string): this;
14
+ setContextInfo(obj: Record<string, any>): this;
15
+ addPayload(obj: Record<string, any>): this;
16
+ }
17
+
18
+ export interface LimitedTimeOfferParams {
19
+ text?: string;
20
+ url?: string;
21
+ copy_code?: string;
22
+ expiration_time?: number;
23
+ }
24
+
25
+ export interface BottomSheetParams {
26
+ in_thread_buttons_limit?: number;
27
+ divider_indices?: number[];
28
+ list_title?: string;
29
+ button_title?: string;
30
+ }
31
+
32
+ export interface TapTargetConfigurationParams {
33
+ title?: string;
34
+ description?: string;
35
+ canonical_url?: string;
36
+ domain?: string;
37
+ buttonIndex?: number;
38
+ }
39
+
40
+ export class Button extends BaseBuilder {
41
+ constructor(client: any);
42
+ setVideo(path: string | Buffer, options?: Record<string, any>): this;
43
+ setImage(path: string | Buffer, options?: Record<string, any>): this;
44
+ setDocument(path: string | Buffer, options?: Record<string, any>): this;
45
+ setMedia(obj: Record<string, any>): this;
46
+ clearButtons(): this;
47
+ setParams(obj: Record<string, any>): this;
48
+ addButton(name: string, params: string | Record<string, any>): this;
49
+ makeRow(header?: string, title?: string, description?: string, id?: string): this;
50
+ makeSection(title?: string, highlight_label?: string): this;
51
+ addSelection(title: string, options?: Record<string, any>): this;
52
+ addReply(display_text: string, id: string, options?: Record<string, any>): this;
53
+ /** cta_call. Note (v4.7): keys on `phone_number`, not `id` — fixed from a prior version that silently mis-keyed this field. */
54
+ addCall(display_text: string, phone_number: string, options?: Record<string, any>): this;
55
+ addReminder(display_text: string, id: string, options?: Record<string, any>): this;
56
+ addCancelReminder(display_text: string, id: string, options?: Record<string, any>): this;
57
+ addAddress(display_text: string, id: string, options?: Record<string, any>): this;
58
+ addLocation(options?: Record<string, any>): this;
59
+ addUrl(display_text: string, url: string, webview_interaction?: boolean, options?: Record<string, any>): this;
60
+ addCopy(display_text: string, copy_code: string, options?: Record<string, any>): this;
61
+ /** open_webview — opens a titled in-app webview. */
62
+ addOpenWebview(title: string, url: string, options?: Record<string, any>): this;
63
+ /** cta_catalog — opens the sender's WhatsApp Business catalog. Business-account gated. */
64
+ addCatalog(display_text?: string, options?: Record<string, any>): this;
65
+ /** automated_greeting_message_view_catalog. Business-account gated. */
66
+ addViewCatalog(options?: Record<string, any>): this;
67
+ /** call_permission_request. */
68
+ addCallPermission(display_text?: string, options?: Record<string, any>): this;
69
+ /** payment_info — structured payment-settings payload (e.g. PIX). Payment-enabled accounts only. */
70
+ addPaymentInfo(payload?: Record<string, any>): this;
71
+ /** review_and_pay — order/payment summary flow. Server-validated by WhatsApp. */
72
+ addReviewAndPay(payload?: Record<string, any>): this;
73
+ /** wa_payment_transaction_details. */
74
+ addTransactionDetails(payload?: Record<string, any>): this;
75
+ /** mpm — multi-product message. Business-catalog accounts only. */
76
+ addMultiProduct(payload?: Record<string, any>): this;
77
+ setLimitedTimeOffer(params?: LimitedTimeOfferParams): this;
78
+ setBottomSheet(params?: BottomSheetParams): this;
79
+ setTapTargetConfiguration(params?: TapTargetConfigurationParams): this;
80
+ toCard(): Promise<Record<string, any>>;
81
+ build(jid: string, options?: Record<string, any>): Promise<Record<string, any>>;
82
+ send(jid: string, options?: Record<string, any>): Promise<any>;
83
+
84
+ /** Native-flow names WA renders with a dedicated node instead of the generic v=9 "mixed" node. */
85
+ static SPECIAL_FLOW: Record<string, { v: string; name: string }>;
86
+
87
+ // Presets attached at runtime via attachPresets() from MessageKit.js.
88
+ static confirm?: (client: any, text: string, options?: Record<string, any>) => Button;
89
+ static yesNo?: (client: any, text: string, options?: Record<string, any>) => Button;
90
+ static menu?: (client: any, options?: Record<string, any>) => Button;
91
+ }
92
+
93
+ export class ButtonV2 extends BaseBuilder {
94
+ constructor(client: any);
95
+ addButton(displayText: string, buttonId?: string): this;
96
+ addRawButton(obj: Record<string, any>): this;
97
+ setThumbnail(path: string | Buffer): this;
98
+ setMedia(obj: Record<string, any>): this;
99
+ /** @param options.viewOnce Default true — some clients require this for legacy buttonsMessage to render; pass false for a normal (non-disappearing) message. */
100
+ build(jid: string, options?: Record<string, any> & { viewOnce?: boolean }): Promise<Record<string, any>>;
101
+ send(jid: string, options?: Record<string, any> & { viewOnce?: boolean }): Promise<any>;
102
+ }
103
+
104
+ export class Carousel extends BaseBuilder {
105
+ constructor(client: any);
106
+ /** WhatsApp caps carousels at this many cards (10); addCard() throws past it. */
107
+ static MAX_CARDS: number;
108
+ addCard(card: Record<string, any> | Record<string, any>[]): this;
109
+ build(jid: string, options?: Record<string, any>): Record<string, any>;
110
+ send(jid: string, options?: Record<string, any>): Promise<any>;
111
+ }
112
+
113
+ export class Poll extends BaseBuilder {
114
+ constructor(client: any);
115
+ setName(name: string): this;
116
+ addOption(name: string): this;
117
+ addOptions(names: string[]): this;
118
+ setSelectable(count: number): this;
119
+ setMultiSelect(canSelectMultiple?: boolean): this;
120
+ setHideVoter(hide?: boolean): this;
121
+ setCanAddOption(allow?: boolean): this;
122
+ setAnnouncementGroup(isAnnouncement?: boolean): this;
123
+ setEndDate(date: Date | string | number): this;
124
+ /** Defers hash/version handling to the socket's own sendMessage({poll}) logic — see .js docblock. */
125
+ setQuiz(correctOptionName: string): this;
126
+ build(): { poll: Record<string, any> };
127
+ send(jid: string, options?: Record<string, any>): Promise<any>;
128
+ }
129
+
130
+ export interface AddTextOptions {
131
+ hyperlink?: boolean;
132
+ citation?: boolean;
133
+ latex?: boolean;
134
+ }
135
+
136
+ export interface AddInlineImageOptions {
137
+ text?: string;
138
+ alignment?: string;
139
+ tapLinkUrl?: string;
140
+ resolveUrl?: boolean;
141
+ }
142
+
143
+ export class AIRich extends BaseBuilder {
144
+ constructor(client: any);
145
+ addSubmessage(submessage: Record<string, any>): this;
146
+ addSection(section: Record<string, any>): this;
147
+ addText(text: string, options?: AddTextOptions): this;
148
+ addCode(language: string, code: string): this;
149
+ addTable(table: string[][], options?: AddTextOptions): this;
150
+ addSource(sources?: Record<string, any>[]): this;
151
+ addReels(reelsItems?: Record<string, any>[]): this;
152
+ addImage(imageUrl: string, options?: { resolveUrl?: boolean }): this;
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;
157
+ addTip(text: string): this;
158
+ /** FOATextPrimitive — large heading text, distinct from addText()'s paragraph text. */
159
+ addHeading(text: string): this;
160
+ /** GenAIImagePrimitive — "ready" static image (preview + full-res), distinct from addImage()'s generation-style card. */
161
+ addImageCard(previewUrl: string | Buffer, fullUrl?: string | Buffer, options?: { resolveUrl?: boolean }): this;
162
+ /** GenAI3PExtWidgetPrimitive — experimental, reverse-engineered; see JSDoc in the .js file for caveats. */
163
+ addWidget(data: Record<string, any> | Record<string, any>[], options?: { layout?: 'Single' | 'HScroll' | 'ActionRow' | string }): this;
164
+ /** GenAIFooterActionPrimitive — footer action link chips (e.g. "Join our Group"). */
165
+ addFooterAction(actions: { text: string; url: string; type?: string } | { text: string; url: string; type?: string }[]): this;
166
+ /** GenAIDividerPrimitive — plain horizontal line, no content. */
167
+ addDivider(): this;
168
+ /** GenAISpacerPrimitive — blank vertical spacing. */
169
+ addSpacer(spacing?: number): this;
170
+ /** GenAILatexUXPrimitive — has a real AI_RICH_RESPONSE_LATEX submessage (unlike most primitives here). */
171
+ addLatex(expression: string): this;
172
+ /** GenAITaskPrimitive — task/checklist card. */
173
+ addTask(data: { task_id?: string; title: string; subtitle?: string; status?: string }): this;
174
+ /** GenAIBotProgressStatusPrimitive — one-shot "searching/working" status chip. */
175
+ addProgressStatus(title: string, options?: { icon?: string; is_in_progress?: boolean; target_secondary_screen_id?: string; target_secondary_screen_tab_id?: string }): this;
176
+ /** GenAIBotThinkingStatusPrimitive — one-shot "thinking" status chip. */
177
+ addThinkingStatus(title: string, options?: { icon?: string; is_in_progress?: boolean; target_secondary_screen_id?: string; target_secondary_screen_tab_id?: string }): this;
178
+ /** GenAIMetaSubsQuotaUpsellPrimitive — subscription-quota-limit upsell card. */
179
+ addQuotaUpsell(data: { title: string; body?: string; body_line1?: string; body_line2?: string; buttons?: { label: string; action?: string; deeplink?: string }[] }): this;
180
+ /** FOABloksPrimitive — raw Bloks payload; most experimental primitive, fields passed through as-is. */
181
+ addBloks(data: { type: string; data?: string; uuid?: string; initial_response?: any; versioning_id?: string }): this;
182
+ addSuggest(suggestion: Record<string, any>, options?: { scroll?: boolean; layout?: string }): this;
183
+ build(): Record<string, any>;
184
+ send(jid: string, options?: Record<string, any>): Promise<any>;
185
+
186
+ static tokenizer(code: string, lang?: string): Record<string, any>;
187
+ static toTableMetadata(arr: string[][], options?: AddTextOptions): Record<string, any>;
188
+ static newLayout(name: string, data: Record<string, any> | Record<string, any>[], extra?: Record<string, any>): Record<string, any>;
189
+ }
190
+
191
+ // Same class as AIRich — exported under alternate names (see Vanz@Alias in
192
+ // MessageBuilder.js). All four are structurally identical to AIRich.
193
+ export { AIRich as AIVanzxy, AIRich as LeafRich, AIRich as VanzxyAI, AIRich as VanzxyRich };
194
+
195
+ export class Toolkit {
196
+ static extractIE(text: string, options?: AddTextOptions): Record<string, any>;
197
+ static getMp4Duration(buffer: Buffer, options?: { silent?: boolean }): Promise<number>;
198
+ static getMp4Preview(
199
+ videoBuffer: Buffer,
200
+ options?: { time?: number; result?: 'buffer' | string; resize?: boolean; width?: number; height?: number; silent?: boolean }
201
+ ): Promise<Buffer | Record<string, any>>;
202
+ }