@vinzsocket/baileys 3.2.7 → 3.2.9

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
@@ -5,7 +5,7 @@
5
5
  **A lightweight WebSocket library for WhatsApp Web Multi-Device**
6
6
 
7
7
  [![GitHub](https://img.shields.io/badge/GitHub-VinzSocket/Baileys-blue?style=for-the-badge&logo=github)](https://github.com/VinzSocket/Baileys)
8
- ![Version](https://img.shields.io/badge/version-3.2.7-blue)
8
+ ![Version](https://img.shields.io/badge/version-3.2.9-blue)
9
9
  ![Node.js](https://img.shields.io/badge/Node.js-%3E%3D20-green)
10
10
 
11
11
  </div>
@@ -20,9 +20,9 @@ npm install @vinzsocket/baileys
20
20
 
21
21
  ---
22
22
 
23
- ## 🔔 Changelog v3.2.6
23
+ ## 🔔 Changelog v3.2.9
24
24
 
25
- ### ✅ Group Status V2 — Semua Media + Caption
25
+ ### ✅ Group Status V4 — Semua Media + Caption
26
26
 
27
27
  `handleGroupStory` sekarang support semua tipe media dengan caption:
28
28
 
@@ -327,4 +327,4 @@ await relayMessage(jid, msg.message, {
327
327
 
328
328
  ## 📄 License
329
329
 
330
- MIT — © VinzSocket
330
+ MIT — © Alvin-B2T
@@ -334,8 +334,13 @@ export class ExtendedMessageBuilder {
334
334
  * textArgb?: number
335
335
  * font?: number (0-5)
336
336
  */
337
+ /**
338
+ * Group Status V2 — kirim story/status ke grup.
339
+ * messageSecret wajib ada supaya WA client bisa decrypt & tampilkan konten.
340
+ */
337
341
  async handleGroupStory(content, jid) {
338
342
  const s = content.groupStatusMessage;
343
+ const secret = randomBytes(32);
339
344
 
340
345
  // Mode 1: raw relay langsung
341
346
  if (s.raw) {
@@ -344,89 +349,107 @@ export class ExtendedMessageBuilder {
344
349
  });
345
350
  }
346
351
 
347
- // Mode 2: inner WAMessage sudah disiapkan
352
+ // Mode 2: inner WAMessage sudah disiapkan — wrap dengan secret
348
353
  if (s.message) {
349
354
  return await this.relayMessage(jid, {
350
- groupStatusMessageV2: { message: s.message }
355
+ groupStatusMessageV2: {
356
+ message: {
357
+ messageContextInfo: {
358
+ messageSecret: secret,
359
+ deviceListMetadata: {},
360
+ deviceListMetadataVersion: 2
361
+ },
362
+ ...s.message
363
+ }
364
+ }
351
365
  }, { messageId: this.bail.generateMessageID() });
352
366
  }
353
367
 
354
368
  // Mode 3: generate dari media/teks
355
- let innerMessage;
369
+ let innerMessage = {};
356
370
 
357
371
  if (s.text || (!s.image && !s.video && !s.audio && !s.sticker && !s.document)) {
358
- // Teks — pakai extendedTextMessage supaya support backgroundColor & font
359
- const textMsg = {
372
+ // Teks
373
+ innerMessage = {
360
374
  extendedTextMessage: {
361
375
  text: s.text || s.caption || '',
362
376
  ...(typeof s.backgroundColor !== 'undefined' ? { backgroundArgb: s.backgroundColor } : {}),
363
- ...(typeof s.textArgb !== 'undefined' ? { textArgb: s.textArgb } : {}),
364
- ...(typeof s.font !== 'undefined' ? { font: s.font } : {})
377
+ ...(typeof s.textArgb !== 'undefined' ? { textArgb: s.textArgb } : {}),
378
+ ...(typeof s.font !== 'undefined' ? { font: s.font } : {})
365
379
  }
366
380
  };
367
- innerMessage = textMsg;
368
381
  } else if (s.image) {
369
- // Foto dengan caption
370
382
  const media = await this.utils.prepareWAMessageMedia(
371
- { image: s.image, ...(s.caption ? { caption: s.caption } : {}) },
383
+ { image: s.image },
384
+ { upload: this.waUploadToServer }
385
+ );
386
+ if (s.caption) media.imageMessage.caption = s.caption;
387
+ innerMessage = media;
388
+ } else if (s.card) {
389
+ // Mode: canvas-rendered story card (gradient + title/body/footer text),
390
+ // see lib/Utils/story-card.js. `s.card` accepts the same options as
391
+ // renderStoryCard() — e.g. { title, body, footer, gradient, direction }.
392
+ const cardBuffer = await this.utils.renderStoryCard(s.card);
393
+ const media = await this.utils.prepareWAMessageMedia(
394
+ { image: cardBuffer },
372
395
  { upload: this.waUploadToServer }
373
396
  );
374
397
  if (s.caption) media.imageMessage.caption = s.caption;
375
398
  innerMessage = media;
376
399
  } else if (s.video) {
377
- // Video dengan caption, support gifPlayback
378
400
  const media = await this.utils.prepareWAMessageMedia(
379
- {
380
- video: s.video,
381
- ...(s.caption ? { caption: s.caption } : {}),
382
- ...(s.gifPlayback ? { gifPlayback: s.gifPlayback } : {}),
383
- ...(s.seconds ? { seconds: s.seconds } : {})
384
- },
401
+ { video: s.video },
385
402
  { upload: this.waUploadToServer }
386
403
  );
387
- if (s.caption) media.videoMessage.caption = s.caption;
404
+ if (s.caption) media.videoMessage.caption = s.caption;
388
405
  if (s.gifPlayback) media.videoMessage.gifPlayback = true;
406
+ if (s.seconds) media.videoMessage.seconds = s.seconds;
389
407
  innerMessage = media;
390
408
  } else if (s.audio) {
391
- // Audio — voice note (ptt: true) atau musik (ptt: false)
392
409
  const media = await this.utils.prepareWAMessageMedia(
393
410
  {
394
411
  audio: s.audio,
395
412
  ptt: s.ptt !== false,
396
- ...(s.seconds ? { seconds: s.seconds } : {}),
397
- ...(s.mimetype ? { mimetype: s.mimetype } : {})
413
+ ...(s.seconds ? { seconds: s.seconds } : {}),
414
+ ...(s.mimetype ? { mimetype: s.mimetype } : {})
398
415
  },
399
416
  { upload: this.waUploadToServer }
400
417
  );
401
418
  innerMessage = media;
402
419
  } else if (s.sticker) {
403
- // Sticker
404
420
  const media = await this.utils.prepareWAMessageMedia(
405
421
  { sticker: s.sticker },
406
422
  { upload: this.waUploadToServer }
407
423
  );
408
424
  innerMessage = media;
409
425
  } else if (s.document) {
410
- // Dokumen dengan caption
411
426
  const media = await this.utils.prepareWAMessageMedia(
412
427
  {
413
428
  document: s.document,
414
429
  mimetype: s.mimetype || 'application/octet-stream',
415
- fileName: s.fileName || 'file',
416
- ...(s.caption ? { caption: s.caption } : {})
430
+ fileName: s.fileName || 'file'
417
431
  },
418
432
  { upload: this.waUploadToServer }
419
433
  );
420
- if (s.caption && media.documentMessage) media.documentMessage.caption = s.caption;
434
+ if (s.caption && media.documentMessage) media.documentMessage.caption = s.caption;
421
435
  if (s.fileName && media.documentMessage) media.documentMessage.fileName = s.fileName;
422
436
  innerMessage = media;
423
437
  } else {
424
- // Fallback: generate via generateWAMessageContent
425
438
  innerMessage = await this.bail.generateWAMessageContent(s, { upload: this.waUploadToServer });
426
439
  }
427
440
 
441
+ // Wrap dengan messageContextInfo + messageSecret — WAJIB supaya konten bisa ditampilkan
428
442
  return await this.relayMessage(jid, {
429
- groupStatusMessageV2: { message: innerMessage }
443
+ groupStatusMessageV2: {
444
+ message: {
445
+ messageContextInfo: {
446
+ messageSecret: secret,
447
+ deviceListMetadata: {},
448
+ deviceListMetadataVersion: 2
449
+ },
450
+ ...innerMessage
451
+ }
452
+ }
430
453
  }, { messageId: this.bail.generateMessageID() });
431
454
  }
432
455
  }
@@ -2,7 +2,7 @@ import NodeCache from '@cacheable/node-cache';
2
2
  import { Boom } from '@hapi/boom';
3
3
  import { proto } from '../../WAProto/index.js';
4
4
  import { DEFAULT_CACHE_TTLS, WA_DEFAULT_EPHEMERAL } from '../Defaults/index.js';
5
- import { aggregateMessageKeysNotFromMe, assertMediaContent, assertMeId, bindWaitForEvent, buildInteractiveAdditionalNodes, decryptMediaRetryData, DEF_MEDIA_HOST, encodeNewsletterMessage, encodeSignedDeviceIdentity, encodeWAMessage, encryptMediaRetryRequest, extractDeviceJids, generateMessageID, generateMessageIDV2, generateParticipantHashV2, generateWAMessage, generateWAMessageContent, generateWAMessageFromContent, getStatusCodeForMediaRetry, getUrlFromDirectPath, getWAUploadToServer, MessageRetryManager, normalizeMessageContent, parseAndInjectE2ESessions, prepareWAMessageMedia, unixTimestampSeconds } from '../Utils/index.js';
5
+ import { aggregateMessageKeysNotFromMe, assertMediaContent, assertMeId, bindWaitForEvent, buildInteractiveAdditionalNodes, decryptMediaRetryData, DEF_MEDIA_HOST, encodeNewsletterMessage, encodeSignedDeviceIdentity, encodeWAMessage, encryptMediaRetryRequest, extractDeviceJids, generateMessageID, generateMessageIDV2, generateParticipantHashV2, generateWAMessage, generateWAMessageContent, generateWAMessageFromContent, getStatusCodeForMediaRetry, getUrlFromDirectPath, getWAUploadToServer, MessageRetryManager, normalizeMessageContent, parseAndInjectE2ESessions, prepareWAMessageMedia, renderStoryCard, unixTimestampSeconds } from '../Utils/index.js';
6
6
  import { getUrlInfo } from '../Utils/link-preview.js';
7
7
  import { makeKeyedMutex, makeMutex } from '../Utils/make-mutex.js';
8
8
  import { getMessageReportingToken, shouldIncludeReportingToken } from '../Utils/reporting-utils.js';
@@ -984,7 +984,8 @@ export const makeMessagesSocket = (config) => {
984
984
  generateMessageID,
985
985
  generateWAMessage,
986
986
  generateWAMessageFromContent,
987
- prepareWAMessageMedia
987
+ prepareWAMessageMedia,
988
+ renderStoryCard
988
989
  }, waUploadToServer, relayMessage);
989
990
  const waitForMsgMediaUpdate = bindWaitForEvent(ev, 'messages.media-update');
990
991
  registerSocketEndHandler(() => {
@@ -20,4 +20,5 @@ export * from './companion-reg-client-utils.js';
20
20
  export * from './identity-change-handler.js';
21
21
  export * from './stanza-ack.js';
22
22
  export * from './mention.js';
23
+ export * from './story-card.js';
23
24
  //# sourceMappingURL=index.js.map
@@ -393,13 +393,14 @@ export const buildInteractiveAdditionalNodes = (jid, m) => {
393
393
  content: [{ tag: 'list', attrs: { type: 'product_list', v: '2' } }]
394
394
  });
395
395
  } else if (inner.interactiveMessage || inner.buttonsMessage || inner.templateMessage || inner.productMessage) {
396
+ const isCarousel = !!inner.interactiveMessage?.carouselMessage;
396
397
  nodes.push({
397
398
  tag: 'biz',
398
399
  attrs: {},
399
400
  content: [{
400
401
  tag: 'interactive',
401
402
  attrs: { type: 'native_flow', v: '1' },
402
- content: [{ tag: 'native_flow', attrs: { name: 'mixed', v: '9' } }]
403
+ content: [{ tag: 'native_flow', attrs: { name: isCarousel ? 'carousel' : 'mixed', v: '9' } }]
403
404
  }]
404
405
  });
405
406
  } else if (inner.groupStatusMessageV2) {
@@ -691,6 +692,47 @@ export const generateWAMessageContent = async (message, options) => {
691
692
  }
692
693
  };
693
694
  }
695
+ else if (hasNonNullishProperty(message, 'cards')) {
696
+ // Convenience: top-level `cards` shorthand -> interactiveMessage.carouselMessage
697
+ // (horizontal-scroll product/card carousel). Each entry in `cards` may contain:
698
+ // { image | video, title?, body?, footer?, buttons? }
699
+ // `buttons` per card accepts the same shapes as the top-level `buttons` shorthand.
700
+ if (!Array.isArray(message.cards) || !message.cards.length) {
701
+ throw new Boom('cards must be a non-empty array', { statusCode: 400 });
702
+ }
703
+ const cards = await Promise.all(message.cards.map(async (card) => {
704
+ const cardButtons = normalizeToNativeFlowButtons(card.interactiveButtons || card.buttons || card.templateButtons || []);
705
+ const cardInteractive = {
706
+ body: { text: card.text || card.body || card.caption || '' },
707
+ footer: { text: card.footer || '' },
708
+ nativeFlowMessage: { buttons: cardButtons }
709
+ };
710
+ if (card.image || card.video) {
711
+ const mediaContent = await prepareWAMessageMedia(card.image ? { image: card.image } : { video: card.video }, options);
712
+ const mediaType = Object.keys(mediaContent)[0];
713
+ cardInteractive.header = {
714
+ title: card.title || '',
715
+ hasMediaAttachment: true,
716
+ ...mediaContent[mediaType]
717
+ };
718
+ }
719
+ else if (card.title) {
720
+ cardInteractive.header = { title: card.title, hasMediaAttachment: false };
721
+ }
722
+ return cardInteractive;
723
+ }));
724
+ m = {
725
+ interactiveMessage: {
726
+ body: { text: message.text || message.caption || '' },
727
+ footer: { text: message.footer || '' },
728
+ carouselMessage: {
729
+ cards,
730
+ messageVersion: 1,
731
+ carouselCardType: proto.Message.InteractiveMessage.CarouselMessage.CarouselCardType.HSCROLL_CARDS
732
+ }
733
+ }
734
+ };
735
+ }
694
736
  if (hasOptionalProperty(message, 'viewOnce') && !!message.viewOnce) {
695
737
  m = { viewOnceMessage: { message: m } };
696
738
  }
@@ -0,0 +1,107 @@
1
+ import { Boom } from '@hapi/boom';
2
+ /**
3
+ * Canvas-rendered "story card" — generates a styled status/story image (gradient
4
+ * background, title, body text, optional footer/branding strip) entirely in JS
5
+ * via Jimp (already an optional peer dependency of this library, no native
6
+ * binary required). Useful for visually distinctive WhatsApp Status / group
7
+ * story (`groupStatusMessageV2`) posts without needing a design tool upstream.
8
+ *
9
+ * Lazily imports `jimp` so this module has zero cost / zero hard dependency
10
+ * for consumers who never call it.
11
+ */
12
+ let _jimpLib;
13
+ const getJimp = async () => {
14
+ if (_jimpLib) return _jimpLib;
15
+ try {
16
+ // @ts-ignore - optional peer dependency
17
+ const [core, fonts] = await Promise.all([import('jimp'), import('jimp/fonts')]);
18
+ _jimpLib = { ...core, fonts };
19
+ return _jimpLib;
20
+ }
21
+ catch {
22
+ throw new Boom('renderStoryCard() requires the optional "jimp" peer dependency. Install it with: npm i jimp', { statusCode: 500 });
23
+ }
24
+ };
25
+ const DEFAULT_GRADIENTS = {
26
+ sunset: [0xff7e5fff, 0xfeb47bff],
27
+ purple: [0x8e2de2ff, 0x4a00e0ff],
28
+ ocean: [0x2193b0ff, 0x6dd5edff],
29
+ forest: [0x134e5eff, 0x71b280ff],
30
+ midnight: [0x232526ff, 0x414345ff],
31
+ fire: [0xf12711ff, 0xf5af19ff]
32
+ };
33
+ const lerpChannel = (a, b, t) => Math.round(a + (b - a) * t);
34
+ const lerpColor = (c1, c2, t, jimpLib) => {
35
+ const { r: r1, g: g1, b: b1, a: a1 } = jimpLib.intToRGBA(c1);
36
+ const { r: r2, g: g2, b: b2, a: a2 } = jimpLib.intToRGBA(c2);
37
+ return jimpLib.rgbaToInt(lerpChannel(r1, r2, t), lerpChannel(g1, g2, t), lerpChannel(b1, b2, t), lerpChannel(a1, a2, t));
38
+ };
39
+ /**
40
+ * Renders a styled story card and returns a PNG buffer.
41
+ *
42
+ * @param {object} opts
43
+ * @param {string} [opts.title] - large headline text
44
+ * @param {string} [opts.body] - smaller body/subtitle text below the title
45
+ * @param {string} [opts.footer] - small branding/footer line pinned to the bottom
46
+ * @param {'sunset'|'purple'|'ocean'|'forest'|'midnight'|'fire'} [opts.gradient='purple'] - preset background gradient
47
+ * @param {[string|number, string|number]} [opts.colors] - explicit [from, to] ARGB hex colors, overrides `gradient`
48
+ * @param {'vertical'|'diagonal'} [opts.direction='vertical'] - gradient direction
49
+ * @param {number} [opts.width=1080] - canvas width (WA status default is 1080x1920)
50
+ * @param {number} [opts.height=1920] - canvas height
51
+ * @returns {Promise<Buffer>} PNG image buffer, ready to pass as `{ image: buffer }`
52
+ */
53
+ export const renderStoryCard = async (opts = {}) => {
54
+ const jimpLib = await getJimp();
55
+ const { Jimp, HorizontalAlign, VerticalAlign, loadFont, measureTextHeight, fonts } = jimpLib;
56
+ const width = opts.width || 1080;
57
+ const height = opts.height || 1920;
58
+ const direction = opts.direction || 'vertical';
59
+ const [from, to] = opts.colors || DEFAULT_GRADIENTS[opts.gradient] || DEFAULT_GRADIENTS.purple;
60
+ const colorFrom = typeof from === 'string' ? parseInt(from.replace('#', ''), 16) : from;
61
+ const colorTo = typeof to === 'string' ? parseInt(to.replace('#', ''), 16) : to;
62
+ const image = new Jimp({ width, height, color: colorFrom });
63
+ // Paint the gradient pixel-row-by-row (vertical) or via a diagonal blend factor (diagonal)
64
+ for (let y = 0; y < height; y++) {
65
+ for (let x = 0; x < width; x++) {
66
+ const t = direction === 'diagonal' ? (x / width + y / height) / 2 : y / height;
67
+ image.setPixelColor(lerpColor(colorFrom, colorTo, t, jimpLib), x, y);
68
+ }
69
+ }
70
+ const titleFont = await loadFont(fonts.SANS_64_WHITE);
71
+ const bodyFont = await loadFont(fonts.SANS_32_WHITE);
72
+ const footerFont = await loadFont(fonts.SANS_16_WHITE);
73
+ const padding = Math.round(width * 0.08);
74
+ const contentWidth = width - padding * 2;
75
+ let cursorY = Math.round(height * 0.38);
76
+ if (opts.title) {
77
+ const titleHeight = measureTextHeight(titleFont, opts.title, contentWidth);
78
+ image.print({
79
+ font: titleFont,
80
+ x: padding,
81
+ y: cursorY,
82
+ text: { text: opts.title, alignmentX: HorizontalAlign.LEFT, alignmentY: VerticalAlign.TOP },
83
+ maxWidth: contentWidth
84
+ });
85
+ cursorY += titleHeight + Math.round(height * 0.03);
86
+ }
87
+ if (opts.body) {
88
+ image.print({
89
+ font: bodyFont,
90
+ x: padding,
91
+ y: cursorY,
92
+ text: { text: opts.body, alignmentX: HorizontalAlign.LEFT, alignmentY: VerticalAlign.TOP },
93
+ maxWidth: contentWidth
94
+ });
95
+ }
96
+ if (opts.footer) {
97
+ image.print({
98
+ font: footerFont,
99
+ x: padding,
100
+ y: height - Math.round(height * 0.06),
101
+ text: { text: opts.footer, alignmentX: HorizontalAlign.LEFT, alignmentY: VerticalAlign.TOP },
102
+ maxWidth: contentWidth
103
+ });
104
+ }
105
+ return image.getBuffer('image/png');
106
+ };
107
+ export const STORY_GRADIENTS = Object.keys(DEFAULT_GRADIENTS);
package/package.json CHANGED
@@ -1,18 +1,18 @@
1
1
  {
2
2
  "name": "@vinzsocket/baileys",
3
3
  "type": "module",
4
- "version": "3.2.7",
4
+ "version": "3.2.9",
5
5
  "description": "A WebSockets library for interacting with WhatsApp Web",
6
6
  "keywords": [
7
7
  "whatsapp",
8
8
  "automation"
9
9
  ],
10
- "homepage": "https://github.com/VinzSocket/Baileys/",
10
+ "homepage": "https://github.com/VinzSocket/baileys/",
11
11
  "repository": {
12
- "url": "git@github.com:VinzSocket/Baileys.git"
12
+ "url": "git@github.com:VinzSocket/baileys.git"
13
13
  },
14
14
  "license": "MIT",
15
- "author": "Alvin-B2T",
15
+ "author": "vinzsocket",
16
16
  "main": "lib/index.js",
17
17
  "types": "lib/index.d.ts",
18
18
  "files": [
@@ -61,7 +61,7 @@
61
61
  "@types/ws": "^8.0.0",
62
62
  "@typescript-eslint/eslint-plugin": "^8",
63
63
  "@typescript-eslint/parser": "^8",
64
- "@whiskeysockets/eslint-config": "^1.0.0",
64
+ "@vinzsocket/eslint-config": "^1.0.0",
65
65
  "conventional-changelog": "^7.1.1",
66
66
  "conventional-changelog-angular": "^8.0.0",
67
67
  "esbuild-register": "^3.6.0",