@vanzxy/baileys 2.0.0 → 2.0.2
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/NOTICE.md +1 -2
- package/README.md +63 -2
- package/lib/{Utils → Builders}/A2UI.js +2 -2
- package/lib/Builders/AIRich.js +2047 -0
- package/lib/Builders/Album.js +71 -0
- package/lib/Builders/Button.js +883 -0
- package/lib/Builders/ButtonV2.js +144 -0
- package/lib/Builders/ButtonV3.js +184 -0
- package/lib/Builders/Carousel.js +111 -0
- package/lib/Builders/Contact.js +83 -0
- package/lib/Builders/Location.js +151 -0
- package/lib/Builders/NativeFlow.js +210 -0
- package/lib/Builders/Poll.js +128 -0
- package/lib/Builders/VanzxyBaileys.js +146 -0
- package/lib/Builders/index.js +15 -0
- package/lib/Builders/shared.js +652 -0
- package/lib/Utils/MessageBuilder.js +2 -4405
- package/lib/Utils/index.d.ts +2 -0
- package/lib/Utils/index.js +0 -1
- package/lib/index.js +3 -0
- package/package.json +4 -7
- package/postinstall-banner.js +51 -25
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { BaseBuilder, generateWAMessageFromContent, prepareWAMessageMedia, generateMessageIDV2, crypto } from './shared.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Album/media-group builder — bundles 2+ images/videos into one WhatsApp
|
|
5
|
+
* album. Fully handled by the existing `content.album` shorthand at the
|
|
6
|
+
* socket layer (see Socket/messages-send.js, `if ('album' in content)`):
|
|
7
|
+
* it sends the `albumMessage` cover then each item as a linked follow-up
|
|
8
|
+
* with a configurable delay, so this builder only needs to shape the array.
|
|
9
|
+
*/
|
|
10
|
+
class Album extends BaseBuilder {
|
|
11
|
+
#client;
|
|
12
|
+
|
|
13
|
+
/** @param {import('../../WAProto/index.js').WASocket} client Active Baileys socket (must expose `sendMessage`). */
|
|
14
|
+
constructor(client) {
|
|
15
|
+
super();
|
|
16
|
+
if (!client) throw new Error('Socket is required');
|
|
17
|
+
this.#client = client;
|
|
18
|
+
|
|
19
|
+
this._items = [];
|
|
20
|
+
this._delayMs;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Append an image. @param {string|Buffer} path Url or buffer. */
|
|
24
|
+
addImage(path, { caption, ...options } = {}) {
|
|
25
|
+
if (!path) throw new Error('Url or buffer needed');
|
|
26
|
+
const image = Buffer.isBuffer(path) ? path : { url: path };
|
|
27
|
+
this._items.push({ image, ...(caption !== undefined && { caption }), ...options });
|
|
28
|
+
return this;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Append a video. @param {string|Buffer} path Url or buffer. */
|
|
32
|
+
addVideo(path, { caption, ...options } = {}) {
|
|
33
|
+
if (!path) throw new Error('Url or buffer needed');
|
|
34
|
+
const video = Buffer.isBuffer(path) ? path : { url: path };
|
|
35
|
+
this._items.push({ video, ...(caption !== undefined && { caption }), ...options });
|
|
36
|
+
return this;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Append several images/videos at once, in `{image|video, caption?}` shape (bypasses addImage()/addVideo()'s shorthand). */
|
|
40
|
+
addItems(items) {
|
|
41
|
+
if (!Array.isArray(items) || !items.length) throw new TypeError('addItems(items) requires a non-empty array');
|
|
42
|
+
items.forEach((item) => this._items.push(item));
|
|
43
|
+
return this;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Remove every item added so far. */
|
|
47
|
+
clearItems() {
|
|
48
|
+
this._items = [];
|
|
49
|
+
return this;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Delay in ms between each follow-up item after the album cover (default: `config.albumDelayMs` or 1500ms). */
|
|
53
|
+
setDelay(ms) {
|
|
54
|
+
if (typeof ms !== 'number' || ms < 0) throw new TypeError('setDelay(ms) requires a non-negative number');
|
|
55
|
+
this._delayMs = ms;
|
|
56
|
+
return this;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** @returns {{album: Record<string, any>[]}} The `sendMessage()`-shaped payload, without sending it. */
|
|
60
|
+
build() {
|
|
61
|
+
if (this._items.length < 2) throw new Error('Album requires at least 2 items (use addImage()/addVideo(), images+videos combined)');
|
|
62
|
+
return { album: this._items };
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** Build and send via the socket's `sendMessage()`. */
|
|
66
|
+
async send(jid, options = {}) {
|
|
67
|
+
return this.#client.sendMessage(jid, this.build(), { ...(this._delayMs !== undefined && { delayMs: this._delayMs }), ...options });
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export { Album };
|