@vinzsocket/baileys 3.2.6 → 3.2.7

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
@@ -4,64 +4,327 @@
4
4
 
5
5
  **A lightweight WebSocket library for WhatsApp Web Multi-Device**
6
6
 
7
- [![GitHub Repo](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.6-blue)
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)
9
9
  ![Node.js](https://img.shields.io/badge/Node.js-%3E%3D20-green)
10
- ![NPM](https://img.shields.io/badge/npm-@vinzsocket/baileys-red)
11
10
 
12
11
  </div>
13
12
 
14
13
  ---
15
14
 
16
- ## 📖 Tentang Harps Baileys
15
+ ## 📦 Install
17
16
 
18
- **Harps Baileys** (`@vinzsocket/baileys`) adalah fork/modifikasi dari library Baileys yang dioptimalkan untuk performa tinggi dan kemudahan penggunaan.
17
+ ```bash
18
+ npm install @vinzsocket/baileys
19
+ ```
20
+
21
+ ---
22
+
23
+ ## 🔔 Changelog v3.2.6
24
+
25
+ ### ✅ Group Status V2 — Semua Media + Caption
26
+
27
+ `handleGroupStory` sekarang support semua tipe media dengan caption:
28
+
29
+ | Tipe | Field | Caption |
30
+ |---|---|---|
31
+ | Teks | `text` | — |
32
+ | Foto | `image` | ✅ `caption` |
33
+ | Video | `video` | ✅ `caption` |
34
+ | Audio voice note | `audio` + `ptt: true` | — |
35
+ | Audio musik | `audio` + `ptt: false` | — |
36
+ | Sticker | `sticker` | — |
37
+ | Dokumen | `document` | ✅ `caption` |
38
+
39
+ ### ✅ Multi-Select Message
40
+
41
+ Satu pesan dengan beberapa tombol dropdown (`single_select`) sekaligus.
42
+ Tiap tombol buka bottom sheet sendiri dengan sections & rows berbeda.
43
+
44
+ ### ✅ Nested List Message
45
+
46
+ Legacy `listMessage` dengan auto-flatten nested rows jadi sections terpisah.
47
+
48
+ ### ✅ NF V7 Button Builders
49
+
50
+ Export semua 12 native flow button builder dari `dugong.js`.
51
+
52
+ ### ✅ buildInteractiveAdditionalNodes
53
+
54
+ Tambah handler `groupStatusMessageV2` — inject `<meta is_vsn2="1">` di grup.
55
+
56
+ ---
57
+
58
+ ## 👥 Group Status V2
59
+
60
+ ### Teks
61
+
62
+ ```js
63
+ await conn.sendMessage(groupJid, {
64
+ groupStatusMessage: {
65
+ text: '📢 Pengumuman penting dari admin!'
66
+ }
67
+ })
68
+ ```
69
+
70
+ ### Teks dengan Background Color
71
+
72
+ ```js
73
+ await conn.sendMessage(groupJid, {
74
+ groupStatusMessage: {
75
+ text: 'Status dengan background merah',
76
+ backgroundColor: 0xFFE53935, // ARGB
77
+ textArgb: 0xFFFFFFFF,
78
+ font: 1 // 0-5
79
+ }
80
+ })
81
+ ```
82
+
83
+ ### Foto dengan Caption
84
+
85
+ ```js
86
+ await conn.sendMessage(groupJid, {
87
+ groupStatusMessage: {
88
+ image: { url: 'https://example.com/photo.jpg' },
89
+ caption: '📸 Foto kegiatan hari ini!'
90
+ }
91
+ })
92
+
93
+ // Atau pakai Buffer
94
+ await conn.sendMessage(groupJid, {
95
+ groupStatusMessage: {
96
+ image: fs.readFileSync('./photo.jpg'),
97
+ caption: 'Caption foto'
98
+ }
99
+ })
100
+ ```
101
+
102
+ ### Video dengan Caption
103
+
104
+ ```js
105
+ await conn.sendMessage(groupJid, {
106
+ groupStatusMessage: {
107
+ video: { url: 'https://example.com/video.mp4' },
108
+ caption: '🎬 Video kegiatan',
109
+ seconds: 30 // opsional, durasi
110
+ }
111
+ })
112
+ ```
113
+
114
+ ### GIF
19
115
 
20
- **Repository Resmi:** [https://github.com/VinzSocket/Baileys](https://github.com/VinzSocket/Baileys)
116
+ ```js
117
+ await conn.sendMessage(groupJid, {
118
+ groupStatusMessage: {
119
+ video: { url: 'https://example.com/anim.mp4' },
120
+ gifPlayback: true
121
+ }
122
+ })
123
+ ```
21
124
 
22
- Library ini memungkinkan kamu berinteraksi langsung dengan **WhatsApp Web Multi-Device** menggunakan WebSocket tanpa browser.
125
+ ### Audio Voice Note
126
+
127
+ ```js
128
+ await conn.sendMessage(groupJid, {
129
+ groupStatusMessage: {
130
+ audio: { url: 'https://example.com/voice.ogg' },
131
+ ptt: true, // voice note
132
+ seconds: 15 // durasi opsional
133
+ }
134
+ })
135
+ ```
136
+
137
+ ### Audio Musik
138
+
139
+ ```js
140
+ await conn.sendMessage(groupJid, {
141
+ groupStatusMessage: {
142
+ audio: { url: 'https://example.com/music.mp3' },
143
+ ptt: false, // bukan voice note
144
+ mimetype: 'audio/mp4' // atau 'audio/mpeg'
145
+ }
146
+ })
147
+ ```
148
+
149
+ ### Sticker
150
+
151
+ ```js
152
+ await conn.sendMessage(groupJid, {
153
+ groupStatusMessage: {
154
+ sticker: { url: 'https://example.com/sticker.webp' }
155
+ }
156
+ })
157
+ ```
158
+
159
+ ### Dokumen dengan Caption
160
+
161
+ ```js
162
+ await conn.sendMessage(groupJid, {
163
+ groupStatusMessage: {
164
+ document: { url: 'https://example.com/file.pdf' },
165
+ mimetype: 'application/pdf',
166
+ fileName: 'Laporan.pdf',
167
+ caption: '📄 Laporan bulan ini'
168
+ }
169
+ })
170
+ ```
23
171
 
24
172
  ---
25
173
 
26
- ## ✨ Features
27
-
28
- ### 🔐 Authentication
29
- - QR Code Login
30
- - Pairing Code (tanpa scan QR)
31
- - Multi-Device Support
32
- - Session Management
33
- - Auto Reconnect
34
-
35
- ### 💬 Messaging
36
- - Text, Image, Video, Audio, Document, Sticker
37
- - Reaction, Mention, Quoted Message
38
- - View Once, Edit Message, Revoke Message
39
- - Location, Contact, Poll
40
-
41
- ### 👥 Group Management
42
- - Create Group
43
- - Update Subject, Description, PP
44
- - Add/Remove Member
45
- - Promote/Demote Admin
46
- - Group Settings
47
-
48
- ### 🔒 Security
49
- - End-to-End Encryption (Signal Protocol)
50
- - Sender Key Distribution
51
-
52
- ### 🔄 Synchronization
53
- - Chat, Contact, Group, Device & History Sync
54
- - Presence (online, typing, etc.)
55
-
56
- ### 🛠️ Lainnya
57
- - Media Upload/Download
58
- - Link Preview
59
- - Business API Support
60
- - Full TypeScript Support
174
+ ## ⚡ Multi-Select Message
175
+
176
+ Satu pesan, beberapa tombol dropdown. Tiap tombol buka bottom sheet sendiri.
177
+
178
+ ```js
179
+ await conn.sendMessage(jid, {
180
+ multiSelectMessage: {
181
+ title: '⚙️ Konfigurasi Karakter',
182
+ footer: 'Pilih semua opsi',
183
+ selectors: [
184
+ {
185
+ displayText: '⚔️ Pilih Senjata',
186
+ sections: [
187
+ {
188
+ title: '🗡️ Melee',
189
+ rows: [
190
+ { id: 'sword', title: '⚔️ Iron Sword', description: '40 ATK' },
191
+ { id: 'axe', title: '🪓 Battle Axe', description: '60 ATK' }
192
+ ]
193
+ },
194
+ {
195
+ title: '🏹 Ranged',
196
+ rows: [
197
+ { id: 'bow', title: '🏹 Busur', description: '30 ATK' },
198
+ { id: 'xbow', title: '🔫 Crossbow', description: '55 ATK' }
199
+ ]
200
+ }
201
+ ]
202
+ },
203
+ {
204
+ displayText: '🛡️ Pilih Armor',
205
+ sections: [
206
+ {
207
+ title: '🧥 Light',
208
+ rows: [
209
+ { id: 'cloth', title: '👕 Cloth', description: '10 DEF' },
210
+ { id: 'leather', title: '🥼 Leather', description: '25 DEF' }
211
+ ]
212
+ }
213
+ ]
214
+ }
215
+ ],
216
+ // Tombol tambahan opsional
217
+ extraButtons: [
218
+ { name: 'quick_reply', buttonParamsJson: JSON.stringify({ display_text: '✅ Konfirmasi', id: 'confirm' }) }
219
+ ]
220
+ }
221
+ }, { quoted: msg })
222
+ ```
61
223
 
62
224
  ---
63
225
 
64
- ## 📦 Installation
226
+ ## 📝 Nested List Message
65
227
 
66
- ```bash
67
- npm install @vinzsocket/baileys
228
+ Legacy `listMessage` dengan nested sections otomatis.
229
+
230
+ ```js
231
+ await conn.sendMessage(jid, {
232
+ nestedListMessage: {
233
+ title: '🛒 Harps Shop',
234
+ buttonText: '📋 Buka Katalog',
235
+ footer: 'Pilih item',
236
+ sections: [
237
+ {
238
+ title: '⚔️ Senjata',
239
+ rows: [
240
+ // Flat row biasa
241
+ { rowId: 'dagger', title: '🗡️ Dagger', description: '25 ATK' },
242
+ // Nested row → otomatis jadi section baru "🏹 Jarak Jauh"
243
+ {
244
+ title: '🏹 Jarak Jauh',
245
+ rows: [
246
+ { rowId: 'bow', title: '🏹 Busur', description: '30 ATK' },
247
+ { rowId: 'xbow', title: '🔫 Crossbow', description: '55 ATK' }
248
+ ]
249
+ }
250
+ ]
251
+ }
252
+ ]
253
+ }
254
+ }, { quoted: msg })
255
+ ```
256
+
257
+ ---
258
+
259
+ ## ⚡ NF V7 Button Builders
260
+
261
+ ```js
262
+ import {
263
+ nfButtonUrl, nfButtonCall, nfButtonCopy,
264
+ nfButtonReminder, nfButtonCancelReminder,
265
+ nfButtonAddress, nfButtonLocation,
266
+ nfButtonQuickReply, nfButtonSingleSelect,
267
+ nfButtonMultiSelect,
268
+ nfButtonReviewPay, nfButtonReviewOrder, nfButtonMPM
269
+ } from '@vinzsocket/baileys/lib/Socket/dugong.js'
270
+
271
+ await conn.sendMessage(jid, {
272
+ interactiveMessage: {
273
+ title: '🎛️ Mixed Buttons',
274
+ footer: 'Harps-MD',
275
+ buttons: [
276
+ nfButtonQuickReply({ id: 'ok', displayText: '✅ OK' }),
277
+ nfButtonUrl({ displayText: '🌐 Website', url: 'https://example.com' }),
278
+ nfButtonCopy({ displayText: '📋 Salin', copyCode: 'KODE123' }),
279
+ nfButtonSingleSelect({
280
+ displayText: '📋 Pilih',
281
+ sections: [
282
+ { title: 'Opsi', rows: [
283
+ { id: 'a', title: 'Opsi A' },
284
+ { id: 'b', title: 'Opsi B' }
285
+ ]}
286
+ ]
287
+ })
288
+ ]
289
+ }
290
+ }, { quoted: msg })
291
+ ```
292
+
293
+ | Builder | Nama Proto | Fungsi |
294
+ |---|---|---|
295
+ | `nfButtonUrl` | `cta_url` | Buka URL |
296
+ | `nfButtonCall` | `cta_call` | Telepon |
297
+ | `nfButtonCopy` | `cta_copy` | Salin kode |
298
+ | `nfButtonReminder` | `cta_reminder` | Set reminder |
299
+ | `nfButtonCancelReminder` | `cta_cancel_reminder` | Batalkan reminder |
300
+ | `nfButtonAddress` | `address_message` | Isi & kirim alamat |
301
+ | `nfButtonLocation` | `send_location` | Kirim GPS |
302
+ | `nfButtonQuickReply` | `quick_reply` | Balas cepat |
303
+ | `nfButtonSingleSelect` | `single_select` | 1 dropdown |
304
+ | `nfButtonMultiSelect` | `single_select` ×N | Beberapa dropdown |
305
+ | `nfButtonReviewPay` | `review_and_pay` | Payment flow |
306
+ | `nfButtonReviewOrder` | `review_order` | Review order |
307
+ | `nfButtonMPM` | `mpm` | Multi-product |
308
+
309
+ ---
310
+
311
+ ## ⚠️ additionalNodes
312
+
313
+ Semua interactive/list message butuh binary node hint. Harps-Baileys inject otomatis — tidak perlu relay manual.
314
+
315
+ Kalau perlu relay manual:
316
+
317
+ ```js
318
+ import { buildInteractiveAdditionalNodes } from '@vinzsocket/baileys/lib/Utils/messages.js'
319
+
320
+ await relayMessage(jid, msg.message, {
321
+ messageId: msg.key.id,
322
+ additionalNodes: buildInteractiveAdditionalNodes(jid, msg.message)
323
+ })
324
+ ```
325
+
326
+ ---
327
+
328
+ ## 📄 License
329
+
330
+ MIT — © VinzSocket
@@ -1,75 +1,205 @@
1
1
  import type { proto } from '../../WAProto/index.js';
2
2
 
3
- export type WAMediaUploadFunction = (stream: Buffer | NodeJS.ReadableStream, options?: any) => Promise<{ url: string; directPath: string }>;
3
+ export type WAMediaUploadFunction = (stream: Buffer | NodeJS.ReadableStream, options?: {
4
+ fileEncSha256?: Buffer;
5
+ mediaType?: string;
6
+ newsletter?: boolean;
7
+ }) => Promise<{
8
+ url: string;
9
+ directPath: string;
10
+ }>;
11
+
12
+ export interface WAMessageContentGenerationOptions {
13
+ upload?: WAMediaUploadFunction;
14
+ mediaCache?: any;
15
+ options?: any;
16
+ logger?: any;
17
+ }
4
18
 
5
19
  export interface ExtendedMessageUtils {
6
- prepareWAMessageMedia(media: any, options: any): Promise<any>;
7
- generateWAMessageContent(content: any, options: any): Promise<any>;
8
- generateWAMessageFromContent(jid: string, content: any, options?: any): any;
9
- generateWAMessage(jid: string, content: any, options?: any): Promise<any>;
10
- generateMessageID(): string;
20
+ prepareWAMessageMedia: (media: any, options: WAMessageContentGenerationOptions) => Promise<any>;
21
+ generateWAMessageContent: (content: any, options: WAMessageContentGenerationOptions) => Promise<any>;
22
+ generateWAMessageFromContent: (jid: string, content: any, options?: any) => any;
23
+ generateWAMessage: (jid: string, content: any, options?: any) => Promise<any>;
24
+ generateMessageID: () => string;
11
25
  }
12
26
 
13
- // ─── NF V7 Button Builders ────────────────────────────────────────────────────
14
- export declare function nfButtonUrl(opts: { id?: string; displayText: string; url: string; merchantUrl?: string }): proto.Message.InteractiveMessage.INativeFlowButton;
15
- export declare function nfButtonCall(opts: { id?: string; displayText: string; phoneNumber: string }): proto.Message.InteractiveMessage.INativeFlowButton;
16
- export declare function nfButtonCopy(opts: { id?: string; displayText: string; copyCode: string }): proto.Message.InteractiveMessage.INativeFlowButton;
17
- export declare function nfButtonReminder(opts: { id?: string; displayText: string; title: string; notes: string; startTime: number; endTime: number; timezone?: string }): proto.Message.InteractiveMessage.INativeFlowButton;
18
- export declare function nfButtonCancelReminder(opts: { id?: string; displayText: string; reminderKey: string }): proto.Message.InteractiveMessage.INativeFlowButton;
19
- export declare function nfButtonAddress(opts: { id?: string; displayText: string; label?: string }): proto.Message.InteractiveMessage.INativeFlowButton;
20
- export declare function nfButtonLocation(opts: { id?: string; displayText: string }): proto.Message.InteractiveMessage.INativeFlowButton;
21
- export declare function nfButtonQuickReply(opts: { id?: string; displayText: string; payload?: string }): proto.Message.InteractiveMessage.INativeFlowButton;
22
-
23
- export interface SelectRow { id?: string; rowId?: string; title: string; description?: string; }
24
- export interface SelectSection { title?: string; highlight_label?: string; rows: SelectRow[]; }
25
- export declare function nfButtonSingleSelect(opts: { id?: string; displayText: string; sections: SelectSection[] }): proto.Message.InteractiveMessage.INativeFlowButton;
26
-
27
- export interface MultiSelectSelector { id?: string; displayText: string; sections: SelectSection[]; }
28
- /** Build array of single_select buttons — satu per selector */
29
- export declare function nfButtonMultiSelect(selectors: MultiSelectSelector[]): proto.Message.InteractiveMessage.INativeFlowButton[];
30
-
31
- export declare function nfButtonReviewPay(opts: { id?: string; currency?: string; totalAmount1000: number; subtotal?: any; tax?: any; items?: any[]; merchant?: any }): proto.Message.InteractiveMessage.INativeFlowButton;
32
- export declare function nfButtonReviewOrder(opts: { id?: string; referenceId: string; type?: string; orderId: string }): proto.Message.InteractiveMessage.INativeFlowButton;
33
- export declare function nfButtonMPM(opts: { id?: string; sections: Array<{ title?: string; productItems: Array<{ productId?: string; product_id?: string }> }> }): proto.Message.InteractiveMessage.INativeFlowButton;
34
-
35
- // ─── Nested List ──────────────────────────────────────────────────────────────
36
- export interface NestedListRow { rowId?: string; id?: string; title: string; description?: string; rows?: NestedListRow[]; }
37
- export interface NestedListSection { title?: string; rows: NestedListRow[]; }
38
- export interface NestedListMessageOptions { title: string; buttonText: string; footer?: string; sections: NestedListSection[]; }
39
- export declare function buildNestedListMessage(opts: NestedListMessageOptions): { listMessage: proto.Message.IListMessage };
40
-
41
- // ─── Multi-Select ─────────────────────────────────────────────────────────────
42
- export interface MultiSelectMessageContent {
27
+ export interface StickerMessage {
28
+ url: string;
29
+ fileSha256: Buffer | string;
30
+ fileEncSha256: Buffer | string;
31
+ mediaKey: Buffer | string;
32
+ mimetype: string;
33
+ directPath: string;
34
+ fileLength: number | string;
35
+ mediaKeyTimestamp: number | string;
36
+ isAnimated?: boolean;
37
+ stickerSentTs?: number | string;
38
+ isAvatar?: boolean;
39
+ isAiSticker?: boolean;
40
+ isLottie?: boolean;
41
+ }
42
+
43
+ export interface PaymentMessage {
44
+ amount: number;
45
+ currency?: string;
46
+ from?: string;
47
+ expiry?: number;
48
+ sticker?: { stickerMessage: StickerMessage };
49
+ note?: string;
50
+ background?: {
51
+ id?: string;
52
+ fileLength?: string;
53
+ width?: number;
54
+ height?: number;
55
+ mimetype?: string;
56
+ placeholderArgb?: number;
57
+ textArgb?: number;
58
+ subtextArgb?: number;
59
+ };
60
+ }
61
+
62
+ export interface ProductMessage {
43
63
  title: string;
64
+ description: string;
65
+ thumbnail: Buffer | { url: string };
66
+ productId: string;
67
+ retailerId: string;
68
+ url: string;
69
+ body?: string;
44
70
  footer?: string;
71
+ buttons?: proto.Message.InteractiveMessage.INativeFlowButton[];
72
+ priceAmount1000?: number | null;
73
+ currencyCode?: string;
74
+ }
75
+
76
+ export interface ExternalAdReply {
77
+ title?: string;
78
+ body?: string;
79
+ mediaType?: number;
80
+ thumbnailUrl?: string;
81
+ mediaUrl?: string;
82
+ sourceUrl?: string;
83
+ showAdAttribution?: boolean;
84
+ renderLargerThumbnail?: boolean;
85
+ [key: string]: any;
86
+ }
87
+
88
+ export interface InteractiveMessage {
45
89
  header?: string;
46
- image?: any;
47
- video?: any;
48
- thumbnail?: any;
49
- /** Tiap selector = 1 tombol dropdown terpisah */
50
- selectors: MultiSelectSelector[];
51
- /** Tombol tambahan (quick_reply, url, dll) di samping selector */
52
- extraButtons?: proto.Message.InteractiveMessage.INativeFlowButton[];
53
- contextInfo?: Record<string, any>;
90
+ title: string;
91
+ footer?: string;
92
+ thumbnail?: string | Buffer | { url: string };
93
+ image?: string | Buffer | { url: string };
94
+ video?: string | Buffer | { url: string };
95
+ document?: string | Buffer | { url: string };
96
+ mimetype?: string;
97
+ fileName?: string;
98
+ jpegThumbnail?: string | Buffer | { url: string };
99
+ contextInfo?: {
100
+ mentionedJid?: string[];
101
+ forwardingScore?: number;
102
+ isForwarded?: boolean;
103
+ externalAdReply?: ExternalAdReply;
104
+ [key: string]: any;
105
+ };
106
+ externalAdReply?: ExternalAdReply;
107
+ buttons?: proto.Message.InteractiveMessage.INativeFlowButton[];
108
+ nativeFlowMessage?: {
109
+ messageParamsJson?: string;
110
+ buttons?: proto.Message.InteractiveMessage.INativeFlowButton[];
111
+ [key: string]: any;
112
+ };
54
113
  }
55
114
 
56
- export type ExtendedMessageType =
57
- | 'PAYMENT' | 'PRODUCT' | 'INTERACTIVE'
58
- | 'ALBUM' | 'EVENT' | 'POLL_RESULT'
59
- | 'GROUP_STORY' | 'NESTED_LIST' | 'MULTI_SELECT';
115
+ export interface AlbumItem {
116
+ image?: string | Buffer | { url: string; caption?: string };
117
+ video?: string | Buffer | { url: string; caption?: string };
118
+ }
119
+
120
+ export interface EventMessageLocation {
121
+ degreesLatitude: number;
122
+ degreesLongitude: number;
123
+ name: string;
124
+ }
125
+
126
+ export interface EventMessage {
127
+ isCanceled?: boolean;
128
+ name: string;
129
+ description: string;
130
+ location?: EventMessageLocation;
131
+ joinLink?: string;
132
+ startTime?: string | number;
133
+ endTime?: string | number;
134
+ extraGuestsAllowed?: boolean;
135
+ }
136
+
137
+ export interface PollVote {
138
+ optionName: string;
139
+ optionVoteCount: string | number;
140
+ }
141
+
142
+ export interface PollResultMessage {
143
+ name: string;
144
+ pollVotes: PollVote[];
145
+ }
146
+
147
+ export interface GroupStatusMessage {
148
+ message?: any;
149
+ image?: string | Buffer | { url: string };
150
+ video?: string | Buffer | { url: string };
151
+ text?: string;
152
+ caption?: string;
153
+ document?: string | Buffer | { url: string };
154
+ [key: string]: any;
155
+ }
156
+
157
+ export interface ExtendedMessageContent {
158
+ requestPaymentMessage?: PaymentMessage;
159
+ productMessage?: ProductMessage;
160
+ interactiveMessage?: InteractiveMessage;
161
+ albumMessage?: AlbumItem[];
162
+ eventMessage?: EventMessage;
163
+ pollResultMessage?: PollResultMessage;
164
+ groupStatusMessage?: GroupStatusMessage;
165
+ sender?: string;
166
+ }
167
+
168
+ export type ExtendedMessageType = 'PAYMENT' | 'PRODUCT' | 'INTERACTIVE' | 'ALBUM' | 'EVENT' | 'POLL_RESULT' | 'GROUP_STORY';
60
169
 
61
170
  export declare class ExtendedMessageBuilder {
171
+ utils: ExtendedMessageUtils;
172
+ relayMessage: (jid: string, content: any, options?: any) => Promise<any>;
173
+ waUploadToServer: WAMediaUploadFunction;
174
+ bail: {
175
+ generateWAMessageContent: ExtendedMessageUtils['generateWAMessageContent'];
176
+ generateMessageID: () => string;
177
+ getContentType: (msg: any) => string;
178
+ };
179
+
62
180
  constructor(utils: ExtendedMessageUtils, waUploadToServer: WAMediaUploadFunction, relayMessageFn: (jid: string, content: any, options?: any) => Promise<any>);
63
- detectType(content: any): ExtendedMessageType | null;
64
- handlePayment(content: any, quoted?: any): Promise<any>;
65
- handleProduct(content: any, jid: string, quoted?: any): Promise<any>;
66
- handleInteractive(content: any, jid: string, quoted?: any, options?: any): Promise<any>;
67
- handleMultiSelect(content: any, jid: string, quoted?: any, options?: any): Promise<any>;
68
- handleNestedList(content: any, jid: string, quoted?: any): Promise<any>;
69
- handleAlbum(content: any, jid: string, quoted?: any): Promise<any>;
70
- handleEvent(content: any, jid: string, quoted?: any): Promise<any>;
71
- handlePollResult(content: any, jid: string, quoted?: any): Promise<any>;
72
- handleGroupStory(content: any, jid: string, quoted?: any): Promise<any>;
181
+
182
+ detectType(content: ExtendedMessageContent): ExtendedMessageType | null;
183
+
184
+ handlePayment(content: { requestPaymentMessage: PaymentMessage }, quoted?: proto.IWebMessageInfo | null): Promise<{
185
+ requestPaymentMessage: proto.Message.RequestPaymentMessage;
186
+ }>;
187
+
188
+ handleProduct(content: { productMessage: ProductMessage }, jid: string, quoted?: proto.IWebMessageInfo | null): Promise<{
189
+ viewOnceMessage: { message: { interactiveMessage: any } };
190
+ }>;
191
+
192
+ handleInteractive(content: { interactiveMessage: InteractiveMessage }, jid: string, quoted?: proto.IWebMessageInfo | null, options?: { mentions?: string[] }): Promise<{
193
+ interactiveMessage: any;
194
+ }>;
195
+
196
+ handleAlbum(content: { albumMessage: AlbumItem[] }, jid: string, quoted?: proto.IWebMessageInfo | null): Promise<any>;
197
+
198
+ handleEvent(content: { eventMessage: EventMessage }, jid: string, quoted?: proto.IWebMessageInfo | null): Promise<any>;
199
+
200
+ handlePollResult(content: { pollResultMessage: PollResultMessage }, jid: string, quoted?: proto.IWebMessageInfo | null): Promise<any>;
201
+
202
+ handleGroupStory(content: { groupStatusMessage: GroupStatusMessage }, jid: string, quoted?: proto.IWebMessageInfo | null): Promise<any>;
73
203
  }
74
204
 
75
205
  export default ExtendedMessageBuilder;
@@ -1,11 +1,6 @@
1
- // dugong.js — extended message builders
2
- // Handles: Request Payment, Product, Interactive (NF V7 full), Album, Event,
3
- // Poll Result, Group Status V2, Nested Legacy List, Multi-Select (chained list engine).
4
- //
5
- // Native Flow V7 button shapes:
6
- // cta_url, cta_call, cta_copy, cta_reminder, cta_cancel_reminder,
7
- // address_message, send_location, quick_reply, single_select,
8
- // review_and_pay, review_order, mpm
1
+ // dugong.js — Harps-Baileys extended message builders v3.2.0
2
+ // Handles: Payment, Product, Interactive (NF V7 full), Album, Event,
3
+ // Poll Result, Group Status V2, Nested Legacy List, Multi-Select.
9
4
 
10
5
  import { randomBytes } from 'crypto';
11
6
  import { proto } from '../../WAProto/index.js';
@@ -18,43 +13,36 @@ export const nfButtonUrl = ({ id, displayText, url, merchantUrl }) => ({
18
13
  buttonParamsJson: JSON.stringify({ display_text: displayText, url, merchant_url: merchantUrl || url }),
19
14
  ...(id ? { id } : {})
20
15
  });
21
-
22
16
  export const nfButtonCall = ({ id, displayText, phoneNumber }) => ({
23
17
  name: 'cta_call',
24
18
  buttonParamsJson: JSON.stringify({ display_text: displayText, phone_number: phoneNumber }),
25
19
  ...(id ? { id } : {})
26
20
  });
27
-
28
21
  export const nfButtonCopy = ({ id, displayText, copyCode }) => ({
29
22
  name: 'cta_copy',
30
23
  buttonParamsJson: JSON.stringify({ display_text: displayText, copy_code: copyCode }),
31
24
  ...(id ? { id } : {})
32
25
  });
33
-
34
26
  export const nfButtonReminder = ({ id, displayText, title, notes, startTime, endTime, timezone = 'Asia/Jakarta' }) => ({
35
27
  name: 'cta_reminder',
36
28
  buttonParamsJson: JSON.stringify({ display_text: displayText, title, notes, start_timestamp: startTime, end_timestamp: endTime, timezone }),
37
29
  ...(id ? { id } : {})
38
30
  });
39
-
40
31
  export const nfButtonCancelReminder = ({ id, displayText, reminderKey }) => ({
41
32
  name: 'cta_cancel_reminder',
42
33
  buttonParamsJson: JSON.stringify({ display_text: displayText, reminder_key: reminderKey }),
43
34
  ...(id ? { id } : {})
44
35
  });
45
-
46
36
  export const nfButtonAddress = ({ id, displayText, label = '' }) => ({
47
37
  name: 'address_message',
48
38
  buttonParamsJson: JSON.stringify({ display_text: displayText, label }),
49
39
  ...(id ? { id } : {})
50
40
  });
51
-
52
41
  export const nfButtonLocation = ({ id, displayText }) => ({
53
42
  name: 'send_location',
54
43
  buttonParamsJson: JSON.stringify({ display_text: displayText }),
55
44
  ...(id ? { id } : {})
56
45
  });
57
-
58
46
  export const nfButtonQuickReply = ({ id, displayText, payload }) => ({
59
47
  name: 'quick_reply',
60
48
  buttonParamsJson: JSON.stringify({ display_text: displayText, id: id || payload || displayText }),
@@ -62,8 +50,8 @@ export const nfButtonQuickReply = ({ id, displayText, payload }) => ({
62
50
  });
63
51
 
64
52
  /**
65
- * Single-select dropdown — 1 tombol yang buka bottom sheet list.
66
- * sections: [{ title, highlight_label?, rows: [{ id, title, description? }] }]
53
+ * Single-select dropdown.
54
+ * sections: [{ title, highlight_label?, rows: [{id, title, description?}] }]
67
55
  */
68
56
  export const nfButtonSingleSelect = ({ id, displayText, sections = [] }) => ({
69
57
  name: 'single_select',
@@ -83,8 +71,9 @@ export const nfButtonSingleSelect = ({ id, displayText, sections = [] }) => ({
83
71
  });
84
72
 
85
73
  /**
86
- * Multi-select: array dari beberapa single_select button sekaligus.
87
- * selectors: [{ id?, displayText, sections: [...] }]
74
+ * Multi-select: beberapa single_select buttons sekaligus dalam 1 pesan.
75
+ * selectors: [{ id?, displayText, sections }]
76
+ * Returns: array of buttons
88
77
  */
89
78
  export const nfButtonMultiSelect = (selectors = []) =>
90
79
  selectors.map((sel, i) => nfButtonSingleSelect({
@@ -98,13 +87,11 @@ export const nfButtonReviewPay = ({ id, currency = 'IDR', totalAmount1000, subto
98
87
  buttonParamsJson: JSON.stringify({ currency, total_amount: { value: totalAmount1000, offset: 1000 }, subtotal, tax, items, order: { status: 'pending', items }, merchant }),
99
88
  ...(id ? { id } : {})
100
89
  });
101
-
102
90
  export const nfButtonReviewOrder = ({ id, referenceId, type = 'ORDER', orderId }) => ({
103
91
  name: 'review_order',
104
92
  buttonParamsJson: JSON.stringify({ reference_id: referenceId, type, order_id: orderId }),
105
93
  ...(id ? { id } : {})
106
94
  });
107
-
108
95
  export const nfButtonMPM = ({ id, sections = [] }) => ({
109
96
  name: 'mpm',
110
97
  buttonParamsJson: JSON.stringify({
@@ -119,42 +106,27 @@ export const nfButtonMPM = ({ id, sections = [] }) => ({
119
106
  // ─── Nested Legacy List Helper ────────────────────────────────────────────────
120
107
 
121
108
  /**
122
- * Build raw proto listMessage payload dengan nested row flattening.
123
- * Row yang punya field `rows` sendiri otomatis dijadikan section baru.
124
- *
125
- * sections: [{ title, rows: [ {rowId,title,description?} | {title, rows:[...]} ] }]
109
+ * Build proto listMessage payload.
110
+ * Row yang punya field `rows` sendiri otomatis di-flatten jadi section baru.
126
111
  */
127
112
  export const buildNestedListMessage = ({ title, buttonText, footer = '', sections = [] }) => {
128
113
  const flat = [];
129
- for (const section of sections) {
130
- const topRows = [];
131
- const childSections = [];
132
- for (const row of (section.rows || [])) {
114
+ for (const sec of sections) {
115
+ const topRows = [], childSecs = [];
116
+ for (const row of (sec.rows || [])) {
133
117
  if (Array.isArray(row.rows) && row.rows.length > 0) {
134
- childSections.push({
118
+ childSecs.push({
135
119
  title: row.title || '',
136
- rows: row.rows.map(r => ({
137
- rowId: r.rowId || r.id || '',
138
- title: r.title || '',
139
- description: r.description || ''
140
- }))
120
+ rows: row.rows.map(r => ({ rowId: r.rowId || r.id || '', title: r.title || '', description: r.description || '' }))
141
121
  });
142
122
  } else {
143
123
  topRows.push({ rowId: row.rowId || row.id || '', title: row.title || '', description: row.description || '' });
144
124
  }
145
125
  }
146
- if (topRows.length > 0) flat.push({ title: section.title || '', rows: topRows });
147
- for (const cs of childSections) flat.push(cs);
126
+ if (topRows.length) flat.push({ title: sec.title || '', rows: topRows });
127
+ for (const cs of childSecs) flat.push(cs);
148
128
  }
149
- return {
150
- listMessage: {
151
- title,
152
- description: footer,
153
- buttonText,
154
- listType: 1, // SINGLE_SELECT
155
- sections: flat
156
- }
157
- };
129
+ return { listMessage: { title, description: footer, buttonText, listType: 1, sections: flat } };
158
130
  };
159
131
 
160
132
  // ─── ExtendedMessageBuilder ───────────────────────────────────────────────────
@@ -194,12 +166,9 @@ export class ExtendedMessageBuilder {
194
166
  }
195
167
  return {
196
168
  requestPaymentMessage: proto.Message.RequestPaymentMessage.fromObject({
197
- expiryTimestamp: data.expiry || 0,
198
- amount1000: data.amount || 0,
199
- currencyCodeIso4217: data.currency || 'IDR',
200
- requestFrom: data.from || '0@s.whatsapp.net',
201
- noteMessage: notes,
202
- background: data.background ?? { id: 'DEFAULT', placeholderArgb: 0xFFF0F0F0 }
169
+ expiryTimestamp: data.expiry || 0, amount1000: data.amount || 0,
170
+ currencyCodeIso4217: data.currency || 'IDR', requestFrom: data.from || '0@s.whatsapp.net',
171
+ noteMessage: notes, background: data.background ?? { id: 'DEFAULT', placeholderArgb: 0xFFF0F0F0 }
203
172
  })
204
173
  };
205
174
  }
@@ -214,17 +183,7 @@ export class ExtendedMessageBuilder {
214
183
  const { imageMessage } = await this.utils.generateWAMessageContent({ image: { url: thumbnail.url } }, { upload: this.waUploadToServer });
215
184
  productImage = imageMessage;
216
185
  }
217
- return {
218
- viewOnceMessage: {
219
- message: {
220
- interactiveMessage: {
221
- body: { text: body }, footer: { text: footer },
222
- header: { title, hasMediaAttachment: true, productMessage: { product: { productImage, productId, title, description, currencyCode, priceAmount1000, retailerId, url, productImageCount: 1 }, businessOwnerJid: '0@s.whatsapp.net' } },
223
- nativeFlowMessage: { buttons }
224
- }
225
- }
226
- }
227
- };
186
+ return { viewOnceMessage: { message: { interactiveMessage: { body: { text: body }, footer: { text: footer }, header: { title, hasMediaAttachment: true, productMessage: { product: { productImage, productId, title, description, currencyCode, priceAmount1000, retailerId, url, productImageCount: 1 }, businessOwnerJid: '0@s.whatsapp.net' } }, nativeFlowMessage: { buttons } } } } };
228
187
  }
229
188
 
230
189
  async handleInteractive(content, jid, quoted, options = {}) {
@@ -242,61 +201,63 @@ export class ExtendedMessageBuilder {
242
201
  if (fileName && media.documentMessage) media.documentMessage.fileName = fileName;
243
202
  if (mimetype && media.documentMessage) media.documentMessage.mimetype = mimetype;
244
203
  }
245
-
246
204
  let im = { body: { text: title || '' }, footer: { text: footer || '' } };
247
- if (buttons && buttons.length > 0) {
248
- im.nativeFlowMessage = { buttons };
249
- if (nativeFlowMessage) im.nativeFlowMessage = { ...im.nativeFlowMessage, ...nativeFlowMessage };
250
- } else if (nativeFlowMessage) {
251
- im.nativeFlowMessage = nativeFlowMessage;
252
- }
205
+ if (buttons?.length) { im.nativeFlowMessage = { buttons }; if (nativeFlowMessage) im.nativeFlowMessage = { ...im.nativeFlowMessage, ...nativeFlowMessage }; }
206
+ else if (nativeFlowMessage) im.nativeFlowMessage = nativeFlowMessage;
253
207
  im.header = media ? { title: header || '', hasMediaAttachment: true, ...media } : { title: header || '', hasMediaAttachment: false };
254
-
255
208
  let ci = { forwardingScore: contextInfo.forwardingScore || 0, isForwarded: contextInfo.isForwarded || false, ...contextInfo, mentionedJid: normalizeMentions(contextInfo.mentionedJid || options.mentions || []) };
256
209
  if (externalAdReply) ci.externalAdReply = { title: '', body: '', mediaType: 1, thumbnailUrl: '', mediaUrl: '', sourceUrl: '', showAdAttribution: false, renderLargerThumbnail: false, ...externalAdReply };
257
210
  if (!Array.isArray(ci.mentionedJid)) ci.mentionedJid = [ci.mentionedJid].filter(Boolean);
258
- if (Object.keys(ci).length > 0) im.contextInfo = ci;
211
+ if (Object.keys(ci).length) im.contextInfo = ci;
259
212
  return { interactiveMessage: im };
260
213
  }
261
214
 
262
215
  /**
263
- * Multi-Select — satu pesan dengan BEBERAPA tombol single_select terpisah.
264
- * Tiap selector membuka bottom sheet sendiri dengan sections & rows di dalamnya.
216
+ * Multi-Select — 1 pesan dengan BEBERAPA tombol single_select.
217
+ * Tiap selector = 1 tombol dropdown terpisah, buka bottom sheet sendiri.
265
218
  *
266
- * content.multiSelectMessage = {
267
- * title, footer?, header?, image?,
268
- * selectors: [{ id?, displayText, sections: [{title, rows:[{id,title,description?}]}] }],
269
- * extraButtons?: [ nfButtonQuickReply(...), ... ]
270
- * }
219
+ * Gunakan dari plugin:
220
+ * conn.sendMessage(jid, {
221
+ * multiSelectMessage: {
222
+ * title: 'Judul',
223
+ * footer: 'Footer',
224
+ * selectors: [
225
+ * { displayText: '⚔️ Senjata', sections: [{ title: 'Melee', rows: [{ id:'sword', title:'Pedang' }] }] },
226
+ * { displayText: '🛡️ Armor', sections: [{ title: 'Light', rows: [{ id:'cloth', title:'Cloth' }] }] },
227
+ * ]
228
+ * }
229
+ * })
271
230
  */
272
231
  async handleMultiSelect(content, jid, quoted, options = {}) {
273
232
  const { title, footer, image, video, thumbnail, selectors = [], extraButtons = [], contextInfo = {}, header } = content.multiSelectMessage;
274
- const buttons = [
275
- ...nfButtonMultiSelect(selectors),
276
- ...extraButtons
277
- ];
278
- return this.handleInteractive({
279
- interactiveMessage: { title, footer, image, video, thumbnail, header, contextInfo, buttons }
280
- }, jid, quoted, options);
233
+ const buttons = [...nfButtonMultiSelect(selectors), ...extraButtons];
234
+ return this.handleInteractive({ interactiveMessage: { title, footer, image, video, thumbnail, header, contextInfo, buttons } }, jid, quoted, options);
281
235
  }
282
236
 
283
237
  /**
284
- * Nested List — legacy listMessage dengan auto-flatten nested rows.
238
+ * Nested List — legacy listMessage.
239
+ * Row yang punya `.rows` otomatis di-flatten jadi section baru.
285
240
  *
286
- * content.nestedListMessage = {
287
- * title, buttonText, footer?,
288
- * sections: [{ title, rows: [ flat_row | { title, rows:[...] } ] }]
289
- * }
241
+ * conn.sendMessage(jid, {
242
+ * nestedListMessage: {
243
+ * title: 'Menu',
244
+ * buttonText: 'Buka',
245
+ * footer: '...',
246
+ * sections: [
247
+ * { title: 'Kategori A', rows: [
248
+ * { rowId: 'a1', title: 'Item A1' },
249
+ * { title: 'Sub-Kategori', rows: [ ← ini jadi section baru
250
+ * { rowId: 'b1', title: 'Item B1' },
251
+ * ]}
252
+ * ]}
253
+ * ]
254
+ * }
255
+ * })
290
256
  */
291
257
  async handleNestedList(content, jid, quoted) {
292
258
  const payload = buildNestedListMessage(content.nestedListMessage);
293
259
  return await this.utils.generateWAMessageFromContent(jid, {
294
- viewOnceMessage: {
295
- message: {
296
- messageContextInfo: { deviceListMetadata: {}, deviceListMetadataVersion: 2 },
297
- ...payload
298
- }
299
- }
260
+ viewOnceMessage: { message: { messageContextInfo: { deviceListMetadata: {}, deviceListMetadataVersion: 2 }, ...payload } }
300
261
  }, { quoted });
301
262
  }
302
263
 
@@ -309,20 +270,11 @@ export class ExtendedMessageBuilder {
309
270
  expectedVideoCount: array.filter(a => Object.hasOwn(a, 'video')).length
310
271
  }
311
272
  }, { userJid: this.utils.generateMessageID().split('@')[0] + '@s.whatsapp.net', quoted, upload: this.waUploadToServer });
312
-
313
273
  await this.relayMessage(jid, album.message, { messageId: album.key.id });
314
-
315
274
  for (const item of array) {
316
275
  const img = await this.utils.generateWAMessage(jid, item, { upload: this.waUploadToServer });
317
- img.message.messageContextInfo = {
318
- messageSecret: randomBytes(32),
319
- messageAssociation: { associationType: 1, parentMessageKey: album.key },
320
- participant: jid, forwardingScore: 0, isForwarded: false
321
- };
322
- await this.relayMessage(jid, img.message, {
323
- messageId: img.key.id,
324
- quoted: { key: { remoteJid: album.key.remoteJid, id: album.key.id, fromMe: true, participant: this.utils.generateMessageID().split('@')[0] + '@s.whatsapp.net' }, message: album.message }
325
- });
276
+ img.message.messageContextInfo = { messageSecret: randomBytes(32), messageAssociation: { associationType: 1, parentMessageKey: album.key }, participant: jid, forwardingScore: 0, isForwarded: false };
277
+ await this.relayMessage(jid, img.message, { messageId: img.key.id, quoted: { key: { remoteJid: album.key.remoteJid, id: album.key.id, fromMe: true, participant: this.utils.generateMessageID().split('@')[0] + '@s.whatsapp.net' }, message: album.message } });
326
278
  }
327
279
  return album;
328
280
  }
@@ -330,20 +282,7 @@ export class ExtendedMessageBuilder {
330
282
  async handleEvent(content, jid, quoted) {
331
283
  const e = content.eventMessage;
332
284
  const msg = await this.utils.generateWAMessageFromContent(jid, {
333
- viewOnceMessage: {
334
- message: {
335
- messageContextInfo: { deviceListMetadata: {}, deviceListMetadataVersion: 2, messageSecret: randomBytes(32), supportPayload: JSON.stringify({ version: 2, is_ai_message: true, should_show_system_message: true, ticket_id: randomBytes(16).toString('hex') }) },
336
- eventMessage: {
337
- contextInfo: { mentionedJid: [jid], participant: jid, remoteJid: 'status@broadcast' },
338
- isCanceled: e.isCanceled || false, name: e.name, description: e.description,
339
- location: e.location || { degreesLatitude: 0, degreesLongitude: 0, name: 'Location' },
340
- joinLink: e.joinLink || '',
341
- startTime: typeof e.startTime === 'string' ? parseInt(e.startTime, 10) : e.startTime || Date.now(),
342
- endTime: typeof e.endTime === 'string' ? parseInt(e.endTime, 10) : e.endTime || Date.now() + 3600000,
343
- extraGuestsAllowed: e.extraGuestsAllowed !== false
344
- }
345
- }
346
- }
285
+ viewOnceMessage: { message: { messageContextInfo: { deviceListMetadata: {}, deviceListMetadataVersion: 2, messageSecret: randomBytes(32), supportPayload: JSON.stringify({ version: 2, is_ai_message: true, should_show_system_message: true, ticket_id: randomBytes(16).toString('hex') }) }, eventMessage: { contextInfo: { mentionedJid: [jid], participant: jid, remoteJid: 'status@broadcast' }, isCanceled: e.isCanceled || false, name: e.name, description: e.description, location: e.location || { degreesLatitude: 0, degreesLongitude: 0, name: 'Location' }, joinLink: e.joinLink || '', startTime: typeof e.startTime === 'string' ? parseInt(e.startTime, 10) : e.startTime || Date.now(), endTime: typeof e.endTime === 'string' ? parseInt(e.endTime, 10) : e.endTime || Date.now() + 3600000, extraGuestsAllowed: e.extraGuestsAllowed !== false } } }
347
286
  }, { quoted });
348
287
  await this.relayMessage(jid, msg.message, { messageId: msg.key.id });
349
288
  return msg;
@@ -352,34 +291,143 @@ export class ExtendedMessageBuilder {
352
291
  async handlePollResult(content, jid, quoted) {
353
292
  const p = content.pollResultMessage;
354
293
  const msg = await this.utils.generateWAMessageFromContent(jid, {
355
- pollResultSnapshotMessage: {
356
- name: p.name,
357
- pollVotes: p.pollVotes.map(v => ({ optionName: v.optionName, optionVoteCount: typeof v.optionVoteCount === 'number' ? v.optionVoteCount.toString() : v.optionVoteCount }))
358
- }
294
+ pollResultSnapshotMessage: { name: p.name, pollVotes: p.pollVotes.map(v => ({ optionName: v.optionName, optionVoteCount: typeof v.optionVoteCount === 'number' ? v.optionVoteCount.toString() : v.optionVoteCount })) }
359
295
  }, { userJid: this.utils.generateMessageID().split('@')[0] + '@s.whatsapp.net', quoted });
360
296
  await this.relayMessage(jid, msg.message, { messageId: msg.key.id });
361
297
  return msg;
362
298
  }
363
299
 
364
300
  /**
365
- * Group Status V2 — story ke grup.
366
- * 3 mode:
367
- * { message: <inner WAMessage> } → pakai langsung
368
- * { raw: <msgPayload> } → relay langsung
369
- * { image/video/text/... } → generate dulu
301
+ * Group Status V2 — kirim story/status ke grup.
302
+ *
303
+ * Format groupStatusMessage:
304
+ *
305
+ * // Teks biasa
306
+ * { text: 'Halo grup!' }
307
+ *
308
+ * // Foto dengan caption
309
+ * { image: Buffer | { url: '...' }, caption: 'Caption foto' }
310
+ *
311
+ * // Video dengan caption
312
+ * { video: Buffer | { url: '...' }, caption: 'Caption video', gifPlayback?: true }
313
+ *
314
+ * // Audio (voice note)
315
+ * { audio: Buffer | { url: '...' }, ptt: true, seconds: 10 }
316
+ *
317
+ * // Audio biasa (musik)
318
+ * { audio: Buffer | { url: '...' }, ptt: false, mimetype: 'audio/mp4' }
319
+ *
320
+ * // Sticker
321
+ * { sticker: Buffer | { url: '...' } }
322
+ *
323
+ * // Dokumen
324
+ * { document: Buffer | { url: '...' }, mimetype: 'application/pdf', fileName: 'file.pdf', caption: 'Caption' }
325
+ *
326
+ * // Pre-built WAMessage (advanced)
327
+ * { message: { imageMessage: { ... } } }
328
+ *
329
+ * // Raw relay (forward story)
330
+ * { raw: <msgPayload> }
331
+ *
332
+ * Semua mode support field tambahan:
333
+ * backgroundColor?: number (ARGB hex, untuk teks/audio)
334
+ * textArgb?: number
335
+ * font?: number (0-5)
370
336
  */
371
- async handleGroupStory(content, jid, quoted) {
372
- const storyData = content.groupStatusMessage;
337
+ async handleGroupStory(content, jid) {
338
+ const s = content.groupStatusMessage;
339
+
340
+ // Mode 1: raw relay langsung
341
+ if (s.raw) {
342
+ return await this.relayMessage(jid, s.raw, {
343
+ messageId: this.bail.generateMessageID()
344
+ });
345
+ }
346
+
347
+ // Mode 2: inner WAMessage sudah disiapkan
348
+ if (s.message) {
349
+ return await this.relayMessage(jid, {
350
+ groupStatusMessageV2: { message: s.message }
351
+ }, { messageId: this.bail.generateMessageID() });
352
+ }
353
+
354
+ // Mode 3: generate dari media/teks
373
355
  let innerMessage;
374
- if (storyData.message) {
375
- innerMessage = storyData.message;
376
- } else if (storyData.raw) {
377
- return await this.relayMessage(jid, storyData.raw, { messageId: this.bail.generateMessageID() });
356
+
357
+ if (s.text || (!s.image && !s.video && !s.audio && !s.sticker && !s.document)) {
358
+ // Teks — pakai extendedTextMessage supaya support backgroundColor & font
359
+ const textMsg = {
360
+ extendedTextMessage: {
361
+ text: s.text || s.caption || '',
362
+ ...(typeof s.backgroundColor !== 'undefined' ? { backgroundArgb: s.backgroundColor } : {}),
363
+ ...(typeof s.textArgb !== 'undefined' ? { textArgb: s.textArgb } : {}),
364
+ ...(typeof s.font !== 'undefined' ? { font: s.font } : {})
365
+ }
366
+ };
367
+ innerMessage = textMsg;
368
+ } else if (s.image) {
369
+ // Foto dengan caption
370
+ const media = await this.utils.prepareWAMessageMedia(
371
+ { image: s.image, ...(s.caption ? { caption: s.caption } : {}) },
372
+ { upload: this.waUploadToServer }
373
+ );
374
+ if (s.caption) media.imageMessage.caption = s.caption;
375
+ innerMessage = media;
376
+ } else if (s.video) {
377
+ // Video dengan caption, support gifPlayback
378
+ 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
+ },
385
+ { upload: this.waUploadToServer }
386
+ );
387
+ if (s.caption) media.videoMessage.caption = s.caption;
388
+ if (s.gifPlayback) media.videoMessage.gifPlayback = true;
389
+ innerMessage = media;
390
+ } else if (s.audio) {
391
+ // Audio — voice note (ptt: true) atau musik (ptt: false)
392
+ const media = await this.utils.prepareWAMessageMedia(
393
+ {
394
+ audio: s.audio,
395
+ ptt: s.ptt !== false,
396
+ ...(s.seconds ? { seconds: s.seconds } : {}),
397
+ ...(s.mimetype ? { mimetype: s.mimetype } : {})
398
+ },
399
+ { upload: this.waUploadToServer }
400
+ );
401
+ innerMessage = media;
402
+ } else if (s.sticker) {
403
+ // Sticker
404
+ const media = await this.utils.prepareWAMessageMedia(
405
+ { sticker: s.sticker },
406
+ { upload: this.waUploadToServer }
407
+ );
408
+ innerMessage = media;
409
+ } else if (s.document) {
410
+ // Dokumen dengan caption
411
+ const media = await this.utils.prepareWAMessageMedia(
412
+ {
413
+ document: s.document,
414
+ mimetype: s.mimetype || 'application/octet-stream',
415
+ fileName: s.fileName || 'file',
416
+ ...(s.caption ? { caption: s.caption } : {})
417
+ },
418
+ { upload: this.waUploadToServer }
419
+ );
420
+ if (s.caption && media.documentMessage) media.documentMessage.caption = s.caption;
421
+ if (s.fileName && media.documentMessage) media.documentMessage.fileName = s.fileName;
422
+ innerMessage = media;
378
423
  } else {
379
- const generated = await this.bail.generateWAMessageContent(storyData, { upload: this.waUploadToServer });
380
- innerMessage = generated;
424
+ // Fallback: generate via generateWAMessageContent
425
+ innerMessage = await this.bail.generateWAMessageContent(s, { upload: this.waUploadToServer });
381
426
  }
382
- return await this.relayMessage(jid, { groupStatusMessageV2: { message: innerMessage } }, { messageId: this.bail.generateMessageID() });
427
+
428
+ return await this.relayMessage(jid, {
429
+ groupStatusMessageV2: { message: innerMessage }
430
+ }, { messageId: this.bail.generateMessageID() });
383
431
  }
384
432
  }
385
433
 
@@ -387,32 +387,24 @@ export const buildInteractiveAdditionalNodes = (jid, m) => {
387
387
  const nodes = [];
388
388
  const group = isJidGroup(jid);
389
389
  if (inner.listMessage) {
390
- // Legacy listMessage (sendList, sendNestedList)
391
390
  nodes.push({
392
391
  tag: 'biz',
393
392
  attrs: {},
394
393
  content: [{ tag: 'list', attrs: { type: 'product_list', v: '2' } }]
395
394
  });
396
395
  } else if (inner.interactiveMessage || inner.buttonsMessage || inner.templateMessage || inner.productMessage) {
397
- // Native flow (sendMultiButton, sendListButton, sendCard, multiSelectMessage, dll)
398
396
  nodes.push({
399
397
  tag: 'biz',
400
398
  attrs: {},
401
- content: [
402
- {
403
- tag: 'interactive',
404
- attrs: { type: 'native_flow', v: '1' },
405
- content: [{ tag: 'native_flow', attrs: { name: 'mixed', v: '9' } }]
406
- }
407
- ]
399
+ content: [{
400
+ tag: 'interactive',
401
+ attrs: { type: 'native_flow', v: '1' },
402
+ content: [{ tag: 'native_flow', attrs: { name: 'mixed', v: '9' } }]
403
+ }]
408
404
  });
409
405
  } else if (inner.groupStatusMessageV2) {
410
- // Group story V2 — butuh hint is_vsn2 supaya render sebagai story di grup
411
- if (group) {
412
- nodes.push({ tag: 'meta', attrs: { is_vsn2: '1' } });
413
- }
406
+ if (group) nodes.push({ tag: 'meta', attrs: { is_vsn2: '1' } });
414
407
  }
415
- // DM (bukan grup) butuh bot node tambahan supaya interactive render
416
408
  if (nodes.length > 0 && !group) {
417
409
  nodes.push({ tag: 'bot', attrs: { biz_bot: '1' } });
418
410
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vinzsocket/baileys",
3
3
  "type": "module",
4
- "version": "3.2.6",
4
+ "version": "3.2.7",
5
5
  "description": "A WebSockets library for interacting with WhatsApp Web",
6
6
  "keywords": [
7
7
  "whatsapp",
@@ -12,7 +12,7 @@
12
12
  "url": "git@github.com:VinzSocket/Baileys.git"
13
13
  },
14
14
  "license": "MIT",
15
- "author": "VinzSocket",
15
+ "author": "Alvin-B2T",
16
16
  "main": "lib/index.js",
17
17
  "types": "lib/index.d.ts",
18
18
  "files": [
@@ -136,4 +136,4 @@
136
136
  "engines": {
137
137
  "node": ">=20.0.0"
138
138
  }
139
- }
139
+ }