@pontasockets/baileys 0.2.2 โ 0.2.3
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 +115 -0
- package/lib/Utils/messages.js +1 -1
- package/lib/Utils/rich-message-utils.js +98 -20
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -62,6 +62,7 @@ This fork introduces targeted custom patches on top of the original Baileys libr
|
|
|
62
62
|
| # | Patch | Description |
|
|
63
63
|
|---|-------|-------------|
|
|
64
64
|
| `01` | ๐ค **Code Block Message** | Send syntax-highlighted code via `{ code, language }` โ renders as AI bot message in WhatsApp |
|
|
65
|
+
| `02` | ๐ **Table Message** | Send structured tables via `{ table: { title?, headers, rows } }` โ renders as rich table in WhatsApp |
|
|
65
66
|
| `02` | ๐ชช **Custom Message ID** | All outgoing message IDs prefixed with `PONTASOCKETS` |
|
|
66
67
|
| `03` | ๐ **LID Bug Fixes** | Full fix for participant, mentionedJid, sender, and group admin LID resolution |
|
|
67
68
|
| `04` | ๐ฆ **makeInMemoryStore Fix** | Corrected store behavior for stable session handling |
|
|
@@ -240,6 +241,8 @@ await sock.sendMessage(jid, {
|
|
|
240
241
|
|
|
241
242
|
> Renders as a syntax-highlighted code block in WhatsApp (AI bot style message)
|
|
242
243
|
|
|
244
|
+
**Single Code Block**
|
|
245
|
+
|
|
243
246
|
```javascript
|
|
244
247
|
// JavaScript
|
|
245
248
|
await sock.sendMessage(jid, {
|
|
@@ -260,6 +263,39 @@ await sock.sendMessage(jid, {
|
|
|
260
263
|
}, { quoted: message })
|
|
261
264
|
```
|
|
262
265
|
|
|
266
|
+
**Multiple Code Blocks in One Message**
|
|
267
|
+
|
|
268
|
+
> Gunakan key `codes` (array) untuk kirim lebih dari satu code block sekaligus dalam satu pesan
|
|
269
|
+
|
|
270
|
+
```javascript
|
|
271
|
+
// 2 bahasa berbeda dalam 1 pesan
|
|
272
|
+
await sock.sendMessage(jid, {
|
|
273
|
+
codes: [
|
|
274
|
+
{ code: 'console.log("Hello World")', language: 'javascript' },
|
|
275
|
+
{ code: 'print("Hello World")', language: 'python' }
|
|
276
|
+
]
|
|
277
|
+
}, { quoted: message })
|
|
278
|
+
|
|
279
|
+
// Input vs Output
|
|
280
|
+
await sock.sendMessage(jid, {
|
|
281
|
+
codes: [
|
|
282
|
+
{ code: 'SELECT * FROM users WHERE id = 1;', language: 'sql' },
|
|
283
|
+
{ code: '{ "id": 1, "name": "Ponta", "role": "admin" }', language: 'json' }
|
|
284
|
+
]
|
|
285
|
+
}, { quoted: message })
|
|
286
|
+
|
|
287
|
+
// Banyak snippet sekaligus
|
|
288
|
+
await sock.sendMessage(jid, {
|
|
289
|
+
codes: [
|
|
290
|
+
{ code: 'npm install @pontasockets/baileys', language: 'bash' },
|
|
291
|
+
{ code: 'import makeWASocket from "@pontasockets/baileys"', language: 'javascript' },
|
|
292
|
+
{ code: 'const sock = makeWASocket({ printQRInTerminal: true })', language: 'javascript' }
|
|
293
|
+
]
|
|
294
|
+
}, { quoted: message })
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
> **Note:** Key `code` (single) dan `codes` (array) keduanya tetap support โ tidak breaking change.
|
|
298
|
+
|
|
263
299
|
**Supported Languages:**
|
|
264
300
|
|
|
265
301
|
| Language | Keys |
|
|
@@ -277,6 +313,85 @@ await sock.sendMessage(jid, {
|
|
|
277
313
|
| HTML | `html` |
|
|
278
314
|
| PowerShell | `powershell` ยท `ps1` |
|
|
279
315
|
| CMD | `cmd` ยท `bat` |
|
|
316
|
+
| SQL | `sql` |
|
|
317
|
+
| JSON | `json` |
|
|
318
|
+
|
|
319
|
+
</details>
|
|
320
|
+
|
|
321
|
+
<details>
|
|
322
|
+
<summary><b>๐ Table Message <kbd>NEW</kbd></b></summary>
|
|
323
|
+
<br>
|
|
324
|
+
|
|
325
|
+
> Renders as a structured table in WhatsApp (AI bot style rich message)
|
|
326
|
+
|
|
327
|
+
**Simple Table**
|
|
328
|
+
|
|
329
|
+
```javascript
|
|
330
|
+
await sock.sendMessage(jid, {
|
|
331
|
+
table: {
|
|
332
|
+
title: 'Daftar User',
|
|
333
|
+
headers: ['Name', 'Role', 'Status'],
|
|
334
|
+
rows: [
|
|
335
|
+
['Ponta', 'Admin', 'Active'],
|
|
336
|
+
['Yue', 'Member', 'Idle'],
|
|
337
|
+
['Frieren', 'Guest', 'Offline']
|
|
338
|
+
]
|
|
339
|
+
}
|
|
340
|
+
}, { quoted: message })
|
|
341
|
+
```
|
|
342
|
+
|
|
343
|
+
**Table tanpa title**
|
|
344
|
+
|
|
345
|
+
```javascript
|
|
346
|
+
await sock.sendMessage(jid, {
|
|
347
|
+
table: {
|
|
348
|
+
headers: ['Command', 'Description'],
|
|
349
|
+
rows: [
|
|
350
|
+
['.ping', 'Cek latency bot'],
|
|
351
|
+
['.info', 'Info bot'],
|
|
352
|
+
['.help', 'List semua command']
|
|
353
|
+
]
|
|
354
|
+
}
|
|
355
|
+
}, { quoted: message })
|
|
356
|
+
```
|
|
357
|
+
|
|
358
|
+
**Table tanpa header (data only)**
|
|
359
|
+
|
|
360
|
+
```javascript
|
|
361
|
+
await sock.sendMessage(jid, {
|
|
362
|
+
table: {
|
|
363
|
+
rows: [
|
|
364
|
+
['RAM', '512 MB'],
|
|
365
|
+
['CPU', '4 Core'],
|
|
366
|
+
['Uptime', '99.9%']
|
|
367
|
+
]
|
|
368
|
+
}
|
|
369
|
+
}, { quoted: message })
|
|
370
|
+
```
|
|
371
|
+
|
|
372
|
+
**Mixed: Table + Code Block dalam 1 pesan**
|
|
373
|
+
|
|
374
|
+
> Gunakan key `items` untuk gabungkan berbagai tipe dalam urutan bebas
|
|
375
|
+
|
|
376
|
+
```javascript
|
|
377
|
+
await sock.sendMessage(jid, {
|
|
378
|
+
items: [
|
|
379
|
+
{
|
|
380
|
+
table: {
|
|
381
|
+
title: 'Query Result',
|
|
382
|
+
headers: ['id', 'name', 'score'],
|
|
383
|
+
rows: [
|
|
384
|
+
['1', 'Ponta', '98'],
|
|
385
|
+
['2', 'Yue', '87']
|
|
386
|
+
]
|
|
387
|
+
}
|
|
388
|
+
},
|
|
389
|
+
{ code: 'SELECT * FROM users ORDER BY score DESC', language: 'sql' }
|
|
390
|
+
]
|
|
391
|
+
}, { quoted: message })
|
|
392
|
+
```
|
|
393
|
+
|
|
394
|
+
> **Note:** `items` array juga bisa diisi full code blocks saja (pengganti `codes`), atau full tables saja, atau campuran keduanya โ bebas urutannya.
|
|
280
395
|
|
|
281
396
|
</details>
|
|
282
397
|
|
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) {
|
|
412
|
+
if ('code' in message || 'codes' in message || 'table' in message || 'items' in message) {
|
|
413
413
|
return rich_message_utils_1.prepareRichResponseMessage(message)
|
|
414
414
|
} else if ('text' in message) {
|
|
415
415
|
const extContent = {
|
|
@@ -24,7 +24,7 @@ const CodeHighlightType = {
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
const RichSubMessageType = {
|
|
27
|
-
UNKNOWN: 0, TEXT: 2, CODE: 5
|
|
27
|
+
UNKNOWN: 0, TEXT: 2, TABLE: 4, CODE: 5
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
// โโโ Keyword Sets โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
@@ -167,6 +167,22 @@ exports.tokenizeCode = tokenizeCode
|
|
|
167
167
|
const toUnified = (submessages, uuid) => ({
|
|
168
168
|
response_id: uuid,
|
|
169
169
|
sections: submessages.map((submessage) => {
|
|
170
|
+
if (submessage.messageType === RichSubMessageType.TABLE) {
|
|
171
|
+
const tm = submessage.tableMetadata
|
|
172
|
+
return {
|
|
173
|
+
view_model: {
|
|
174
|
+
primitive: {
|
|
175
|
+
title: tm.title || null,
|
|
176
|
+
rows: tm.rows.map(row => ({
|
|
177
|
+
cells: row.items,
|
|
178
|
+
is_heading: row.isHeading || false
|
|
179
|
+
})),
|
|
180
|
+
__typename: 'GenAITableUXPrimitive'
|
|
181
|
+
},
|
|
182
|
+
__typename: 'GenAISingleLayoutViewModel'
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
170
186
|
if (submessage.messageType === RichSubMessageType.CODE) {
|
|
171
187
|
const cm = submessage.codeMetadata
|
|
172
188
|
return {
|
|
@@ -218,35 +234,97 @@ const botMetadataCertificate = (length = 685) => {
|
|
|
218
234
|
// โโโ prepareRichResponseMessage โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
219
235
|
|
|
220
236
|
const prepareRichResponseMessage = (content) => {
|
|
221
|
-
const { code, language } = content
|
|
222
|
-
const lang = language || 'javascript'
|
|
223
237
|
const proto = WAProto_1.proto
|
|
224
238
|
|
|
225
|
-
|
|
239
|
+
// Normalize ke array of items
|
|
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
|
|
245
|
+
let items = []
|
|
246
|
+
|
|
247
|
+
if (content.items) {
|
|
248
|
+
items = content.items
|
|
249
|
+
} else if (content.codes) {
|
|
250
|
+
items = content.codes.map(c => ({ code: c.code, language: c.language }))
|
|
251
|
+
} else if (content.table) {
|
|
252
|
+
items = [{ table: content.table }]
|
|
253
|
+
} else {
|
|
254
|
+
items = [{ code: content.code, language: content.language }]
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
const built = items.map(item => {
|
|
258
|
+
if (item.table) {
|
|
259
|
+
const { title, headers, rows } = item.table
|
|
226
260
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
261
|
+
// Build rows: header row dulu (kalau ada), baru data rows
|
|
262
|
+
const allRows = []
|
|
263
|
+
if (headers && headers.length) {
|
|
264
|
+
allRows.push(proto.AIRichResponseTableMetadata.AIRichResponseTableRow.create({
|
|
265
|
+
items: headers,
|
|
266
|
+
isHeading: true
|
|
267
|
+
}))
|
|
268
|
+
}
|
|
269
|
+
for (const row of (rows || [])) {
|
|
270
|
+
allRows.push(proto.AIRichResponseTableMetadata.AIRichResponseTableRow.create({
|
|
271
|
+
items: row,
|
|
272
|
+
isHeading: false
|
|
273
|
+
}))
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
const tableMetadata = proto.AIRichResponseTableMetadata.create({
|
|
277
|
+
title: title || null,
|
|
278
|
+
rows: allRows
|
|
279
|
+
})
|
|
280
|
+
|
|
281
|
+
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
|
+
}
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
// Default: code block
|
|
300
|
+
const lang = item.language || 'javascript'
|
|
301
|
+
const codeBlocks = tokenizeCode(item.code, lang)
|
|
302
|
+
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
|
+
)
|
|
236
313
|
})
|
|
237
|
-
)
|
|
238
|
-
|
|
314
|
+
}),
|
|
315
|
+
unified: {
|
|
316
|
+
messageType: RichSubMessageType.CODE,
|
|
317
|
+
codeMetadata: { codeLanguage: lang, codeBlocks }
|
|
318
|
+
}
|
|
319
|
+
}
|
|
239
320
|
})
|
|
240
321
|
|
|
241
322
|
const uuid = crypto_1.randomUUID()
|
|
242
|
-
const unified = toUnified(
|
|
243
|
-
messageType: RichSubMessageType.CODE,
|
|
244
|
-
codeMetadata: { codeLanguage: lang, codeBlocks }
|
|
245
|
-
}], uuid)
|
|
323
|
+
const unified = toUnified(built.map(b => b.unified), uuid)
|
|
246
324
|
|
|
247
325
|
// Build AIRichResponseMessage using E2E proto class
|
|
248
326
|
const richResponseMessage = proto.AIRichResponseMessage.create({
|
|
249
|
-
submessages:
|
|
327
|
+
submessages: built.map(b => b.submessage),
|
|
250
328
|
messageType: 1, // AI_RICH_RESPONSE_TYPE_STANDARD
|
|
251
329
|
unifiedResponse: proto.AIRichResponseUnifiedResponse
|
|
252
330
|
? proto.AIRichResponseUnifiedResponse.create({
|