@pontasockets/baileys 0.2.3 → 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/README.md CHANGED
@@ -63,6 +63,8 @@ This fork introduces targeted custom patches on top of the original Baileys libr
63
63
  |---|-------|-------------|
64
64
  | `01` | 🤖 **Code Block Message** | Send syntax-highlighted code via `{ code, language }` — renders as AI bot message in WhatsApp |
65
65
  | `02` | 📊 **Table Message** | Send structured tables via `{ table: { title?, headers, rows } }` — renders as rich table in WhatsApp |
66
+ | `03` | 📝 **Rich Text Message** | Send styled text via `{ richText: '...' }` — renders as AI bot markdown text in WhatsApp |
67
+ | `04` | 🔀 **Mixed Rich Message** | Combine text + code + table in one message via `{ items: [...] }` |
66
68
  | `02` | 🪪 **Custom Message ID** | All outgoing message IDs prefixed with `PONTASOCKETS` |
67
69
  | `03` | 🐛 **LID Bug Fixes** | Full fix for participant, mentionedJid, sender, and group admin LID resolution |
68
70
  | `04` | 📦 **makeInMemoryStore Fix** | Corrected store behavior for stable session handling |
@@ -395,6 +397,99 @@ await sock.sendMessage(jid, {
395
397
 
396
398
  </details>
397
399
 
400
+ <details>
401
+ <summary><b>📝 Rich Text Message <kbd>NEW</kbd></b></summary>
402
+ <br>
403
+
404
+ > Renders as AI bot markdown-style text dalam WhatsApp (gunakan `richText`, bukan `text` — supaya tidak konflik dengan text message biasa)
405
+
406
+ ```javascript
407
+ // Simple text
408
+ await sock.sendMessage(jid, {
409
+ richText: 'Halo! Ini adalah pesan teks rich dari bot.'
410
+ }, { quoted: message })
411
+
412
+ // Markdown supported (bold, italic, code inline)
413
+ await sock.sendMessage(jid, {
414
+ richText: '*Hasil eksekusi:*\nStatus: `success`\nWaktu: _120ms_'
415
+ }, { quoted: message })
416
+ ```
417
+
418
+ </details>
419
+
420
+ <details>
421
+ <summary><b>🔀 Mixed Rich Message <kbd>NEW</kbd></b></summary>
422
+ <br>
423
+
424
+ > Gabungkan text, code block, dan table dalam urutan bebas dalam satu pesan menggunakan key `items`
425
+
426
+ **Text → Code → Text**
427
+
428
+ ```javascript
429
+ await sock.sendMessage(jid, {
430
+ items: [
431
+ { text: 'Contoh fungsi JavaScript:' },
432
+ { code: 'function greet(name) {\n return `Hello, ${name}!`\n}', language: 'javascript' },
433
+ { text: 'Panggil fungsi di atas dengan `greet("Ponta")` untuk mendapat output `Hello, Ponta!`' }
434
+ ]
435
+ }, { quoted: message })
436
+ ```
437
+
438
+ **Text → Code → Table**
439
+
440
+ ```javascript
441
+ await sock.sendMessage(jid, {
442
+ items: [
443
+ { text: 'Query yang dijalankan:' },
444
+ { code: 'SELECT id, name, score FROM users ORDER BY score DESC LIMIT 3', language: 'sql' },
445
+ { text: 'Hasil:' },
446
+ {
447
+ table: {
448
+ headers: ['id', 'name', 'score'],
449
+ rows: [
450
+ ['1', 'Ponta', '98'],
451
+ ['2', 'Yue', '87'],
452
+ ['3', 'Frieren', '75']
453
+ ]
454
+ }
455
+ }
456
+ ]
457
+ }, { quoted: message })
458
+ ```
459
+
460
+ **Full mixed**
461
+
462
+ ```javascript
463
+ await sock.sendMessage(jid, {
464
+ items: [
465
+ { text: '*Dokumentasi Command `.eval`*' },
466
+ { text: 'Syntax:' },
467
+ { code: '.eval <kode javascript>', language: 'bash' },
468
+ { text: 'Contoh penggunaan:' },
469
+ { code: 'return 1 + 1', language: 'javascript' },
470
+ { text: 'Supported types:' },
471
+ {
472
+ table: {
473
+ headers: ['Type', 'Contoh'],
474
+ rows: [
475
+ ['Expression', '2 ** 10'],
476
+ ['Statement', 'let x = 5; return x'],
477
+ ['Async', 'await fetch(url)']
478
+ ]
479
+ }
480
+ },
481
+ { text: '_Hanya owner yang bisa menggunakan command ini._' }
482
+ ]
483
+ }, { quoted: message })
484
+ ```
485
+
486
+ > **Tipe yang valid di dalam `items`:**
487
+ > - `{ text: 'string' }` — teks / markdown
488
+ > - `{ code: 'string', language: 'string' }` — code block
489
+ > - `{ table: { title?, headers?, rows } }` — tabel
490
+
491
+ </details>
492
+
398
493
  <details>
399
494
  <summary><b>🖼️ Image Message</b></summary>
400
495
  <br>
@@ -1013,4 +1108,4 @@ This project is licensed for **personal and non-commercial use only**.
1013
1108
 
1014
1109
  *Made with ♥ by PONTASOCKETS*
1015
1110
 
1016
- </div>
1111
+ </div>
@@ -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) {
412
+ if ('code' in message || 'codes' in message || 'table' in message || 'items' in message || 'richText' in message) {
413
413
  return rich_message_utils_1.prepareRichResponseMessage(message)
414
414
  } else if ('text' in message) {
415
415
  const extContent = {
@@ -2,7 +2,7 @@
2
2
 
3
3
  /**
4
4
  * rich-message-utils.js
5
- * @pontasockets-baileys
5
+ * @pontasockets/baileys
6
6
  * Tambahkan file ini ke: node_modules/@whiskeysockets/baileys/lib/Utils/rich-message-utils.js
7
7
  */
8
8
 
@@ -238,10 +238,11 @@ const prepareRichResponseMessage = (content) => {
238
238
 
239
239
  // Normalize ke array of items
240
240
  // Support:
241
- // { code, language } — single code block
242
- // { codes: [{ code, language }, ...] } — multi code block
243
- // { table: { title?, headers?, rows } } — single table
244
- // { items: [{ code, language } | { table }] } mixed, bebas urutan
241
+ // { code, language } — single code block
242
+ // { codes: [{ code, language }, ...] } — multi code block
243
+ // { table: { title?, headers?, rows } } — single table
244
+ // { text: 'string' } single text
245
+ // { items: [{ text } | { code, language } | { table }] } — mixed, bebas urutan
245
246
  let items = []
246
247
 
247
248
  if (content.items) {
@@ -250,97 +251,113 @@ const prepareRichResponseMessage = (content) => {
250
251
  items = content.codes.map(c => ({ code: c.code, language: c.language }))
251
252
  } else if (content.table) {
252
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 }]
253
258
  } else {
254
259
  items = [{ code: content.code, language: content.language }]
255
260
  }
256
261
 
257
- const built = items.map(item => {
262
+ // Build submessages as plain objects (sesuai struktur relay)
263
+ const submessages = items.map(item => {
264
+ // ── TEXT ──────────────────────────────────────────────────────────────
265
+ if ('text' in item) {
266
+ return {
267
+ messageType: RichSubMessageType.TEXT, // 2
268
+ messageText: item.text
269
+ }
270
+ }
271
+
272
+ // ── TABLE ─────────────────────────────────────────────────────────────
258
273
  if (item.table) {
259
274
  const { title, headers, rows } = item.table
260
-
261
- // Build rows: header row dulu (kalau ada), baru data rows
262
275
  const allRows = []
263
276
  if (headers && headers.length) {
264
- allRows.push(proto.AIRichResponseTableMetadata.AIRichResponseTableRow.create({
265
- items: headers,
266
- isHeading: true
267
- }))
277
+ allRows.push({ items: headers, isHeading: true })
268
278
  }
269
279
  for (const row of (rows || [])) {
270
- allRows.push(proto.AIRichResponseTableMetadata.AIRichResponseTableRow.create({
271
- items: row,
272
- isHeading: false
273
- }))
280
+ allRows.push({ items: row, isHeading: false })
274
281
  }
275
-
276
- const tableMetadata = proto.AIRichResponseTableMetadata.create({
277
- title: title || null,
278
- rows: allRows
279
- })
280
-
281
282
  return {
282
- submessage: proto.AIRichResponseSubMessage.create({
283
- messageType: RichSubMessageType.TABLE, // 4
284
- tableMetadata
285
- }),
286
- unified: {
287
- messageType: RichSubMessageType.TABLE,
288
- tableMetadata: {
289
- title: title || null,
290
- rows: [
291
- ...(headers ? [{ items: headers, isHeading: true }] : []),
292
- ...(rows || []).map(r => ({ items: r, isHeading: false }))
293
- ]
294
- }
283
+ messageType: RichSubMessageType.TABLE, // 4
284
+ tableMetadata: {
285
+ ...(title ? { title } : {}),
286
+ rows: allRows
295
287
  }
296
288
  }
297
289
  }
298
290
 
299
- // Default: code block
291
+ // ── CODE (default) ────────────────────────────────────────────────────
300
292
  const lang = item.language || 'javascript'
301
293
  const codeBlocks = tokenizeCode(item.code, lang)
302
294
  return {
303
- submessage: proto.AIRichResponseSubMessage.create({
304
- messageType: RichSubMessageType.CODE, // 5
305
- codeMetadata: proto.AIRichResponseCodeMetadata.create({
306
- codeLanguage: lang,
307
- codeBlocks: codeBlocks.map(b =>
308
- proto.AIRichResponseCodeMetadata.AIRichResponseCodeBlock.create({
309
- highlightType: b.highlightType,
310
- codeContent: b.codeContent
311
- })
312
- )
313
- })
314
- }),
315
- unified: {
316
- messageType: RichSubMessageType.CODE,
317
- 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
+ }))
318
302
  }
319
303
  }
320
304
  })
321
305
 
322
306
  const uuid = crypto_1.randomUUID()
323
- const unified = toUnified(built.map(b => b.unified), uuid)
324
307
 
325
- // Build AIRichResponseMessage using E2E proto class
326
- const richResponseMessage = proto.AIRichResponseMessage.create({
327
- submessages: built.map(b => b.submessage),
328
- messageType: 1, // AI_RICH_RESPONSE_TYPE_STANDARD
329
- unifiedResponse: proto.AIRichResponseUnifiedResponse
330
- ? proto.AIRichResponseUnifiedResponse.create({
331
- data: Buffer.from(JSON.stringify(unified))
332
- })
333
- : { data: Buffer.from(JSON.stringify(unified)) },
334
- contextInfo: {
335
- isForwarded: true,
336
- forwardingScore: 1,
337
- forwardedAiBotMessageInfo: { botJid: '867051314767696@bot' },
338
- forwardOrigin: 4
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
+ }
339
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
+ }
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 {}
340
355
  })
341
356
 
342
- // Wrap in botForwardedMessage
343
- const message = {
357
+ const unified = { response_id: uuid, sections: unifiedSections }
358
+
359
+ // Plain object structure — sama persis kayak relay
360
+ return {
344
361
  messageContextInfo: {
345
362
  botMetadata: {
346
363
  verificationMetadata: {
@@ -355,10 +372,22 @@ const prepareRichResponseMessage = (content) => {
355
372
  }
356
373
  },
357
374
  botForwardedMessage: {
358
- message: { richResponseMessage }
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
+ }
359
390
  }
360
391
  }
361
-
362
- return message
363
392
  }
364
393
  exports.prepareRichResponseMessage = prepareRichResponseMessage
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pontasockets/baileys",
3
- "version": "0.2.3",
3
+ "version": "0.2.5",
4
4
  "description": "Baileys is a lightweight JavaScript library for interacting with the WhatsApp Web API using WebSocket.",
5
5
  "keywords": [
6
6
  "facebook",