@pontasockets/baileys 0.2.5 โ 0.2.7
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/README.md +132 -2
- package/lib/Utils/messages.js +2 -2
- package/lib/Utils/rich-message-utils.js +95 -106
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -65,6 +65,7 @@ This fork introduces targeted custom patches on top of the original Baileys libr
|
|
|
65
65
|
| `02` | ๐ **Table Message** | Send structured tables via `{ table: { title?, headers, rows } }` โ renders as rich table in WhatsApp |
|
|
66
66
|
| `03` | ๐ **Rich Text Message** | Send styled text via `{ richText: '...' }` โ renders as AI bot markdown text in WhatsApp |
|
|
67
67
|
| `04` | ๐ **Mixed Rich Message** | Combine text + code + table in one message via `{ items: [...] }` |
|
|
68
|
+
| `05` | ๐ **Inline Citation Message** | Send text with clickable footnote citations via `{ richResponse: [...] }` |
|
|
68
69
|
| `02` | ๐ชช **Custom Message ID** | All outgoing message IDs prefixed with `PONTASOCKETS` |
|
|
69
70
|
| `03` | ๐ **LID Bug Fixes** | Full fix for participant, mentionedJid, sender, and group admin LID resolution |
|
|
70
71
|
| `04` | ๐ฆ **makeInMemoryStore Fix** | Corrected store behavior for stable session handling |
|
|
@@ -485,7 +486,136 @@ await sock.sendMessage(jid, {
|
|
|
485
486
|
|
|
486
487
|
> **Tipe yang valid di dalam `items`:**
|
|
487
488
|
> - `{ text: 'string' }` โ teks / markdown
|
|
488
|
-
> -
|
|
489
|
+
> -
|
|
490
|
+
|
|
491
|
+
<details>
|
|
492
|
+
<summary><b>๐ Inline Citation Message <kbd>NEW</kbd></b></summary>
|
|
493
|
+
<br>
|
|
494
|
+
|
|
495
|
+
> Render teks dengan citation/footnote yang bisa diklik โ mirip jawaban AI WhatsApp yang punya referensi sumber
|
|
496
|
+
|
|
497
|
+
**Format citation di teks:** `{{KEY}}N{{/KEY}}`
|
|
498
|
+
- `KEY` harus cocok dengan field `key` di `inlineEntities`
|
|
499
|
+
- `N` adalah nomor urut footnote (ยนยฒยณ atau 1 2 3)
|
|
500
|
+
|
|
501
|
+
---
|
|
502
|
+
|
|
503
|
+
**Single citation**
|
|
504
|
+
|
|
505
|
+
```javascript
|
|
506
|
+
await sock.sendMessage(jid, {
|
|
507
|
+
richResponse: [
|
|
508
|
+
{
|
|
509
|
+
text: 'Koperasi Merah Putih adalah inisiatif pemerintah. {{SS_0}}ยน{{/SS_0}} ',
|
|
510
|
+
inlineEntities: [{
|
|
511
|
+
key: 'SS_0',
|
|
512
|
+
metadata: {
|
|
513
|
+
reference_id: 1,
|
|
514
|
+
reference_url: 'https://example.com',
|
|
515
|
+
reference_title: 'Judul Sumber',
|
|
516
|
+
reference_display_name: 'Sumber',
|
|
517
|
+
sources: [{
|
|
518
|
+
source_type: 'THIRD_PARTY',
|
|
519
|
+
source_display_name: 'Sumber',
|
|
520
|
+
source_subtitle: 'example.com',
|
|
521
|
+
source_url: 'https://example.com'
|
|
522
|
+
}],
|
|
523
|
+
__typename: 'GenAISearchCitationItem'
|
|
524
|
+
}
|
|
525
|
+
}]
|
|
526
|
+
}
|
|
527
|
+
]
|
|
528
|
+
}, { quoted: message })
|
|
529
|
+
```
|
|
530
|
+
|
|
531
|
+
**Multi citation dalam satu teks**
|
|
532
|
+
|
|
533
|
+
```javascript
|
|
534
|
+
await sock.sendMessage(jid, {
|
|
535
|
+
richResponse: [
|
|
536
|
+
{
|
|
537
|
+
text: 'Node.js {{SS_0}}ยน{{/SS_0}} adalah runtime JavaScript. Dibuat oleh Ryan Dahl {{SS_1}}ยฒ{{/SS_1}} pada 2009.',
|
|
538
|
+
inlineEntities: [
|
|
539
|
+
{
|
|
540
|
+
key: 'SS_0',
|
|
541
|
+
metadata: {
|
|
542
|
+
reference_id: 1,
|
|
543
|
+
reference_url: 'https://nodejs.org',
|
|
544
|
+
reference_title: 'Node.js Official',
|
|
545
|
+
reference_display_name: 'nodejs.org',
|
|
546
|
+
sources: [{
|
|
547
|
+
source_type: 'THIRD_PARTY',
|
|
548
|
+
source_display_name: 'nodejs.org',
|
|
549
|
+
source_subtitle: 'nodejs.org',
|
|
550
|
+
source_url: 'https://nodejs.org'
|
|
551
|
+
}],
|
|
552
|
+
__typename: 'GenAISearchCitationItem'
|
|
553
|
+
}
|
|
554
|
+
},
|
|
555
|
+
{
|
|
556
|
+
key: 'SS_1',
|
|
557
|
+
metadata: {
|
|
558
|
+
reference_id: 2,
|
|
559
|
+
reference_url: 'https://wikipedia.org/wiki/Ryan_Dahl',
|
|
560
|
+
reference_title: 'Ryan Dahl - Wikipedia',
|
|
561
|
+
reference_display_name: 'Wikipedia',
|
|
562
|
+
sources: [{
|
|
563
|
+
source_type: 'THIRD_PARTY',
|
|
564
|
+
source_display_name: 'Wikipedia',
|
|
565
|
+
source_subtitle: 'wikipedia.org',
|
|
566
|
+
source_url: 'https://wikipedia.org/wiki/Ryan_Dahl'
|
|
567
|
+
}],
|
|
568
|
+
__typename: 'GenAISearchCitationItem'
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
]
|
|
572
|
+
}
|
|
573
|
+
]
|
|
574
|
+
}, { quoted: message })
|
|
575
|
+
```
|
|
576
|
+
|
|
577
|
+
**Citation + Code Block dalam satu pesan**
|
|
578
|
+
|
|
579
|
+
```javascript
|
|
580
|
+
await sock.sendMessage(jid, {
|
|
581
|
+
richResponse: [
|
|
582
|
+
{
|
|
583
|
+
text: 'Cara install Node.js {{SS_0}}ยน{{/SS_0}}:',
|
|
584
|
+
inlineEntities: [{
|
|
585
|
+
key: 'SS_0',
|
|
586
|
+
metadata: {
|
|
587
|
+
reference_id: 1,
|
|
588
|
+
reference_url: 'https://nodejs.org/en/download',
|
|
589
|
+
reference_title: 'Download Node.js',
|
|
590
|
+
reference_display_name: 'nodejs.org',
|
|
591
|
+
sources: [{
|
|
592
|
+
source_type: 'THIRD_PARTY',
|
|
593
|
+
source_display_name: 'nodejs.org',
|
|
594
|
+
source_subtitle: 'nodejs.org',
|
|
595
|
+
source_url: 'https://nodejs.org/en/download'
|
|
596
|
+
}],
|
|
597
|
+
__typename: 'GenAISearchCitationItem'
|
|
598
|
+
}
|
|
599
|
+
}]
|
|
600
|
+
},
|
|
601
|
+
{
|
|
602
|
+
code: 'curl -fsSL https://deb.nodesource.com/setup_lts.x | bash -
|
|
603
|
+
apt-get install -y nodejs',
|
|
604
|
+
language: 'bash'
|
|
605
|
+
},
|
|
606
|
+
{
|
|
607
|
+
text: '_Verifikasi instalasi dengan_ `node --version`'
|
|
608
|
+
}
|
|
609
|
+
]
|
|
610
|
+
}, { quoted: message })
|
|
611
|
+
```
|
|
612
|
+
|
|
613
|
+
> **Tipe yang valid di dalam `richResponse`:**
|
|
614
|
+
> - `{ text, inlineEntities? }` โ teks/markdown, dengan optional citation
|
|
615
|
+
> - `{ code, language }` โ code block (tokenized)
|
|
616
|
+
> - `{ table, title? }` โ tabel, `table` berupa `[{ items: string[], isHeading?: bool }, ...]`
|
|
617
|
+
|
|
618
|
+
</details>`{ code: 'string', language: 'string' }` โ code block
|
|
489
619
|
> - `{ table: { title?, headers?, rows } }` โ tabel
|
|
490
620
|
|
|
491
621
|
</details>
|
|
@@ -1108,4 +1238,4 @@ This project is licensed for **personal and non-commercial use only**.
|
|
|
1108
1238
|
|
|
1109
1239
|
*Made with โฅ by PONTASOCKETS*
|
|
1110
1240
|
|
|
1111
|
-
</div>
|
|
1241
|
+
</div>
|
package/lib/Utils/messages.js
CHANGED
|
@@ -409,7 +409,7 @@ const generateForwardMessageContent = (message, forceForward) => {
|
|
|
409
409
|
|
|
410
410
|
const generateWAMessageContent = async (message, options) => {
|
|
411
411
|
let m = {}
|
|
412
|
-
if ('code' in message || 'codes' in message || 'table' in message || 'items' in message || 'richText' in message) {
|
|
412
|
+
if ('code' in message || 'codes' in message || 'table' in message || 'items' in message || 'richText' in message || 'richResponse' in message) {
|
|
413
413
|
return rich_message_utils_1.prepareRichResponseMessage(message)
|
|
414
414
|
} else if ('text' in message) {
|
|
415
415
|
const extContent = {
|
|
@@ -1728,4 +1728,4 @@ module.exports = {
|
|
|
1728
1728
|
downloadMediaMessage,
|
|
1729
1729
|
assertMediaContent,
|
|
1730
1730
|
patchMessageForMdIfRequired
|
|
1731
|
-
}
|
|
1731
|
+
}
|
|
@@ -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
|
|
|
@@ -174,10 +174,11 @@ const toUnified = (submessages, uuid) => ({
|
|
|
174
174
|
primitive: {
|
|
175
175
|
title: tm.title || null,
|
|
176
176
|
rows: tm.rows.map(row => ({
|
|
177
|
+
is_header: row.isHeading || false,
|
|
177
178
|
cells: row.items,
|
|
178
|
-
|
|
179
|
+
markdown_cells: row.items.map(item => ({ text: item }))
|
|
179
180
|
})),
|
|
180
|
-
__typename: '
|
|
181
|
+
__typename: 'GenATableUXPrimitive'
|
|
181
182
|
},
|
|
182
183
|
__typename: 'GenAISingleLayoutViewModel'
|
|
183
184
|
}
|
|
@@ -204,7 +205,7 @@ const toUnified = (submessages, uuid) => ({
|
|
|
204
205
|
view_model: {
|
|
205
206
|
primitive: {
|
|
206
207
|
text: submessage.messageText,
|
|
207
|
-
inline_entities: [],
|
|
208
|
+
inline_entities: submessage.inlineEntities || [],
|
|
208
209
|
__typename: 'GenAIMarkdownTextUXPrimitive'
|
|
209
210
|
},
|
|
210
211
|
__typename: 'GenAISingleLayoutViewModel'
|
|
@@ -234,129 +235,117 @@ const botMetadataCertificate = (length = 685) => {
|
|
|
234
235
|
// โโโ prepareRichResponseMessage โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
235
236
|
|
|
236
237
|
const prepareRichResponseMessage = (content) => {
|
|
237
|
-
const proto = WAProto_1.proto
|
|
238
238
|
|
|
239
239
|
// Normalize ke array of items
|
|
240
240
|
// Support:
|
|
241
|
-
// { code, language }
|
|
242
|
-
// { codes: [{ code, language }, ...] }
|
|
243
|
-
// { table: { title?, headers?, rows } }
|
|
244
|
-
// {
|
|
245
|
-
// { items: [{ text } | { code, language } | { table }] }
|
|
246
|
-
|
|
241
|
+
// { code, language } โ single code block
|
|
242
|
+
// { codes: [{ code, language }, ...] } โ multi code block
|
|
243
|
+
// { table: { title?, headers?, rows } } โ single table
|
|
244
|
+
// { richText: 'string' } โ single text
|
|
245
|
+
// { items: [{ text } | { code, language } | { table }] } โ mixed, bebas urutan
|
|
246
|
+
// { richResponse: [{ text, inlineEntities? } | { code, language } โ full array mode
|
|
247
|
+
// | { table, title? } | { inlineImage } | ...] }
|
|
247
248
|
|
|
248
|
-
|
|
249
|
-
items = content.items
|
|
250
|
-
} else if (content.codes) {
|
|
251
|
-
items = content.codes.map(c => ({ code: c.code, language: c.language }))
|
|
252
|
-
} else if (content.table) {
|
|
253
|
-
items = [{ table: content.table }]
|
|
254
|
-
} else if ('richText' in content) {
|
|
255
|
-
items = Array.isArray(content.richText)
|
|
256
|
-
? content.richText.map(t => ({ text: t }))
|
|
257
|
-
: [{ text: content.richText }]
|
|
258
|
-
} else {
|
|
259
|
-
items = [{ code: content.code, language: content.language }]
|
|
260
|
-
}
|
|
249
|
+
let submessages = []
|
|
261
250
|
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
// โโ TABLE โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
273
|
-
if (item.table) {
|
|
274
|
-
const { title, headers, rows } = item.table
|
|
275
|
-
const allRows = []
|
|
276
|
-
if (headers && headers.length) {
|
|
277
|
-
allRows.push({ items: headers, isHeading: true })
|
|
251
|
+
if (Array.isArray(content.richResponse)) {
|
|
252
|
+
// โโ richResponse array mode (dari Lia) โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
253
|
+
submessages = content.richResponse.map(sub => {
|
|
254
|
+
if (sub.text !== undefined) {
|
|
255
|
+
return {
|
|
256
|
+
messageType: RichSubMessageType.TEXT,
|
|
257
|
+
messageText: sub.text,
|
|
258
|
+
...(sub.inlineEntities ? { inlineEntities: sub.inlineEntities } : {})
|
|
259
|
+
}
|
|
278
260
|
}
|
|
279
|
-
|
|
280
|
-
|
|
261
|
+
if (sub.code !== undefined) {
|
|
262
|
+
const lang = sub.language || 'javascript'
|
|
263
|
+
return {
|
|
264
|
+
messageType: RichSubMessageType.CODE,
|
|
265
|
+
codeMetadata: {
|
|
266
|
+
codeLanguage: lang,
|
|
267
|
+
codeBlocks: tokenizeCode(sub.code, lang)
|
|
268
|
+
}
|
|
269
|
+
}
|
|
281
270
|
}
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
271
|
+
if (sub.table !== undefined) {
|
|
272
|
+
return {
|
|
273
|
+
messageType: RichSubMessageType.TABLE,
|
|
274
|
+
tableMetadata: {
|
|
275
|
+
...(sub.title ? { title: sub.title } : {}),
|
|
276
|
+
rows: sub.table
|
|
277
|
+
}
|
|
287
278
|
}
|
|
288
279
|
}
|
|
289
|
-
|
|
280
|
+
// passthrough โ kalau ada tipe lain langsung lewat
|
|
281
|
+
return sub
|
|
282
|
+
})
|
|
283
|
+
} else {
|
|
284
|
+
// โโ shorthand / items mode โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
285
|
+
let items = []
|
|
290
286
|
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
}
|
|
287
|
+
if (content.items) {
|
|
288
|
+
items = content.items
|
|
289
|
+
} else if (content.codes) {
|
|
290
|
+
items = content.codes.map(c => ({ code: c.code, language: c.language }))
|
|
291
|
+
} else if (content.table) {
|
|
292
|
+
items = [{ table: content.table }]
|
|
293
|
+
} else if ('richText' in content) {
|
|
294
|
+
items = Array.isArray(content.richText)
|
|
295
|
+
? content.richText.map(t => ({ text: t }))
|
|
296
|
+
: [{ text: content.richText }]
|
|
297
|
+
} else {
|
|
298
|
+
items = [{ code: content.code, language: content.language }]
|
|
303
299
|
}
|
|
304
|
-
})
|
|
305
300
|
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
primitive: {
|
|
314
|
-
text: sub.messageText,
|
|
315
|
-
inline_entities: [],
|
|
316
|
-
__typename: 'GenAIMarkdownTextUXPrimitive'
|
|
317
|
-
},
|
|
318
|
-
__typename: 'GenAISingleLayoutViewModel'
|
|
301
|
+
submessages = items.map(item => {
|
|
302
|
+
// โโ TEXT โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
303
|
+
if ('text' in item) {
|
|
304
|
+
return {
|
|
305
|
+
messageType: RichSubMessageType.TEXT,
|
|
306
|
+
messageText: item.text,
|
|
307
|
+
...(item.inlineEntities ? { inlineEntities: item.inlineEntities } : {})
|
|
319
308
|
}
|
|
320
309
|
}
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
310
|
+
|
|
311
|
+
// โโ TABLE โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
312
|
+
if (item.table) {
|
|
313
|
+
const { title, headers, rows } = item.table
|
|
314
|
+
const allRows = []
|
|
315
|
+
if (headers && headers.length) {
|
|
316
|
+
allRows.push({ items: headers, isHeading: true })
|
|
317
|
+
}
|
|
318
|
+
for (const row of (rows || [])) {
|
|
319
|
+
allRows.push({ items: row, isHeading: false })
|
|
320
|
+
}
|
|
321
|
+
return {
|
|
322
|
+
messageType: RichSubMessageType.TABLE,
|
|
323
|
+
tableMetadata: {
|
|
324
|
+
...(title ? { title } : {}),
|
|
325
|
+
rows: allRows
|
|
326
|
+
}
|
|
335
327
|
}
|
|
336
328
|
}
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
const
|
|
329
|
+
|
|
330
|
+
// โโ CODE (default) โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
331
|
+
const lang = item.language || 'javascript'
|
|
332
|
+
const codeBlocks = tokenizeCode(item.code, lang)
|
|
340
333
|
return {
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
__typename: 'GenAICodeUXPrimitive'
|
|
349
|
-
},
|
|
350
|
-
__typename: 'GenAISingleLayoutViewModel'
|
|
334
|
+
messageType: RichSubMessageType.CODE,
|
|
335
|
+
codeMetadata: {
|
|
336
|
+
codeLanguage: lang,
|
|
337
|
+
codeBlocks: codeBlocks.map(b => ({
|
|
338
|
+
highlightType: b.highlightType,
|
|
339
|
+
codeContent: b.codeContent
|
|
340
|
+
}))
|
|
351
341
|
}
|
|
352
342
|
}
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
})
|
|
343
|
+
})
|
|
344
|
+
}
|
|
356
345
|
|
|
357
|
-
const
|
|
346
|
+
const uuid = crypto_1.randomUUID()
|
|
347
|
+
const unified = toUnified(submessages, uuid)
|
|
358
348
|
|
|
359
|
-
// Plain object structure โ sama persis kayak relay
|
|
360
349
|
return {
|
|
361
350
|
messageContextInfo: {
|
|
362
351
|
botMetadata: {
|