@fvckerss/baileys 1.0.14 → 1.0.15
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.
- package/lib/Builder/extras.d.ts +332 -0
- package/lib/Builder/extras.js +948 -0
- package/lib/Builder/index.d.ts +169 -0
- package/lib/Builder/index.js +3298 -0
- package/lib/Socket/messages-send.js +62 -1
- package/lib/Utils/html-app.js +96 -0
- package/lib/Utils/optional-media.js +45 -0
- package/lib/Utils/rich-message-utils.js +269 -1028
- package/lib/index.js +2 -0
- package/package.json +1 -1
|
@@ -4,111 +4,55 @@ import {
|
|
|
4
4
|
randomUUID
|
|
5
5
|
} from 'crypto';
|
|
6
6
|
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
} from '
|
|
11
|
-
|
|
12
|
-
import {
|
|
13
|
-
LANGUAGE_KEYWORDS
|
|
14
|
-
} from '../WABinary/constants.js';
|
|
15
|
-
|
|
16
|
-
import {
|
|
17
|
-
CodeHighlightType,
|
|
18
|
-
RichSubMessageType
|
|
19
|
-
} from '../Types/RichType.js';
|
|
20
|
-
|
|
21
|
-
import {
|
|
22
|
-
proto
|
|
23
|
-
} from '../../WAProto/index.js';
|
|
7
|
+
import { DONATE_URL, LEXER_REGEX } from '../Defaults/index.js';
|
|
8
|
+
import { LANGUAGE_KEYWORDS } from '../WABinary/constants.js';
|
|
9
|
+
import { CodeHighlightType, RichSubMessageType } from '../Types/RichType.js';
|
|
10
|
+
import { proto } from '../../WAProto/index.js';
|
|
24
11
|
|
|
25
12
|
const NOOP = new Set([]);
|
|
26
13
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
* CODE TOKENIZER
|
|
30
|
-
* ========================================================= */
|
|
31
|
-
|
|
32
|
-
export const tokenizeCode = (
|
|
33
|
-
code,
|
|
34
|
-
language = 'javascript'
|
|
35
|
-
) => {
|
|
36
|
-
|
|
37
|
-
const keywords =
|
|
38
|
-
LANGUAGE_KEYWORDS[language] || NOOP;
|
|
39
|
-
|
|
14
|
+
export const tokenizeCode = (code, language = 'javascript') => {
|
|
15
|
+
const keywords = LANGUAGE_KEYWORDS[language] || NOOP;
|
|
40
16
|
const blocks = [];
|
|
41
17
|
|
|
42
18
|
LEXER_REGEX.lastIndex = 0;
|
|
43
19
|
|
|
44
20
|
let match;
|
|
45
21
|
|
|
46
|
-
while (
|
|
47
|
-
(match = LEXER_REGEX.exec(code)) !== null
|
|
48
|
-
) {
|
|
49
|
-
|
|
22
|
+
while ((match = LEXER_REGEX.exec(code)) !== null) {
|
|
50
23
|
if (match[1]) {
|
|
51
|
-
|
|
52
24
|
blocks.push({
|
|
53
|
-
highlightType:
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
codeContent:
|
|
57
|
-
match[1]
|
|
25
|
+
highlightType: CodeHighlightType.COMMENT,
|
|
26
|
+
codeContent: match[1]
|
|
58
27
|
});
|
|
59
|
-
|
|
60
28
|
} else if (match[2]) {
|
|
61
|
-
|
|
62
29
|
blocks.push({
|
|
63
|
-
highlightType:
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
codeContent:
|
|
67
|
-
match[2]
|
|
30
|
+
highlightType: CodeHighlightType.STRING,
|
|
31
|
+
codeContent: match[2]
|
|
68
32
|
});
|
|
69
|
-
|
|
70
33
|
} else if (match[3]) {
|
|
71
|
-
|
|
72
34
|
blocks.push({
|
|
73
|
-
highlightType:
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
codeContent:
|
|
79
|
-
match[3]
|
|
35
|
+
highlightType: keywords.has(match[3])
|
|
36
|
+
? CodeHighlightType.KEYWORD
|
|
37
|
+
: CodeHighlightType.METHOD,
|
|
38
|
+
codeContent: match[3]
|
|
80
39
|
});
|
|
81
|
-
|
|
82
40
|
} else if (match[4]) {
|
|
83
|
-
|
|
84
41
|
blocks.push({
|
|
85
|
-
highlightType:
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
codeContent:
|
|
91
|
-
match[4]
|
|
42
|
+
highlightType: keywords.has(match[4])
|
|
43
|
+
? CodeHighlightType.KEYWORD
|
|
44
|
+
: CodeHighlightType.DEFAULT,
|
|
45
|
+
codeContent: match[4]
|
|
92
46
|
});
|
|
93
|
-
|
|
94
47
|
} else if (match[5]) {
|
|
95
|
-
|
|
96
48
|
blocks.push({
|
|
97
|
-
highlightType:
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
codeContent:
|
|
101
|
-
match[5]
|
|
49
|
+
highlightType: CodeHighlightType.NUMBER,
|
|
50
|
+
codeContent: match[5]
|
|
102
51
|
});
|
|
103
|
-
|
|
104
52
|
} else {
|
|
105
|
-
|
|
106
53
|
blocks.push({
|
|
107
|
-
highlightType:
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
codeContent:
|
|
111
|
-
match[6]
|
|
54
|
+
highlightType: CodeHighlightType.DEFAULT,
|
|
55
|
+
codeContent: match[6]
|
|
112
56
|
});
|
|
113
57
|
}
|
|
114
58
|
}
|
|
@@ -116,146 +60,71 @@ export const tokenizeCode = (
|
|
|
116
60
|
return blocks;
|
|
117
61
|
};
|
|
118
62
|
|
|
119
|
-
export const toUnified = (
|
|
120
|
-
submessages,
|
|
121
|
-
uuid,
|
|
122
|
-
footerText
|
|
123
|
-
) => {
|
|
124
|
-
|
|
63
|
+
export const toUnified = (submessages, uuid, footerText) => {
|
|
125
64
|
const sections = [];
|
|
126
65
|
|
|
127
66
|
for (const submessage of submessages) {
|
|
128
|
-
|
|
129
67
|
switch (submessage.messageType) {
|
|
130
68
|
|
|
131
|
-
/* =============================================
|
|
132
|
-
* CODE
|
|
133
|
-
* ============================================= */
|
|
134
|
-
|
|
135
69
|
case RichSubMessageType.CODE: {
|
|
136
|
-
|
|
137
|
-
const codeMetadata =
|
|
138
|
-
submessage.codeMetadata;
|
|
70
|
+
const codeMetadata = submessage.codeMetadata;
|
|
139
71
|
|
|
140
72
|
sections.push({
|
|
141
73
|
view_model: {
|
|
142
74
|
primitive: {
|
|
143
|
-
language:
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
content:
|
|
150
|
-
block.codeContent,
|
|
151
|
-
|
|
152
|
-
type:
|
|
153
|
-
CodeHighlightType[
|
|
154
|
-
block.highlightType
|
|
155
|
-
]
|
|
156
|
-
})
|
|
157
|
-
),
|
|
158
|
-
|
|
159
|
-
__typename:
|
|
160
|
-
'GenAICodeUXPrimitive'
|
|
75
|
+
language: codeMetadata.codeLanguage,
|
|
76
|
+
code_blocks: codeMetadata.codeBlocks.map((block) => ({
|
|
77
|
+
content: block.codeContent,
|
|
78
|
+
type: CodeHighlightType[block.highlightType]
|
|
79
|
+
})),
|
|
80
|
+
__typename: 'GenAICodeUXPrimitive'
|
|
161
81
|
},
|
|
162
|
-
|
|
163
|
-
__typename:
|
|
164
|
-
'GenAISingleLayoutViewModel'
|
|
82
|
+
__typename: 'GenAISingleLayoutViewModel'
|
|
165
83
|
}
|
|
166
84
|
});
|
|
167
85
|
|
|
168
86
|
break;
|
|
169
87
|
}
|
|
170
88
|
|
|
171
|
-
|
|
172
|
-
/* =============================================
|
|
173
|
-
* TEXT
|
|
174
|
-
* ============================================= */
|
|
175
|
-
|
|
176
89
|
case RichSubMessageType.TEXT: {
|
|
177
|
-
|
|
178
90
|
sections.push({
|
|
179
91
|
view_model: {
|
|
180
92
|
primitive: {
|
|
181
|
-
text:
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
inline_entities:
|
|
185
|
-
submessage.inlineEntities || [],
|
|
186
|
-
|
|
187
|
-
__typename:
|
|
188
|
-
'GenAIMarkdownTextUXPrimitive'
|
|
93
|
+
text: submessage.messageText,
|
|
94
|
+
inline_entities: submessage.inlineEntities || [],
|
|
95
|
+
__typename: 'GenAIMarkdownTextUXPrimitive'
|
|
189
96
|
},
|
|
190
|
-
|
|
191
|
-
__typename:
|
|
192
|
-
'GenAISingleLayoutViewModel'
|
|
97
|
+
__typename: 'GenAISingleLayoutViewModel'
|
|
193
98
|
}
|
|
194
99
|
});
|
|
195
100
|
|
|
196
101
|
break;
|
|
197
102
|
}
|
|
198
103
|
|
|
199
|
-
|
|
200
|
-
/* =============================================
|
|
201
|
-
* CONTENT ITEMS
|
|
202
|
-
* ============================================= */
|
|
203
|
-
|
|
204
104
|
case RichSubMessageType.CONTENT_ITEMS: {
|
|
105
|
+
const meta = submessage.contentItemsMetadata;
|
|
106
|
+
const items = meta?.itemsMetadata || [];
|
|
205
107
|
|
|
206
|
-
|
|
207
|
-
submessage.contentItemsMetadata;
|
|
108
|
+
if (!items.length) break;
|
|
208
109
|
|
|
209
|
-
const
|
|
210
|
-
meta?.itemsMetadata || [];
|
|
211
|
-
|
|
212
|
-
if (!items.length) {
|
|
213
|
-
break;
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
const first =
|
|
217
|
-
items[0];
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
/* -----------------------------------------
|
|
221
|
-
* PRODUCT
|
|
222
|
-
* ----------------------------------------- */
|
|
223
|
-
|
|
224
|
-
if (
|
|
225
|
-
first?.__typename ===
|
|
226
|
-
'GenAIProductItemCardPrimitive'
|
|
227
|
-
) {
|
|
110
|
+
const first = items[0];
|
|
228
111
|
|
|
112
|
+
if (first?.__typename === 'GenAIProductItemCardPrimitive') {
|
|
229
113
|
sections.push({
|
|
230
114
|
view_model: {
|
|
231
|
-
primitive:
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
__typename:
|
|
235
|
-
'GenAISingleLayoutViewModel'
|
|
115
|
+
primitive: first,
|
|
116
|
+
__typename: 'GenAISingleLayoutViewModel'
|
|
236
117
|
}
|
|
237
118
|
});
|
|
238
119
|
|
|
239
120
|
break;
|
|
240
121
|
}
|
|
241
122
|
|
|
242
|
-
|
|
243
|
-
/* -----------------------------------------
|
|
244
|
-
* SUGGESTED
|
|
245
|
-
* ----------------------------------------- */
|
|
246
|
-
|
|
247
|
-
if (
|
|
248
|
-
first?.__typename ===
|
|
249
|
-
'GenAIFollowUpSuggestionPillPrimitive'
|
|
250
|
-
) {
|
|
251
|
-
|
|
123
|
+
if (first?.__typename === 'GenAIFollowUpSuggestionPillPrimitive') {
|
|
252
124
|
sections.push({
|
|
253
125
|
view_model: {
|
|
254
|
-
primitives:
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
__typename:
|
|
258
|
-
'GenAIActionRowLayoutViewModel'
|
|
126
|
+
primitives: items,
|
|
127
|
+
__typename: 'GenAIActionRowLayoutViewModel'
|
|
259
128
|
}
|
|
260
129
|
});
|
|
261
130
|
|
|
@@ -265,48 +134,21 @@ export const toUnified = (
|
|
|
265
134
|
break;
|
|
266
135
|
}
|
|
267
136
|
|
|
268
|
-
|
|
269
|
-
/* =============================================
|
|
270
|
-
* TABLE
|
|
271
|
-
* ============================================= */
|
|
272
|
-
|
|
273
137
|
case RichSubMessageType.TABLE: {
|
|
274
|
-
|
|
275
|
-
const tableMetadata =
|
|
276
|
-
submessage.tableMetadata;
|
|
138
|
+
const tableMetadata = submessage.tableMetadata;
|
|
277
139
|
|
|
278
140
|
sections.push({
|
|
279
141
|
view_model: {
|
|
280
142
|
primitive: {
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
is_header:
|
|
289
|
-
row.isHeading,
|
|
290
|
-
|
|
291
|
-
cells:
|
|
292
|
-
row.items,
|
|
293
|
-
|
|
294
|
-
markdown_cells:
|
|
295
|
-
row.items.map(
|
|
296
|
-
(item) => ({
|
|
297
|
-
text:
|
|
298
|
-
item
|
|
299
|
-
})
|
|
300
|
-
)
|
|
301
|
-
})
|
|
302
|
-
),
|
|
303
|
-
|
|
304
|
-
__typename:
|
|
305
|
-
'GenATableUXPrimitive'
|
|
143
|
+
title: tableMetadata.title,
|
|
144
|
+
rows: tableMetadata.rows.map((row) => ({
|
|
145
|
+
is_header: row.isHeading,
|
|
146
|
+
cells: row.items,
|
|
147
|
+
markdown_cells: row.items.map((item) => ({ text: item }))
|
|
148
|
+
})),
|
|
149
|
+
__typename: 'GenATableUXPrimitive'
|
|
306
150
|
},
|
|
307
|
-
|
|
308
|
-
__typename:
|
|
309
|
-
'GenAISingleLayoutViewModel'
|
|
151
|
+
__typename: 'GenAISingleLayoutViewModel'
|
|
310
152
|
}
|
|
311
153
|
});
|
|
312
154
|
|
|
@@ -319,46 +161,26 @@ export const toUnified = (
|
|
|
319
161
|
break;
|
|
320
162
|
}
|
|
321
163
|
}
|
|
322
|
-
|
|
323
|
-
if (
|
|
324
|
-
typeof footerText === 'string' &&
|
|
325
|
-
footerText.trim()
|
|
326
|
-
) {
|
|
327
|
-
|
|
164
|
+
|
|
165
|
+
if (typeof footerText === 'string' && footerText.trim()) {
|
|
328
166
|
sections.push({
|
|
329
167
|
view_model: {
|
|
330
168
|
primitive: {
|
|
331
|
-
text:
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
__typename:
|
|
335
|
-
'GenAIMarkdownTextUXPrimitive'
|
|
169
|
+
text: footerText,
|
|
170
|
+
__typename: 'GenAIMarkdownTextUXPrimitive'
|
|
336
171
|
},
|
|
337
|
-
|
|
338
|
-
__typename:
|
|
339
|
-
'GenAISingleLayoutViewModel'
|
|
172
|
+
__typename: 'GenAISingleLayoutViewModel'
|
|
340
173
|
}
|
|
341
174
|
});
|
|
342
175
|
}
|
|
343
176
|
|
|
344
|
-
|
|
345
177
|
return {
|
|
346
|
-
response_id:
|
|
347
|
-
uuid || randomUUID(),
|
|
348
|
-
|
|
178
|
+
response_id: uuid || randomUUID(),
|
|
349
179
|
sections
|
|
350
180
|
};
|
|
351
181
|
};
|
|
352
182
|
|
|
353
|
-
|
|
354
|
-
/* =========================================================
|
|
355
|
-
* PREPARE RICH RESPONSE MESSAGE
|
|
356
|
-
* ========================================================= */
|
|
357
|
-
|
|
358
|
-
export const prepareRichResponseMessage = (
|
|
359
|
-
content
|
|
360
|
-
) => {
|
|
361
|
-
|
|
183
|
+
export const prepareRichResponseMessage = (content) => {
|
|
362
184
|
const {
|
|
363
185
|
alignment,
|
|
364
186
|
code,
|
|
@@ -384,948 +206,367 @@ export const prepareRichResponseMessage = (
|
|
|
384
206
|
title
|
|
385
207
|
} = content;
|
|
386
208
|
|
|
387
|
-
|
|
388
|
-
/* =====================================================
|
|
389
|
-
* PRODUCT / PRODUCTS
|
|
390
|
-
* ===================================================== */
|
|
391
|
-
|
|
392
|
-
const dataProduct =
|
|
393
|
-
products || product;
|
|
394
|
-
|
|
209
|
+
const dataProduct = products || product;
|
|
395
210
|
|
|
396
211
|
let submessages = [];
|
|
397
212
|
|
|
213
|
+
if (Array.isArray(richResponse)) {
|
|
214
|
+
submessages = richResponse.map((submessage) => {
|
|
398
215
|
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
submessages =
|
|
408
|
-
richResponse.map(
|
|
409
|
-
(submessage) => {
|
|
410
|
-
|
|
411
|
-
/* =====================================
|
|
412
|
-
* TEXT
|
|
413
|
-
* ===================================== */
|
|
414
|
-
|
|
415
|
-
if (
|
|
416
|
-
submessage.text
|
|
417
|
-
) {
|
|
418
|
-
|
|
419
|
-
return {
|
|
420
|
-
messageType:
|
|
421
|
-
RichSubMessageType.TEXT,
|
|
422
|
-
|
|
423
|
-
messageText:
|
|
424
|
-
submessage.text,
|
|
425
|
-
|
|
426
|
-
inlineEntities:
|
|
427
|
-
submessage.inlineEntities
|
|
428
|
-
};
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
/* =====================================
|
|
433
|
-
* CODE
|
|
434
|
-
* ===================================== */
|
|
435
|
-
|
|
436
|
-
if (
|
|
437
|
-
submessage.code
|
|
438
|
-
) {
|
|
439
|
-
|
|
440
|
-
const codeLanguage =
|
|
441
|
-
submessage.language ||
|
|
442
|
-
'javascript';
|
|
443
|
-
|
|
444
|
-
return {
|
|
445
|
-
messageType:
|
|
446
|
-
RichSubMessageType.CODE,
|
|
447
|
-
|
|
448
|
-
codeMetadata: {
|
|
449
|
-
|
|
450
|
-
codeLanguage,
|
|
451
|
-
|
|
452
|
-
codeBlocks:
|
|
453
|
-
Array.isArray(
|
|
454
|
-
submessage.code
|
|
455
|
-
)
|
|
456
|
-
? submessage.code
|
|
457
|
-
: tokenizeCode(
|
|
458
|
-
submessage.code,
|
|
459
|
-
codeLanguage
|
|
460
|
-
)
|
|
461
|
-
}
|
|
462
|
-
};
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
/* =====================================
|
|
467
|
-
* ITEMS
|
|
468
|
-
* ===================================== */
|
|
469
|
-
|
|
470
|
-
if (
|
|
471
|
-
submessage.items
|
|
472
|
-
) {
|
|
473
|
-
|
|
474
|
-
return {
|
|
475
|
-
messageType:
|
|
476
|
-
RichSubMessageType.CONTENT_ITEMS,
|
|
477
|
-
|
|
478
|
-
contentItemsMetadata: {
|
|
479
|
-
|
|
480
|
-
itemsMetadata:
|
|
481
|
-
submessage.items,
|
|
482
|
-
|
|
483
|
-
contentType:
|
|
484
|
-
proto
|
|
485
|
-
.AIRichResponseContentItemsMetadata
|
|
486
|
-
.ContentType
|
|
487
|
-
.CAROUSEL
|
|
488
|
-
}
|
|
489
|
-
};
|
|
490
|
-
}
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
/* =====================================
|
|
494
|
-
* INLINE IMAGE
|
|
495
|
-
* ===================================== */
|
|
496
|
-
|
|
497
|
-
if (
|
|
498
|
-
submessage.inlineImage
|
|
499
|
-
) {
|
|
500
|
-
|
|
501
|
-
return {
|
|
502
|
-
messageType:
|
|
503
|
-
RichSubMessageType.INLINE_IMAGE,
|
|
504
|
-
|
|
505
|
-
imageMetadata: {
|
|
506
|
-
|
|
507
|
-
imageUrl:
|
|
508
|
-
submessage.inlineImage,
|
|
509
|
-
|
|
510
|
-
imageText:
|
|
511
|
-
submessage.imageText,
|
|
216
|
+
if (submessage.text) {
|
|
217
|
+
return {
|
|
218
|
+
messageType: RichSubMessageType.TEXT,
|
|
219
|
+
messageText: submessage.text,
|
|
220
|
+
inlineEntities: submessage.inlineEntities
|
|
221
|
+
};
|
|
222
|
+
}
|
|
512
223
|
|
|
513
|
-
|
|
514
|
-
|
|
224
|
+
if (submessage.code) {
|
|
225
|
+
const codeLanguage = submessage.language || 'javascript';
|
|
515
226
|
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
227
|
+
return {
|
|
228
|
+
messageType: RichSubMessageType.CODE,
|
|
229
|
+
codeMetadata: {
|
|
230
|
+
codeLanguage,
|
|
231
|
+
codeBlocks: Array.isArray(submessage.code)
|
|
232
|
+
? submessage.code
|
|
233
|
+
: tokenizeCode(submessage.code, codeLanguage)
|
|
520
234
|
}
|
|
235
|
+
};
|
|
236
|
+
}
|
|
521
237
|
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
) {
|
|
530
|
-
|
|
531
|
-
return {
|
|
532
|
-
messageType:
|
|
533
|
-
RichSubMessageType.TEXT,
|
|
534
|
-
|
|
535
|
-
messageText:
|
|
536
|
-
'INLINE_VIDEO'
|
|
537
|
-
};
|
|
238
|
+
if (submessage.items) {
|
|
239
|
+
return {
|
|
240
|
+
messageType: RichSubMessageType.CONTENT_ITEMS,
|
|
241
|
+
contentItemsMetadata: {
|
|
242
|
+
itemsMetadata: submessage.items,
|
|
243
|
+
contentType:
|
|
244
|
+
proto.AIRichResponseContentItemsMetadata.ContentType.CAROUSEL
|
|
538
245
|
}
|
|
246
|
+
};
|
|
247
|
+
}
|
|
539
248
|
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
submessage.
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
return {
|
|
550
|
-
messageType:
|
|
551
|
-
RichSubMessageType.LATEX,
|
|
552
|
-
|
|
553
|
-
latexMetadata: {
|
|
554
|
-
|
|
555
|
-
text:
|
|
556
|
-
submessage.text,
|
|
557
|
-
|
|
558
|
-
expressions:
|
|
559
|
-
submessage.latex
|
|
560
|
-
}
|
|
561
|
-
};
|
|
249
|
+
if (submessage.inlineImage) {
|
|
250
|
+
return {
|
|
251
|
+
messageType: RichSubMessageType.INLINE_IMAGE,
|
|
252
|
+
imageMetadata: {
|
|
253
|
+
imageUrl: submessage.inlineImage,
|
|
254
|
+
imageText: submessage.imageText,
|
|
255
|
+
alignment: submessage.alignment,
|
|
256
|
+
tapLinkUrl: submessage.tapLinkUrl
|
|
562
257
|
}
|
|
258
|
+
};
|
|
259
|
+
}
|
|
563
260
|
|
|
261
|
+
if (submessage.inlineVideo) {
|
|
262
|
+
return {
|
|
263
|
+
messageType: RichSubMessageType.TEXT,
|
|
264
|
+
messageText: 'INLINE_VIDEO'
|
|
265
|
+
};
|
|
266
|
+
}
|
|
564
267
|
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
submessage.
|
|
571
|
-
) {
|
|
572
|
-
|
|
573
|
-
return {
|
|
574
|
-
messageType:
|
|
575
|
-
RichSubMessageType.TEXT,
|
|
576
|
-
|
|
577
|
-
messageText:
|
|
578
|
-
'POSTS'
|
|
579
|
-
};
|
|
268
|
+
if (submessage.latex) {
|
|
269
|
+
return {
|
|
270
|
+
messageType: RichSubMessageType.LATEX,
|
|
271
|
+
latexMetadata: {
|
|
272
|
+
text: submessage.text,
|
|
273
|
+
expressions: submessage.latex
|
|
580
274
|
}
|
|
275
|
+
};
|
|
276
|
+
}
|
|
581
277
|
|
|
278
|
+
if (submessage.posts) {
|
|
279
|
+
return {
|
|
280
|
+
messageType: RichSubMessageType.TEXT,
|
|
281
|
+
messageText: 'POSTS'
|
|
282
|
+
};
|
|
283
|
+
}
|
|
582
284
|
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
messageType:
|
|
593
|
-
RichSubMessageType.CONTENT_ITEMS,
|
|
594
|
-
|
|
595
|
-
contentItemsMetadata: {
|
|
596
|
-
|
|
597
|
-
itemsMetadata:
|
|
598
|
-
submessage.suggested.map(
|
|
599
|
-
(text) => ({
|
|
600
|
-
prompt_text:
|
|
601
|
-
text,
|
|
602
|
-
|
|
603
|
-
prompt_type:
|
|
604
|
-
'SUGGESTED_PROMPT',
|
|
605
|
-
|
|
606
|
-
__typename:
|
|
607
|
-
'GenAIFollowUpSuggestionPillPrimitive'
|
|
608
|
-
})
|
|
609
|
-
)
|
|
610
|
-
}
|
|
611
|
-
};
|
|
285
|
+
if (submessage.suggested) {
|
|
286
|
+
return {
|
|
287
|
+
messageType: RichSubMessageType.CONTENT_ITEMS,
|
|
288
|
+
contentItemsMetadata: {
|
|
289
|
+
itemsMetadata: submessage.suggested.map((text) => ({
|
|
290
|
+
prompt_text: text,
|
|
291
|
+
prompt_type: 'SUGGESTED_PROMPT',
|
|
292
|
+
__typename: 'GenAIFollowUpSuggestionPillPrimitive'
|
|
293
|
+
}))
|
|
612
294
|
}
|
|
295
|
+
};
|
|
296
|
+
}
|
|
613
297
|
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
submessage.table
|
|
621
|
-
) {
|
|
622
|
-
|
|
623
|
-
return {
|
|
624
|
-
messageType:
|
|
625
|
-
RichSubMessageType.TABLE,
|
|
626
|
-
|
|
627
|
-
tableMetadata: {
|
|
628
|
-
|
|
629
|
-
title:
|
|
630
|
-
submessage.title,
|
|
631
|
-
|
|
632
|
-
rows:
|
|
633
|
-
submessage.table
|
|
634
|
-
}
|
|
635
|
-
};
|
|
298
|
+
if (submessage.table) {
|
|
299
|
+
return {
|
|
300
|
+
messageType: RichSubMessageType.TABLE,
|
|
301
|
+
tableMetadata: {
|
|
302
|
+
title: submessage.title,
|
|
303
|
+
rows: submessage.table
|
|
636
304
|
}
|
|
305
|
+
};
|
|
306
|
+
}
|
|
637
307
|
|
|
308
|
+
return submessage;
|
|
309
|
+
});
|
|
310
|
+
} else {
|
|
638
311
|
|
|
639
|
-
|
|
640
|
-
}
|
|
641
|
-
);
|
|
642
|
-
}
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
/* =====================================================
|
|
646
|
-
* NORMAL OBJECT
|
|
647
|
-
* ===================================================== */
|
|
648
|
-
|
|
649
|
-
else {
|
|
650
|
-
|
|
651
|
-
/* ================================================
|
|
652
|
-
* HEADER
|
|
653
|
-
* ================================================ */
|
|
654
|
-
|
|
655
|
-
if (
|
|
656
|
-
headerText
|
|
657
|
-
) {
|
|
658
|
-
|
|
312
|
+
if (headerText) {
|
|
659
313
|
submessages.push({
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
RichSubMessageType.TEXT,
|
|
663
|
-
|
|
664
|
-
messageText:
|
|
665
|
-
headerText
|
|
314
|
+
messageType: RichSubMessageType.TEXT,
|
|
315
|
+
messageText: headerText
|
|
666
316
|
});
|
|
667
317
|
}
|
|
668
318
|
|
|
669
|
-
|
|
670
|
-
/* ================================================
|
|
671
|
-
* CONTENT
|
|
672
|
-
* ================================================ */
|
|
673
|
-
|
|
674
|
-
if (
|
|
675
|
-
contentText
|
|
676
|
-
) {
|
|
677
|
-
|
|
319
|
+
if (contentText) {
|
|
678
320
|
submessages.push({
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
RichSubMessageType.TEXT,
|
|
682
|
-
|
|
683
|
-
messageText:
|
|
684
|
-
contentText
|
|
321
|
+
messageType: RichSubMessageType.TEXT,
|
|
322
|
+
messageText: contentText
|
|
685
323
|
});
|
|
686
324
|
}
|
|
687
325
|
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
* CODE
|
|
691
|
-
* ================================================ */
|
|
692
|
-
|
|
693
|
-
if (
|
|
694
|
-
code
|
|
695
|
-
) {
|
|
696
|
-
|
|
697
|
-
const codeLanguage =
|
|
698
|
-
language || 'javascript';
|
|
326
|
+
if (code) {
|
|
327
|
+
const codeLanguage = language || 'javascript';
|
|
699
328
|
|
|
700
329
|
submessages.push({
|
|
701
|
-
|
|
702
|
-
messageType:
|
|
703
|
-
RichSubMessageType.CODE,
|
|
704
|
-
|
|
330
|
+
messageType: RichSubMessageType.CODE,
|
|
705
331
|
codeMetadata: {
|
|
706
|
-
|
|
707
332
|
codeLanguage,
|
|
708
|
-
|
|
709
|
-
codeBlocks:
|
|
710
|
-
tokenizeCode(
|
|
711
|
-
code,
|
|
712
|
-
codeLanguage
|
|
713
|
-
)
|
|
333
|
+
codeBlocks: tokenizeCode(code, codeLanguage)
|
|
714
334
|
}
|
|
715
335
|
});
|
|
716
336
|
}
|
|
717
337
|
|
|
718
|
-
|
|
719
|
-
/* ================================================
|
|
720
|
-
* ITEMS
|
|
721
|
-
* ================================================ */
|
|
722
|
-
|
|
723
|
-
if (
|
|
724
|
-
items
|
|
725
|
-
) {
|
|
726
|
-
|
|
338
|
+
if (items) {
|
|
727
339
|
submessages.push({
|
|
728
|
-
|
|
729
|
-
messageType:
|
|
730
|
-
RichSubMessageType.CONTENT_ITEMS,
|
|
731
|
-
|
|
340
|
+
messageType: RichSubMessageType.CONTENT_ITEMS,
|
|
732
341
|
contentItemsMetadata: {
|
|
733
|
-
|
|
734
|
-
itemsMetadata:
|
|
735
|
-
items,
|
|
736
|
-
|
|
342
|
+
itemsMetadata: items,
|
|
737
343
|
contentType:
|
|
738
|
-
proto
|
|
739
|
-
.AIRichResponseContentItemsMetadata
|
|
740
|
-
.ContentType
|
|
741
|
-
.CAROUSEL
|
|
344
|
+
proto.AIRichResponseContentItemsMetadata.ContentType.CAROUSEL
|
|
742
345
|
}
|
|
743
346
|
});
|
|
744
347
|
}
|
|
745
348
|
|
|
746
|
-
|
|
747
|
-
/* ================================================
|
|
748
|
-
* INLINE IMAGE
|
|
749
|
-
* ================================================ */
|
|
750
|
-
|
|
751
|
-
if (
|
|
752
|
-
inlineImage
|
|
753
|
-
) {
|
|
754
|
-
|
|
349
|
+
if (inlineImage) {
|
|
755
350
|
submessages.push({
|
|
756
|
-
|
|
757
|
-
messageType:
|
|
758
|
-
RichSubMessageType.INLINE_IMAGE,
|
|
759
|
-
|
|
351
|
+
messageType: RichSubMessageType.INLINE_IMAGE,
|
|
760
352
|
imageMetadata: {
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
imageText:
|
|
766
|
-
imageText,
|
|
767
|
-
|
|
768
|
-
alignment:
|
|
769
|
-
alignment,
|
|
770
|
-
|
|
771
|
-
tapLinkUrl:
|
|
772
|
-
tapLinkUrl
|
|
353
|
+
imageUrl: inlineImage,
|
|
354
|
+
imageText,
|
|
355
|
+
alignment,
|
|
356
|
+
tapLinkUrl
|
|
773
357
|
}
|
|
774
358
|
});
|
|
775
359
|
}
|
|
776
360
|
|
|
777
|
-
|
|
778
|
-
/* ================================================
|
|
779
|
-
* INLINE VIDEO
|
|
780
|
-
* ================================================ */
|
|
781
|
-
|
|
782
|
-
if (
|
|
783
|
-
inlineVideo
|
|
784
|
-
) {
|
|
785
|
-
|
|
361
|
+
if (inlineVideo) {
|
|
786
362
|
submessages.push({
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
RichSubMessageType.TEXT,
|
|
790
|
-
|
|
791
|
-
messageText:
|
|
792
|
-
'INLINE_VIDEO'
|
|
363
|
+
messageType: RichSubMessageType.TEXT,
|
|
364
|
+
messageText: 'INLINE_VIDEO'
|
|
793
365
|
});
|
|
794
366
|
}
|
|
795
367
|
|
|
796
|
-
|
|
797
|
-
/* ================================================
|
|
798
|
-
* LATEX
|
|
799
|
-
* ================================================ */
|
|
800
|
-
|
|
801
|
-
if (
|
|
802
|
-
latex
|
|
803
|
-
) {
|
|
804
|
-
|
|
368
|
+
if (latex) {
|
|
805
369
|
submessages.push({
|
|
806
|
-
|
|
807
|
-
messageType:
|
|
808
|
-
RichSubMessageType.LATEX,
|
|
809
|
-
|
|
370
|
+
messageType: RichSubMessageType.LATEX,
|
|
810
371
|
latexMetadata: {
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
contentText,
|
|
814
|
-
|
|
815
|
-
expressions:
|
|
816
|
-
latex
|
|
372
|
+
text: contentText,
|
|
373
|
+
expressions: latex
|
|
817
374
|
}
|
|
818
375
|
});
|
|
819
376
|
}
|
|
820
377
|
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
'
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
sourceField.displayName ||
|
|
849
|
-
'Donate',
|
|
850
|
-
|
|
851
|
-
source_subtitle:
|
|
852
|
-
sourceField.subtitle ||
|
|
853
|
-
'Saweria',
|
|
854
|
-
|
|
855
|
-
source_url:
|
|
856
|
-
sourceField.url ||
|
|
857
|
-
url
|
|
858
|
-
})
|
|
859
|
-
);
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
submessages.push({
|
|
863
|
-
|
|
864
|
-
messageType:
|
|
865
|
-
RichSubMessageType.TEXT,
|
|
866
|
-
|
|
867
|
-
messageText:
|
|
868
|
-
linkField.text +
|
|
869
|
-
` {{${prefix}}}¹{{/${prefix}}} `,
|
|
870
|
-
|
|
871
|
-
inlineEntities: [
|
|
872
|
-
{
|
|
873
|
-
|
|
874
|
-
key:
|
|
875
|
-
prefix,
|
|
876
|
-
|
|
877
|
-
metadata: {
|
|
878
|
-
|
|
879
|
-
reference_id:
|
|
880
|
-
index + 1,
|
|
881
|
-
|
|
882
|
-
reference_url:
|
|
883
|
-
url,
|
|
884
|
-
|
|
885
|
-
reference_title:
|
|
886
|
-
linkField.title ||
|
|
887
|
-
'For Donation via Saweria',
|
|
888
|
-
|
|
889
|
-
reference_display_name:
|
|
890
|
-
linkField.displayName ||
|
|
891
|
-
'Donation',
|
|
892
|
-
|
|
893
|
-
sources:
|
|
894
|
-
sources || [],
|
|
895
|
-
|
|
896
|
-
__typename:
|
|
897
|
-
'GenAISearchCitationItem'
|
|
898
|
-
}
|
|
378
|
+
if (links) {
|
|
379
|
+
links.forEach((linkField, index) => {
|
|
380
|
+
const prefix = 'SS_' + index;
|
|
381
|
+
const url = linkField.url || DONATE_URL;
|
|
382
|
+
|
|
383
|
+
const sources = linkField.sources?.map((sourceField) => ({
|
|
384
|
+
source_type: 'THIRD_PARTY',
|
|
385
|
+
source_display_name: sourceField.displayName || 'Donate',
|
|
386
|
+
source_subtitle: sourceField.subtitle || 'Saweria',
|
|
387
|
+
source_url: sourceField.url || url
|
|
388
|
+
}));
|
|
389
|
+
|
|
390
|
+
submessages.push({
|
|
391
|
+
messageType: RichSubMessageType.TEXT,
|
|
392
|
+
messageText: linkField.text + ` {{${prefix}}}¹{{/${prefix}}} `,
|
|
393
|
+
inlineEntities: [
|
|
394
|
+
{
|
|
395
|
+
key: prefix,
|
|
396
|
+
metadata: {
|
|
397
|
+
reference_id: index + 1,
|
|
398
|
+
reference_url: url,
|
|
399
|
+
reference_title:
|
|
400
|
+
linkField.title || 'For Donation via Saweria',
|
|
401
|
+
reference_display_name:
|
|
402
|
+
linkField.displayName || 'Donation',
|
|
403
|
+
sources: sources || [],
|
|
404
|
+
__typename: 'GenAISearchCitationItem'
|
|
899
405
|
}
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
}
|
|
903
|
-
);
|
|
406
|
+
}
|
|
407
|
+
]
|
|
408
|
+
});
|
|
409
|
+
});
|
|
904
410
|
}
|
|
905
411
|
|
|
906
|
-
|
|
907
|
-
/* ================================================
|
|
908
|
-
* POSTS
|
|
909
|
-
* ================================================ */
|
|
910
|
-
|
|
911
|
-
if (
|
|
912
|
-
posts
|
|
913
|
-
) {
|
|
914
|
-
|
|
412
|
+
if (posts) {
|
|
915
413
|
submessages.push({
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
RichSubMessageType.TEXT,
|
|
919
|
-
|
|
920
|
-
messageText:
|
|
921
|
-
'POSTS'
|
|
414
|
+
messageType: RichSubMessageType.TEXT,
|
|
415
|
+
messageText: 'POSTS'
|
|
922
416
|
});
|
|
923
417
|
}
|
|
924
418
|
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
* PRODUCT
|
|
928
|
-
* ================================================ */
|
|
929
|
-
|
|
930
|
-
if (
|
|
931
|
-
dataProduct
|
|
932
|
-
) {
|
|
933
|
-
|
|
934
|
-
const list =
|
|
935
|
-
Array.isArray(dataProduct)
|
|
936
|
-
? dataProduct
|
|
937
|
-
: [dataProduct];
|
|
938
|
-
|
|
419
|
+
if (dataProduct) {
|
|
420
|
+
const list = Array.isArray(dataProduct) ? dataProduct : [dataProduct];
|
|
939
421
|
|
|
940
422
|
submessages.push({
|
|
941
|
-
|
|
942
|
-
messageType:
|
|
943
|
-
RichSubMessageType.CONTENT_ITEMS,
|
|
944
|
-
|
|
423
|
+
messageType: RichSubMessageType.CONTENT_ITEMS,
|
|
945
424
|
contentItemsMetadata: {
|
|
946
|
-
|
|
947
425
|
contentType:
|
|
948
|
-
proto
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
item.brand,
|
|
962
|
-
|
|
963
|
-
price:
|
|
964
|
-
item.price,
|
|
965
|
-
|
|
966
|
-
sale_price:
|
|
967
|
-
item.sale_price,
|
|
968
|
-
|
|
969
|
-
product_url:
|
|
970
|
-
item.product_url,
|
|
971
|
-
|
|
972
|
-
image:
|
|
973
|
-
item.image_url
|
|
974
|
-
? {
|
|
975
|
-
url:
|
|
976
|
-
item.image_url
|
|
977
|
-
}
|
|
978
|
-
: undefined,
|
|
979
|
-
|
|
980
|
-
additional_images:
|
|
981
|
-
item.icon_url
|
|
982
|
-
? [
|
|
983
|
-
{
|
|
984
|
-
url:
|
|
985
|
-
item.icon_url
|
|
986
|
-
}
|
|
987
|
-
]
|
|
988
|
-
: [],
|
|
989
|
-
|
|
990
|
-
__typename:
|
|
991
|
-
'GenAIProductItemCardPrimitive'
|
|
992
|
-
})
|
|
993
|
-
)
|
|
426
|
+
proto.AIRichResponseContentItemsMetadata.ContentType.CAROUSEL,
|
|
427
|
+
itemsMetadata: list.map((item) => ({
|
|
428
|
+
title: item.title,
|
|
429
|
+
brand: item.brand,
|
|
430
|
+
price: item.price,
|
|
431
|
+
sale_price: item.sale_price,
|
|
432
|
+
product_url: item.product_url,
|
|
433
|
+
image: item.image_url ? { url: item.image_url } : undefined,
|
|
434
|
+
additional_images: item.icon_url
|
|
435
|
+
? [{ url: item.icon_url }]
|
|
436
|
+
: [],
|
|
437
|
+
__typename: 'GenAIProductItemCardPrimitive'
|
|
438
|
+
}))
|
|
994
439
|
}
|
|
995
440
|
});
|
|
996
441
|
}
|
|
997
442
|
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
* SUGGESTED
|
|
1001
|
-
* ================================================ */
|
|
1002
|
-
|
|
1003
|
-
if (
|
|
1004
|
-
suggested
|
|
1005
|
-
) {
|
|
1006
|
-
|
|
1007
|
-
const suggestionList =
|
|
1008
|
-
Array.isArray(suggested)
|
|
1009
|
-
? suggested
|
|
1010
|
-
: [suggested];
|
|
1011
|
-
|
|
443
|
+
if (suggested) {
|
|
444
|
+
const suggestionList = Array.isArray(suggested) ? suggested : [suggested];
|
|
1012
445
|
|
|
1013
446
|
submessages.push({
|
|
1014
|
-
|
|
1015
|
-
messageType:
|
|
1016
|
-
RichSubMessageType.CONTENT_ITEMS,
|
|
1017
|
-
|
|
447
|
+
messageType: RichSubMessageType.CONTENT_ITEMS,
|
|
1018
448
|
contentItemsMetadata: {
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
prompt_text:
|
|
1025
|
-
text,
|
|
1026
|
-
|
|
1027
|
-
prompt_type:
|
|
1028
|
-
'SUGGESTED_PROMPT',
|
|
1029
|
-
|
|
1030
|
-
__typename:
|
|
1031
|
-
'GenAIFollowUpSuggestionPillPrimitive'
|
|
1032
|
-
})
|
|
1033
|
-
)
|
|
449
|
+
itemsMetadata: suggestionList.map((text) => ({
|
|
450
|
+
prompt_text: text,
|
|
451
|
+
prompt_type: 'SUGGESTED_PROMPT',
|
|
452
|
+
__typename: 'GenAIFollowUpSuggestionPillPrimitive'
|
|
453
|
+
}))
|
|
1034
454
|
}
|
|
1035
455
|
});
|
|
1036
456
|
}
|
|
1037
457
|
|
|
1038
|
-
|
|
1039
|
-
/* ================================================
|
|
1040
|
-
* TABLE
|
|
1041
|
-
* ================================================ */
|
|
1042
|
-
|
|
1043
|
-
if (
|
|
1044
|
-
table
|
|
1045
|
-
) {
|
|
1046
|
-
|
|
458
|
+
if (table) {
|
|
1047
459
|
submessages.push({
|
|
1048
|
-
|
|
1049
|
-
messageType:
|
|
1050
|
-
RichSubMessageType.TABLE,
|
|
1051
|
-
|
|
460
|
+
messageType: RichSubMessageType.TABLE,
|
|
1052
461
|
tableMetadata: {
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
table.map(
|
|
1059
|
-
(items, index) => ({
|
|
1060
|
-
|
|
1061
|
-
isHeading:
|
|
1062
|
-
!noHeading &&
|
|
1063
|
-
index === 0,
|
|
1064
|
-
|
|
1065
|
-
items
|
|
1066
|
-
})
|
|
1067
|
-
)
|
|
462
|
+
title,
|
|
463
|
+
rows: table.map((items, index) => ({
|
|
464
|
+
isHeading: !noHeading && index === 0,
|
|
465
|
+
items
|
|
466
|
+
}))
|
|
1068
467
|
}
|
|
1069
468
|
});
|
|
1070
469
|
}
|
|
1071
470
|
}
|
|
1072
471
|
|
|
472
|
+
const uuid = randomUUID();
|
|
473
|
+
const unified = toUnified(submessages, uuid, footerText);
|
|
1073
474
|
|
|
1074
|
-
|
|
1075
|
-
* RESPONSE ID
|
|
1076
|
-
* ===================================================== */
|
|
1077
|
-
|
|
1078
|
-
const uuid =
|
|
1079
|
-
randomUUID();
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
/* =====================================================
|
|
1083
|
-
* UNIFIED RESPONSE
|
|
1084
|
-
* ===================================================== */
|
|
1085
|
-
|
|
1086
|
-
const unified =
|
|
1087
|
-
toUnified(
|
|
1088
|
-
submessages,
|
|
1089
|
-
uuid,
|
|
1090
|
-
footerText
|
|
1091
|
-
);
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
const base64Data =
|
|
1095
|
-
Buffer
|
|
1096
|
-
.from(
|
|
1097
|
-
JSON.stringify(unified)
|
|
1098
|
-
)
|
|
1099
|
-
.toString('base64');
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
/* =====================================================
|
|
1103
|
-
* OURIN V2 CONTEXT INFO
|
|
1104
|
-
* ===================================================== */
|
|
475
|
+
const base64Data = Buffer.from(JSON.stringify(unified)).toString('base64');
|
|
1105
476
|
|
|
1106
477
|
const contextInfo = {
|
|
1107
|
-
|
|
1108
478
|
mentionedJid: [],
|
|
1109
|
-
|
|
1110
479
|
groupMentions: [],
|
|
1111
|
-
|
|
1112
480
|
statusAttributions: [],
|
|
1113
|
-
|
|
1114
481
|
forwardingScore: 2,
|
|
1115
|
-
|
|
1116
482
|
isForwarded: true,
|
|
1117
|
-
|
|
1118
483
|
forwardedAiBotMessageInfo: {
|
|
1119
|
-
|
|
1120
|
-
botJid:
|
|
1121
|
-
'259786046210223@bot'
|
|
484
|
+
botJid: '259786046210223@bot'
|
|
1122
485
|
},
|
|
1123
|
-
|
|
1124
486
|
forwardOrigin: 4,
|
|
1125
|
-
|
|
1126
487
|
botMessageSharingInfo: {
|
|
1127
|
-
|
|
1128
488
|
botEntryPointOrigin: 1,
|
|
1129
|
-
|
|
1130
489
|
forwardScore: 2
|
|
1131
490
|
}
|
|
1132
491
|
};
|
|
1133
492
|
|
|
1134
|
-
const richResponseMessage =
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
unifiedResponse: {
|
|
1145
|
-
|
|
1146
|
-
data:
|
|
1147
|
-
base64Data
|
|
1148
|
-
},
|
|
1149
|
-
|
|
1150
|
-
contextInfo
|
|
1151
|
-
});
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
/* =====================================================
|
|
1155
|
-
* WRAP
|
|
1156
|
-
* ===================================================== */
|
|
1157
|
-
|
|
1158
|
-
const message =
|
|
1159
|
-
wrapToBotForwardedMessage(
|
|
1160
|
-
richResponseMessage
|
|
1161
|
-
);
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
/* =====================================================
|
|
1165
|
-
* BOT METADATA
|
|
1166
|
-
* ===================================================== */
|
|
1167
|
-
|
|
1168
|
-
const botMetadata =
|
|
1169
|
-
message
|
|
1170
|
-
.messageContextInfo
|
|
1171
|
-
.botMetadata;
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
/* =====================================================
|
|
1175
|
-
* DISCLAIMER
|
|
1176
|
-
* ===================================================== */
|
|
493
|
+
const richResponseMessage = proto.AIRichResponseMessage.create({
|
|
494
|
+
submessages: [],
|
|
495
|
+
messageType:
|
|
496
|
+
proto.AIRichResponseMessageType.AI_RICH_RESPONSE_TYPE_STANDARD,
|
|
497
|
+
unifiedResponse: {
|
|
498
|
+
data: base64Data
|
|
499
|
+
},
|
|
500
|
+
contextInfo
|
|
501
|
+
});
|
|
1177
502
|
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
) {
|
|
503
|
+
const message = wrapToBotForwardedMessage(richResponseMessage);
|
|
504
|
+
const botMetadata = message.messageContextInfo.botMetadata;
|
|
1181
505
|
|
|
1182
|
-
|
|
1183
|
-
|
|
506
|
+
if (disclaimerText) {
|
|
507
|
+
botMetadata.messageDisclaimerText = disclaimerText;
|
|
1184
508
|
}
|
|
1185
509
|
|
|
1186
|
-
|
|
1187
|
-
/* =====================================================
|
|
1188
|
-
* RESPONSE ID
|
|
1189
|
-
* ===================================================== */
|
|
1190
|
-
|
|
1191
|
-
botMetadata.botResponseId =
|
|
1192
|
-
uuid;
|
|
1193
|
-
|
|
510
|
+
botMetadata.botResponseId = uuid;
|
|
1194
511
|
|
|
1195
512
|
return message;
|
|
1196
513
|
};
|
|
1197
514
|
|
|
1198
|
-
|
|
1199
|
-
/* =========================================================
|
|
1200
|
-
* BOT METADATA SIGNATURE
|
|
1201
|
-
* ========================================================= */
|
|
1202
|
-
|
|
1203
515
|
export const botMetadataSignature = () => {
|
|
516
|
+
const signature = new Uint8Array(64);
|
|
1204
517
|
|
|
1205
|
-
|
|
1206
|
-
new Uint8Array(64);
|
|
1207
|
-
|
|
1208
|
-
getRandomValues(
|
|
1209
|
-
signature
|
|
1210
|
-
);
|
|
518
|
+
getRandomValues(signature);
|
|
1211
519
|
|
|
1212
520
|
return signature;
|
|
1213
521
|
};
|
|
1214
522
|
|
|
523
|
+
export const botMetadataCertificate = (length = 685) => {
|
|
524
|
+
const certificate = new Uint8Array(length);
|
|
1215
525
|
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
* ========================================================= */
|
|
1219
|
-
|
|
1220
|
-
export const botMetadataCertificate = (
|
|
1221
|
-
length = 685
|
|
1222
|
-
) => {
|
|
1223
|
-
|
|
1224
|
-
const certificate =
|
|
1225
|
-
new Uint8Array(length);
|
|
1226
|
-
|
|
1227
|
-
certificate[0] =
|
|
1228
|
-
48;
|
|
526
|
+
certificate[0] = 48;
|
|
527
|
+
certificate[1] = 130;
|
|
1229
528
|
|
|
1230
|
-
certificate
|
|
1231
|
-
130;
|
|
1232
|
-
|
|
1233
|
-
getRandomValues(
|
|
1234
|
-
certificate.subarray(2)
|
|
1235
|
-
);
|
|
529
|
+
getRandomValues(certificate.subarray(2));
|
|
1236
530
|
|
|
1237
531
|
return certificate;
|
|
1238
532
|
};
|
|
1239
533
|
|
|
1240
|
-
|
|
1241
|
-
/* =========================================================
|
|
1242
|
-
* WRAP TO BOT FORWARDED MESSAGE
|
|
1243
|
-
* ========================================================= */
|
|
1244
|
-
|
|
1245
|
-
export const wrapToBotForwardedMessage = (
|
|
1246
|
-
richResponseMessage
|
|
1247
|
-
) => {
|
|
1248
|
-
|
|
534
|
+
export const wrapToBotForwardedMessage = (richResponseMessage) => {
|
|
1249
535
|
return {
|
|
1250
|
-
|
|
1251
536
|
messageContextInfo: {
|
|
1252
|
-
|
|
1253
|
-
/* =============================================
|
|
1254
|
-
* OURIN V2 MESSAGE CONTEXT
|
|
1255
|
-
* ============================================= */
|
|
1256
|
-
|
|
1257
537
|
threadId: [],
|
|
1258
|
-
|
|
1259
538
|
deviceListMetadata: {
|
|
1260
|
-
|
|
1261
539
|
senderKeyIndexes: [],
|
|
1262
|
-
|
|
1263
540
|
recipientKeyIndexes: [],
|
|
1264
|
-
|
|
1265
541
|
recipientKeyHash: '',
|
|
1266
|
-
|
|
1267
|
-
recipientTimestamp:
|
|
1268
|
-
Math.floor(
|
|
1269
|
-
Date.now() / 1000
|
|
1270
|
-
)
|
|
542
|
+
recipientTimestamp: Math.floor(Date.now() / 1000)
|
|
1271
543
|
},
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
2,
|
|
1275
|
-
|
|
1276
|
-
messageSecret:
|
|
1277
|
-
randomBytes(32),
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
/* =============================================
|
|
1281
|
-
* BOT METADATA
|
|
1282
|
-
* ============================================= */
|
|
544
|
+
deviceListMetadataVersion: 2,
|
|
545
|
+
messageSecret: randomBytes(32),
|
|
1283
546
|
|
|
1284
547
|
botMetadata: {
|
|
1285
|
-
|
|
1286
548
|
verificationMetadata: {
|
|
1287
|
-
|
|
1288
549
|
proofs: [
|
|
1289
550
|
{
|
|
1290
|
-
|
|
1291
551
|
certificateChain: [
|
|
1292
|
-
|
|
1293
552
|
botMetadataCertificate(),
|
|
1294
|
-
|
|
1295
|
-
botMetadataCertificate(
|
|
1296
|
-
892
|
|
1297
|
-
)
|
|
553
|
+
botMetadataCertificate(892)
|
|
1298
554
|
],
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
useCase:
|
|
1304
|
-
1,
|
|
1305
|
-
|
|
1306
|
-
signature:
|
|
1307
|
-
botMetadataSignature()
|
|
555
|
+
version: 1,
|
|
556
|
+
useCase: 1,
|
|
557
|
+
signature: botMetadataSignature()
|
|
1308
558
|
}
|
|
1309
559
|
]
|
|
1310
560
|
}
|
|
1311
561
|
}
|
|
1312
562
|
},
|
|
1313
563
|
|
|
1314
|
-
|
|
1315
|
-
/* ================================================
|
|
1316
|
-
* BOT FORWARDED MESSAGE
|
|
1317
|
-
* ================================================ */
|
|
1318
|
-
|
|
1319
564
|
botForwardedMessage: {
|
|
1320
|
-
|
|
1321
565
|
message: {
|
|
1322
|
-
|
|
1323
566
|
richResponseMessage
|
|
1324
|
-
|
|
1325
567
|
}
|
|
1326
568
|
}
|
|
1327
569
|
};
|
|
1328
570
|
};
|
|
1329
571
|
|
|
1330
|
-
|
|
1331
572
|
//# sourceMappingURL=rich-message-utils.js.map
|