@nuiisweety/baileys 0.1.2 → 0.1.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 CHANGED
@@ -1236,15 +1236,20 @@ await sock.sendMessage(jid, {
1236
1236
 
1237
1237
  > ✏️ Kirim rumus matematika dalam format LaTeX — tampil dengan render formula yang indah~
1238
1238
 
1239
+ > ⚠️ **Catatan penting:**
1240
+ > - `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).
1241
+ > - Gunakan `latex: {...}` langsung (flat) — **bukan** dibungkus dalam `richResponse: [{ latex: {...} }]`.
1242
+ > - `headerText`, `footerText`, `disclaimerText` tetap bisa dipakai bersama `latex`.
1243
+
1239
1244
  ```js
1240
- // Rumus sederhana
1245
+ // Rumus sederhana — url auto-generate jika tidak diisi
1241
1246
  await sock.sendMessage(jid, {
1242
1247
  latex: {
1243
1248
  text: 'Berikut rumus yang kamu minta:',
1244
1249
  expressions: [
1245
1250
  {
1246
1251
  expression: 'E = mc^2',
1247
- url: 'https://example.com/formula/e-mc2.png', // opsional: gambar render-nya
1252
+ // url auto-generate dari codecogs kalau tidak diisi~
1248
1253
  width: 120,
1249
1254
  height: 40
1250
1255
  }
@@ -1254,7 +1259,7 @@ await sock.sendMessage(jid, {
1254
1259
  footerText: 'E = energi, m = massa, c = kecepatan cahaya 💡'
1255
1260
  })
1256
1261
 
1257
- // Multiple expressions
1262
+ // Multiple expressions
1258
1263
  await sock.sendMessage(jid, {
1259
1264
  latex: {
1260
1265
  text: 'Rumus-rumus fisika dasar:',
@@ -1267,9 +1272,34 @@ await sock.sendMessage(jid, {
1267
1272
  headerText: 'Hukum Newton 🍎',
1268
1273
  disclaimerText: 'Fisika dasar kelas 10~'
1269
1274
  })
1275
+
1276
+ // ✅ Dengan url custom (jika kamu punya server render sendiri)
1277
+ await sock.sendMessage(jid, {
1278
+ latex: {
1279
+ text: 'Energi massa Einstein:',
1280
+ expressions: [
1281
+ {
1282
+ expression: 'E = mc^2',
1283
+ url: 'https://latex.codecogs.com/png.image?\dpi{150}\bg{white}E%20%3D%20mc%5E2',
1284
+ width: 120,
1285
+ height: 40
1286
+ }
1287
+ ]
1288
+ },
1289
+ headerText: 'Fisika Modern ⚛️'
1290
+ })
1270
1291
  ```
1271
1292
 
1272
- > 💡 `expression` menggunakan sintaks LaTeX standar. `url` adalah opsional URL gambar hasil render LaTeX (misalnya dari layanan seperti render.githubusercontent.com)~
1293
+ > 💡 `expression` menggunakan sintaks LaTeX standar. `url` akan **otomatis di-generate** dari codecogs jika tidak diisi jadi kamu tidak perlu khawatir soal ini~
1294
+
1295
+ > ❌ **Jangan pakai cara ini** (akan kosong/error):
1296
+ > ```js
1297
+ > // SALAH — latex tidak boleh dibungkus richResponse array untuk flat usage
1298
+ > await sock.sendMessage(jid, {
1299
+ > richResponse: [{ latex: { text: '...', expressions: [...] } }],
1300
+ > headerText: 'Judul' // ← headerText diabaikan di mode array lama
1301
+ > })
1302
+ > ```
1273
1303
 
1274
1304
  ---
1275
1305
 
@@ -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,18 @@ 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
+
10
22
  /* ─────────────────────────────────────────────────────────────
11
23
  TOKENIZER
12
24
  ───────────────────────────────────────────────────────────── */
@@ -446,17 +458,22 @@ const makeLatexSub = (text, expressions = []) => ({
446
458
  messageType: RichSubMessageType.LATEX,
447
459
  latexMetadata: {
448
460
  text,
449
- expressions: expressions.map(e => ({
450
- latexExpression: e.expression || e.latexExpression || '',
451
- url: e.url || null,
452
- width: e.width ?? 0,
453
- height: e.height ?? 0,
454
- fontHeight: e.fontHeight ?? 0,
455
- imageTopPadding: e.imageTopPadding ?? 0,
456
- imageLeadingPadding: e.imageLeadingPadding ?? 0,
457
- imageBottomPadding: e.imageBottomPadding ?? 0,
458
- imageTrailingPadding: e.imageTrailingPadding ?? 0
459
- }))
461
+ expressions: expressions.map(e => {
462
+ const expr = e.expression || e.latexExpression || '';
463
+ // url WAJIB ada agar WA client bisa render — auto-generate jika tidak disupply
464
+ const url = e.url || buildLatexUrl(expr);
465
+ return {
466
+ latexExpression: expr,
467
+ url,
468
+ width: e.width ?? 120,
469
+ height: e.height ?? 40,
470
+ fontHeight: e.fontHeight ?? 0,
471
+ imageTopPadding: e.imageTopPadding ?? 0,
472
+ imageLeadingPadding: e.imageLeadingPadding ?? 0,
473
+ imageBottomPadding: e.imageBottomPadding ?? 0,
474
+ imageTrailingPadding: e.imageTrailingPadding ?? 0
475
+ };
476
+ })
460
477
  }
461
478
  });
462
479
 
@@ -499,7 +516,9 @@ export const prepareRichResponseMessage = (content) => {
499
516
 
500
517
  /* ── mode array (richResponse) — multi-section campuran ── */
501
518
  if (Array.isArray(richResponse)) {
502
- submessages = richResponse.map(sub => {
519
+ // headerText dan footerText tetap dihormati meskipun pakai mode array
520
+ if (headerText) submessages.push(makeTextSub(headerText));
521
+ submessages.push(...richResponse.map(sub => {
503
522
  if (sub.text != null) return makeTextSub(sub.text, sub.inlineEntities);
504
523
  if (sub.code != null) return makeCodeSub(sub.code, sub.language || 'javascript');
505
524
  if (sub.table != null) return makeTableSub(sub.table, sub.title, sub.noHeading);
@@ -510,7 +529,8 @@ export const prepareRichResponseMessage = (content) => {
510
529
  if (sub.latex != null) return makeLatexSub(sub.latex.text, sub.latex.expressions);
511
530
  if (sub.contentItems != null) return makeContentItemsSub(sub.contentItems.items, sub.contentItems.contentType);
512
531
  return sub; // passthrough kalau sudah bentuk proto
513
- }).filter(Boolean);
532
+ }).filter(Boolean));
533
+ if (footerText) submessages.push(makeTextSub(footerText));
514
534
 
515
535
  /* ── mode flat (convenience fields) ── */
516
536
  } else {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@nuiisweety/baileys",
3
3
  "type": "module",
4
- "version": "0.1.2",
4
+ "version": "0.1.3",
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",