@pontasockets/baileys 0.2.4 → 0.2.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.
- package/lib/Utils/rich-message-utils.js +87 -76
- package/package.json +1 -1
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* rich-message-utils.js
|
|
5
|
-
* @pontasockets
|
|
5
|
+
* @pontasockets/baileys
|
|
6
6
|
* Tambahkan file ini ke: node_modules/@whiskeysockets/baileys/lib/Utils/rich-message-utils.js
|
|
7
7
|
*/
|
|
8
8
|
|
|
@@ -252,64 +252,38 @@ const prepareRichResponseMessage = (content) => {
|
|
|
252
252
|
} else if (content.table) {
|
|
253
253
|
items = [{ table: content.table }]
|
|
254
254
|
} else if ('richText' in content) {
|
|
255
|
-
items =
|
|
255
|
+
items = Array.isArray(content.richText)
|
|
256
|
+
? content.richText.map(t => ({ text: t }))
|
|
257
|
+
: [{ text: content.richText }]
|
|
256
258
|
} else {
|
|
257
259
|
items = [{ code: content.code, language: content.language }]
|
|
258
260
|
}
|
|
259
261
|
|
|
260
|
-
|
|
262
|
+
// Build submessages as plain objects (sesuai struktur relay)
|
|
263
|
+
const submessages = items.map(item => {
|
|
261
264
|
// ── TEXT ──────────────────────────────────────────────────────────────
|
|
262
265
|
if ('text' in item) {
|
|
263
266
|
return {
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
messageText: item.text
|
|
267
|
-
}),
|
|
268
|
-
unified: {
|
|
269
|
-
messageType: RichSubMessageType.TEXT,
|
|
270
|
-
messageText: item.text
|
|
271
|
-
}
|
|
267
|
+
messageType: RichSubMessageType.TEXT, // 2
|
|
268
|
+
messageText: item.text
|
|
272
269
|
}
|
|
273
270
|
}
|
|
274
271
|
|
|
275
272
|
// ── TABLE ─────────────────────────────────────────────────────────────
|
|
276
273
|
if (item.table) {
|
|
277
274
|
const { title, headers, rows } = item.table
|
|
278
|
-
|
|
279
|
-
// Build rows: header row dulu (kalau ada), baru data rows
|
|
280
275
|
const allRows = []
|
|
281
276
|
if (headers && headers.length) {
|
|
282
|
-
allRows.push(
|
|
283
|
-
items: headers,
|
|
284
|
-
isHeading: true
|
|
285
|
-
}))
|
|
277
|
+
allRows.push({ items: headers, isHeading: true })
|
|
286
278
|
}
|
|
287
279
|
for (const row of (rows || [])) {
|
|
288
|
-
allRows.push(
|
|
289
|
-
items: row,
|
|
290
|
-
isHeading: false
|
|
291
|
-
}))
|
|
280
|
+
allRows.push({ items: row, isHeading: false })
|
|
292
281
|
}
|
|
293
|
-
|
|
294
|
-
const tableMetadata = proto.AIRichResponseTableMetadata.create({
|
|
295
|
-
title: title || null,
|
|
296
|
-
rows: allRows
|
|
297
|
-
})
|
|
298
|
-
|
|
299
282
|
return {
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
unified: {
|
|
305
|
-
messageType: RichSubMessageType.TABLE,
|
|
306
|
-
tableMetadata: {
|
|
307
|
-
title: title || null,
|
|
308
|
-
rows: [
|
|
309
|
-
...(headers ? [{ items: headers, isHeading: true }] : []),
|
|
310
|
-
...(rows || []).map(r => ({ items: r, isHeading: false }))
|
|
311
|
-
]
|
|
312
|
-
}
|
|
283
|
+
messageType: RichSubMessageType.TABLE, // 4
|
|
284
|
+
tableMetadata: {
|
|
285
|
+
...(title ? { title } : {}),
|
|
286
|
+
rows: allRows
|
|
313
287
|
}
|
|
314
288
|
}
|
|
315
289
|
}
|
|
@@ -318,47 +292,72 @@ const prepareRichResponseMessage = (content) => {
|
|
|
318
292
|
const lang = item.language || 'javascript'
|
|
319
293
|
const codeBlocks = tokenizeCode(item.code, lang)
|
|
320
294
|
return {
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
codeContent: b.codeContent
|
|
329
|
-
})
|
|
330
|
-
)
|
|
331
|
-
})
|
|
332
|
-
}),
|
|
333
|
-
unified: {
|
|
334
|
-
messageType: RichSubMessageType.CODE,
|
|
335
|
-
codeMetadata: { codeLanguage: lang, codeBlocks }
|
|
295
|
+
messageType: RichSubMessageType.CODE, // 5
|
|
296
|
+
codeMetadata: {
|
|
297
|
+
codeLanguage: lang,
|
|
298
|
+
codeBlocks: codeBlocks.map(b => ({
|
|
299
|
+
highlightType: b.highlightType,
|
|
300
|
+
codeContent: b.codeContent
|
|
301
|
+
}))
|
|
336
302
|
}
|
|
337
303
|
}
|
|
338
304
|
})
|
|
339
305
|
|
|
340
306
|
const uuid = crypto_1.randomUUID()
|
|
341
|
-
const unified = toUnified(built.map(b => b.unified), uuid)
|
|
342
307
|
|
|
343
|
-
// Build
|
|
344
|
-
const
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
308
|
+
// Build unified JSON untuk unifiedResponse
|
|
309
|
+
const unifiedSections = submessages.map(sub => {
|
|
310
|
+
if (sub.messageType === RichSubMessageType.TEXT) {
|
|
311
|
+
return {
|
|
312
|
+
view_model: {
|
|
313
|
+
primitive: {
|
|
314
|
+
text: sub.messageText,
|
|
315
|
+
inline_entities: [],
|
|
316
|
+
__typename: 'GenAIMarkdownTextUXPrimitive'
|
|
317
|
+
},
|
|
318
|
+
__typename: 'GenAISingleLayoutViewModel'
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
if (sub.messageType === RichSubMessageType.TABLE) {
|
|
323
|
+
const tm = sub.tableMetadata
|
|
324
|
+
return {
|
|
325
|
+
view_model: {
|
|
326
|
+
primitive: {
|
|
327
|
+
...(tm.title ? { title: tm.title } : {}),
|
|
328
|
+
rows: tm.rows.map(row => ({
|
|
329
|
+
cells: row.items,
|
|
330
|
+
is_heading: row.isHeading || false
|
|
331
|
+
})),
|
|
332
|
+
__typename: 'GenAITableUXPrimitive'
|
|
333
|
+
},
|
|
334
|
+
__typename: 'GenAISingleLayoutViewModel'
|
|
335
|
+
}
|
|
336
|
+
}
|
|
357
337
|
}
|
|
338
|
+
if (sub.messageType === RichSubMessageType.CODE) {
|
|
339
|
+
const cm = sub.codeMetadata
|
|
340
|
+
return {
|
|
341
|
+
view_model: {
|
|
342
|
+
primitive: {
|
|
343
|
+
language: cm.codeLanguage,
|
|
344
|
+
code_blocks: cm.codeBlocks.map(b => ({
|
|
345
|
+
content: b.codeContent,
|
|
346
|
+
type: Object.keys(CodeHighlightType).find(k => CodeHighlightType[k] === b.highlightType) || 'DEFAULT'
|
|
347
|
+
})),
|
|
348
|
+
__typename: 'GenAICodeUXPrimitive'
|
|
349
|
+
},
|
|
350
|
+
__typename: 'GenAISingleLayoutViewModel'
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
return {}
|
|
358
355
|
})
|
|
359
356
|
|
|
360
|
-
|
|
361
|
-
|
|
357
|
+
const unified = { response_id: uuid, sections: unifiedSections }
|
|
358
|
+
|
|
359
|
+
// Plain object structure — sama persis kayak relay
|
|
360
|
+
return {
|
|
362
361
|
messageContextInfo: {
|
|
363
362
|
botMetadata: {
|
|
364
363
|
verificationMetadata: {
|
|
@@ -373,10 +372,22 @@ const prepareRichResponseMessage = (content) => {
|
|
|
373
372
|
}
|
|
374
373
|
},
|
|
375
374
|
botForwardedMessage: {
|
|
376
|
-
message: {
|
|
375
|
+
message: {
|
|
376
|
+
richResponseMessage: {
|
|
377
|
+
messageType: 1,
|
|
378
|
+
submessages,
|
|
379
|
+
unifiedResponse: {
|
|
380
|
+
data: Buffer.from(JSON.stringify(unified))
|
|
381
|
+
},
|
|
382
|
+
contextInfo: {
|
|
383
|
+
isForwarded: true,
|
|
384
|
+
forwardingScore: 1,
|
|
385
|
+
forwardedAiBotMessageInfo: { botJid: '867051314767696@bot' },
|
|
386
|
+
forwardOrigin: 4
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
}
|
|
377
390
|
}
|
|
378
391
|
}
|
|
379
|
-
|
|
380
|
-
return message
|
|
381
392
|
}
|
|
382
|
-
exports.prepareRichResponseMessage = prepareRichResponseMessage
|
|
393
|
+
exports.prepareRichResponseMessage = prepareRichResponseMessage
|