@nuiisweety/baileys 0.1.2 → 0.1.4
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 +79 -20
- package/lib/Utils/messages.js +7 -1
- package/lib/Utils/rich-message-utils.js +73 -18
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1102,33 +1102,48 @@ await sock.sendMessage(jid, {
|
|
|
1102
1102
|
|
|
1103
1103
|
> 🌸 Kirim grid gambar — satu gambar utama dengan beberapa thumbnail, tampil sebagai AI Rich Response~
|
|
1104
1104
|
|
|
1105
|
+
> ⚠️ **Catatan penting:** Setiap URL gambar harus berupa object `{ imagePreviewUrl, imageHighResUrl, sourceUrl }`. Bisa juga pakai string URL langsung — akan otomatis di-expand~
|
|
1106
|
+
|
|
1105
1107
|
```js
|
|
1108
|
+
// ✅ Dengan object URL lengkap (recommended)
|
|
1106
1109
|
await sock.sendMessage(jid, {
|
|
1107
1110
|
gridImage: {
|
|
1108
1111
|
gridImageUrl: {
|
|
1109
|
-
imagePreviewUrl: 'https://
|
|
1110
|
-
imageHighResUrl: 'https://
|
|
1111
|
-
sourceUrl: 'https://
|
|
1112
|
+
imagePreviewUrl: 'https://picsum.photos/id/10/300/300',
|
|
1113
|
+
imageHighResUrl: 'https://picsum.photos/id/10/1200/1200',
|
|
1114
|
+
sourceUrl: 'https://picsum.photos'
|
|
1112
1115
|
},
|
|
1113
1116
|
imageUrls: [
|
|
1114
1117
|
{
|
|
1115
|
-
imagePreviewUrl: 'https://
|
|
1116
|
-
imageHighResUrl: 'https://
|
|
1117
|
-
sourceUrl: 'https://
|
|
1118
|
+
imagePreviewUrl: 'https://picsum.photos/id/11/300/300',
|
|
1119
|
+
imageHighResUrl: 'https://picsum.photos/id/11/1200/1200',
|
|
1120
|
+
sourceUrl: 'https://picsum.photos'
|
|
1118
1121
|
},
|
|
1119
1122
|
{
|
|
1120
|
-
imagePreviewUrl: 'https://
|
|
1121
|
-
imageHighResUrl: 'https://
|
|
1122
|
-
sourceUrl: 'https://
|
|
1123
|
+
imagePreviewUrl: 'https://picsum.photos/id/12/300/300',
|
|
1124
|
+
imageHighResUrl: 'https://picsum.photos/id/12/1200/1200',
|
|
1125
|
+
sourceUrl: 'https://picsum.photos'
|
|
1123
1126
|
}
|
|
1124
1127
|
]
|
|
1125
1128
|
},
|
|
1126
1129
|
headerText: 'Hasil pencarian gambar 🌸',
|
|
1127
1130
|
footerText: 'Sumber: Internet 🌐'
|
|
1128
1131
|
})
|
|
1132
|
+
|
|
1133
|
+
// ✅ Dengan string URL langsung (shorthand)
|
|
1134
|
+
await sock.sendMessage(jid, {
|
|
1135
|
+
gridImage: {
|
|
1136
|
+
gridImageUrl: 'https://picsum.photos/id/10/300/300',
|
|
1137
|
+
imageUrls: [
|
|
1138
|
+
'https://picsum.photos/id/11/300/300',
|
|
1139
|
+
'https://picsum.photos/id/12/300/300'
|
|
1140
|
+
]
|
|
1141
|
+
},
|
|
1142
|
+
headerText: 'Hasil pencarian gambar 🌸'
|
|
1143
|
+
})
|
|
1129
1144
|
```
|
|
1130
1145
|
|
|
1131
|
-
> 💡 `imageUrls` adalah array gambar pendukung di bawah gambar utama~
|
|
1146
|
+
> 💡 `imageUrls` adalah array gambar pendukung di bawah gambar utama. Gunakan URL yang bisa diakses publik~
|
|
1132
1147
|
|
|
1133
1148
|
---
|
|
1134
1149
|
|
|
@@ -1136,21 +1151,35 @@ await sock.sendMessage(jid, {
|
|
|
1136
1151
|
|
|
1137
1152
|
> ✨ Kirim gambar yang muncul inline di dalam teks — seperti ilustrasi di dalam respons AI~
|
|
1138
1153
|
|
|
1154
|
+
> ⚠️ **Catatan penting:** `imageUrl` harus berupa object `{ imagePreviewUrl, imageHighResUrl, sourceUrl }` atau string URL langsung~
|
|
1155
|
+
|
|
1139
1156
|
```js
|
|
1157
|
+
// ✅ Dengan object URL lengkap
|
|
1140
1158
|
await sock.sendMessage(jid, {
|
|
1141
1159
|
inlineImage: {
|
|
1142
1160
|
imageUrl: {
|
|
1143
|
-
imagePreviewUrl: 'https://
|
|
1144
|
-
imageHighResUrl: 'https://
|
|
1145
|
-
sourceUrl: 'https://
|
|
1161
|
+
imagePreviewUrl: 'https://picsum.photos/id/237/300/300',
|
|
1162
|
+
imageHighResUrl: 'https://picsum.photos/id/237/1200/1200',
|
|
1163
|
+
sourceUrl: 'https://picsum.photos'
|
|
1146
1164
|
},
|
|
1147
|
-
imageText: 'Ilustrasi
|
|
1148
|
-
alignment:
|
|
1149
|
-
tapLinkUrl: 'https://
|
|
1165
|
+
imageText: 'Ilustrasi gambar random 🌸',
|
|
1166
|
+
alignment: 2, // 0 = leading, 1 = trailing, 2 = center
|
|
1167
|
+
tapLinkUrl: 'https://picsum.photos'
|
|
1150
1168
|
},
|
|
1151
1169
|
headerText: 'Berikut ilustrasinya~ 🌷',
|
|
1152
1170
|
footerText: 'Tap gambar untuk detail 🔍'
|
|
1153
1171
|
})
|
|
1172
|
+
|
|
1173
|
+
// ✅ Shorthand dengan string URL
|
|
1174
|
+
await sock.sendMessage(jid, {
|
|
1175
|
+
inlineImage: {
|
|
1176
|
+
imageUrl: 'https://picsum.photos/id/237/300/300',
|
|
1177
|
+
imageText: 'Ilustrasi gambar random 🌸',
|
|
1178
|
+
alignment: 2,
|
|
1179
|
+
tapLinkUrl: 'https://picsum.photos'
|
|
1180
|
+
},
|
|
1181
|
+
headerText: 'Berikut ilustrasinya~ 🌷'
|
|
1182
|
+
})
|
|
1154
1183
|
```
|
|
1155
1184
|
|
|
1156
1185
|
---
|
|
@@ -1236,15 +1265,20 @@ await sock.sendMessage(jid, {
|
|
|
1236
1265
|
|
|
1237
1266
|
> ✏️ Kirim rumus matematika dalam format LaTeX — tampil dengan render formula yang indah~
|
|
1238
1267
|
|
|
1268
|
+
> ⚠️ **Catatan penting:**
|
|
1269
|
+
> - `url` di setiap expression **wajib ada** agar WA client bisa menampilkan gambar LaTeX. Jika tidak diisi, library akan **auto-generate** URL dari [latex.codecogs.com](https://latex.codecogs.com).
|
|
1270
|
+
> - Gunakan `latex: {...}` langsung (flat) — **bukan** dibungkus dalam `richResponse: [{ latex: {...} }]`.
|
|
1271
|
+
> - `headerText`, `footerText`, `disclaimerText` tetap bisa dipakai bersama `latex`.
|
|
1272
|
+
|
|
1239
1273
|
```js
|
|
1240
|
-
// Rumus sederhana
|
|
1274
|
+
// ✅ Rumus sederhana — url auto-generate jika tidak diisi
|
|
1241
1275
|
await sock.sendMessage(jid, {
|
|
1242
1276
|
latex: {
|
|
1243
1277
|
text: 'Berikut rumus yang kamu minta:',
|
|
1244
1278
|
expressions: [
|
|
1245
1279
|
{
|
|
1246
1280
|
expression: 'E = mc^2',
|
|
1247
|
-
url
|
|
1281
|
+
// url auto-generate dari codecogs kalau tidak diisi~
|
|
1248
1282
|
width: 120,
|
|
1249
1283
|
height: 40
|
|
1250
1284
|
}
|
|
@@ -1254,7 +1288,7 @@ await sock.sendMessage(jid, {
|
|
|
1254
1288
|
footerText: 'E = energi, m = massa, c = kecepatan cahaya 💡'
|
|
1255
1289
|
})
|
|
1256
1290
|
|
|
1257
|
-
// Multiple expressions
|
|
1291
|
+
// ✅ Multiple expressions
|
|
1258
1292
|
await sock.sendMessage(jid, {
|
|
1259
1293
|
latex: {
|
|
1260
1294
|
text: 'Rumus-rumus fisika dasar:',
|
|
@@ -1267,9 +1301,34 @@ await sock.sendMessage(jid, {
|
|
|
1267
1301
|
headerText: 'Hukum Newton 🍎',
|
|
1268
1302
|
disclaimerText: 'Fisika dasar kelas 10~'
|
|
1269
1303
|
})
|
|
1304
|
+
|
|
1305
|
+
// ✅ Dengan url custom (jika kamu punya server render sendiri)
|
|
1306
|
+
await sock.sendMessage(jid, {
|
|
1307
|
+
latex: {
|
|
1308
|
+
text: 'Energi massa Einstein:',
|
|
1309
|
+
expressions: [
|
|
1310
|
+
{
|
|
1311
|
+
expression: 'E = mc^2',
|
|
1312
|
+
url: 'https://latex.codecogs.com/png.image?\dpi{150}\bg{white}E%20%3D%20mc%5E2',
|
|
1313
|
+
width: 120,
|
|
1314
|
+
height: 40
|
|
1315
|
+
}
|
|
1316
|
+
]
|
|
1317
|
+
},
|
|
1318
|
+
headerText: 'Fisika Modern ⚛️'
|
|
1319
|
+
})
|
|
1270
1320
|
```
|
|
1271
1321
|
|
|
1272
|
-
> 💡 `expression` menggunakan sintaks LaTeX standar. `url`
|
|
1322
|
+
> 💡 `expression` menggunakan sintaks LaTeX standar. `url` akan **otomatis di-generate** dari codecogs jika tidak diisi — jadi kamu tidak perlu khawatir soal ini~
|
|
1323
|
+
|
|
1324
|
+
> ❌ **Jangan pakai cara ini** (akan kosong/error):
|
|
1325
|
+
> ```js
|
|
1326
|
+
> // SALAH — latex tidak boleh dibungkus richResponse array untuk flat usage
|
|
1327
|
+
> await sock.sendMessage(jid, {
|
|
1328
|
+
> richResponse: [{ latex: { text: '...', expressions: [...] } }],
|
|
1329
|
+
> headerText: 'Judul' // ← headerText diabaikan di mode array lama
|
|
1330
|
+
> })
|
|
1331
|
+
> ```
|
|
1273
1332
|
|
|
1274
1333
|
---
|
|
1275
1334
|
|
package/lib/Utils/messages.js
CHANGED
|
@@ -561,7 +561,13 @@ export const generateWAMessageContent = async (message, options) => {
|
|
|
561
561
|
else if (hasNonNullishProperty(message, 'code') ||
|
|
562
562
|
hasNonNullishProperty(message, 'links') ||
|
|
563
563
|
hasNonNullishProperty(message, 'table') ||
|
|
564
|
-
hasNonNullishProperty(message, 'richResponse')
|
|
564
|
+
hasNonNullishProperty(message, 'richResponse') ||
|
|
565
|
+
hasNonNullishProperty(message, 'latex') ||
|
|
566
|
+
hasNonNullishProperty(message, 'gridImage') ||
|
|
567
|
+
hasNonNullishProperty(message, 'inlineImage') ||
|
|
568
|
+
hasNonNullishProperty(message, 'dynamic') ||
|
|
569
|
+
hasNonNullishProperty(message, 'map') ||
|
|
570
|
+
hasNonNullishProperty(message, 'contentItems')) {
|
|
565
571
|
m = prepareRichResponseMessage(message);
|
|
566
572
|
}
|
|
567
573
|
else if (hasNonNullishProperty(message, 'text')) {
|
|
@@ -7,6 +7,34 @@ import { unixTimestampSeconds } from './generics.js';
|
|
|
7
7
|
|
|
8
8
|
const NOOP = new Set([]);
|
|
9
9
|
|
|
10
|
+
/* ─────────────────────────────────────────────────────────────
|
|
11
|
+
LATEX URL GENERATOR
|
|
12
|
+
WhatsApp client membutuhkan URL gambar render untuk setiap
|
|
13
|
+
LaTeX expression. Tanpa URL, pesan tampil kosong.
|
|
14
|
+
Gunakan latex.codecogs.com sebagai fallback gratis~
|
|
15
|
+
───────────────────────────────────────────────────────────── */
|
|
16
|
+
const buildLatexUrl = (expression) => {
|
|
17
|
+
if (!expression) return null;
|
|
18
|
+
const encoded = encodeURIComponent(expression);
|
|
19
|
+
return `https://latex.codecogs.com/png.image?\dpi{150}\bg{white}${encoded}`;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/* ─────────────────────────────────────────────────────────────
|
|
23
|
+
IMAGE URL HELPER
|
|
24
|
+
Konversi objek AIRichResponseImageURL ke snake_case JSON
|
|
25
|
+
agar WA client bisa baca dengan benar~
|
|
26
|
+
───────────────────────────────────────────────────────────── */
|
|
27
|
+
const toImageUrlJson = (imgUrl) => {
|
|
28
|
+
if (!imgUrl) return null;
|
|
29
|
+
// support both plain string and object
|
|
30
|
+
if (typeof imgUrl === 'string') return { image_preview_url: imgUrl, image_high_res_url: imgUrl, source_url: null };
|
|
31
|
+
return {
|
|
32
|
+
image_preview_url: imgUrl.imagePreviewUrl || imgUrl.image_preview_url || null,
|
|
33
|
+
image_high_res_url: imgUrl.imageHighResUrl || imgUrl.image_high_res_url || null,
|
|
34
|
+
source_url: imgUrl.sourceUrl || imgUrl.source_url || null
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
|
|
10
38
|
/* ─────────────────────────────────────────────────────────────
|
|
11
39
|
TOKENIZER
|
|
12
40
|
───────────────────────────────────────────────────────────── */
|
|
@@ -247,8 +275,8 @@ const buildUnifiedSection = (submessage) => {
|
|
|
247
275
|
return {
|
|
248
276
|
view_model: {
|
|
249
277
|
primitive: {
|
|
250
|
-
grid_image_url: gm.gridImageUrl,
|
|
251
|
-
image_urls: gm.imageUrls,
|
|
278
|
+
grid_image_url: toImageUrlJson(gm.gridImageUrl),
|
|
279
|
+
image_urls: (gm.imageUrls || []).map(toImageUrlJson),
|
|
252
280
|
__typename: 'GenAIGridImageUXPrimitive'
|
|
253
281
|
},
|
|
254
282
|
__typename: 'GenAISingleLayoutViewModel'
|
|
@@ -261,7 +289,7 @@ const buildUnifiedSection = (submessage) => {
|
|
|
261
289
|
return {
|
|
262
290
|
view_model: {
|
|
263
291
|
primitive: {
|
|
264
|
-
image_url: im.imageUrl,
|
|
292
|
+
image_url: toImageUrlJson(im.imageUrl),
|
|
265
293
|
image_text: im.imageText,
|
|
266
294
|
alignment: im.alignment ?? 0,
|
|
267
295
|
tap_link_url: im.tapLinkUrl || null,
|
|
@@ -404,16 +432,35 @@ const makeTableSub = (rows, title, noHeading) => ({
|
|
|
404
432
|
}
|
|
405
433
|
});
|
|
406
434
|
|
|
435
|
+
/** Normalize input ke format AIRichResponseImageURL */
|
|
436
|
+
const normalizeImageUrl = (u) => {
|
|
437
|
+
if (!u) return null;
|
|
438
|
+
if (typeof u === 'string') return { imagePreviewUrl: u, imageHighResUrl: u, sourceUrl: null };
|
|
439
|
+
return {
|
|
440
|
+
imagePreviewUrl: u.imagePreviewUrl || u.image_preview_url || null,
|
|
441
|
+
imageHighResUrl: u.imageHighResUrl || u.image_high_res_url || null,
|
|
442
|
+
sourceUrl: u.sourceUrl || u.source_url || null
|
|
443
|
+
};
|
|
444
|
+
};
|
|
445
|
+
|
|
407
446
|
/** Buat submessage GRID_IMAGE */
|
|
408
447
|
const makeGridImageSub = (gridImageUrl, imageUrls = []) => ({
|
|
409
448
|
messageType: RichSubMessageType.GRID_IMAGE,
|
|
410
|
-
gridImageMetadata: {
|
|
449
|
+
gridImageMetadata: {
|
|
450
|
+
gridImageUrl: normalizeImageUrl(gridImageUrl),
|
|
451
|
+
imageUrls: (imageUrls || []).map(normalizeImageUrl)
|
|
452
|
+
}
|
|
411
453
|
});
|
|
412
454
|
|
|
413
455
|
/** Buat submessage INLINE_IMAGE */
|
|
414
456
|
const makeInlineImageSub = (imageUrl, imageText = '', alignment = 0, tapLinkUrl = null) => ({
|
|
415
457
|
messageType: RichSubMessageType.INLINE_IMAGE,
|
|
416
|
-
imageMetadata: {
|
|
458
|
+
imageMetadata: {
|
|
459
|
+
imageUrl: normalizeImageUrl(imageUrl),
|
|
460
|
+
imageText,
|
|
461
|
+
alignment,
|
|
462
|
+
tapLinkUrl
|
|
463
|
+
}
|
|
417
464
|
});
|
|
418
465
|
|
|
419
466
|
/** Buat submessage DYNAMIC (animated image/GIF) */
|
|
@@ -446,17 +493,22 @@ const makeLatexSub = (text, expressions = []) => ({
|
|
|
446
493
|
messageType: RichSubMessageType.LATEX,
|
|
447
494
|
latexMetadata: {
|
|
448
495
|
text,
|
|
449
|
-
expressions: expressions.map(e =>
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
496
|
+
expressions: expressions.map(e => {
|
|
497
|
+
const expr = e.expression || e.latexExpression || '';
|
|
498
|
+
// url WAJIB ada agar WA client bisa render — auto-generate jika tidak disupply
|
|
499
|
+
const url = e.url || buildLatexUrl(expr);
|
|
500
|
+
return {
|
|
501
|
+
latexExpression: expr,
|
|
502
|
+
url,
|
|
503
|
+
width: e.width ?? 120,
|
|
504
|
+
height: e.height ?? 40,
|
|
505
|
+
fontHeight: e.fontHeight ?? 0,
|
|
506
|
+
imageTopPadding: e.imageTopPadding ?? 0,
|
|
507
|
+
imageLeadingPadding: e.imageLeadingPadding ?? 0,
|
|
508
|
+
imageBottomPadding: e.imageBottomPadding ?? 0,
|
|
509
|
+
imageTrailingPadding: e.imageTrailingPadding ?? 0
|
|
510
|
+
};
|
|
511
|
+
})
|
|
460
512
|
}
|
|
461
513
|
});
|
|
462
514
|
|
|
@@ -499,7 +551,9 @@ export const prepareRichResponseMessage = (content) => {
|
|
|
499
551
|
|
|
500
552
|
/* ── mode array (richResponse) — multi-section campuran ── */
|
|
501
553
|
if (Array.isArray(richResponse)) {
|
|
502
|
-
|
|
554
|
+
// headerText dan footerText tetap dihormati meskipun pakai mode array
|
|
555
|
+
if (headerText) submessages.push(makeTextSub(headerText));
|
|
556
|
+
submessages.push(...richResponse.map(sub => {
|
|
503
557
|
if (sub.text != null) return makeTextSub(sub.text, sub.inlineEntities);
|
|
504
558
|
if (sub.code != null) return makeCodeSub(sub.code, sub.language || 'javascript');
|
|
505
559
|
if (sub.table != null) return makeTableSub(sub.table, sub.title, sub.noHeading);
|
|
@@ -510,7 +564,8 @@ export const prepareRichResponseMessage = (content) => {
|
|
|
510
564
|
if (sub.latex != null) return makeLatexSub(sub.latex.text, sub.latex.expressions);
|
|
511
565
|
if (sub.contentItems != null) return makeContentItemsSub(sub.contentItems.items, sub.contentItems.contentType);
|
|
512
566
|
return sub; // passthrough kalau sudah bentuk proto
|
|
513
|
-
}).filter(Boolean);
|
|
567
|
+
}).filter(Boolean));
|
|
568
|
+
if (footerText) submessages.push(makeTextSub(footerText));
|
|
514
569
|
|
|
515
570
|
/* ── mode flat (convenience fields) ── */
|
|
516
571
|
} else {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nuiisweety/baileys",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.4",
|
|
5
5
|
"description": "A WebSockets library for interacting with WhatsApp Web — forked STRICTLY from @whiskeysockets/baileys only, NOT from any other baileys fork. Modified by NuiiSweety.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"whatsapp",
|