@vinzsocket/baileys 3.0.20 → 3.0.30
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/engine-requirements.js +18 -1
- package/lib/Utils/messages.js +36 -0
- package/package.json +2 -2
package/engine-requirements.js
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
const major =
|
|
1
|
+
const [major, minor] = process.versions.node.split('.').map(Number);
|
|
2
|
+
|
|
3
|
+
// require(esm) is only stable on Node 20.19.0+ and 22.12.0+ (and any 23.x+).
|
|
4
|
+
// Below that, `require('@vinzsocket/baileys')` from a CommonJS bot will throw ERR_REQUIRE_ESM.
|
|
5
|
+
const supportsRequireEsm =
|
|
6
|
+
major >= 23 ||
|
|
7
|
+
(major === 22 && minor >= 12) ||
|
|
8
|
+
(major === 20 && minor >= 19);
|
|
2
9
|
|
|
3
10
|
if (major < 20) {
|
|
4
11
|
console.error(
|
|
@@ -8,3 +15,13 @@ if (major < 20) {
|
|
|
8
15
|
);
|
|
9
16
|
process.exit(1);
|
|
10
17
|
}
|
|
18
|
+
|
|
19
|
+
if (!supportsRequireEsm) {
|
|
20
|
+
console.warn(
|
|
21
|
+
`\n⚠️ Node.js ${process.versions.node} detected.\n` +
|
|
22
|
+
` This package is ESM ("type": "module"). If your bot uses require() to load it,\n` +
|
|
23
|
+
` you need Node.js 20.19.0+ or 22.12.0+ for require(esm) support.\n` +
|
|
24
|
+
` Either upgrade Node.js, or load this package with dynamic import() instead:\n` +
|
|
25
|
+
` const baileys = await import('@vinzsocket/baileys')\n`
|
|
26
|
+
);
|
|
27
|
+
}
|
package/lib/Utils/messages.js
CHANGED
|
@@ -330,6 +330,40 @@ export const normalizeToNativeFlowButtons = (buttons) => {
|
|
|
330
330
|
return null;
|
|
331
331
|
}).filter(Boolean);
|
|
332
332
|
};
|
|
333
|
+
/**
|
|
334
|
+
* WhatsApp requires interactive/button/list/product messages to be wrapped in a
|
|
335
|
+
* viewOnceMessage with deviceListMetadataVersion set, or the recipient's client
|
|
336
|
+
* silently drops the buttons (the message still delivers, but renders empty/invisible).
|
|
337
|
+
* This mirrors the official Baileys `patchMessageBeforeSending` behavior.
|
|
338
|
+
*
|
|
339
|
+
* Safe to call on any message content object `m` (the shape produced internally
|
|
340
|
+
* while building a proto.IMessage, i.e. `{ interactiveMessage: {...} }` etc).
|
|
341
|
+
* No-ops if `m` is already wrapped, or doesn't need wrapping.
|
|
342
|
+
*/
|
|
343
|
+
export const patchInteractiveMessage = (m) => {
|
|
344
|
+
if (!m || typeof m !== 'object') return m;
|
|
345
|
+
const needsInteractivePatch = !m.viewOnceMessage && (
|
|
346
|
+
m.interactiveMessage ||
|
|
347
|
+
m.buttonsMessage ||
|
|
348
|
+
m.templateMessage ||
|
|
349
|
+
m.listMessage ||
|
|
350
|
+
m.productMessage
|
|
351
|
+
);
|
|
352
|
+
if (!needsInteractivePatch) return m;
|
|
353
|
+
const { messageContextInfo: existingContextInfo, ...rest } = m;
|
|
354
|
+
return {
|
|
355
|
+
viewOnceMessage: {
|
|
356
|
+
message: {
|
|
357
|
+
...rest,
|
|
358
|
+
messageContextInfo: {
|
|
359
|
+
deviceListMetadata: {},
|
|
360
|
+
deviceListMetadataVersion: 2,
|
|
361
|
+
...existingContextInfo
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
};
|
|
366
|
+
};
|
|
333
367
|
export const hasNonNullishProperty = (message, key) => {
|
|
334
368
|
return (typeof message === 'object' &&
|
|
335
369
|
message !== null &&
|
|
@@ -669,6 +703,7 @@ export const generateWAMessageContent = async (message, options) => {
|
|
|
669
703
|
m.messageContextInfo.messageSecret = randomBytes(32);
|
|
670
704
|
}
|
|
671
705
|
}
|
|
706
|
+
m = patchInteractiveMessage(m);
|
|
672
707
|
return WAProto.Message.create(m);
|
|
673
708
|
};
|
|
674
709
|
export const generateWAMessageFromContent = (jid, message, options) => {
|
|
@@ -723,6 +758,7 @@ export const generateWAMessageFromContent = (jid, message, options) => {
|
|
|
723
758
|
//ephemeralSettingTimestamp: options.ephemeralOptions.eph_setting_ts?.toString()
|
|
724
759
|
};
|
|
725
760
|
}
|
|
761
|
+
message = patchInteractiveMessage(message);
|
|
726
762
|
message = WAProto.Message.create(message);
|
|
727
763
|
const messageJSON = {
|
|
728
764
|
key: {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vinzsocket/baileys",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "3.0.
|
|
4
|
+
"version": "3.0.30",
|
|
5
5
|
"description": "A WebSockets library for interacting with WhatsApp Web",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"whatsapp",
|
|
@@ -136,4 +136,4 @@
|
|
|
136
136
|
"engines": {
|
|
137
137
|
"node": ">=20.0.0"
|
|
138
138
|
}
|
|
139
|
-
}
|
|
139
|
+
}
|