@vinzsocket/baileys 3.0.15 → 3.0.25
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/Types/Message.d.ts +49 -1
- package/lib/Utils/messages.js +124 -1
- 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/Types/Message.d.ts
CHANGED
|
@@ -85,6 +85,54 @@ type ViewOnce = {
|
|
|
85
85
|
type Editable = {
|
|
86
86
|
edit?: WAMessageKey;
|
|
87
87
|
};
|
|
88
|
+
/** A single native flow button, already normalized, or one of the common legacy shapes
|
|
89
|
+
* that Baileys will auto-normalize into a native flow button. */
|
|
90
|
+
export type WAButtonShape = {
|
|
91
|
+
/** native flow button name, e.g. 'quick_reply', 'cta_url', 'cta_call', 'cta_copy', 'single_select' */
|
|
92
|
+
name: string;
|
|
93
|
+
buttonParamsJson: string;
|
|
94
|
+
} | {
|
|
95
|
+
buttonId: string;
|
|
96
|
+
buttonText: {
|
|
97
|
+
displayText: string;
|
|
98
|
+
};
|
|
99
|
+
type?: number;
|
|
100
|
+
} | {
|
|
101
|
+
id: string;
|
|
102
|
+
text?: string;
|
|
103
|
+
displayText?: string;
|
|
104
|
+
} | {
|
|
105
|
+
index?: number;
|
|
106
|
+
urlButton?: {
|
|
107
|
+
displayText: string;
|
|
108
|
+
url: string;
|
|
109
|
+
};
|
|
110
|
+
callButton?: {
|
|
111
|
+
displayText: string;
|
|
112
|
+
phoneNumber: string;
|
|
113
|
+
};
|
|
114
|
+
quickReplyButton?: {
|
|
115
|
+
displayText: string;
|
|
116
|
+
id: string;
|
|
117
|
+
};
|
|
118
|
+
};
|
|
119
|
+
type WithNativeFlowButtons = {
|
|
120
|
+
/** Buttons to render as a native flow (button/native flow/bottom sheet) interactive message.
|
|
121
|
+
* Accepts native flow shape, or common legacy shapes (auto-normalized). */
|
|
122
|
+
buttons?: WAButtonShape[];
|
|
123
|
+
/** alias of `buttons`, kept for compatibility with bots migrating from templateButtons */
|
|
124
|
+
templateButtons?: WAButtonShape[];
|
|
125
|
+
/** alias of `buttons`, the most explicit/preferred name for native flow buttons */
|
|
126
|
+
interactiveButtons?: WAButtonShape[];
|
|
127
|
+
/** header title shown above the body text when buttons/sections are present */
|
|
128
|
+
title?: string;
|
|
129
|
+
/** footer text shown below the body text */
|
|
130
|
+
footer?: string;
|
|
131
|
+
/** list sections, renders as a `listMessage` instead of buttons */
|
|
132
|
+
sections?: proto.Message.ListMessage.ISection[];
|
|
133
|
+
/** button label that opens the list, used together with `sections` */
|
|
134
|
+
buttonText?: string;
|
|
135
|
+
};
|
|
88
136
|
type WithDimensions = {
|
|
89
137
|
width?: number;
|
|
90
138
|
height?: number;
|
|
@@ -204,7 +252,7 @@ export type AnyRegularMessageContent = (({
|
|
|
204
252
|
businessOwnerJid?: string;
|
|
205
253
|
body?: string;
|
|
206
254
|
footer?: string;
|
|
207
|
-
} | SharePhoneNumber | RequestPhoneNumber) & ViewOnce;
|
|
255
|
+
} | SharePhoneNumber | RequestPhoneNumber) & ViewOnce & WithNativeFlowButtons;
|
|
208
256
|
export type AnyMessageContent = AnyRegularMessageContent | {
|
|
209
257
|
forward: WAMessage;
|
|
210
258
|
force?: boolean;
|
package/lib/Utils/messages.js
CHANGED
|
@@ -7,7 +7,7 @@ import { CALL_AUDIO_PREFIX, CALL_VIDEO_PREFIX, MEDIA_KEYS, URL_REGEX, WA_DEFAULT
|
|
|
7
7
|
import { WAMessageStatus, WAProto } from '../Types/index.js';
|
|
8
8
|
import { isJidGroup, isJidNewsletter, isJidStatusBroadcast, jidNormalizedUser } from '../WABinary/index.js';
|
|
9
9
|
import { sha256 } from './crypto.js';
|
|
10
|
-
import { generateMessageIDV2, getKeyAuthor, unixTimestampSeconds } from './generics.js';
|
|
10
|
+
import { generateMessageID, generateMessageIDV2, getKeyAuthor, unixTimestampSeconds } from './generics.js';
|
|
11
11
|
import { downloadContentFromMessage, encryptedStream, generateThumbnail, getAudioDuration, getAudioWaveform, getRawMediaUploadData } from './messages-media.js';
|
|
12
12
|
import { shouldIncludeReportingToken } from './reporting-utils.js';
|
|
13
13
|
const MIMETYPE_MAP = {
|
|
@@ -260,6 +260,76 @@ export const generateForwardMessageContent = (message, forceForward) => {
|
|
|
260
260
|
}
|
|
261
261
|
return content;
|
|
262
262
|
};
|
|
263
|
+
/**
|
|
264
|
+
* Normalize a community-style `buttons` / `templateButtons` / `interactiveButtons` array
|
|
265
|
+
* into WhatsApp's modern native flow button shape: `{ name, buttonParamsJson }`.
|
|
266
|
+
*
|
|
267
|
+
* Accepts, per button:
|
|
268
|
+
* - Already-normalized native flow shape: { name, buttonParamsJson }
|
|
269
|
+
* - Legacy quick-reply shape: { buttonId, buttonText: { displayText } }
|
|
270
|
+
* - Simple shape: { id, text } or { id, displayText }
|
|
271
|
+
* - Legacy template button shapes: { urlButton: { displayText, url } },
|
|
272
|
+
* { callButton: { displayText, phoneNumber } }, { quickReplyButton: { displayText, id } }
|
|
273
|
+
*/
|
|
274
|
+
export const normalizeToNativeFlowButtons = (buttons) => {
|
|
275
|
+
if (!Array.isArray(buttons)) return [];
|
|
276
|
+
return buttons.map((b) => {
|
|
277
|
+
if (!b || typeof b !== 'object') return null;
|
|
278
|
+
// Already in native flow shape
|
|
279
|
+
if (typeof b.name === 'string' && typeof b.buttonParamsJson === 'string') {
|
|
280
|
+
return { name: b.name, buttonParamsJson: b.buttonParamsJson };
|
|
281
|
+
}
|
|
282
|
+
// Legacy template button wrapper shapes
|
|
283
|
+
if (b.urlButton) {
|
|
284
|
+
return {
|
|
285
|
+
name: 'cta_url',
|
|
286
|
+
buttonParamsJson: JSON.stringify({
|
|
287
|
+
display_text: b.urlButton.displayText,
|
|
288
|
+
url: b.urlButton.url
|
|
289
|
+
})
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
if (b.callButton) {
|
|
293
|
+
return {
|
|
294
|
+
name: 'cta_call',
|
|
295
|
+
buttonParamsJson: JSON.stringify({
|
|
296
|
+
display_text: b.callButton.displayText,
|
|
297
|
+
id: b.callButton.phoneNumber
|
|
298
|
+
})
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
if (b.quickReplyButton) {
|
|
302
|
+
return {
|
|
303
|
+
name: 'quick_reply',
|
|
304
|
+
buttonParamsJson: JSON.stringify({
|
|
305
|
+
display_text: b.quickReplyButton.displayText,
|
|
306
|
+
id: b.quickReplyButton.id
|
|
307
|
+
})
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
// Legacy `buttonId` + `buttonText.displayText` (classic buttonsMessage shape)
|
|
311
|
+
if (b.buttonId || b.buttonText) {
|
|
312
|
+
return {
|
|
313
|
+
name: 'quick_reply',
|
|
314
|
+
buttonParamsJson: JSON.stringify({
|
|
315
|
+
display_text: b.buttonText?.displayText || b.displayText || '',
|
|
316
|
+
id: b.buttonId || b.id || generateMessageID()
|
|
317
|
+
})
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
// Simple { id, text } or { id, displayText }
|
|
321
|
+
if (b.id && (b.text || b.displayText)) {
|
|
322
|
+
return {
|
|
323
|
+
name: 'quick_reply',
|
|
324
|
+
buttonParamsJson: JSON.stringify({
|
|
325
|
+
display_text: b.text || b.displayText,
|
|
326
|
+
id: b.id
|
|
327
|
+
})
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
return null;
|
|
331
|
+
}).filter(Boolean);
|
|
332
|
+
};
|
|
263
333
|
export const hasNonNullishProperty = (message, key) => {
|
|
264
334
|
return (typeof message === 'object' &&
|
|
265
335
|
message !== null &&
|
|
@@ -488,6 +558,59 @@ export const generateWAMessageContent = async (message, options) => {
|
|
|
488
558
|
else {
|
|
489
559
|
m = await prepareWAMessageMedia(message, options);
|
|
490
560
|
}
|
|
561
|
+
// Convenience layer: `buttons` / `templateButtons` / `interactiveButtons` (top-level shorthand,
|
|
562
|
+
// as used by most community Baileys forks) are converted into a modern `interactiveMessage`
|
|
563
|
+
// with `nativeFlowMessage` buttons. We intentionally do NOT emit legacy `buttonsMessage` /
|
|
564
|
+
// `templateMessage` (hydratedTemplate) — those were deprecated by WhatsApp and were the
|
|
565
|
+
// subject of a spoofing security advisory upstream; native flow is the only supported path.
|
|
566
|
+
if (hasNonNullishProperty(message, 'interactiveButtons') ||
|
|
567
|
+
hasNonNullishProperty(message, 'buttons') ||
|
|
568
|
+
hasNonNullishProperty(message, 'templateButtons')) {
|
|
569
|
+
const rawButtons = message.interactiveButtons || message.buttons || message.templateButtons;
|
|
570
|
+
const nativeButtons = normalizeToNativeFlowButtons(rawButtons);
|
|
571
|
+
const existingType = Object.keys(m)[0];
|
|
572
|
+
const existingContent = existingType ? m[existingType] : undefined;
|
|
573
|
+
const interactiveMessage = {
|
|
574
|
+
body: {
|
|
575
|
+
text: message.text || message.caption || ''
|
|
576
|
+
},
|
|
577
|
+
footer: {
|
|
578
|
+
text: message.footer || ''
|
|
579
|
+
},
|
|
580
|
+
nativeFlowMessage: {
|
|
581
|
+
buttons: nativeButtons
|
|
582
|
+
}
|
|
583
|
+
};
|
|
584
|
+
// If a media/caption type was generated above (image, video, document, etc.),
|
|
585
|
+
// attach it as the interactive header so the media still displays.
|
|
586
|
+
if (existingContent && existingType !== 'extendedTextMessage' && existingType !== 'conversation') {
|
|
587
|
+
interactiveMessage.header = {
|
|
588
|
+
title: message.title || '',
|
|
589
|
+
hasMediaAttachment: true,
|
|
590
|
+
...existingContent
|
|
591
|
+
};
|
|
592
|
+
}
|
|
593
|
+
else if (message.title) {
|
|
594
|
+
interactiveMessage.header = {
|
|
595
|
+
title: message.title,
|
|
596
|
+
hasMediaAttachment: false
|
|
597
|
+
};
|
|
598
|
+
}
|
|
599
|
+
m = { interactiveMessage };
|
|
600
|
+
}
|
|
601
|
+
else if (hasNonNullishProperty(message, 'sections')) {
|
|
602
|
+
// Convenience: top-level `sections` shorthand -> listMessage (single select list)
|
|
603
|
+
m = {
|
|
604
|
+
listMessage: {
|
|
605
|
+
sections: message.sections,
|
|
606
|
+
buttonText: message.buttonText,
|
|
607
|
+
title: message.title,
|
|
608
|
+
footerText: message.footer,
|
|
609
|
+
description: message.text || message.caption,
|
|
610
|
+
listType: proto.Message.ListMessage.ListType.SINGLE_SELECT
|
|
611
|
+
}
|
|
612
|
+
};
|
|
613
|
+
}
|
|
491
614
|
if (hasOptionalProperty(message, 'viewOnce') && !!message.viewOnce) {
|
|
492
615
|
m = { viewOnceMessage: { message: m } };
|
|
493
616
|
}
|
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.25",
|
|
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
|
+
}
|