@nuiisweety/baileys 0.1.3 → 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 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://example.com/thumb.jpg',
1110
- imageHighResUrl: 'https://example.com/image.jpg',
1111
- sourceUrl: 'https://example.com'
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://example.com/t1.jpg',
1116
- imageHighResUrl: 'https://example.com/i1.jpg',
1117
- sourceUrl: 'https://example.com/1'
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://example.com/t2.jpg',
1121
- imageHighResUrl: 'https://example.com/i2.jpg',
1122
- sourceUrl: 'https://example.com/2'
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://example.com/preview.jpg',
1144
- imageHighResUrl: 'https://example.com/hires.jpg',
1145
- sourceUrl: 'https://example.com'
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 diagram arsitektur 💡',
1148
- alignment: 0, // 0 = leading, 1 = trailing, 2 = center
1149
- tapLinkUrl: 'https://example.com/detail'
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
  ---
@@ -19,6 +19,22 @@ const buildLatexUrl = (expression) => {
19
19
  return `https://latex.codecogs.com/png.image?\dpi{150}\bg{white}${encoded}`;
20
20
  };
21
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
+
22
38
  /* ─────────────────────────────────────────────────────────────
23
39
  TOKENIZER
24
40
  ───────────────────────────────────────────────────────────── */
@@ -259,8 +275,8 @@ const buildUnifiedSection = (submessage) => {
259
275
  return {
260
276
  view_model: {
261
277
  primitive: {
262
- grid_image_url: gm.gridImageUrl,
263
- image_urls: gm.imageUrls,
278
+ grid_image_url: toImageUrlJson(gm.gridImageUrl),
279
+ image_urls: (gm.imageUrls || []).map(toImageUrlJson),
264
280
  __typename: 'GenAIGridImageUXPrimitive'
265
281
  },
266
282
  __typename: 'GenAISingleLayoutViewModel'
@@ -273,7 +289,7 @@ const buildUnifiedSection = (submessage) => {
273
289
  return {
274
290
  view_model: {
275
291
  primitive: {
276
- image_url: im.imageUrl,
292
+ image_url: toImageUrlJson(im.imageUrl),
277
293
  image_text: im.imageText,
278
294
  alignment: im.alignment ?? 0,
279
295
  tap_link_url: im.tapLinkUrl || null,
@@ -416,16 +432,35 @@ const makeTableSub = (rows, title, noHeading) => ({
416
432
  }
417
433
  });
418
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
+
419
446
  /** Buat submessage GRID_IMAGE */
420
447
  const makeGridImageSub = (gridImageUrl, imageUrls = []) => ({
421
448
  messageType: RichSubMessageType.GRID_IMAGE,
422
- gridImageMetadata: { gridImageUrl, imageUrls }
449
+ gridImageMetadata: {
450
+ gridImageUrl: normalizeImageUrl(gridImageUrl),
451
+ imageUrls: (imageUrls || []).map(normalizeImageUrl)
452
+ }
423
453
  });
424
454
 
425
455
  /** Buat submessage INLINE_IMAGE */
426
456
  const makeInlineImageSub = (imageUrl, imageText = '', alignment = 0, tapLinkUrl = null) => ({
427
457
  messageType: RichSubMessageType.INLINE_IMAGE,
428
- imageMetadata: { imageUrl, imageText, alignment, tapLinkUrl }
458
+ imageMetadata: {
459
+ imageUrl: normalizeImageUrl(imageUrl),
460
+ imageText,
461
+ alignment,
462
+ tapLinkUrl
463
+ }
429
464
  });
430
465
 
431
466
  /** Buat submessage DYNAMIC (animated image/GIF) */
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@nuiisweety/baileys",
3
3
  "type": "module",
4
- "version": "0.1.3",
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",