@systemzero/baileys 1.0.3 → 1.0.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.
@@ -0,0 +1,2509 @@
1
+ /**
2
+ * Copyright (c) 2026
3
+ */
4
+
5
+ "use strict";
6
+
7
+ const VERSION = "4.6";
8
+
9
+ const {
10
+ generateWAMessageFromContent,
11
+ prepareWAMessageMedia,
12
+ } = require("@systemzero/baileys");
13
+ const crypto = require("crypto");
14
+ const sharp = require("sharp");
15
+ const ffmpeg = require("fluent-ffmpeg");
16
+ const { PassThrough, Readable } = require("stream");
17
+
18
+ function extractIE(
19
+ text,
20
+ { extract = true, hyperlink = true, citation = true, latex = true } = {},
21
+ ) {
22
+ if (!extract) {
23
+ return {
24
+ text,
25
+ ie: [],
26
+ inline_entities: [],
27
+ };
28
+ }
29
+
30
+ const createIE = (type, ie) => {
31
+ if (type == "hyperlink") {
32
+ return {
33
+ key: ie.key,
34
+ metadata: {
35
+ display_name: ie.text,
36
+ is_trusted: ie.is_trusted,
37
+ url: ie.url,
38
+ __typename: "GenAIInlineLinkItem",
39
+ },
40
+ };
41
+ }
42
+
43
+ if (type == "citation") {
44
+ return {
45
+ key: ie.key,
46
+ metadata: {
47
+ reference_id: ie.reference_id,
48
+ reference_url: ie.url,
49
+ reference_title: ie.url,
50
+ reference_display_name: ie.url,
51
+ sources: [],
52
+ __typename: "GenAISearchCitationItem",
53
+ },
54
+ };
55
+ }
56
+
57
+ if (type == "latex") {
58
+ return {
59
+ key: ie.key,
60
+ metadata: {
61
+ latex_expression: ie.text,
62
+ latex_image: {
63
+ url: ie.url,
64
+ width: Number(ie.width) || 100,
65
+ height: Number(ie.height) || 100,
66
+ },
67
+ font_height: Number(ie.font_height) || 83.333333333333,
68
+ padding: Number(ie.padding) || 15,
69
+ __typename: "GenAILatexItem",
70
+ },
71
+ };
72
+ }
73
+ };
74
+
75
+ let ie = [];
76
+ let inline_entities = [];
77
+ let result = "";
78
+ let last = 0;
79
+ let citation_index = 1;
80
+ let hyperlink_index = 0;
81
+ let latex_index = 0;
82
+ let stack = [];
83
+
84
+ for (let i = 0; i < text.length; i++) {
85
+ if (text[i] == "[" && text[i - 1] != "\\") {
86
+ stack.push(i);
87
+ } else if (text[i] == "]" && (text[i + 1] == "(" || text[i + 1] == "<")) {
88
+ let start = stack.pop();
89
+
90
+ if (start == null) continue;
91
+
92
+ let open = text[i + 1];
93
+ let close = open == "(" ? ")" : ">";
94
+ let type = open == "(" ? "link" : "latex";
95
+ let end = i + 2;
96
+ let depth = 1;
97
+
98
+ while (end < text.length && depth) {
99
+ if (text[end] == open && text[end - 1] != "\\") depth++;
100
+ else if (text[end] == close && text[end - 1] != "\\") depth--;
101
+ end++;
102
+ }
103
+
104
+ if (depth) continue;
105
+
106
+ let raw = text.slice(start + 1, i).trim();
107
+ let url = text.slice(i + 2, end - 1).trim();
108
+
109
+ let key;
110
+ let tag;
111
+ let data;
112
+
113
+ if (type == "latex") {
114
+ if (!latex) continue;
115
+
116
+ let [
117
+ txt = "",
118
+ width = null,
119
+ height = null,
120
+ font_height = null,
121
+ padding = null,
122
+ ] = raw.split("|");
123
+
124
+ key = `\u004E\u0049\u0058\u0045\u004C_LATEX_${latex_index++}`;
125
+ tag = `{{${key}}}${txt || "image"}{{/${key}}}`;
126
+
127
+ data = {
128
+ type: "latex",
129
+ ie: {
130
+ key,
131
+ text: txt,
132
+ url,
133
+ width,
134
+ height,
135
+ font_height,
136
+ padding,
137
+ },
138
+ };
139
+ } else if (raw) {
140
+ if (!hyperlink) continue;
141
+
142
+ const trusted = !url.startsWith("!");
143
+
144
+ if (!trusted) {
145
+ url = url.slice(1);
146
+ }
147
+
148
+ key = `\u004E\u0049\u0058\u0045\u004C_HYPERLINK_${hyperlink_index++}`;
149
+ tag = `{{${key}}}${url}{{/${key}}}`;
150
+
151
+ data = {
152
+ type: "hyperlink",
153
+ ie: {
154
+ key,
155
+ text: raw,
156
+ url,
157
+ is_trusted: trusted,
158
+ },
159
+ };
160
+ } else {
161
+ if (!citation) continue;
162
+
163
+ key = `\u004E\u0049\u0058\u0045\u004C_CITATION_${citation_index - 1}`;
164
+ tag = `{{${key}}}${url}{{/${key}}}`;
165
+
166
+ data = {
167
+ type: "citation",
168
+ ie: {
169
+ reference_id: citation_index++,
170
+ key,
171
+ text: "",
172
+ url,
173
+ },
174
+ };
175
+ }
176
+
177
+ result += text.slice(last, start) + tag;
178
+ last = end;
179
+
180
+ ie.push(data);
181
+
182
+ const entity = createIE(data.type, data.ie);
183
+
184
+ if (entity) {
185
+ inline_entities.push(entity);
186
+ }
187
+
188
+ i = end - 1;
189
+ }
190
+ }
191
+
192
+ result += text.slice(last);
193
+
194
+ return {
195
+ text: result,
196
+ ie,
197
+ inline_entities,
198
+ };
199
+ }
200
+
201
+ async function waitAllPromises(input) {
202
+ const isPromise = (v) => v && typeof v.then === "function";
203
+ const isObject = (v) => v && typeof v === "object";
204
+
205
+ const deep = async (v) => {
206
+ if (isPromise(v)) return deep(await v);
207
+ if (Array.isArray(v)) return Promise.all(v.map(deep));
208
+ if (isObject(v)) {
209
+ const entries = await Promise.all(
210
+ Object.entries(v).map(async ([k, val]) => [k, await deep(val)]),
211
+ );
212
+ return Object.fromEntries(entries);
213
+ }
214
+ return v;
215
+ };
216
+
217
+ return deep(await input);
218
+ }
219
+
220
+ class Toolkit {
221
+ constructor() {}
222
+
223
+ static extractIE(
224
+ text,
225
+ { extract = true, hyperlink = true, citation = true, latex = true } = {},
226
+ ) {
227
+ return extractIE(text, { extract, hyperlink, citation, latex });
228
+ }
229
+
230
+ static async resize(buffer, x, y, fit = "cover") {
231
+ return await sharp(buffer)
232
+ .resize(x, y, {
233
+ fit,
234
+ position: "center",
235
+ background: { r: 0, g: 0, b: 0, alpha: 0 },
236
+ })
237
+ .png()
238
+ .toBuffer();
239
+ }
240
+
241
+ static async waitAllPromises(input) {
242
+ return await waitAllPromises(input);
243
+ }
244
+
245
+ static async fetchBuffer(url, options = {}, { silent = true } = {}) {
246
+ try {
247
+ let response = await fetch(url, options);
248
+ if (!response.ok) throw Error(`HTTP ${response.status}`);
249
+ return Buffer.from(await response.arrayBuffer());
250
+ } catch (error) {
251
+ if (silent) return Buffer.alloc(0);
252
+ throw error;
253
+ }
254
+ }
255
+
256
+ static async toUrl(_client, path, mediaType = "document") {
257
+ if (!path) throw new Error("Url or buffer needed");
258
+
259
+ const media = await prepareWAMessageMedia(
260
+ {
261
+ [mediaType]: Buffer.isBuffer(path) ? path : { url: path },
262
+ },
263
+ {
264
+ upload: _client.waUploadToServer,
265
+ jid: "\u0040\u006e\u0065\u0077\u0073\u006c\u0065\u0074\u0074\u0065\u0072",
266
+ },
267
+ );
268
+
269
+ return Object.values(media)[0]?.url;
270
+ }
271
+
272
+ static async resolveMedia(
273
+ _client,
274
+ media,
275
+ mediaType = "image",
276
+ {
277
+ resolveUrl = false,
278
+ resolveWAUrl = false,
279
+ result = "url",
280
+ resize = false,
281
+ width = 300,
282
+ height = 300,
283
+ } = {},
284
+ ) {
285
+ const isUrl = (str) => /^https?:\/\/.+/i.test(str);
286
+
287
+ const isWAUrl = (str) => /^https?:\/\/[^/]*\.whatsapp\.net\//i.test(str);
288
+
289
+ if (Array.isArray(media)) {
290
+ return Promise.all(
291
+ media.map((item) =>
292
+ Toolkit.resolveMedia(_client, item, mediaType, {
293
+ resolveUrl,
294
+ resolveWAUrl,
295
+ result,
296
+ resize,
297
+ width,
298
+ height,
299
+ }),
300
+ ),
301
+ );
302
+ }
303
+
304
+ const originalIsBuffer = Buffer.isBuffer(media);
305
+
306
+ if (typeof media === "string" && isUrl(media)) {
307
+ if (isWAUrl(media)) {
308
+ if (resolveWAUrl) {
309
+ media = await Toolkit.fetchBuffer(media, {}, { silent: true });
310
+ } else if (!resolveUrl) {
311
+ if (result === "url") return media;
312
+
313
+ media = await Toolkit.fetchBuffer(media, {}, { silent: true });
314
+ }
315
+ } else {
316
+ if (!resolveUrl) {
317
+ if (result === "url") return media;
318
+
319
+ media = await Toolkit.fetchBuffer(media, {}, { silent: true });
320
+ } else {
321
+ media = await Toolkit.fetchBuffer(media, {}, { silent: true });
322
+ }
323
+ }
324
+ }
325
+
326
+ if (typeof media === "string" && !isUrl(media)) {
327
+ media = Buffer.from(media, "base64");
328
+ }
329
+
330
+ if (!Buffer.isBuffer(media) || !media.length) {
331
+ return;
332
+ }
333
+
334
+ if (resize && Buffer.isBuffer(media)) {
335
+ media = await Toolkit.resize(media, width, height);
336
+ }
337
+
338
+ if (result === "buffer") {
339
+ return media;
340
+ }
341
+
342
+ if (result === "base64") {
343
+ return media.toString("base64");
344
+ }
345
+
346
+ if (originalIsBuffer) {
347
+ return Toolkit.toUrl(_client, media, mediaType);
348
+ }
349
+
350
+ return Toolkit.toUrl(_client, media, mediaType);
351
+ }
352
+
353
+ static getMp4Duration(buffer, { silent = true } = {}) {
354
+ try {
355
+ if (!Buffer.isBuffer(buffer) || buffer.length < 8) {
356
+ if (silent) return 0;
357
+ throw new Error("Invalid buffer");
358
+ }
359
+
360
+ let offset = 0;
361
+
362
+ while (offset < buffer.length - 8) {
363
+ const size = buffer.readUInt32BE(offset);
364
+
365
+ if (size < 8 || offset + size > buffer.length) {
366
+ if (silent) return 0;
367
+ throw new Error("Invalid atom size");
368
+ }
369
+
370
+ const type = buffer.toString("ascii", offset + 4, offset + 8);
371
+
372
+ if (type === "moov") {
373
+ let moovOffset = offset + 8;
374
+ const moovEnd = offset + size;
375
+
376
+ while (moovOffset < moovEnd - 8) {
377
+ const childSize = buffer.readUInt32BE(moovOffset);
378
+
379
+ if (childSize < 8 || moovOffset + childSize > moovEnd) {
380
+ if (silent) return 0;
381
+ throw new Error("Invalid child atom size");
382
+ }
383
+
384
+ const childType = buffer.toString(
385
+ "ascii",
386
+ moovOffset + 4,
387
+ moovOffset + 8,
388
+ );
389
+
390
+ if (childType === "mvhd") {
391
+ const version = buffer.readUInt8(moovOffset + 8);
392
+
393
+ if (version === 0) {
394
+ const timescale = buffer.readUInt32BE(moovOffset + 20);
395
+ const duration = buffer.readUInt32BE(moovOffset + 24);
396
+
397
+ if (!timescale) {
398
+ if (silent) return 0;
399
+ throw new Error("Invalid timescale");
400
+ }
401
+
402
+ return duration / timescale;
403
+ }
404
+
405
+ if (version === 1) {
406
+ const timescale = buffer.readUInt32BE(moovOffset + 32);
407
+ const duration = Number(
408
+ buffer.readBigUInt64BE(moovOffset + 36),
409
+ );
410
+
411
+ if (!timescale) {
412
+ if (silent) return 0;
413
+ throw new Error("Invalid timescale");
414
+ }
415
+
416
+ return duration / timescale;
417
+ }
418
+ }
419
+
420
+ moovOffset += childSize;
421
+ }
422
+ }
423
+
424
+ offset += size;
425
+ }
426
+
427
+ if (silent) return 0;
428
+
429
+ throw new Error("No mvhd found!");
430
+ } catch (err) {
431
+ if (silent) return 0;
432
+ throw err;
433
+ }
434
+ }
435
+
436
+ static getMp4Preview(
437
+ videoBuffer,
438
+ {
439
+ time,
440
+ result = "buffer",
441
+ resize = true,
442
+ width = 300,
443
+ height = 300,
444
+ silent = true,
445
+ } = {},
446
+ ) {
447
+ return new Promise((resolve, reject) => {
448
+ const fail = (err) => {
449
+ if (silent) {
450
+ return resolve(result === "base64" ? "" : Buffer.alloc(0));
451
+ }
452
+ return reject(err);
453
+ };
454
+
455
+ try {
456
+ if (!Buffer.isBuffer(videoBuffer) || !videoBuffer.length) {
457
+ return fail(new Error("videoBuffer tidak valid atau kosong"));
458
+ }
459
+
460
+ const inputStream = new Readable({ read() {} });
461
+ inputStream.push(videoBuffer);
462
+ inputStream.push(null);
463
+
464
+ const outputStream = new PassThrough();
465
+ const chunks = [];
466
+
467
+ outputStream.on("data", (chunk) => chunks.push(chunk));
468
+
469
+ outputStream.on("end", async () => {
470
+ try {
471
+ let output = Buffer.concat(chunks);
472
+
473
+ if (!output.length) {
474
+ return fail(
475
+ new Error("Output kosong — cek format atau timestamp video"),
476
+ );
477
+ }
478
+
479
+ if (resize) {
480
+ output = await Toolkit.resize(output, width, height);
481
+ }
482
+
483
+ return resolve(
484
+ result === "base64" ? output.toString("base64") : output,
485
+ );
486
+ } catch (err) {
487
+ return fail(err);
488
+ }
489
+ });
490
+
491
+ outputStream.on("error", fail);
492
+
493
+ time ??= Math.min(Toolkit.getMp4Duration(videoBuffer) * 0.2, 10);
494
+
495
+ ffmpeg(inputStream)
496
+ .outputOptions([
497
+ `-ss ${time}`,
498
+ "-vframes 1",
499
+ "-vcodec png",
500
+ "-f image2pipe",
501
+ ])
502
+ .on("error", (err) => fail(new Error(`ffmpeg error: ${err.message}`)))
503
+ .pipe(outputStream, { end: true });
504
+ } catch (err) {
505
+ return fail(err);
506
+ }
507
+ });
508
+ }
509
+ }
510
+
511
+ class BaseBuilder {
512
+ constructor() {
513
+ this._title = "";
514
+ this._subtitle = "";
515
+ this._body = "";
516
+ this._footer = "";
517
+ this._contextInfo = {};
518
+ this._extraPayload = {};
519
+ }
520
+
521
+ setTitle(title) {
522
+ if (typeof title !== "string") {
523
+ throw new TypeError("Title must be a string");
524
+ }
525
+ this._title = title;
526
+ return this;
527
+ }
528
+
529
+ setSubtitle(subtitle) {
530
+ if (typeof subtitle !== "string") {
531
+ throw new TypeError("Subtitle must be a string");
532
+ }
533
+ this._subtitle = subtitle;
534
+ return this;
535
+ }
536
+
537
+ setBody(body) {
538
+ if (typeof body !== "string") {
539
+ throw new TypeError("Body must be a string");
540
+ }
541
+ this._body = body;
542
+ return this;
543
+ }
544
+
545
+ setFooter(footer) {
546
+ if (typeof footer !== "string") {
547
+ throw new TypeError("Footer must be a string");
548
+ }
549
+ this._footer = footer;
550
+ return this;
551
+ }
552
+
553
+ setContextInfo(obj) {
554
+ if (typeof obj !== "object" || obj === null || Array.isArray(obj)) {
555
+ throw new TypeError("ContextInfo must be a plain object");
556
+ }
557
+
558
+ this._contextInfo = obj;
559
+ return this;
560
+ }
561
+
562
+ addPayload(obj) {
563
+ if (typeof obj !== "object" || obj === null || Array.isArray(obj)) {
564
+ throw new TypeError("Payload must be a plain object");
565
+ }
566
+
567
+ Object.assign(this._extraPayload, obj);
568
+
569
+ return this;
570
+ }
571
+ }
572
+
573
+ class Button extends BaseBuilder {
574
+ #client;
575
+
576
+ constructor(client) {
577
+ super();
578
+ if (!client) {
579
+ throw new Error("Socket is required");
580
+ }
581
+ this.#client = client;
582
+
583
+ this._buttons = [];
584
+ this._data;
585
+ this._currentSelectionIndex = -1;
586
+ this._currentSectionIndex = -1;
587
+ this._params = {};
588
+ }
589
+
590
+ setVideo(path, options = {}) {
591
+ if (!path) throw new Error("Url or buffer needed");
592
+ Buffer.isBuffer(path)
593
+ ? (this._data = { video: path, ...options })
594
+ : (this._data = { video: { url: path }, ...options });
595
+ return this;
596
+ }
597
+
598
+ setImage(path, options = {}) {
599
+ if (!path) throw new Error("Url or buffer needed");
600
+ Buffer.isBuffer(path)
601
+ ? (this._data = { image: path, ...options })
602
+ : (this._data = { image: { url: path }, ...options });
603
+ return this;
604
+ }
605
+
606
+ setDocument(path, options = {}) {
607
+ if (!path) throw new Error("Url or buffer needed");
608
+ Buffer.isBuffer(path)
609
+ ? (this._data = { document: path, ...options })
610
+ : (this._data = { document: { url: path }, ...options });
611
+ return this;
612
+ }
613
+
614
+ setMedia(obj) {
615
+ if (typeof obj !== "object" || obj === null || Array.isArray(obj)) {
616
+ throw new TypeError("Media must be a plain object");
617
+ }
618
+
619
+ this._data = obj;
620
+ return this;
621
+ }
622
+
623
+ clearButtons() {
624
+ this._buttons = [];
625
+ return this;
626
+ }
627
+
628
+ setParams(obj) {
629
+ this._params = obj;
630
+ return this;
631
+ }
632
+
633
+ addButton(name, params) {
634
+ this._buttons.push({
635
+ name,
636
+ buttonParamsJson:
637
+ typeof params === "string" ? params : JSON.stringify(params),
638
+ });
639
+
640
+ return this;
641
+ }
642
+
643
+ makeRow(header = "", title = "", description = "", id = "") {
644
+ if (
645
+ this._currentSelectionIndex === -1 ||
646
+ this._currentSectionIndex === -1
647
+ ) {
648
+ throw new Error("You need to create a selection and a section first");
649
+ }
650
+ const buttonParams = JSON.parse(
651
+ this._buttons[this._currentSelectionIndex].buttonParamsJson,
652
+ );
653
+ buttonParams.sections[this._currentSectionIndex].rows.push({
654
+ header,
655
+ title,
656
+ description,
657
+ id,
658
+ });
659
+ this._buttons[this._currentSelectionIndex].buttonParamsJson =
660
+ JSON.stringify(buttonParams);
661
+ return this;
662
+ }
663
+
664
+ makeSection(title = "", highlight_label = "") {
665
+ if (this._currentSelectionIndex === -1) {
666
+ throw new Error("You need to create a selection first");
667
+ }
668
+ const buttonParams = JSON.parse(
669
+ this._buttons[this._currentSelectionIndex].buttonParamsJson,
670
+ );
671
+ buttonParams.sections.push({ title, highlight_label, rows: [] });
672
+ this._currentSectionIndex = buttonParams.sections.length - 1;
673
+ this._buttons[this._currentSelectionIndex].buttonParamsJson =
674
+ JSON.stringify(buttonParams);
675
+ return this;
676
+ }
677
+
678
+ addSelection(title, options = {}) {
679
+ this._buttons.push({
680
+ ...options,
681
+ name: "single_select",
682
+ buttonParamsJson: JSON.stringify({ title, sections: [] }),
683
+ });
684
+ this._currentSelectionIndex = this._buttons.length - 1;
685
+ this._currentSectionIndex = -1;
686
+ return this;
687
+ }
688
+
689
+ addReply(display_text = "", id = "", options = {}) {
690
+ this._buttons.push({
691
+ name: "quick_reply",
692
+ buttonParamsJson: JSON.stringify({
693
+ display_text,
694
+ id,
695
+ ...options,
696
+ }),
697
+ });
698
+ return this;
699
+ }
700
+
701
+ addCall(display_text = "", id = "", options = {}) {
702
+ this._buttons.push({
703
+ name: "cta_call",
704
+ buttonParamsJson: JSON.stringify({
705
+ display_text,
706
+ id,
707
+ ...options,
708
+ }),
709
+ });
710
+ return this;
711
+ }
712
+
713
+ addReminder(display_text = "", id = "", options = {}) {
714
+ this._buttons.push({
715
+ name: "cta_reminder",
716
+ buttonParamsJson: JSON.stringify({
717
+ display_text,
718
+ id,
719
+ ...options,
720
+ }),
721
+ });
722
+ return this;
723
+ }
724
+
725
+ addCancelReminder(display_text = "", id = "", options = {}) {
726
+ this._buttons.push({
727
+ name: "cta_cancel_reminder",
728
+ buttonParamsJson: JSON.stringify({
729
+ display_text,
730
+ id,
731
+ ...options,
732
+ }),
733
+ });
734
+ return this;
735
+ }
736
+
737
+ addAddress(display_text = "", id = "", options = {}) {
738
+ this._buttons.push({
739
+ name: "address_message",
740
+ buttonParamsJson: JSON.stringify({
741
+ display_text,
742
+ id,
743
+ ...options,
744
+ }),
745
+ });
746
+ return this;
747
+ }
748
+
749
+ addLocation(options = {}) {
750
+ this._buttons.push({
751
+ name: "send_location",
752
+ buttonParamsJson: JSON.stringify(options),
753
+ });
754
+ return this;
755
+ }
756
+
757
+ addUrl(
758
+ display_text = "",
759
+ url = "",
760
+ webview_interaction = false,
761
+ options = {},
762
+ ) {
763
+ this._buttons.push({
764
+ ...options,
765
+ name: "cta_url",
766
+ buttonParamsJson: JSON.stringify({
767
+ display_text,
768
+ url,
769
+ webview_interaction,
770
+ ...options,
771
+ }),
772
+ });
773
+ return this;
774
+ }
775
+
776
+ addCopy(display_text = "", copy_code = "", options = {}) {
777
+ this._buttons.push({
778
+ name: "cta_copy",
779
+ buttonParamsJson: JSON.stringify({
780
+ display_text,
781
+ copy_code,
782
+ ...options,
783
+ }),
784
+ });
785
+ return this;
786
+ }
787
+
788
+ static paramsList = {
789
+ limited_time_offer: {
790
+ text: "string",
791
+ url: "string",
792
+ copy_code: "string",
793
+ expiration_time: "number",
794
+ },
795
+ bottom_sheet: {
796
+ in_thread_buttons_limit: "number",
797
+ divider_indices: ["number"],
798
+ list_title: "string",
799
+ button_title: "string",
800
+ },
801
+ tap_target_configuration: {
802
+ title: "string",
803
+ description: "string",
804
+ canonical_url: "string",
805
+ domain: "string",
806
+ buttonIndex: "number",
807
+ },
808
+ };
809
+
810
+ async toCard() {
811
+ return {
812
+ body: {
813
+ text: this._body,
814
+ },
815
+ footer: {
816
+ text: this._footer,
817
+ },
818
+ header: {
819
+ title: this._title,
820
+ subtitle: this._subtitle,
821
+ hasMediaAttachment: !!this._data,
822
+ ...(this._data
823
+ ? await prepareWAMessageMedia(this._data, {
824
+ upload: this.#client.waUploadToServer,
825
+ }).catch((e) => {
826
+ if (String(e).includes("Invalid media type")) return this._data;
827
+ throw e;
828
+ })
829
+ : {}),
830
+ },
831
+ nativeFlowMessage: {
832
+ messageParamsJson: JSON.stringify(this._params),
833
+ buttons: this._buttons,
834
+ },
835
+ };
836
+ }
837
+
838
+ async build(jid, { ...options } = {}) {
839
+ const message = await this.toCard();
840
+
841
+ return generateWAMessageFromContent(
842
+ jid,
843
+ {
844
+ ...this._extraPayload,
845
+ interactiveMessage: {
846
+ ...message,
847
+ contextInfo: this._contextInfo,
848
+ },
849
+ },
850
+ { ...options },
851
+ );
852
+ }
853
+
854
+ async send(jid, { ...options } = {}) {
855
+ const msg = await this.build(jid, options);
856
+
857
+ await this.#client.relayMessage(msg.key.remoteJid, msg.message, {
858
+ messageId: msg.key.id,
859
+ additionalNodes: [
860
+ {
861
+ tag: "biz",
862
+ attrs: {},
863
+ content: [
864
+ {
865
+ tag: "interactive",
866
+ attrs: { type: "native_flow", v: "1" },
867
+ content: [
868
+ { tag: "native_flow", attrs: { v: "9", name: "mixed" } },
869
+ ],
870
+ },
871
+ ],
872
+ },
873
+ ],
874
+ ...options,
875
+ });
876
+ return msg;
877
+ }
878
+ }
879
+
880
+ class ButtonV2 extends BaseBuilder {
881
+ #client;
882
+
883
+ constructor(client) {
884
+ super();
885
+ if (!client) {
886
+ throw new Error("Socket is required");
887
+ }
888
+
889
+ this.#client = client;
890
+ this._image;
891
+ this._data;
892
+ this._buttons = [];
893
+ }
894
+
895
+ addButton(displayText = "", buttonId = crypto.randomUUID()) {
896
+ this._buttons.push({
897
+ buttonId,
898
+ buttonText: { displayText },
899
+ type: 1,
900
+ });
901
+ return this;
902
+ }
903
+
904
+ addRawButton(obj) {
905
+ if (typeof obj !== "object" || obj === null || Array.isArray(obj)) {
906
+ throw new TypeError("Buttons must be a plain object");
907
+ }
908
+
909
+ this._buttons.push(obj);
910
+ return this;
911
+ }
912
+
913
+ setThumbnail(path) {
914
+ if (!path) throw new Error("Url or buffer needed");
915
+ this._image = path;
916
+ return this;
917
+ }
918
+
919
+ setMedia(obj) {
920
+ if (typeof obj !== "object" || obj === null || Array.isArray(obj)) {
921
+ throw new TypeError("Media must be a plain object");
922
+ }
923
+
924
+ this._data = obj;
925
+ return this;
926
+ }
927
+
928
+ async build(jid, { ...options } = {}) {
929
+ let _thumbnail = this._image
930
+ ? await Toolkit.resize(
931
+ Buffer.isBuffer(this._image)
932
+ ? this._image
933
+ : await Toolkit.fetchBuffer(this._image, {}, { silent: true }),
934
+ 300,
935
+ 300,
936
+ )
937
+ : null;
938
+ const msg = generateWAMessageFromContent(
939
+ jid,
940
+ {
941
+ ...this._extraPayload,
942
+ buttonsMessage: {
943
+ contentText: this._body,
944
+ footerText: this._footer,
945
+ ...(this._data
946
+ ? this._data
947
+ : {
948
+ headerType: 6,
949
+ locationMessage: {
950
+ degreesLatitude: 0,
951
+ degreesLongitude: 0,
952
+ name: this._title,
953
+ address: this._subtitle,
954
+ jpegThumbnail: _thumbnail,
955
+ },
956
+ }),
957
+ viewOnce: true,
958
+ contextInfo: this._contextInfo,
959
+ buttons: [...this._buttons],
960
+ },
961
+ },
962
+ { ...options },
963
+ );
964
+ return msg;
965
+ }
966
+
967
+ async send(jid, { ...options } = {}) {
968
+ if (this._buttons.length < 1)
969
+ throw new Error("ButtonV2 requires at least one button");
970
+ const msg = await this.build(jid, options);
971
+
972
+ await this.#client.relayMessage(msg.key.remoteJid, msg.message, {
973
+ messageId: msg.key.id,
974
+ additionalNodes: [
975
+ {
976
+ tag: "biz",
977
+ attrs: {},
978
+ content: [
979
+ {
980
+ tag: "interactive",
981
+ attrs: { type: "native_flow", v: "1" },
982
+ content: [
983
+ { tag: "native_flow", attrs: { v: "9", name: "mixed" } },
984
+ ],
985
+ },
986
+ ],
987
+ },
988
+ ],
989
+ ...options,
990
+ });
991
+ return msg;
992
+ }
993
+ }
994
+
995
+ class Carousel extends BaseBuilder {
996
+ #client;
997
+
998
+ constructor(client) {
999
+ super();
1000
+ if (!client) {
1001
+ throw new Error("Socket is required");
1002
+ }
1003
+
1004
+ this.#client = client;
1005
+ this._cards = [];
1006
+ }
1007
+
1008
+ addCard(card) {
1009
+ const cards = Array.isArray(card) ? card : [card];
1010
+ const baseIndex = this._cards.length;
1011
+
1012
+ for (const [index, c] of cards.entries()) {
1013
+ if (!c?.header?.hasMediaAttachment) {
1014
+ throw new Error(
1015
+ `Card [${baseIndex + index}] must include an image or video in header`,
1016
+ );
1017
+ }
1018
+ }
1019
+
1020
+ this._cards.push(...cards);
1021
+ return this;
1022
+ }
1023
+
1024
+ build(jid, { ...options } = {}) {
1025
+ return generateWAMessageFromContent(
1026
+ jid,
1027
+ {
1028
+ ...this._extraPayload,
1029
+ interactiveMessage: {
1030
+ header: {
1031
+ hasMediaAttachment: false,
1032
+ },
1033
+ body: { text: this._body },
1034
+ footer: { text: this._footer },
1035
+ contextInfo: this._contextInfo,
1036
+ carouselMessage: {
1037
+ cards: this._cards,
1038
+ },
1039
+ },
1040
+ },
1041
+ { ...options },
1042
+ );
1043
+ }
1044
+
1045
+ async send(jid, { ...options } = {}) {
1046
+ const msg = this.build(jid, options);
1047
+
1048
+ await this.#client.relayMessage(msg.key.remoteJid, msg.message, {
1049
+ messageId: msg.key.id,
1050
+ additionalNodes: [
1051
+ {
1052
+ tag: "biz",
1053
+ attrs: {},
1054
+ content: [
1055
+ {
1056
+ tag: "interactive",
1057
+ attrs: { type: "native_flow", v: "1" },
1058
+ content: [
1059
+ { tag: "native_flow", attrs: { v: "9", name: "mixed" } },
1060
+ ],
1061
+ },
1062
+ ],
1063
+ },
1064
+ ],
1065
+ ...options,
1066
+ });
1067
+ return msg;
1068
+ }
1069
+ }
1070
+
1071
+ class AIRich extends BaseBuilder {
1072
+ #client;
1073
+
1074
+ constructor(client) {
1075
+ if (!client) {
1076
+ throw new Error("Socket is required");
1077
+ }
1078
+
1079
+ super();
1080
+ this.#client = client;
1081
+ this._contextInfo = {};
1082
+ this._submessages = [];
1083
+ this._sections = [];
1084
+ this._richResponseSources = [];
1085
+ }
1086
+
1087
+ addSubmessage(submessage) {
1088
+ const items = Array.isArray(submessage) ? submessage : [submessage];
1089
+
1090
+ for (const item of items) {
1091
+ if (typeof item !== "object" || item === null || Array.isArray(item)) {
1092
+ throw new TypeError(
1093
+ "Submessage must be a plain object or array of plain objects",
1094
+ );
1095
+ }
1096
+
1097
+ this._submessages.push(item);
1098
+ }
1099
+
1100
+ return this;
1101
+ }
1102
+
1103
+ addSection(section) {
1104
+ const items = Array.isArray(section) ? section : [section];
1105
+
1106
+ for (const item of items) {
1107
+ if (typeof item !== "object" || item === null || Array.isArray(item)) {
1108
+ throw new TypeError(
1109
+ "Section must be a plain object or array of plain objects",
1110
+ );
1111
+ }
1112
+
1113
+ this._sections.push(item);
1114
+ }
1115
+
1116
+ return this;
1117
+ }
1118
+
1119
+ addText(text, { hyperlink = true, citation = true, latex = true } = {}) {
1120
+ if (typeof text != "string") {
1121
+ throw new TypeError("Text must be a string");
1122
+ }
1123
+
1124
+ const { text: extractedText, inline_entities } = extractIE(text, {
1125
+ hyperlink,
1126
+ citation,
1127
+ latex,
1128
+ });
1129
+
1130
+ this._submessages.push({
1131
+ messageType: 2,
1132
+ messageText: extractedText,
1133
+ });
1134
+
1135
+ this._sections.push(
1136
+ AIRich.newLayout("Single", {
1137
+ text: extractedText,
1138
+ ...(inline_entities.length && {
1139
+ inline_entities,
1140
+ }),
1141
+ __typename: "GenAIMarkdownTextUXPrimitive",
1142
+ }),
1143
+ );
1144
+
1145
+ return this;
1146
+ }
1147
+
1148
+ addCode(language, code) {
1149
+ if (typeof language !== "string" || typeof code !== "string") {
1150
+ throw new TypeError("Language and code must be a string");
1151
+ }
1152
+
1153
+ const meta = AIRich.tokenizer(code, language);
1154
+
1155
+ this._submessages.push({
1156
+ messageType: 5,
1157
+ codeMetadata: {
1158
+ codeLanguage: language,
1159
+ codeBlocks: meta.codeBlock,
1160
+ },
1161
+ });
1162
+
1163
+ this._sections.push(
1164
+ AIRich.newLayout("Single", {
1165
+ language,
1166
+ code_blocks: meta.unified_codeBlock,
1167
+ __typename: "GenAICodeUXPrimitive",
1168
+ }),
1169
+ );
1170
+
1171
+ return this;
1172
+ }
1173
+
1174
+ addTable(table, { hyperlink = true, citation = true, latex = true } = {}) {
1175
+ if (!Array.isArray(table)) {
1176
+ throw new TypeError("Table must be an array");
1177
+ }
1178
+
1179
+ const meta = AIRich.toTableMetadata(table, { hyperlink, citation, latex });
1180
+
1181
+ this._submessages.push({
1182
+ messageType: 4,
1183
+ tableMetadata: {
1184
+ title: meta.title,
1185
+ rows: meta.rows,
1186
+ },
1187
+ });
1188
+
1189
+ this._sections.push(
1190
+ AIRich.newLayout("Single", {
1191
+ rows: meta.unified_rows,
1192
+ __typename: "GenATableUXPrimitive",
1193
+ }),
1194
+ );
1195
+
1196
+ return this;
1197
+ }
1198
+
1199
+ addSource(sources = []) {
1200
+ if (
1201
+ !(
1202
+ Array.isArray(sources) &&
1203
+ (sources.every((item) => typeof item === "string") ||
1204
+ sources.every(
1205
+ (item) =>
1206
+ Array.isArray(item) && item.every((v) => typeof v === "string"),
1207
+ ))
1208
+ )
1209
+ ) {
1210
+ throw new TypeError(
1211
+ "Sources must be a string array or an array of string arrays",
1212
+ );
1213
+ }
1214
+
1215
+ if (sources.every((item) => typeof item === "string")) {
1216
+ sources = [sources];
1217
+ }
1218
+
1219
+ const source = sources.map(([icon, url, text]) => ({
1220
+ source_type: "THIRD_PARTY",
1221
+ source_display_name: text ?? "",
1222
+ source_subtitle: "AI",
1223
+ source_url: url ?? "",
1224
+ favicon: {
1225
+ url: Toolkit.resolveMedia(this.#client, icon ?? "", "image"),
1226
+ mime_type: "image/jpeg",
1227
+ width: 16,
1228
+ height: 16,
1229
+ },
1230
+ }));
1231
+
1232
+ this._sections.push(
1233
+ AIRich.newLayout("Single", {
1234
+ sources: source,
1235
+ __typename: "GenAISearchResultPrimitive",
1236
+ }),
1237
+ );
1238
+
1239
+ return this;
1240
+ }
1241
+
1242
+ addReels(reelsItems = []) {
1243
+ if (
1244
+ !(
1245
+ (reelsItems &&
1246
+ typeof reelsItems === "object" &&
1247
+ !Array.isArray(reelsItems)) ||
1248
+ (Array.isArray(reelsItems) &&
1249
+ reelsItems.every(
1250
+ (item) => item && typeof item === "object" && !Array.isArray(item),
1251
+ ))
1252
+ )
1253
+ ) {
1254
+ throw new TypeError(
1255
+ "Reels items must be an object or an array of objects",
1256
+ );
1257
+ }
1258
+
1259
+ if (!Array.isArray(reelsItems)) {
1260
+ reelsItems = [reelsItems];
1261
+ }
1262
+
1263
+ const reels = reelsItems.map((item) => ({
1264
+ ...item,
1265
+ _avatar: Toolkit.resolveMedia(
1266
+ this.#client,
1267
+ item.profileIconUrl ?? item.profile_url ?? item.profile ?? "",
1268
+ "image",
1269
+ ),
1270
+ _thumbnail: Toolkit.resolveMedia(
1271
+ this.#client,
1272
+ item.thumbnailUrl ?? item.thumbnail ?? "",
1273
+ "image",
1274
+ ),
1275
+ }));
1276
+
1277
+ this._submessages.push({
1278
+ messageType: 9,
1279
+ contentItemsMetadata: {
1280
+ contentType: 1,
1281
+ itemsMetadata: reels.map((item) => ({
1282
+ reelItem: {
1283
+ title: item.username ?? "",
1284
+ profileIconUrl: item._avatar,
1285
+ thumbnailUrl: item._thumbnail,
1286
+ videoUrl: item.videoUrl ?? item.url ?? "",
1287
+ },
1288
+ })),
1289
+ },
1290
+ });
1291
+
1292
+ reels.forEach((item, idx) => {
1293
+ this._richResponseSources.push({
1294
+ provider: "\u004E\u0049\u0058\u0045\u004C",
1295
+ thumbnailCDNURL: item._thumbnail,
1296
+ sourceProviderURL: item.videoUrl ?? item.url ?? "",
1297
+ sourceQuery: "",
1298
+ faviconCDNURL: item._avatar,
1299
+ citationNumber: idx + 1,
1300
+ sourceTitle: item.username ?? "",
1301
+ });
1302
+ });
1303
+
1304
+ this._sections.push(
1305
+ AIRich.newLayout(
1306
+ "HScroll",
1307
+ reels.map((item) => ({
1308
+ reels_url: item.videoUrl ?? item.url ?? "",
1309
+ thumbnail_url: item._thumbnail,
1310
+ creator: item.username ?? item.title ?? "",
1311
+ avatar_url: item._avatar,
1312
+ reels_title: item.reels_title ?? item.title ?? "",
1313
+ likes_count: item.likes_count ?? item.like ?? 0,
1314
+ shares_count: item.shares_count ?? item.share ?? 0,
1315
+ view_count: item.view_count ?? item.view ?? 0,
1316
+ reel_source: item.reel_source ?? item.source ?? "IG",
1317
+ is_verified: !!(item.is_verified || item.verified),
1318
+ __typename: "GenAIReelPrimitive",
1319
+ })),
1320
+ ),
1321
+ );
1322
+
1323
+ return this;
1324
+ }
1325
+
1326
+ addImage(imageUrl, { resolveUrl = false } = {}) {
1327
+ if (
1328
+ !(
1329
+ typeof imageUrl === "string" ||
1330
+ Buffer.isBuffer(imageUrl) ||
1331
+ (Array.isArray(imageUrl) &&
1332
+ imageUrl.every((v) => typeof v === "string" || Buffer.isBuffer(v)))
1333
+ )
1334
+ ) {
1335
+ throw new TypeError(
1336
+ "imageUrl must be string | buffer | array of string/buffer",
1337
+ );
1338
+ }
1339
+
1340
+ const list = Array.isArray(imageUrl)
1341
+ ? imageUrl.map((v) => {
1342
+ const url = Toolkit.resolveMedia(this.#client, v, "image", {
1343
+ resolveUrl,
1344
+ });
1345
+ return {
1346
+ imagePreviewUrl: url,
1347
+ imageHighResUrl: url,
1348
+ sourceUrl: url,
1349
+ };
1350
+ })
1351
+ : (() => {
1352
+ const url = Toolkit.resolveMedia(this.#client, imageUrl, "image", {
1353
+ resolveUrl,
1354
+ });
1355
+ return [
1356
+ {
1357
+ imagePreviewUrl: url,
1358
+ imageHighResUrl: url,
1359
+ sourceUrl: url,
1360
+ },
1361
+ ];
1362
+ })();
1363
+
1364
+ this._submessages.push({
1365
+ messageType: 1,
1366
+ gridImageMetadata: {
1367
+ gridImageUrl: {
1368
+ imagePreviewUrl: list[0]?.imagePreviewUrl,
1369
+ },
1370
+ imageUrls: list,
1371
+ },
1372
+ });
1373
+
1374
+ list.forEach(({ imagePreviewUrl }) => {
1375
+ this._sections.push(
1376
+ AIRich.newLayout("Single", {
1377
+ media: {
1378
+ url: imagePreviewUrl,
1379
+ mime_type: "image/png",
1380
+ },
1381
+ imagine_type: "IMAGE",
1382
+ status: { status: "READY" },
1383
+ __typename: "GenAIImaginePrimitive",
1384
+ }),
1385
+ );
1386
+ });
1387
+
1388
+ return this;
1389
+ }
1390
+
1391
+ addVideo(videoUrl, { autoFill = true } = {}) {
1392
+ const isObjectVideo = (v) => v && typeof v === "object" && v.url;
1393
+
1394
+ const isValidPrimitive =
1395
+ typeof videoUrl === "string" ||
1396
+ Buffer.isBuffer(videoUrl) ||
1397
+ isObjectVideo(videoUrl) ||
1398
+ (Array.isArray(videoUrl) &&
1399
+ videoUrl.every(
1400
+ (v) =>
1401
+ typeof v === "string" || Buffer.isBuffer(v) || isObjectVideo(v),
1402
+ ));
1403
+
1404
+ if (!isValidPrimitive) {
1405
+ throw new TypeError("videoUrl must be string | buffer | object | array");
1406
+ }
1407
+
1408
+ const items = Array.isArray(videoUrl) ? videoUrl : [videoUrl];
1409
+
1410
+ this._submessages.push({
1411
+ messageType: 2,
1412
+ messageText: "[ CANNOT_LOAD_VIDEO - \u004E\u0049\u0058\u0045\u004C ]",
1413
+ });
1414
+
1415
+ items.forEach((item) => {
1416
+ const isObject = isObjectVideo(item);
1417
+
1418
+ const url = isObject
1419
+ ? Toolkit.resolveMedia(this.#client, item.url ?? "", "video")
1420
+ : Toolkit.resolveMedia(this.#client, item, "video");
1421
+
1422
+ const bufferPromise = autoFill
1423
+ ? Promise.resolve(url).then((u) => Toolkit.fetchBuffer(u))
1424
+ : null;
1425
+
1426
+ const file_length =
1427
+ isObject && item.file_length != null
1428
+ ? item.file_length
1429
+ : autoFill
1430
+ ? bufferPromise.then((b) => b?.length ?? 0)
1431
+ : 0;
1432
+
1433
+ const duration =
1434
+ isObject && item.duration != null
1435
+ ? item.duration
1436
+ : autoFill
1437
+ ? bufferPromise.then((b) =>
1438
+ Toolkit.getMp4Duration(b, {
1439
+ silent: true,
1440
+ }),
1441
+ )
1442
+ : 0;
1443
+
1444
+ const thumbnail =
1445
+ isObject && item.thumbnail
1446
+ ? Toolkit.resolveMedia(this.#client, item.thumbnail, "image", {
1447
+ result: "base64",
1448
+ resize: true,
1449
+ width: 300,
1450
+ height: 300,
1451
+ })
1452
+ : autoFill
1453
+ ? bufferPromise
1454
+ ? bufferPromise.then((b) =>
1455
+ Toolkit.getMp4Preview(b, {
1456
+ time: 0,
1457
+ result: "base64",
1458
+ }),
1459
+ )
1460
+ : null
1461
+ : null;
1462
+
1463
+ this._sections.push(
1464
+ AIRich.newLayout("Single", {
1465
+ media: {
1466
+ url,
1467
+ mime_type: isObject ? (item.mime_type ?? "video/mp4") : "video/mp4",
1468
+ file_length,
1469
+ duration,
1470
+ },
1471
+ imagine_type: "ANIMATE",
1472
+ status: { status: "READY" },
1473
+ thumbnail: {
1474
+ raw_media: thumbnail,
1475
+ },
1476
+ __typename: "GenAIImaginePrimitive",
1477
+ }),
1478
+ );
1479
+ });
1480
+
1481
+ return this;
1482
+ }
1483
+
1484
+ addProduct(data = {}) {
1485
+ if (
1486
+ !(
1487
+ (data && typeof data === "object" && !Array.isArray(data)) ||
1488
+ (Array.isArray(data) &&
1489
+ data.every(
1490
+ (item) => item && typeof item === "object" && !Array.isArray(item),
1491
+ ))
1492
+ )
1493
+ ) {
1494
+ throw new TypeError(
1495
+ "Product items must be an object or an array of objects",
1496
+ );
1497
+ }
1498
+
1499
+ this._submessages.push({
1500
+ messageType: 2,
1501
+ messageText: "[ CANNOT_LOAD_PRODUCT - NIXEL ]",
1502
+ });
1503
+
1504
+ const items = Array.isArray(data) ? data : [data];
1505
+
1506
+ const product = items.map((item) => ({
1507
+ title: item.title,
1508
+ brand: item.brand,
1509
+ price: item.price,
1510
+ sale_price: item.sale_price,
1511
+ product_url: item.product_url ?? item.url,
1512
+ image: {
1513
+ url: Toolkit.resolveMedia(
1514
+ this.#client,
1515
+ item.image_url ?? item.image,
1516
+ "image",
1517
+ ),
1518
+ },
1519
+ additional_images: [
1520
+ {
1521
+ url: Toolkit.resolveMedia(
1522
+ this.#client,
1523
+ item.icon_url ?? item.icon,
1524
+ "image",
1525
+ ),
1526
+ },
1527
+ ],
1528
+ __typename: "GenAIProductItemCardPrimitive",
1529
+ }));
1530
+
1531
+ this._sections.push(
1532
+ AIRich.newLayout(
1533
+ Array.isArray(data) ? "HScroll" : "Single",
1534
+ Array.isArray(data) ? product : product[0],
1535
+ ),
1536
+ );
1537
+
1538
+ return this;
1539
+ }
1540
+
1541
+ addPost(data = {}) {
1542
+ if (
1543
+ !(
1544
+ (data && typeof data === "object" && !Array.isArray(data)) ||
1545
+ (Array.isArray(data) &&
1546
+ data.every(
1547
+ (item) => item && typeof item === "object" && !Array.isArray(item),
1548
+ ))
1549
+ )
1550
+ ) {
1551
+ throw new TypeError(
1552
+ "Post items must be an object or an array of objects",
1553
+ );
1554
+ }
1555
+
1556
+ const posts = Array.isArray(data) ? data : [data];
1557
+
1558
+ this._submessages.push({
1559
+ messageType: 2,
1560
+ messageText: "[ CANNOT_LOAD_POST - NIXEL ]",
1561
+ });
1562
+
1563
+ const primitives = posts.map((p) => ({
1564
+ title: p.title ?? "",
1565
+ subtitle: p.subtitle ?? "",
1566
+ username: p.username ?? "",
1567
+ profile_picture_url: Toolkit.resolveMedia(
1568
+ this.#client,
1569
+ p.profile_picture_url ?? p.profile_url ?? p.profile ?? "",
1570
+ "image",
1571
+ ),
1572
+ is_verified: !!(p.is_verified || p.verified),
1573
+ thumbnail_url: Toolkit.resolveMedia(
1574
+ this.#client,
1575
+ p.thumbnail_url ?? p.thumbnail ?? "",
1576
+ "image",
1577
+ ),
1578
+ post_caption: p.post_caption ?? p.caption ?? "",
1579
+ likes_count: p.likes_count ?? p.like ?? 0,
1580
+ comments_count: p.comments_count ?? p.comment ?? 0,
1581
+ shares_count: p.shares_count ?? p.share ?? 0,
1582
+ post_url: p.post_url ?? p.url ?? "",
1583
+ post_deeplink: p.post_deeplink ?? p.deeplink ?? "",
1584
+ source_app: p.source_app || p.source || "INSTAGRAM",
1585
+ footer_label: p.footer_label ?? p.footer ?? "",
1586
+ footer_icon: Toolkit.resolveMedia(
1587
+ this.#client,
1588
+ p.footer_icon ?? p.icon ?? "",
1589
+ "image",
1590
+ ),
1591
+ is_carousel: posts.length > 1,
1592
+ orientation: p.orientation ?? "LANDSCAPE",
1593
+ post_type: p.post_type ?? "VIDEO",
1594
+ __typename: "GenAIPostPrimitive",
1595
+ }));
1596
+
1597
+ this._sections.push(AIRich.newLayout("HScroll", primitives));
1598
+
1599
+ return this;
1600
+ }
1601
+
1602
+ addTip(text) {
1603
+ this._submessages.push({
1604
+ messageType: 2,
1605
+ messageText: text,
1606
+ });
1607
+
1608
+ this._sections.push(
1609
+ AIRich.newLayout("Single", {
1610
+ text,
1611
+ __typename: "GenAIMetadataTextPrimitive",
1612
+ }),
1613
+ );
1614
+
1615
+ return this;
1616
+ }
1617
+
1618
+ addSuggest(suggestion, { scroll = true, layout } = {}) {
1619
+ if (
1620
+ !(
1621
+ typeof suggestion === "string" ||
1622
+ (Array.isArray(suggestion) &&
1623
+ suggestion.every((v) => typeof v === "string"))
1624
+ )
1625
+ ) {
1626
+ throw new TypeError("Suggestion must be a string or array of strings");
1627
+ }
1628
+
1629
+ const suggest = Array.isArray(suggestion)
1630
+ ? suggestion.map((text) => ({
1631
+ prompt_text: text,
1632
+ prompt_type: "SUGGESTED_PROMPT",
1633
+ __typename: "GenAIFollowUpSuggestionPillPrimitive",
1634
+ }))
1635
+ : [
1636
+ {
1637
+ prompt_text: suggestion,
1638
+ prompt_type: "SUGGESTED_PROMPT",
1639
+ __typename: "GenAIFollowUpSuggestionPillPrimitive",
1640
+ },
1641
+ ];
1642
+
1643
+ const type =
1644
+ layout ??
1645
+ (suggest.length === 1 ? "Single" : scroll ? "HScroll" : "ActionRow");
1646
+
1647
+ this._sections.push(
1648
+ AIRich.newLayout(type, type === "Single" ? suggest[0] : suggest, {
1649
+ __typename: "GenAIUnifiedResponseSection",
1650
+ }),
1651
+ );
1652
+
1653
+ return this;
1654
+ }
1655
+
1656
+ async build({
1657
+ forwarded = true,
1658
+ notification = false,
1659
+ includesUnifiedResponse = true,
1660
+ includesSubmessages = true,
1661
+ quoted,
1662
+ quotedParticipant,
1663
+ ...options
1664
+ } = {}) {
1665
+ const forward = forwarded
1666
+ ? {
1667
+ forwardingScore: 1,
1668
+ isForwarded: true,
1669
+ forwardedAiBotMessageInfo: { botJid: "0@bot" },
1670
+ forwardOrigin: 4,
1671
+ }
1672
+ : {};
1673
+
1674
+ const notif = notification
1675
+ ? {
1676
+ sessionTransparencyMetadata: {
1677
+ disclaimerText: "~ Ahmad tumbuh kembang",
1678
+ hcaId: `hca_${Date.now()}`,
1679
+ sessionTransparencyType: 1,
1680
+ },
1681
+ }
1682
+ : {};
1683
+
1684
+ const qObj = quoted
1685
+ ? {
1686
+ stanzaId: quoted?.key?.id || quoted?.id,
1687
+ participant:
1688
+ quotedParticipant ||
1689
+ quoted?.key?.participant ||
1690
+ quoted?.key?.remoteJid,
1691
+ quotedType: 0,
1692
+ quotedMessage:
1693
+ typeof quoted === "object" && quoted !== null
1694
+ ? (quoted.message ?? quoted)
1695
+ : undefined,
1696
+ }
1697
+ : {};
1698
+
1699
+ const sections = this._footer
1700
+ ? [
1701
+ ...(await waitAllPromises(this._sections)),
1702
+ AIRich.newLayout("Single", {
1703
+ text: this._footer,
1704
+ __typename: "GenAIMetadataTextPrimitive",
1705
+ }),
1706
+ ]
1707
+ : [...(await waitAllPromises(this._sections))];
1708
+
1709
+ return {
1710
+ messageContextInfo: {
1711
+ deviceListMetadata: {},
1712
+ deviceListMetadataVersion: 2,
1713
+ botMetadata: {
1714
+ messageDisclaimerText: this._title,
1715
+ richResponseSourcesMetadata: { sources: this._richResponseSources },
1716
+ ...notif,
1717
+ },
1718
+ },
1719
+ ...this._extraPayload,
1720
+ botForwardedMessage: {
1721
+ message: {
1722
+ richResponseMessage: {
1723
+ messageType: 1,
1724
+ submessages: includesSubmessages
1725
+ ? await waitAllPromises(this._submessages)
1726
+ : [],
1727
+ unifiedResponse: {
1728
+ data: includesUnifiedResponse
1729
+ ? Buffer.from(
1730
+ JSON.stringify({
1731
+ response_id: crypto.randomUUID(),
1732
+ sections,
1733
+ }),
1734
+ ).toString("base64")
1735
+ : "",
1736
+ },
1737
+ contextInfo: {
1738
+ ...forward,
1739
+ ...qObj,
1740
+ ...this._contextInfo,
1741
+ },
1742
+ },
1743
+ },
1744
+ },
1745
+ };
1746
+ }
1747
+
1748
+ async send(
1749
+ jid,
1750
+ {
1751
+ forwarded,
1752
+ notification,
1753
+ includesUnifiedResponse,
1754
+ includesSubmessages,
1755
+ ...options
1756
+ } = {},
1757
+ ) {
1758
+ const msg = await this.build({
1759
+ forwarded,
1760
+ notification,
1761
+ includesUnifiedResponse,
1762
+ includesSubmessages,
1763
+ ...options,
1764
+ });
1765
+
1766
+ return await this.#client.relayMessage(jid, msg, { ...options });
1767
+ }
1768
+
1769
+ static tokenizer(code, lang = "javascript") {
1770
+ const keywordsMap = {
1771
+ javascript: new Set([
1772
+ "break",
1773
+ "case",
1774
+ "catch",
1775
+ "continue",
1776
+ "debugger",
1777
+ "delete",
1778
+ "do",
1779
+ "else",
1780
+ "finally",
1781
+ "for",
1782
+ "function",
1783
+ "if",
1784
+ "in",
1785
+ "instanceof",
1786
+ "new",
1787
+ "return",
1788
+ "switch",
1789
+ "this",
1790
+ "throw",
1791
+ "try",
1792
+ "typeof",
1793
+ "var",
1794
+ "void",
1795
+ "while",
1796
+ "with",
1797
+ "true",
1798
+ "false",
1799
+ "null",
1800
+ "undefined",
1801
+ "class",
1802
+ "const",
1803
+ "let",
1804
+ "super",
1805
+ "extends",
1806
+ "export",
1807
+ "import",
1808
+ "yield",
1809
+ "static",
1810
+ "constructor",
1811
+ "async",
1812
+ "await",
1813
+ "get",
1814
+ "set",
1815
+ ]),
1816
+
1817
+ typescript: new Set([
1818
+ "abstract",
1819
+ "any",
1820
+ "as",
1821
+ "asserts",
1822
+ "bigint",
1823
+ "boolean",
1824
+ "declare",
1825
+ "enum",
1826
+ "implements",
1827
+ "infer",
1828
+ "interface",
1829
+ "is",
1830
+ "keyof",
1831
+ "module",
1832
+ "namespace",
1833
+ "never",
1834
+ "readonly",
1835
+ "require",
1836
+ "number",
1837
+ "object",
1838
+ "override",
1839
+ "private",
1840
+ "protected",
1841
+ "public",
1842
+ "satisfies",
1843
+ "string",
1844
+ "symbol",
1845
+ "type",
1846
+ "unknown",
1847
+ "using",
1848
+ "from",
1849
+ "break",
1850
+ "case",
1851
+ "catch",
1852
+ "continue",
1853
+ "do",
1854
+ "else",
1855
+ "finally",
1856
+ "for",
1857
+ "function",
1858
+ "if",
1859
+ "new",
1860
+ "return",
1861
+ "switch",
1862
+ "this",
1863
+ "throw",
1864
+ "try",
1865
+ "var",
1866
+ "void",
1867
+ "while",
1868
+ "class",
1869
+ "const",
1870
+ "let",
1871
+ "extends",
1872
+ "import",
1873
+ "export",
1874
+ "async",
1875
+ "await",
1876
+ ]),
1877
+
1878
+ python: new Set([
1879
+ "False",
1880
+ "None",
1881
+ "True",
1882
+ "and",
1883
+ "as",
1884
+ "assert",
1885
+ "async",
1886
+ "await",
1887
+ "break",
1888
+ "class",
1889
+ "continue",
1890
+ "def",
1891
+ "del",
1892
+ "elif",
1893
+ "else",
1894
+ "except",
1895
+ "finally",
1896
+ "for",
1897
+ "from",
1898
+ "global",
1899
+ "if",
1900
+ "import",
1901
+ "in",
1902
+ "is",
1903
+ "lambda",
1904
+ "nonlocal",
1905
+ "not",
1906
+ "or",
1907
+ "pass",
1908
+ "raise",
1909
+ "return",
1910
+ "try",
1911
+ "while",
1912
+ "with",
1913
+ "yield",
1914
+ ]),
1915
+
1916
+ java: new Set([
1917
+ "abstract",
1918
+ "assert",
1919
+ "boolean",
1920
+ "break",
1921
+ "byte",
1922
+ "case",
1923
+ "catch",
1924
+ "char",
1925
+ "class",
1926
+ "const",
1927
+ "continue",
1928
+ "default",
1929
+ "do",
1930
+ "double",
1931
+ "else",
1932
+ "enum",
1933
+ "extends",
1934
+ "final",
1935
+ "finally",
1936
+ "float",
1937
+ "for",
1938
+ "goto",
1939
+ "if",
1940
+ "implements",
1941
+ "import",
1942
+ "instanceof",
1943
+ "int",
1944
+ "interface",
1945
+ "long",
1946
+ "native",
1947
+ "new",
1948
+ "package",
1949
+ "private",
1950
+ "protected",
1951
+ "public",
1952
+ "return",
1953
+ "short",
1954
+ "static",
1955
+ "strictfp",
1956
+ "super",
1957
+ "switch",
1958
+ "synchronized",
1959
+ "this",
1960
+ "throw",
1961
+ "throws",
1962
+ "transient",
1963
+ "try",
1964
+ "void",
1965
+ "volatile",
1966
+ "while",
1967
+ ]),
1968
+
1969
+ golang: new Set([
1970
+ "break",
1971
+ "case",
1972
+ "chan",
1973
+ "const",
1974
+ "continue",
1975
+ "default",
1976
+ "defer",
1977
+ "else",
1978
+ "fallthrough",
1979
+ "for",
1980
+ "func",
1981
+ "go",
1982
+ "goto",
1983
+ "if",
1984
+ "import",
1985
+ "interface",
1986
+ "map",
1987
+ "package",
1988
+ "range",
1989
+ "return",
1990
+ "select",
1991
+ "struct",
1992
+ "switch",
1993
+ "type",
1994
+ "var",
1995
+ ]),
1996
+
1997
+ c: new Set([
1998
+ "auto",
1999
+ "break",
2000
+ "case",
2001
+ "char",
2002
+ "const",
2003
+ "continue",
2004
+ "default",
2005
+ "do",
2006
+ "double",
2007
+ "else",
2008
+ "enum",
2009
+ "extern",
2010
+ "float",
2011
+ "for",
2012
+ "goto",
2013
+ "if",
2014
+ "int",
2015
+ "long",
2016
+ "register",
2017
+ "return",
2018
+ "short",
2019
+ "signed",
2020
+ "sizeof",
2021
+ "static",
2022
+ "struct",
2023
+ "switch",
2024
+ "typedef",
2025
+ "union",
2026
+ "unsigned",
2027
+ "void",
2028
+ "volatile",
2029
+ "while",
2030
+ ]),
2031
+
2032
+ cpp: new Set([
2033
+ "alignas",
2034
+ "alignof",
2035
+ "and",
2036
+ "auto",
2037
+ "bool",
2038
+ "break",
2039
+ "case",
2040
+ "catch",
2041
+ "class",
2042
+ "const",
2043
+ "constexpr",
2044
+ "continue",
2045
+ "delete",
2046
+ "do",
2047
+ "double",
2048
+ "else",
2049
+ "enum",
2050
+ "explicit",
2051
+ "export",
2052
+ "extern",
2053
+ "false",
2054
+ "float",
2055
+ "for",
2056
+ "friend",
2057
+ "if",
2058
+ "inline",
2059
+ "int",
2060
+ "long",
2061
+ "mutable",
2062
+ "namespace",
2063
+ "new",
2064
+ "noexcept",
2065
+ "nullptr",
2066
+ "operator",
2067
+ "private",
2068
+ "protected",
2069
+ "public",
2070
+ "return",
2071
+ "short",
2072
+ "signed",
2073
+ "sizeof",
2074
+ "static",
2075
+ "struct",
2076
+ "switch",
2077
+ "template",
2078
+ "this",
2079
+ "throw",
2080
+ "true",
2081
+ "try",
2082
+ "typedef",
2083
+ "typename",
2084
+ "union",
2085
+ "unsigned",
2086
+ "using",
2087
+ "virtual",
2088
+ "void",
2089
+ "while",
2090
+ ]),
2091
+
2092
+ php: new Set([
2093
+ "abstract",
2094
+ "and",
2095
+ "array",
2096
+ "as",
2097
+ "break",
2098
+ "callable",
2099
+ "case",
2100
+ "catch",
2101
+ "class",
2102
+ "clone",
2103
+ "const",
2104
+ "continue",
2105
+ "declare",
2106
+ "default",
2107
+ "do",
2108
+ "echo",
2109
+ "else",
2110
+ "elseif",
2111
+ "empty",
2112
+ "enddeclare",
2113
+ "endfor",
2114
+ "endforeach",
2115
+ "endif",
2116
+ "endswitch",
2117
+ "endwhile",
2118
+ "extends",
2119
+ "final",
2120
+ "finally",
2121
+ "fn",
2122
+ "for",
2123
+ "foreach",
2124
+ "function",
2125
+ "global",
2126
+ "goto",
2127
+ "if",
2128
+ "implements",
2129
+ "include",
2130
+ "include_once",
2131
+ "instanceof",
2132
+ "interface",
2133
+ "match",
2134
+ "namespace",
2135
+ "new",
2136
+ "null",
2137
+ "or",
2138
+ "private",
2139
+ "protected",
2140
+ "public",
2141
+ "require",
2142
+ "require_once",
2143
+ "return",
2144
+ "static",
2145
+ "switch",
2146
+ "throw",
2147
+ "trait",
2148
+ "try",
2149
+ "use",
2150
+ "var",
2151
+ "while",
2152
+ "yield",
2153
+ ]),
2154
+
2155
+ rust: new Set([
2156
+ "as",
2157
+ "break",
2158
+ "const",
2159
+ "continue",
2160
+ "crate",
2161
+ "else",
2162
+ "enum",
2163
+ "extern",
2164
+ "false",
2165
+ "fn",
2166
+ "for",
2167
+ "if",
2168
+ "impl",
2169
+ "in",
2170
+ "let",
2171
+ "loop",
2172
+ "match",
2173
+ "mod",
2174
+ "move",
2175
+ "mut",
2176
+ "pub",
2177
+ "ref",
2178
+ "return",
2179
+ "self",
2180
+ "Self",
2181
+ "static",
2182
+ "struct",
2183
+ "super",
2184
+ "trait",
2185
+ "true",
2186
+ "type",
2187
+ "unsafe",
2188
+ "use",
2189
+ "where",
2190
+ "while",
2191
+ ]),
2192
+
2193
+ html: new Set([
2194
+ "html",
2195
+ "head",
2196
+ "body",
2197
+ "div",
2198
+ "span",
2199
+ "p",
2200
+ "a",
2201
+ "img",
2202
+ "video",
2203
+ "audio",
2204
+ "script",
2205
+ "style",
2206
+ "link",
2207
+ "meta",
2208
+ "form",
2209
+ "input",
2210
+ "button",
2211
+ "table",
2212
+ "tr",
2213
+ "td",
2214
+ "th",
2215
+ "ul",
2216
+ "ol",
2217
+ "li",
2218
+ "section",
2219
+ "article",
2220
+ "header",
2221
+ "footer",
2222
+ "nav",
2223
+ "main",
2224
+ ]),
2225
+
2226
+ bash: new Set([
2227
+ "if",
2228
+ "then",
2229
+ "else",
2230
+ "elif",
2231
+ "fi",
2232
+ "for",
2233
+ "while",
2234
+ "do",
2235
+ "done",
2236
+ "case",
2237
+ "esac",
2238
+ "function",
2239
+ "in",
2240
+ "select",
2241
+ "until",
2242
+ "break",
2243
+ "continue",
2244
+ "return",
2245
+ "export",
2246
+ "readonly",
2247
+ "local",
2248
+ "declare",
2249
+ ]),
2250
+
2251
+ markdown: new Set(["#", "##", "###", "####", "#####", "######"]),
2252
+ };
2253
+
2254
+ if (!lang || lang === "txt" || lang === "text" || lang === "plaintext") {
2255
+ return {
2256
+ codeBlock: [
2257
+ {
2258
+ codeContent: code,
2259
+ highlightType: 0,
2260
+ },
2261
+ ],
2262
+ unified_codeBlock: [
2263
+ {
2264
+ content: code,
2265
+ type: "DEFAULT",
2266
+ },
2267
+ ],
2268
+ };
2269
+ }
2270
+
2271
+ const TYPE_MAP = {
2272
+ 0: "DEFAULT",
2273
+ 1: "KEYWORD",
2274
+ 2: "METHOD",
2275
+ 3: "STR",
2276
+ 4: "NUMBER",
2277
+ 5: "COMMENT",
2278
+ };
2279
+
2280
+ const keywords = keywordsMap[lang.toLowerCase()] || new Set();
2281
+ const tokens = [];
2282
+
2283
+ let i = 0;
2284
+
2285
+ const push = (content, type) => {
2286
+ if (!content) return;
2287
+
2288
+ const last = tokens[tokens.length - 1];
2289
+
2290
+ if (last && last.highlightType === type) {
2291
+ last.codeContent += content;
2292
+ } else {
2293
+ tokens.push({
2294
+ codeContent: content,
2295
+ highlightType: type,
2296
+ });
2297
+ }
2298
+ };
2299
+
2300
+ const isIdentifier = (char) => {
2301
+ switch (lang.toLowerCase()) {
2302
+ case "css":
2303
+ return /[a-zA-Z0-9_$-]/.test(char);
2304
+
2305
+ case "html":
2306
+ return /[a-zA-Z0-9_$:-]/.test(char);
2307
+
2308
+ default:
2309
+ return /[a-zA-Z0-9_$]/.test(char);
2310
+ }
2311
+ };
2312
+
2313
+ while (i < code.length) {
2314
+ const c = code[i];
2315
+
2316
+ if (/\s/.test(c)) {
2317
+ let s = i;
2318
+
2319
+ while (i < code.length && /\s/.test(code[i])) {
2320
+ i++;
2321
+ }
2322
+
2323
+ push(code.slice(s, i), 0);
2324
+ continue;
2325
+ }
2326
+
2327
+ if (
2328
+ (c === "/" && code[i + 1] === "/") ||
2329
+ (c === "#" && ["python", "bash"].includes(lang))
2330
+ ) {
2331
+ let s = i;
2332
+
2333
+ while (i < code.length && code[i] !== "\n") {
2334
+ i++;
2335
+ }
2336
+
2337
+ push(code.slice(s, i), 5);
2338
+ continue;
2339
+ }
2340
+
2341
+ if (c === '"' || c === "'" || c === "`") {
2342
+ let s = i;
2343
+ const q = c;
2344
+
2345
+ i++;
2346
+
2347
+ while (i < code.length) {
2348
+ if (code[i] === "\\" && i + 1 < code.length) {
2349
+ i += 2;
2350
+ } else if (code[i] === q) {
2351
+ i++;
2352
+ break;
2353
+ } else {
2354
+ i++;
2355
+ }
2356
+ }
2357
+
2358
+ push(code.slice(s, i), 3);
2359
+ continue;
2360
+ }
2361
+
2362
+ if (/[0-9]/.test(c)) {
2363
+ let s = i;
2364
+
2365
+ while (i < code.length && /[0-9._]/.test(code[i])) {
2366
+ i++;
2367
+ }
2368
+
2369
+ push(code.slice(s, i), 4);
2370
+ continue;
2371
+ }
2372
+
2373
+ if (/[a-zA-Z_$]/.test(c)) {
2374
+ let s = i;
2375
+
2376
+ while (i < code.length && isIdentifier(code[i])) {
2377
+ i++;
2378
+ }
2379
+
2380
+ const word = code.slice(s, i);
2381
+
2382
+ let type = 0;
2383
+
2384
+ if (keywords.has(word)) {
2385
+ type = 1;
2386
+ } else if (lang === "css") {
2387
+ let j = i;
2388
+
2389
+ while (j < code.length && /\s/.test(code[j])) {
2390
+ j++;
2391
+ }
2392
+
2393
+ if (code[j] === ":") {
2394
+ type = 1;
2395
+ }
2396
+ } else if (lang === "html") {
2397
+ let p = s - 1;
2398
+
2399
+ while (p >= 0 && /\s/.test(code[p])) {
2400
+ p--;
2401
+ }
2402
+
2403
+ if (code[p] === "<" || (code[p] === "/" && code[p - 1] === "<")) {
2404
+ type = 1;
2405
+ }
2406
+ }
2407
+
2408
+ if (type === 0) {
2409
+ let j = i;
2410
+
2411
+ while (j < code.length && /\s/.test(code[j])) {
2412
+ j++;
2413
+ }
2414
+
2415
+ if (code[j] === "(") {
2416
+ type = 2;
2417
+ }
2418
+ }
2419
+
2420
+ push(word, type);
2421
+ continue;
2422
+ }
2423
+
2424
+ push(c, 0);
2425
+ i++;
2426
+ }
2427
+
2428
+ return {
2429
+ codeBlock: tokens,
2430
+ unified_codeBlock: tokens.map((t) => ({
2431
+ content: t.codeContent,
2432
+ type: TYPE_MAP[t.highlightType],
2433
+ })),
2434
+ };
2435
+ }
2436
+
2437
+ static toTableMetadata(
2438
+ arr,
2439
+ { hyperlink = true, citation = true, latex = true } = {},
2440
+ ) {
2441
+ if (
2442
+ !Array.isArray(arr) ||
2443
+ !arr.every(
2444
+ (row) =>
2445
+ Array.isArray(row) && row.every((cell) => typeof cell === "string"),
2446
+ )
2447
+ ) {
2448
+ throw new TypeError("Table must be a nested array of strings");
2449
+ }
2450
+
2451
+ const [header, ...rows] = arr;
2452
+
2453
+ const maxLen = Math.max(header.length, ...rows.map((r) => r.length));
2454
+
2455
+ const normalize = (r) => [...r, ...Array(maxLen - r.length).fill("")];
2456
+
2457
+ const unified_rows = [
2458
+ {
2459
+ is_header: true,
2460
+ cells: normalize(header),
2461
+ },
2462
+ ...rows.map((r) => ({
2463
+ is_header: false,
2464
+ cells: normalize(r),
2465
+ })),
2466
+ ].map((row) => {
2467
+ const markdown_cells = row.cells.map((cell) => {
2468
+ const extracted = extractIE(cell, { hyperlink, citation, latex });
2469
+
2470
+ return {
2471
+ text: extracted.text,
2472
+ ...(extracted.inline_entities.length
2473
+ ? { inline_entities: extracted.inline_entities }
2474
+ : {}),
2475
+ };
2476
+ });
2477
+
2478
+ return {
2479
+ ...row,
2480
+ ...(markdown_cells.some((c) => c.inline_entities?.length)
2481
+ ? { markdown_cells }
2482
+ : {}),
2483
+ };
2484
+ });
2485
+
2486
+ const rowsMeta = unified_rows.map((r) => ({
2487
+ items: r.cells,
2488
+ ...(r.is_header ? { isHeading: true } : {}),
2489
+ }));
2490
+
2491
+ return {
2492
+ title: "",
2493
+ rows: rowsMeta,
2494
+ unified_rows,
2495
+ };
2496
+ }
2497
+
2498
+ static newLayout(name, data, extra = {}) {
2499
+ return {
2500
+ ...extra,
2501
+ view_model: {
2502
+ [Array.isArray(data) ? "primitives" : "primitive"]: data,
2503
+ __typename: `GenAI${name}LayoutViewModel`,
2504
+ },
2505
+ };
2506
+ }
2507
+ }
2508
+
2509
+ module.exports = { VERSION, Button, ButtonV2, Carousel, AIRich, Toolkit };