@vanzxy/baileys 1.4.4 → 1.4.5

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.
@@ -1736,6 +1736,11 @@ class AIRich extends BaseBuilder {
1736
1736
  status: data.status ?? 'IN_PROGRESS',
1737
1737
  __typename: 'GenAITaskPrimitive',
1738
1738
  }));
1739
+ // Safety net: stock WA client doesn't render this primitive visibly.
1740
+ if (data.textFallback !== false) {
1741
+ const fallbackText = data.subtitle ? `${data.title} — ${data.subtitle}` : data.title;
1742
+ this._sections.push(AIRich.newLayout('Single', { text: `Tugas: ${fallbackText}`, __typename: 'FOATextPrimitive' }));
1743
+ }
1739
1744
  return this;
1740
1745
  }
1741
1746
  addProgressStatus(title, { icon = 'SEARCH', is_in_progress = true, target_secondary_screen_id, target_secondary_screen_tab_id } = {}) {
@@ -2594,6 +2599,64 @@ class AIRich extends BaseBuilder {
2594
2599
  unified_rows,
2595
2600
  };
2596
2601
  }
2602
+ addGenerating({ imagine_type = 'IMAGE', estimated_completion_time } = {}) {
2603
+ this._submessages.push({ messageType: 2, messageText: '[ Sedang diproses... ]' });
2604
+ this._sections.push(AIRich.newLayout('Single', {
2605
+ media: { url: '', mime_type: imagine_type === 'ANIMATE' ? 'video/mp4' : 'image/png' },
2606
+ imagine_type,
2607
+ status: {
2608
+ status: 'GENERATING',
2609
+ estimated_completion_time: estimated_completion_time ?? Math.floor(Date.now() / 1000) + 30,
2610
+ },
2611
+ __typename: 'GenAIImaginePrimitive',
2612
+ }));
2613
+ return this;
2614
+ }
2615
+ static async sendSupportPayload(client, jid, text, { ticketId = crypto_1.default.randomUUID(), isAiMessage = true, shouldShowSystemMessage = true, version = 1 } = {}) {
2616
+ if (!client) throw new Error('Socket is required');
2617
+ if (typeof text !== 'string' || !text) throw new TypeError('sendSupportPayload(client, jid, text) requires a non-empty string text');
2618
+ const msg = {
2619
+ conversation: text,
2620
+ messageContextInfo: {
2621
+ messageSecret: crypto_1.default.randomBytes(32),
2622
+ supportPayload: JSON.stringify({
2623
+ version,
2624
+ is_ai_message: isAiMessage,
2625
+ should_show_system_message: shouldShowSystemMessage,
2626
+ ticket_id: ticketId,
2627
+ }),
2628
+ },
2629
+ };
2630
+ return client.relayMessage(jid, msg, {
2631
+ additionalNodes: [
2632
+ { tag: 'bot', attrs: { biz_bot: '1' } },
2633
+ { tag: 'biz', attrs: {} },
2634
+ ],
2635
+ });
2636
+ }
2637
+ static async sendPairedMedia(client, jid, { image, video } = {}) {
2638
+ if (!client) throw new Error('Socket is required');
2639
+ if (!image || !video) throw new TypeError('sendPairedMedia() requires both "image" and "video"');
2640
+ const imagePrepared = await (0, messages_js_1.prepareWAMessageMedia)({ image: typeof image === 'string' ? { url: image } : image }, { upload: client.waUploadToServer });
2641
+ const videoPrepared = await (0, messages_js_1.prepareWAMessageMedia)({ video: typeof video === 'string' ? { url: video } : video }, { upload: client.waUploadToServer });
2642
+ const imageMsg = (0, messages_js_1.generateWAMessageFromContent)(jid, {
2643
+ imageMessage: {
2644
+ ...imagePrepared.imageMessage,
2645
+ contextInfo: { pairedMediaType: 5, statusSourceType: 0 },
2646
+ },
2647
+ }, {});
2648
+ await client.relayMessage(jid, imageMsg.message, { messageId: imageMsg.key.id });
2649
+ await client.relayMessage(jid, {
2650
+ videoMessage: {
2651
+ ...videoPrepared.videoMessage,
2652
+ contextInfo: { pairedMediaType: 6, statusSourceType: 0 },
2653
+ },
2654
+ messageContextInfo: {
2655
+ messageAssociation: { associationType: 12, parentMessageKey: imageMsg.key },
2656
+ },
2657
+ }, {});
2658
+ return imageMsg.key;
2659
+ }
2597
2660
  static newLayout(name, data, extra = {}) {
2598
2661
  return {
2599
2662
  ...extra,
@@ -166,7 +166,8 @@ const FLOWS_MAP = {
166
166
  authentication_button: true,
167
167
  cta_reminder: true,
168
168
  cta_cancel_reminder: true,
169
- single_select: true,
169
+ // Vanz@Fix (single_select never renders alone) --- see ESM copy for full note.
170
+ // Removed on purpose so single_select always falls through to the mixed-flow branch.
170
171
  };
171
172
  const DECISION_SOURCE_CONTENT = [
172
173
  {
@@ -170,7 +170,7 @@ export class AIRich extends BaseBuilder {
170
170
  /** GenAILatexUXPrimitive — has a real AI_RICH_RESPONSE_LATEX submessage (unlike most primitives here). */
171
171
  addLatex(expression: string): this;
172
172
  /** GenAITaskPrimitive — task/checklist card. */
173
- addTask(data: { task_id?: string; title: string; subtitle?: string; status?: string }): this;
173
+ addTask(data: { task_id?: string; title: string; subtitle?: string; status?: string; textFallback?: boolean }): this;
174
174
  /** GenAIBotProgressStatusPrimitive — one-shot "searching/working" status chip. */
175
175
  addProgressStatus(title: string, options?: { icon?: string; is_in_progress?: boolean; target_secondary_screen_id?: string; target_secondary_screen_tab_id?: string }): this;
176
176
  /** GenAIBotThinkingStatusPrimitive — one-shot "thinking" status chip. */
@@ -180,12 +180,18 @@ export class AIRich extends BaseBuilder {
180
180
  /** FOABloksPrimitive — raw Bloks payload; most experimental primitive, fields passed through as-is. */
181
181
  addBloks(data: { type: string; data?: string; uuid?: string; initial_response?: any; versioning_id?: string; textFallback?: boolean }): this;
182
182
  addSuggest(suggestion: Record<string, any>, options?: { scroll?: boolean; layout?: string }): this;
183
+ /** GenAIImaginePrimitive with status GENERATING — pending-generation placeholder, distinct from addImage()/addVideo()'s READY status. */
184
+ addGenerating(options?: { imagine_type?: 'IMAGE' | 'ANIMATE'; estimated_completion_time?: number }): this;
183
185
  build(): Record<string, any>;
184
186
  send(jid: string, options?: Record<string, any>): Promise<any>;
185
187
 
186
188
  static tokenizer(code: string, lang?: string): Record<string, any>;
187
189
  static toTableMetadata(arr: string[][], options?: AddTextOptions): Record<string, any>;
188
190
  static newLayout(name: string, data: Record<string, any> | Record<string, any>[], extra?: Record<string, any>): Record<string, any>;
191
+ /** Send a support-ticket marker message (messageContextInfo.supportPayload). */
192
+ static sendSupportPayload(client: any, jid: string, text: string, options?: { ticketId?: string; isAiMessage?: boolean; shouldShowSystemMessage?: boolean; version?: number }): Promise<any>;
193
+ /** Send an image + video as one paired-media unit (messageAssociation). */
194
+ static sendPairedMedia(client: any, jid: string, media: { image: string | Buffer; video: string | Buffer }): Promise<any>;
189
195
  }
190
196
 
191
197
  // Same class as AIRich — exported under alternate names (see Vanz@Alias in
@@ -2308,6 +2308,13 @@ class AIRich extends BaseBuilder {
2308
2308
  __typename: 'GenAITaskPrimitive',
2309
2309
  })
2310
2310
  );
2311
+ // Safety net: GenAITaskPrimitive is a custom AI-only component the stock WA client
2312
+ // doesn't render visibly. Append a plain text section so the task is still visible.
2313
+ // Set data.textFallback = false to skip.
2314
+ if (data.textFallback !== false) {
2315
+ const fallbackText = data.subtitle ? `${data.title} — ${data.subtitle}` : data.title;
2316
+ this._sections.push(AIRich.newLayout('Single', { text: `Tugas: ${fallbackText}`, __typename: 'FOATextPrimitive' }));
2317
+ }
2311
2318
  return this;
2312
2319
  }
2313
2320
 
@@ -3275,6 +3282,111 @@ class AIRich extends BaseBuilder {
3275
3282
  };
3276
3283
  }
3277
3284
 
3285
+ /**
3286
+ * Add an "AI is generating..." placeholder card (`GenAIImaginePrimitive` with status
3287
+ * GENERATING) — distinct from addImage()/addVideo() which always send status READY.
3288
+ * Use this to show a pending-generation state before the real media is ready.
3289
+ * @param {{ imagine_type?: 'IMAGE'|'ANIMATE', estimated_completion_time?: number }} [options]
3290
+ */
3291
+ addGenerating({ imagine_type = 'IMAGE', estimated_completion_time } = {}) {
3292
+ this._submessages.push({ messageType: 2, messageText: '[ Sedang diproses... ]' });
3293
+ this._sections.push(
3294
+ AIRich.newLayout('Single', {
3295
+ media: { url: '', mime_type: imagine_type === 'ANIMATE' ? 'video/mp4' : 'image/png' },
3296
+ imagine_type,
3297
+ status: {
3298
+ status: 'GENERATING',
3299
+ estimated_completion_time: estimated_completion_time ?? Math.floor(Date.now() / 1000) + 30,
3300
+ },
3301
+ __typename: 'GenAIImaginePrimitive',
3302
+ })
3303
+ );
3304
+ return this;
3305
+ }
3306
+
3307
+ /**
3308
+ * Send a support-ticket marker message (`messageContextInfo.supportPayload`) — a plain
3309
+ * conversation message tagged as an AI/support-bot ticket, distinct from richResponseMessage.
3310
+ * @param {import('../../WAProto/index.js').WASocket} client
3311
+ * @param {string} jid
3312
+ * @param {string} text
3313
+ * @param {{ ticketId?: string, isAiMessage?: boolean, shouldShowSystemMessage?: boolean, version?: number }} [options]
3314
+ */
3315
+ static async sendSupportPayload(client, jid, text, { ticketId = crypto.randomUUID(), isAiMessage = true, shouldShowSystemMessage = true, version = 1 } = {}) {
3316
+ if (!client) throw new Error('Socket is required');
3317
+ if (typeof text !== 'string' || !text) throw new TypeError('sendSupportPayload(client, jid, text) requires a non-empty string text');
3318
+
3319
+ const msg = {
3320
+ conversation: text,
3321
+ messageContextInfo: {
3322
+ messageSecret: crypto.randomBytes(32),
3323
+ supportPayload: JSON.stringify({
3324
+ version,
3325
+ is_ai_message: isAiMessage,
3326
+ should_show_system_message: shouldShowSystemMessage,
3327
+ ticket_id: ticketId,
3328
+ }),
3329
+ },
3330
+ };
3331
+
3332
+ return client.relayMessage(jid, msg, {
3333
+ additionalNodes: [
3334
+ { tag: 'bot', attrs: { biz_bot: '1' } },
3335
+ { tag: 'biz', attrs: {} },
3336
+ ],
3337
+ });
3338
+ }
3339
+
3340
+ /**
3341
+ * Send an image and video as one paired-media unit (image sent first, video linked to it via
3342
+ * `messageAssociation`). Distinct from a plain album — the client treats them as a single group.
3343
+ * @param {import('../../WAProto/index.js').WASocket} client
3344
+ * @param {string} jid
3345
+ * @param {{ image: string|Buffer, video: string|Buffer }} media
3346
+ */
3347
+ static async sendPairedMedia(client, jid, { image, video } = {}) {
3348
+ if (!client) throw new Error('Socket is required');
3349
+ if (!image || !video) throw new TypeError('sendPairedMedia() requires both "image" and "video"');
3350
+
3351
+ const imagePrepared = await prepareWAMessageMedia(
3352
+ { image: typeof image === 'string' ? { url: image } : image },
3353
+ { upload: client.waUploadToServer }
3354
+ );
3355
+ const videoPrepared = await prepareWAMessageMedia(
3356
+ { video: typeof video === 'string' ? { url: video } : video },
3357
+ { upload: client.waUploadToServer }
3358
+ );
3359
+
3360
+ const imageMsg = generateWAMessageFromContent(
3361
+ jid,
3362
+ {
3363
+ imageMessage: {
3364
+ ...imagePrepared.imageMessage,
3365
+ contextInfo: { pairedMediaType: 5, statusSourceType: 0 },
3366
+ },
3367
+ },
3368
+ {}
3369
+ );
3370
+
3371
+ await client.relayMessage(jid, imageMsg.message, { messageId: imageMsg.key.id });
3372
+
3373
+ await client.relayMessage(
3374
+ jid,
3375
+ {
3376
+ videoMessage: {
3377
+ ...videoPrepared.videoMessage,
3378
+ contextInfo: { pairedMediaType: 6, statusSourceType: 0 },
3379
+ },
3380
+ messageContextInfo: {
3381
+ messageAssociation: { associationType: 12, parentMessageKey: imageMsg.key },
3382
+ },
3383
+ },
3384
+ {}
3385
+ );
3386
+
3387
+ return imageMsg.key;
3388
+ }
3389
+
3278
3390
  /** Build a raw submessage layout block by name — escape hatch for layouts not covered by the add*() helpers. */
3279
3391
  static newLayout(name, data, extra = {}) {
3280
3392
  return {
@@ -153,7 +153,14 @@ const FLOWS_MAP = {
153
153
  authentication_button: true,
154
154
  cta_reminder: true,
155
155
  cta_cancel_reminder: true,
156
- single_select: true,
156
+ // Vanz@Fix (single_select never renders alone) --- single_select must NEVER get
157
+ // its own dedicated native_flow node here. WhatsApp only renders a single_select
158
+ // button through the generic <native_flow v='9' name='mixed'> node — the same one
159
+ // used when it's combined with other buttons. Giving it a dedicated
160
+ // <native_flow v='2' name='single_select'> node (like the other FLOWS_MAP entries)
161
+ // silently fails to render client-side, whether single_select is alone or is simply
162
+ // the first button in the array. Removed from this map on purpose so it always
163
+ // falls through to the `flowMsg` mixed-flow branch below.
157
164
  };
158
165
  const DECISION_SOURCE_CONTENT = [
159
166
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vanzxy/baileys",
3
- "version": "1.4.4",
3
+ "version": "1.4.5",
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",