@vinzsocket/baileys 3.2.8 → 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 +2 -2
- package/lib/Socket/dugong.js +11 -0
- package/lib/Socket/messages-send.js +3 -2
- package/lib/Utils/index.js +1 -0
- package/lib/Utils/messages.js +43 -1
- package/lib/Utils/story-card.js +107 -0
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
**A lightweight WebSocket library for WhatsApp Web Multi-Device**
|
|
6
6
|
|
|
7
7
|
[](https://github.com/VinzSocket/Baileys)
|
|
8
|
-

|
|
9
9
|

|
|
10
10
|
|
|
11
11
|
</div>
|
|
@@ -20,7 +20,7 @@ npm install @vinzsocket/baileys
|
|
|
20
20
|
|
|
21
21
|
---
|
|
22
22
|
|
|
23
|
-
## 🔔 Changelog v3.2.
|
|
23
|
+
## 🔔 Changelog v3.2.9
|
|
24
24
|
|
|
25
25
|
### ✅ Group Status V4 — Semua Media + Caption
|
|
26
26
|
|
package/lib/Socket/dugong.js
CHANGED
|
@@ -385,6 +385,17 @@ export class ExtendedMessageBuilder {
|
|
|
385
385
|
);
|
|
386
386
|
if (s.caption) media.imageMessage.caption = s.caption;
|
|
387
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 },
|
|
395
|
+
{ upload: this.waUploadToServer }
|
|
396
|
+
);
|
|
397
|
+
if (s.caption) media.imageMessage.caption = s.caption;
|
|
398
|
+
innerMessage = media;
|
|
388
399
|
} else if (s.video) {
|
|
389
400
|
const media = await this.utils.prepareWAMessageMedia(
|
|
390
401
|
{ video: s.video },
|
|
@@ -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(() => {
|
package/lib/Utils/index.js
CHANGED
package/lib/Utils/messages.js
CHANGED
|
@@ -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.
|
|
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/
|
|
10
|
+
"homepage": "https://github.com/VinzSocket/baileys/",
|
|
11
11
|
"repository": {
|
|
12
|
-
"url": "git@github.com:
|
|
12
|
+
"url": "git@github.com:VinzSocket/baileys.git"
|
|
13
13
|
},
|
|
14
14
|
"license": "MIT",
|
|
15
|
-
"author": "
|
|
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
|
-
"@
|
|
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",
|