@vinzsocket/baileys 3.2.5 → 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 +221 -275
- package/lib/Socket/dugong.d.ts +18 -167
- package/lib/Socket/dugong.js +272 -532
- package/lib/Socket/messages-send.js +8 -0
- package/lib/Utils/messages.js +10 -24
- package/package.json +1 -1
package/lib/Socket/dugong.js
CHANGED
|
@@ -1,115 +1,59 @@
|
|
|
1
|
-
// dugong.js — extended message builders
|
|
2
|
-
// Handles:
|
|
3
|
-
//
|
|
4
|
-
// List Message (legacy flat + nested multi-section), Nested Section List.
|
|
5
|
-
// Ported from baileys-lily (Socket/dugong.js), adapted to ESM for Harps-Baileys.
|
|
6
|
-
// v7 native-flow button shapes fully supported: cta_url, cta_call, cta_copy, cta_reminder,
|
|
7
|
-
// cta_cancel_reminder, address_message, send_location, quick_reply, single_select,
|
|
8
|
-
// review_and_pay, review_order, mpm (Multi-Product Message).
|
|
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';
|
|
12
7
|
import { normalizeMentions } from '../Utils/mention.js';
|
|
13
8
|
|
|
14
|
-
// ───
|
|
15
|
-
/**
|
|
16
|
-
* Semua builder di bawah ini menghasilkan objek yang langsung dipakai di
|
|
17
|
-
* interactiveMessage.nativeFlowMessage.buttons[]
|
|
18
|
-
* atau di conn.sendInteractive({ buttons: [...] })
|
|
19
|
-
*/
|
|
9
|
+
// ─── NF V7 Button Builders ────────────────────────────────────────────────────
|
|
20
10
|
|
|
21
|
-
|
|
22
|
-
export const nfButtonUrl = ({ id = '', displayText, url, merchantUrl = url }) => ({
|
|
11
|
+
export const nfButtonUrl = ({ id, displayText, url, merchantUrl }) => ({
|
|
23
12
|
name: 'cta_url',
|
|
24
|
-
buttonParamsJson: JSON.stringify({
|
|
25
|
-
display_text: displayText,
|
|
26
|
-
url,
|
|
27
|
-
merchant_url: merchantUrl
|
|
28
|
-
}),
|
|
13
|
+
buttonParamsJson: JSON.stringify({ display_text: displayText, url, merchant_url: merchantUrl || url }),
|
|
29
14
|
...(id ? { id } : {})
|
|
30
15
|
});
|
|
31
|
-
|
|
32
|
-
/** Tombol telepon */
|
|
33
|
-
export const nfButtonCall = ({ id = '', displayText, phoneNumber }) => ({
|
|
16
|
+
export const nfButtonCall = ({ id, displayText, phoneNumber }) => ({
|
|
34
17
|
name: 'cta_call',
|
|
35
|
-
buttonParamsJson: JSON.stringify({
|
|
36
|
-
display_text: displayText,
|
|
37
|
-
phone_number: phoneNumber
|
|
38
|
-
}),
|
|
18
|
+
buttonParamsJson: JSON.stringify({ display_text: displayText, phone_number: phoneNumber }),
|
|
39
19
|
...(id ? { id } : {})
|
|
40
20
|
});
|
|
41
|
-
|
|
42
|
-
/** Tombol salin teks / kode */
|
|
43
|
-
export const nfButtonCopy = ({ id = '', displayText, copyCode }) => ({
|
|
21
|
+
export const nfButtonCopy = ({ id, displayText, copyCode }) => ({
|
|
44
22
|
name: 'cta_copy',
|
|
45
|
-
buttonParamsJson: JSON.stringify({
|
|
46
|
-
display_text: displayText,
|
|
47
|
-
copy_code: copyCode
|
|
48
|
-
}),
|
|
23
|
+
buttonParamsJson: JSON.stringify({ display_text: displayText, copy_code: copyCode }),
|
|
49
24
|
...(id ? { id } : {})
|
|
50
25
|
});
|
|
51
|
-
|
|
52
|
-
/** Tombol set reminder */
|
|
53
|
-
export const nfButtonReminder = ({ id = '', displayText, title, notes, startTime, endTime, timezone = 'Asia/Jakarta' }) => ({
|
|
26
|
+
export const nfButtonReminder = ({ id, displayText, title, notes, startTime, endTime, timezone = 'Asia/Jakarta' }) => ({
|
|
54
27
|
name: 'cta_reminder',
|
|
55
|
-
buttonParamsJson: JSON.stringify({
|
|
56
|
-
display_text: displayText,
|
|
57
|
-
title,
|
|
58
|
-
notes,
|
|
59
|
-
start_timestamp: startTime,
|
|
60
|
-
end_timestamp: endTime,
|
|
61
|
-
timezone
|
|
62
|
-
}),
|
|
28
|
+
buttonParamsJson: JSON.stringify({ display_text: displayText, title, notes, start_timestamp: startTime, end_timestamp: endTime, timezone }),
|
|
63
29
|
...(id ? { id } : {})
|
|
64
30
|
});
|
|
65
|
-
|
|
66
|
-
/** Tombol batalkan reminder */
|
|
67
|
-
export const nfButtonCancelReminder = ({ id = '', displayText, reminderKey }) => ({
|
|
31
|
+
export const nfButtonCancelReminder = ({ id, displayText, reminderKey }) => ({
|
|
68
32
|
name: 'cta_cancel_reminder',
|
|
69
|
-
buttonParamsJson: JSON.stringify({
|
|
70
|
-
display_text: displayText,
|
|
71
|
-
reminder_key: reminderKey
|
|
72
|
-
}),
|
|
33
|
+
buttonParamsJson: JSON.stringify({ display_text: displayText, reminder_key: reminderKey }),
|
|
73
34
|
...(id ? { id } : {})
|
|
74
35
|
});
|
|
75
|
-
|
|
76
|
-
/** Tombol isi alamat */
|
|
77
|
-
export const nfButtonAddress = ({ id = '', displayText, label = '' }) => ({
|
|
36
|
+
export const nfButtonAddress = ({ id, displayText, label = '' }) => ({
|
|
78
37
|
name: 'address_message',
|
|
79
|
-
buttonParamsJson: JSON.stringify({
|
|
80
|
-
display_text: displayText,
|
|
81
|
-
label
|
|
82
|
-
}),
|
|
38
|
+
buttonParamsJson: JSON.stringify({ display_text: displayText, label }),
|
|
83
39
|
...(id ? { id } : {})
|
|
84
40
|
});
|
|
85
|
-
|
|
86
|
-
/** Tombol kirim lokasi */
|
|
87
|
-
export const nfButtonLocation = ({ id = '', displayText }) => ({
|
|
41
|
+
export const nfButtonLocation = ({ id, displayText }) => ({
|
|
88
42
|
name: 'send_location',
|
|
89
|
-
buttonParamsJson: JSON.stringify({
|
|
90
|
-
display_text: displayText
|
|
91
|
-
}),
|
|
43
|
+
buttonParamsJson: JSON.stringify({ display_text: displayText }),
|
|
92
44
|
...(id ? { id } : {})
|
|
93
45
|
});
|
|
94
|
-
|
|
95
|
-
/** Tombol quick reply (balas cepat dengan payload custom) */
|
|
96
|
-
export const nfButtonQuickReply = ({ id = '', displayText, payload = '' }) => ({
|
|
46
|
+
export const nfButtonQuickReply = ({ id, displayText, payload }) => ({
|
|
97
47
|
name: 'quick_reply',
|
|
98
|
-
buttonParamsJson: JSON.stringify({
|
|
99
|
-
display_text: displayText,
|
|
100
|
-
id: id || payload
|
|
101
|
-
}),
|
|
48
|
+
buttonParamsJson: JSON.stringify({ display_text: displayText, id: id || payload || displayText }),
|
|
102
49
|
...(id ? { id } : {})
|
|
103
50
|
});
|
|
104
51
|
|
|
105
52
|
/**
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
* @param {string} opts.displayText - label tombol
|
|
109
|
-
* @param {Array} opts.sections - array section, format:
|
|
110
|
-
* [{ title: 'Section Title', highlight_label: '', rows: [{ id, title, description? }] }]
|
|
53
|
+
* Single-select dropdown.
|
|
54
|
+
* sections: [{ title, highlight_label?, rows: [{id, title, description?}] }]
|
|
111
55
|
*/
|
|
112
|
-
export const nfButtonSingleSelect = ({ id
|
|
56
|
+
export const nfButtonSingleSelect = ({ id, displayText, sections = [] }) => ({
|
|
113
57
|
name: 'single_select',
|
|
114
58
|
buttonParamsJson: JSON.stringify({
|
|
115
59
|
title: displayText,
|
|
@@ -117,8 +61,8 @@ export const nfButtonSingleSelect = ({ id = '', displayText, sections = [] }) =>
|
|
|
117
61
|
title: sec.title || '',
|
|
118
62
|
highlight_label: sec.highlight_label || '',
|
|
119
63
|
rows: (sec.rows || []).map(r => ({
|
|
120
|
-
id: r.id,
|
|
121
|
-
title: r.title,
|
|
64
|
+
id: r.id || r.rowId || '',
|
|
65
|
+
title: r.title || '',
|
|
122
66
|
...(r.description ? { description: r.description } : {})
|
|
123
67
|
}))
|
|
124
68
|
}))
|
|
@@ -126,41 +70,29 @@ export const nfButtonSingleSelect = ({ id = '', displayText, sections = [] }) =>
|
|
|
126
70
|
...(id ? { id } : {})
|
|
127
71
|
});
|
|
128
72
|
|
|
129
|
-
/**
|
|
130
|
-
|
|
73
|
+
/**
|
|
74
|
+
* Multi-select: beberapa single_select buttons sekaligus dalam 1 pesan.
|
|
75
|
+
* selectors: [{ id?, displayText, sections }]
|
|
76
|
+
* Returns: array of buttons
|
|
77
|
+
*/
|
|
78
|
+
export const nfButtonMultiSelect = (selectors = []) =>
|
|
79
|
+
selectors.map((sel, i) => nfButtonSingleSelect({
|
|
80
|
+
id: sel.id || `select_${i}`,
|
|
81
|
+
displayText: sel.displayText,
|
|
82
|
+
sections: sel.sections
|
|
83
|
+
}));
|
|
84
|
+
|
|
85
|
+
export const nfButtonReviewPay = ({ id, currency = 'IDR', totalAmount1000, subtotal, tax, items = [], merchant = {} }) => ({
|
|
131
86
|
name: 'review_and_pay',
|
|
132
|
-
buttonParamsJson: JSON.stringify({
|
|
133
|
-
currency,
|
|
134
|
-
total_amount: { value: totalAmount1000, offset: 1000 },
|
|
135
|
-
subtotal,
|
|
136
|
-
tax,
|
|
137
|
-
items,
|
|
138
|
-
order: {
|
|
139
|
-
status: 'pending',
|
|
140
|
-
items
|
|
141
|
-
},
|
|
142
|
-
merchant
|
|
143
|
-
}),
|
|
87
|
+
buttonParamsJson: JSON.stringify({ currency, total_amount: { value: totalAmount1000, offset: 1000 }, subtotal, tax, items, order: { status: 'pending', items }, merchant }),
|
|
144
88
|
...(id ? { id } : {})
|
|
145
89
|
});
|
|
146
|
-
|
|
147
|
-
/** Tombol review order */
|
|
148
|
-
export const nfButtonReviewOrder = ({ id = '', referenceId, type = 'ORDER', orderId }) => ({
|
|
90
|
+
export const nfButtonReviewOrder = ({ id, referenceId, type = 'ORDER', orderId }) => ({
|
|
149
91
|
name: 'review_order',
|
|
150
|
-
buttonParamsJson: JSON.stringify({
|
|
151
|
-
reference_id: referenceId,
|
|
152
|
-
type,
|
|
153
|
-
order_id: orderId
|
|
154
|
-
}),
|
|
92
|
+
buttonParamsJson: JSON.stringify({ reference_id: referenceId, type, order_id: orderId }),
|
|
155
93
|
...(id ? { id } : {})
|
|
156
94
|
});
|
|
157
|
-
|
|
158
|
-
/**
|
|
159
|
-
* Multi-Product Message (MPM) button — tampilkan katalog produk
|
|
160
|
-
* @param {Object} opts
|
|
161
|
-
* @param {Array} opts.sections - [{ title, productItems: [{ productId }] }]
|
|
162
|
-
*/
|
|
163
|
-
export const nfButtonMPM = ({ id = '', sections = [] }) => ({
|
|
95
|
+
export const nfButtonMPM = ({ id, sections = [] }) => ({
|
|
164
96
|
name: 'mpm',
|
|
165
97
|
buttonParamsJson: JSON.stringify({
|
|
166
98
|
sections: sections.map(sec => ({
|
|
@@ -171,89 +103,39 @@ export const nfButtonMPM = ({ id = '', sections = [] }) => ({
|
|
|
171
103
|
...(id ? { id } : {})
|
|
172
104
|
});
|
|
173
105
|
|
|
174
|
-
// ─── Nested
|
|
106
|
+
// ─── Nested Legacy List Helper ────────────────────────────────────────────────
|
|
107
|
+
|
|
175
108
|
/**
|
|
176
|
-
* Build
|
|
177
|
-
*
|
|
178
|
-
* Mendukung DUA mode:
|
|
179
|
-
* 1. **Flat (sendList lama)** — sections berisi rows langsung.
|
|
180
|
-
* 2. **Nested** — rows punya field `rows` sendiri (sub-list / list dalam list).
|
|
181
|
-
* Nested rows di-flatten ke satu section baru ber-title = row.title induk.
|
|
182
|
-
*
|
|
183
|
-
* @param {Object} opts
|
|
184
|
-
* @param {string} opts.title - judul pesan
|
|
185
|
-
* @param {string} opts.buttonText - label tombol buka list
|
|
186
|
-
* @param {string} [opts.footer] - footer pesan
|
|
187
|
-
* @param {Array} opts.sections - array section:
|
|
188
|
-
* {
|
|
189
|
-
* title: 'Section Title',
|
|
190
|
-
* rows: [
|
|
191
|
-
* // flat row:
|
|
192
|
-
* { rowId, title, description? },
|
|
193
|
-
* // nested row (list dalam list):
|
|
194
|
-
* { rowId?, title: 'Parent Label', rows: [{ rowId, title, description? }] }
|
|
195
|
-
* ]
|
|
196
|
-
* }
|
|
197
|
-
*
|
|
198
|
-
* @returns {Object} raw proto listMessage payload
|
|
109
|
+
* Build proto listMessage payload.
|
|
110
|
+
* Row yang punya field `rows` sendiri otomatis di-flatten jadi section baru.
|
|
199
111
|
*/
|
|
200
112
|
export const buildNestedListMessage = ({ title, buttonText, footer = '', sections = [] }) => {
|
|
201
|
-
const
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
const
|
|
205
|
-
const nestedSections = [];
|
|
206
|
-
|
|
207
|
-
for (const row of (section.rows || [])) {
|
|
113
|
+
const flat = [];
|
|
114
|
+
for (const sec of sections) {
|
|
115
|
+
const topRows = [], childSecs = [];
|
|
116
|
+
for (const row of (sec.rows || [])) {
|
|
208
117
|
if (Array.isArray(row.rows) && row.rows.length > 0) {
|
|
209
|
-
|
|
210
|
-
nestedSections.push({
|
|
118
|
+
childSecs.push({
|
|
211
119
|
title: row.title || '',
|
|
212
|
-
rows: row.rows.map(r => ({
|
|
213
|
-
rowId: r.rowId || r.id || '',
|
|
214
|
-
title: r.title || '',
|
|
215
|
-
description: r.description || ''
|
|
216
|
-
}))
|
|
120
|
+
rows: row.rows.map(r => ({ rowId: r.rowId || r.id || '', title: r.title || '', description: r.description || '' }))
|
|
217
121
|
});
|
|
218
122
|
} else {
|
|
219
|
-
topRows.push({
|
|
220
|
-
rowId: row.rowId || row.id || '',
|
|
221
|
-
title: row.title || '',
|
|
222
|
-
description: row.description || ''
|
|
223
|
-
});
|
|
123
|
+
topRows.push({ rowId: row.rowId || row.id || '', title: row.title || '', description: row.description || '' });
|
|
224
124
|
}
|
|
225
125
|
}
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
flattenedSections.push({
|
|
229
|
-
title: section.title || '',
|
|
230
|
-
rows: topRows
|
|
231
|
-
});
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
for (const ns of nestedSections) {
|
|
235
|
-
flattenedSections.push(ns);
|
|
236
|
-
}
|
|
126
|
+
if (topRows.length) flat.push({ title: sec.title || '', rows: topRows });
|
|
127
|
+
for (const cs of childSecs) flat.push(cs);
|
|
237
128
|
}
|
|
238
|
-
|
|
239
|
-
return {
|
|
240
|
-
listMessage: {
|
|
241
|
-
title,
|
|
242
|
-
description: footer,
|
|
243
|
-
buttonText,
|
|
244
|
-
listType: 1, // SINGLE_SELECT
|
|
245
|
-
sections: flattenedSections
|
|
246
|
-
}
|
|
247
|
-
};
|
|
129
|
+
return { listMessage: { title, description: footer, buttonText, listType: 1, sections: flat } };
|
|
248
130
|
};
|
|
249
131
|
|
|
250
132
|
// ─── ExtendedMessageBuilder ───────────────────────────────────────────────────
|
|
133
|
+
|
|
251
134
|
export class ExtendedMessageBuilder {
|
|
252
135
|
constructor(utils, waUploadToServer, relayMessageFn) {
|
|
253
136
|
this.utils = utils;
|
|
254
137
|
this.relayMessage = relayMessageFn;
|
|
255
138
|
this.waUploadToServer = waUploadToServer;
|
|
256
|
-
|
|
257
139
|
this.bail = {
|
|
258
140
|
generateWAMessageContent: this.utils.generateWAMessageContent,
|
|
259
141
|
generateMessageID: this.utils.generateMessageID,
|
|
@@ -263,431 +145,289 @@ export class ExtendedMessageBuilder {
|
|
|
263
145
|
|
|
264
146
|
detectType(content) {
|
|
265
147
|
if (content.requestPaymentMessage) return 'PAYMENT';
|
|
266
|
-
if (content.productMessage)
|
|
267
|
-
if (content.interactiveMessage)
|
|
268
|
-
if (content.albumMessage)
|
|
269
|
-
if (content.eventMessage)
|
|
270
|
-
if (content.pollResultMessage)
|
|
271
|
-
if (content.groupStatusMessage)
|
|
272
|
-
if (content.nestedListMessage)
|
|
148
|
+
if (content.productMessage) return 'PRODUCT';
|
|
149
|
+
if (content.interactiveMessage) return 'INTERACTIVE';
|
|
150
|
+
if (content.albumMessage) return 'ALBUM';
|
|
151
|
+
if (content.eventMessage) return 'EVENT';
|
|
152
|
+
if (content.pollResultMessage) return 'POLL_RESULT';
|
|
153
|
+
if (content.groupStatusMessage) return 'GROUP_STORY';
|
|
154
|
+
if (content.nestedListMessage) return 'NESTED_LIST';
|
|
155
|
+
if (content.multiSelectMessage) return 'MULTI_SELECT';
|
|
273
156
|
return null;
|
|
274
157
|
}
|
|
275
158
|
|
|
276
|
-
/** Request Payment — tagihan pembayaran + sticker/note & background */
|
|
277
159
|
async handlePayment(content, quoted) {
|
|
278
160
|
const data = content.requestPaymentMessage;
|
|
279
161
|
let notes = {};
|
|
280
|
-
|
|
281
162
|
if (data.sticker?.stickerMessage) {
|
|
282
|
-
notes = {
|
|
283
|
-
stickerMessage: {
|
|
284
|
-
...data.sticker.stickerMessage,
|
|
285
|
-
contextInfo: {
|
|
286
|
-
stanzaId: quoted?.key?.id,
|
|
287
|
-
participant: quoted?.key?.participant || content.sender,
|
|
288
|
-
quotedMessage: quoted?.message
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
};
|
|
163
|
+
notes = { stickerMessage: { ...data.sticker.stickerMessage, contextInfo: { stanzaId: quoted?.key?.id, participant: quoted?.key?.participant || content.sender, quotedMessage: quoted?.message } } };
|
|
292
164
|
} else if (data.note) {
|
|
293
|
-
notes = {
|
|
294
|
-
extendedTextMessage: {
|
|
295
|
-
text: data.note,
|
|
296
|
-
contextInfo: {
|
|
297
|
-
stanzaId: quoted?.key?.id,
|
|
298
|
-
participant: quoted?.key?.participant || content.sender,
|
|
299
|
-
quotedMessage: quoted?.message
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
};
|
|
165
|
+
notes = { extendedTextMessage: { text: data.note, contextInfo: { stanzaId: quoted?.key?.id, participant: quoted?.key?.participant || content.sender, quotedMessage: quoted?.message } } };
|
|
303
166
|
}
|
|
304
|
-
|
|
305
167
|
return {
|
|
306
168
|
requestPaymentMessage: proto.Message.RequestPaymentMessage.fromObject({
|
|
307
|
-
expiryTimestamp: data.expiry || 0,
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
requestFrom: data.from || '0@s.whatsapp.net',
|
|
311
|
-
noteMessage: notes,
|
|
312
|
-
background: data.background ?? {
|
|
313
|
-
id: 'DEFAULT',
|
|
314
|
-
placeholderArgb: 0xFFF0F0F0
|
|
315
|
-
}
|
|
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 }
|
|
316
172
|
})
|
|
317
173
|
};
|
|
318
174
|
}
|
|
319
175
|
|
|
320
|
-
/** Product Message — katalog produk */
|
|
321
176
|
async handleProduct(content, jid, quoted) {
|
|
322
|
-
const {
|
|
323
|
-
title,
|
|
324
|
-
description,
|
|
325
|
-
thumbnail,
|
|
326
|
-
productId,
|
|
327
|
-
retailerId,
|
|
328
|
-
url,
|
|
329
|
-
body = '',
|
|
330
|
-
footer = '',
|
|
331
|
-
buttons = [],
|
|
332
|
-
priceAmount1000 = null,
|
|
333
|
-
currencyCode = 'IDR'
|
|
334
|
-
} = content.productMessage;
|
|
335
|
-
|
|
177
|
+
const { title, description, thumbnail, productId, retailerId, url, body = '', footer = '', buttons = [], priceAmount1000 = null, currencyCode = 'IDR' } = content.productMessage;
|
|
336
178
|
let productImage;
|
|
337
|
-
|
|
338
179
|
if (Buffer.isBuffer(thumbnail)) {
|
|
339
|
-
const { imageMessage } = await this.utils.generateWAMessageContent(
|
|
340
|
-
{ image: thumbnail },
|
|
341
|
-
{ upload: this.waUploadToServer }
|
|
342
|
-
);
|
|
180
|
+
const { imageMessage } = await this.utils.generateWAMessageContent({ image: thumbnail }, { upload: this.waUploadToServer });
|
|
343
181
|
productImage = imageMessage;
|
|
344
|
-
} else if (
|
|
345
|
-
const { imageMessage } = await this.utils.generateWAMessageContent(
|
|
346
|
-
{ image: { url: thumbnail.url } },
|
|
347
|
-
{ upload: this.waUploadToServer }
|
|
348
|
-
);
|
|
182
|
+
} else if (thumbnail?.url) {
|
|
183
|
+
const { imageMessage } = await this.utils.generateWAMessageContent({ image: { url: thumbnail.url } }, { upload: this.waUploadToServer });
|
|
349
184
|
productImage = imageMessage;
|
|
350
185
|
}
|
|
351
|
-
|
|
352
|
-
return {
|
|
353
|
-
viewOnceMessage: {
|
|
354
|
-
message: {
|
|
355
|
-
interactiveMessage: {
|
|
356
|
-
body: { text: body },
|
|
357
|
-
footer: { text: footer },
|
|
358
|
-
header: {
|
|
359
|
-
title,
|
|
360
|
-
hasMediaAttachment: true,
|
|
361
|
-
productMessage: {
|
|
362
|
-
product: {
|
|
363
|
-
productImage,
|
|
364
|
-
productId,
|
|
365
|
-
title,
|
|
366
|
-
description,
|
|
367
|
-
currencyCode,
|
|
368
|
-
priceAmount1000,
|
|
369
|
-
retailerId,
|
|
370
|
-
url,
|
|
371
|
-
productImageCount: 1
|
|
372
|
-
},
|
|
373
|
-
businessOwnerJid: '0@s.whatsapp.net'
|
|
374
|
-
}
|
|
375
|
-
},
|
|
376
|
-
nativeFlowMessage: { buttons }
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
};
|
|
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 } } } } };
|
|
381
187
|
}
|
|
382
188
|
|
|
383
|
-
/**
|
|
384
|
-
* Interactive Message — button, copy code, native flow, bottom sheet,
|
|
385
|
-
* limited time offer, document+thumbnail, external ad reply.
|
|
386
|
-
* Semua V7 native-flow button shape didukung via helper exports di atas.
|
|
387
|
-
*/
|
|
388
189
|
async handleInteractive(content, jid, quoted, options = {}) {
|
|
389
|
-
const {
|
|
390
|
-
title,
|
|
391
|
-
footer,
|
|
392
|
-
thumbnail,
|
|
393
|
-
image,
|
|
394
|
-
video,
|
|
395
|
-
document,
|
|
396
|
-
mimetype,
|
|
397
|
-
fileName,
|
|
398
|
-
jpegThumbnail,
|
|
399
|
-
contextInfo = {},
|
|
400
|
-
externalAdReply,
|
|
401
|
-
buttons = [],
|
|
402
|
-
nativeFlowMessage,
|
|
403
|
-
header
|
|
404
|
-
} = content.interactiveMessage;
|
|
405
|
-
|
|
190
|
+
const { title, footer, thumbnail, image, video, document, mimetype, fileName, jpegThumbnail, contextInfo = {}, externalAdReply, buttons = [], nativeFlowMessage, header } = content.interactiveMessage;
|
|
406
191
|
let media = null;
|
|
407
|
-
|
|
408
|
-
// Media handling (image, video, document)
|
|
409
192
|
if (thumbnail || image) {
|
|
410
|
-
const
|
|
411
|
-
|
|
412
|
-
media = await this.utils.prepareWAMessageMedia(
|
|
413
|
-
{ image: imgObj },
|
|
414
|
-
{ upload: this.waUploadToServer }
|
|
415
|
-
);
|
|
193
|
+
const src = thumbnail || image;
|
|
194
|
+
media = await this.utils.prepareWAMessageMedia({ image: src?.url ? { url: src.url } : src }, { upload: this.waUploadToServer });
|
|
416
195
|
} else if (video) {
|
|
417
|
-
|
|
418
|
-
media = await this.utils.prepareWAMessageMedia(
|
|
419
|
-
{ video: vidObj },
|
|
420
|
-
{ upload: this.waUploadToServer }
|
|
421
|
-
);
|
|
196
|
+
media = await this.utils.prepareWAMessageMedia({ video: video?.url ? { url: video.url } : video }, { upload: this.waUploadToServer });
|
|
422
197
|
} else if (document) {
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
documentPayload.jpegThumbnail = typeof jpegThumbnail === 'object' && jpegThumbnail.url
|
|
427
|
-
? { url: jpegThumbnail.url }
|
|
428
|
-
: jpegThumbnail;
|
|
429
|
-
}
|
|
430
|
-
media = await this.utils.prepareWAMessageMedia(
|
|
431
|
-
documentPayload,
|
|
432
|
-
{ upload: this.waUploadToServer }
|
|
433
|
-
);
|
|
198
|
+
let dp = { document };
|
|
199
|
+
if (jpegThumbnail) dp.jpegThumbnail = jpegThumbnail?.url ? { url: jpegThumbnail.url } : jpegThumbnail;
|
|
200
|
+
media = await this.utils.prepareWAMessageMedia(dp, { upload: this.waUploadToServer });
|
|
434
201
|
if (fileName && media.documentMessage) media.documentMessage.fileName = fileName;
|
|
435
202
|
if (mimetype && media.documentMessage) media.documentMessage.mimetype = mimetype;
|
|
436
203
|
}
|
|
204
|
+
let im = { body: { text: title || '' }, footer: { text: footer || '' } };
|
|
205
|
+
if (buttons?.length) { im.nativeFlowMessage = { buttons }; if (nativeFlowMessage) im.nativeFlowMessage = { ...im.nativeFlowMessage, ...nativeFlowMessage }; }
|
|
206
|
+
else if (nativeFlowMessage) im.nativeFlowMessage = nativeFlowMessage;
|
|
207
|
+
im.header = media ? { title: header || '', hasMediaAttachment: true, ...media } : { title: header || '', hasMediaAttachment: false };
|
|
208
|
+
let ci = { forwardingScore: contextInfo.forwardingScore || 0, isForwarded: contextInfo.isForwarded || false, ...contextInfo, mentionedJid: normalizeMentions(contextInfo.mentionedJid || options.mentions || []) };
|
|
209
|
+
if (externalAdReply) ci.externalAdReply = { title: '', body: '', mediaType: 1, thumbnailUrl: '', mediaUrl: '', sourceUrl: '', showAdAttribution: false, renderLargerThumbnail: false, ...externalAdReply };
|
|
210
|
+
if (!Array.isArray(ci.mentionedJid)) ci.mentionedJid = [ci.mentionedJid].filter(Boolean);
|
|
211
|
+
if (Object.keys(ci).length) im.contextInfo = ci;
|
|
212
|
+
return { interactiveMessage: im };
|
|
213
|
+
}
|
|
437
214
|
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
}
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
if (media) {
|
|
459
|
-
interactiveMessage.header = {
|
|
460
|
-
title: header || '',
|
|
461
|
-
hasMediaAttachment: true,
|
|
462
|
-
...media
|
|
463
|
-
};
|
|
464
|
-
} else {
|
|
465
|
-
interactiveMessage.header = {
|
|
466
|
-
title: header || '',
|
|
467
|
-
hasMediaAttachment: false
|
|
468
|
-
};
|
|
469
|
-
}
|
|
470
|
-
|
|
471
|
-
// contextInfo (mentions + external ad reply)
|
|
472
|
-
let finalContextInfo = {
|
|
473
|
-
forwardingScore: contextInfo.forwardingScore || 0,
|
|
474
|
-
isForwarded: contextInfo.isForwarded || false,
|
|
475
|
-
...contextInfo,
|
|
476
|
-
mentionedJid: normalizeMentions(contextInfo.mentionedJid || options.mentions || [])
|
|
477
|
-
};
|
|
478
|
-
|
|
479
|
-
if (externalAdReply) {
|
|
480
|
-
finalContextInfo.externalAdReply = {
|
|
481
|
-
title: externalAdReply.title || '',
|
|
482
|
-
body: externalAdReply.body || '',
|
|
483
|
-
mediaType: externalAdReply.mediaType || 1,
|
|
484
|
-
thumbnailUrl: externalAdReply.thumbnailUrl || '',
|
|
485
|
-
mediaUrl: externalAdReply.mediaUrl || '',
|
|
486
|
-
sourceUrl: externalAdReply.sourceUrl || '',
|
|
487
|
-
showAdAttribution: externalAdReply.showAdAttribution || false,
|
|
488
|
-
renderLargerThumbnail: externalAdReply.renderLargerThumbnail || false,
|
|
489
|
-
...externalAdReply
|
|
490
|
-
};
|
|
491
|
-
}
|
|
492
|
-
|
|
493
|
-
if (finalContextInfo.mentionedJid && !Array.isArray(finalContextInfo.mentionedJid)) {
|
|
494
|
-
finalContextInfo.mentionedJid = [finalContextInfo.mentionedJid];
|
|
495
|
-
}
|
|
496
|
-
|
|
497
|
-
if (Object.keys(finalContextInfo).length > 0) {
|
|
498
|
-
interactiveMessage.contextInfo = finalContextInfo;
|
|
499
|
-
}
|
|
500
|
-
|
|
501
|
-
return { interactiveMessage };
|
|
215
|
+
/**
|
|
216
|
+
* Multi-Select — 1 pesan dengan BEBERAPA tombol single_select.
|
|
217
|
+
* Tiap selector = 1 tombol dropdown terpisah, buka bottom sheet sendiri.
|
|
218
|
+
*
|
|
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
|
+
* })
|
|
230
|
+
*/
|
|
231
|
+
async handleMultiSelect(content, jid, quoted, options = {}) {
|
|
232
|
+
const { title, footer, image, video, thumbnail, selectors = [], extraButtons = [], contextInfo = {}, header } = content.multiSelectMessage;
|
|
233
|
+
const buttons = [...nfButtonMultiSelect(selectors), ...extraButtons];
|
|
234
|
+
return this.handleInteractive({ interactiveMessage: { title, footer, image, video, thumbnail, header, contextInfo, buttons } }, jid, quoted, options);
|
|
502
235
|
}
|
|
503
236
|
|
|
504
237
|
/**
|
|
505
|
-
* Nested List
|
|
506
|
-
*
|
|
238
|
+
* Nested List — legacy listMessage.
|
|
239
|
+
* Row yang punya `.rows` otomatis di-flatten jadi section baru.
|
|
507
240
|
*
|
|
508
|
-
*
|
|
509
|
-
*
|
|
510
|
-
*
|
|
511
|
-
*
|
|
512
|
-
*
|
|
513
|
-
*
|
|
514
|
-
*
|
|
515
|
-
*
|
|
516
|
-
*
|
|
517
|
-
*
|
|
518
|
-
*
|
|
519
|
-
*
|
|
520
|
-
*
|
|
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
|
+
* })
|
|
521
256
|
*/
|
|
522
257
|
async handleNestedList(content, jid, quoted) {
|
|
523
|
-
const
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
const msg = await this.utils.generateWAMessageFromContent(jid, {
|
|
527
|
-
viewOnceMessage: {
|
|
528
|
-
message: {
|
|
529
|
-
messageContextInfo: {
|
|
530
|
-
deviceListMetadata: {},
|
|
531
|
-
deviceListMetadataVersion: 2
|
|
532
|
-
},
|
|
533
|
-
...payload
|
|
534
|
-
}
|
|
535
|
-
}
|
|
258
|
+
const payload = buildNestedListMessage(content.nestedListMessage);
|
|
259
|
+
return await this.utils.generateWAMessageFromContent(jid, {
|
|
260
|
+
viewOnceMessage: { message: { messageContextInfo: { deviceListMetadata: {}, deviceListMetadataVersion: 2 }, ...payload } }
|
|
536
261
|
}, { quoted });
|
|
537
|
-
|
|
538
|
-
return msg;
|
|
539
262
|
}
|
|
540
263
|
|
|
541
|
-
/** Album Message — kirim banyak foto/video sekaligus */
|
|
542
264
|
async handleAlbum(content, jid, quoted) {
|
|
543
265
|
const array = content.albumMessage;
|
|
544
266
|
const album = await this.utils.generateWAMessageFromContent(jid, {
|
|
545
|
-
messageContextInfo: {
|
|
546
|
-
messageSecret: randomBytes(32)
|
|
547
|
-
},
|
|
267
|
+
messageContextInfo: { messageSecret: randomBytes(32) },
|
|
548
268
|
albumMessage: {
|
|
549
|
-
expectedImageCount: array.filter(
|
|
550
|
-
expectedVideoCount: array.filter(
|
|
269
|
+
expectedImageCount: array.filter(a => Object.hasOwn(a, 'image')).length,
|
|
270
|
+
expectedVideoCount: array.filter(a => Object.hasOwn(a, 'video')).length
|
|
551
271
|
}
|
|
552
|
-
}, {
|
|
553
|
-
|
|
554
|
-
quoted,
|
|
555
|
-
upload: this.waUploadToServer
|
|
556
|
-
});
|
|
557
|
-
|
|
558
|
-
await this.relayMessage(jid, album.message, {
|
|
559
|
-
messageId: album.key.id
|
|
560
|
-
});
|
|
561
|
-
|
|
272
|
+
}, { userJid: this.utils.generateMessageID().split('@')[0] + '@s.whatsapp.net', quoted, upload: this.waUploadToServer });
|
|
273
|
+
await this.relayMessage(jid, album.message, { messageId: album.key.id });
|
|
562
274
|
for (const item of array) {
|
|
563
|
-
const img = await this.utils.generateWAMessage(jid, item, {
|
|
564
|
-
|
|
565
|
-
});
|
|
566
|
-
|
|
567
|
-
img.message.messageContextInfo = {
|
|
568
|
-
messageSecret: randomBytes(32),
|
|
569
|
-
messageAssociation: {
|
|
570
|
-
associationType: 1,
|
|
571
|
-
parentMessageKey: album.key
|
|
572
|
-
},
|
|
573
|
-
participant: jid,
|
|
574
|
-
forwardingScore: 0,
|
|
575
|
-
isForwarded: false
|
|
576
|
-
};
|
|
577
|
-
|
|
578
|
-
await this.relayMessage(jid, img.message, {
|
|
579
|
-
messageId: img.key.id,
|
|
580
|
-
quoted: {
|
|
581
|
-
key: {
|
|
582
|
-
remoteJid: album.key.remoteJid,
|
|
583
|
-
id: album.key.id,
|
|
584
|
-
fromMe: true,
|
|
585
|
-
participant: this.utils.generateMessageID().split('@')[0] + '@s.whatsapp.net'
|
|
586
|
-
},
|
|
587
|
-
message: album.message
|
|
588
|
-
}
|
|
589
|
-
});
|
|
275
|
+
const img = await this.utils.generateWAMessage(jid, item, { upload: this.waUploadToServer });
|
|
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 } });
|
|
590
278
|
}
|
|
591
279
|
return album;
|
|
592
280
|
}
|
|
593
281
|
|
|
594
|
-
/** Event Message — undangan acara dengan lokasi & waktu */
|
|
595
282
|
async handleEvent(content, jid, quoted) {
|
|
596
|
-
const
|
|
597
|
-
|
|
283
|
+
const e = content.eventMessage;
|
|
598
284
|
const msg = await this.utils.generateWAMessageFromContent(jid, {
|
|
599
|
-
viewOnceMessage: {
|
|
600
|
-
message: {
|
|
601
|
-
messageContextInfo: {
|
|
602
|
-
deviceListMetadata: {},
|
|
603
|
-
deviceListMetadataVersion: 2,
|
|
604
|
-
messageSecret: randomBytes(32),
|
|
605
|
-
supportPayload: JSON.stringify({
|
|
606
|
-
version: 2,
|
|
607
|
-
is_ai_message: true,
|
|
608
|
-
should_show_system_message: true,
|
|
609
|
-
ticket_id: randomBytes(16).toString('hex')
|
|
610
|
-
})
|
|
611
|
-
},
|
|
612
|
-
eventMessage: {
|
|
613
|
-
contextInfo: {
|
|
614
|
-
mentionedJid: [jid],
|
|
615
|
-
participant: jid,
|
|
616
|
-
remoteJid: 'status@broadcast'
|
|
617
|
-
},
|
|
618
|
-
isCanceled: eventData.isCanceled || false,
|
|
619
|
-
name: eventData.name,
|
|
620
|
-
description: eventData.description,
|
|
621
|
-
location: eventData.location || {
|
|
622
|
-
degreesLatitude: 0,
|
|
623
|
-
degreesLongitude: 0,
|
|
624
|
-
name: 'Location'
|
|
625
|
-
},
|
|
626
|
-
joinLink: eventData.joinLink || '',
|
|
627
|
-
startTime: typeof eventData.startTime === 'string' ? parseInt(eventData.startTime, 10) : eventData.startTime || Date.now(),
|
|
628
|
-
endTime: typeof eventData.endTime === 'string' ? parseInt(eventData.endTime, 10) : eventData.endTime || Date.now() + 3600000,
|
|
629
|
-
extraGuestsAllowed: eventData.extraGuestsAllowed !== false
|
|
630
|
-
}
|
|
631
|
-
}
|
|
632
|
-
}
|
|
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 } } }
|
|
633
286
|
}, { quoted });
|
|
634
|
-
|
|
635
|
-
await this.relayMessage(jid, msg.message, {
|
|
636
|
-
messageId: msg.key.id
|
|
637
|
-
});
|
|
287
|
+
await this.relayMessage(jid, msg.message, { messageId: msg.key.id });
|
|
638
288
|
return msg;
|
|
639
289
|
}
|
|
640
290
|
|
|
641
|
-
/** Poll Result Message — tampilkan hasil polling */
|
|
642
291
|
async handlePollResult(content, jid, quoted) {
|
|
643
|
-
const
|
|
644
|
-
|
|
292
|
+
const p = content.pollResultMessage;
|
|
645
293
|
const msg = await this.utils.generateWAMessageFromContent(jid, {
|
|
646
|
-
pollResultSnapshotMessage: {
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
optionName: vote.optionName,
|
|
650
|
-
optionVoteCount: typeof vote.optionVoteCount === 'number'
|
|
651
|
-
? vote.optionVoteCount.toString()
|
|
652
|
-
: vote.optionVoteCount
|
|
653
|
-
}))
|
|
654
|
-
}
|
|
655
|
-
}, {
|
|
656
|
-
userJid: this.utils.generateMessageID().split('@')[0] + '@s.whatsapp.net',
|
|
657
|
-
quoted
|
|
658
|
-
});
|
|
659
|
-
|
|
660
|
-
await this.relayMessage(jid, msg.message, {
|
|
661
|
-
messageId: msg.key.id
|
|
662
|
-
});
|
|
663
|
-
|
|
294
|
+
pollResultSnapshotMessage: { name: p.name, pollVotes: p.pollVotes.map(v => ({ optionName: v.optionName, optionVoteCount: typeof v.optionVoteCount === 'number' ? v.optionVoteCount.toString() : v.optionVoteCount })) }
|
|
295
|
+
}, { userJid: this.utils.generateMessageID().split('@')[0] + '@s.whatsapp.net', quoted });
|
|
296
|
+
await this.relayMessage(jid, msg.message, { messageId: msg.key.id });
|
|
664
297
|
return msg;
|
|
665
298
|
}
|
|
666
299
|
|
|
667
|
-
/**
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
300
|
+
/**
|
|
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)
|
|
336
|
+
*/
|
|
337
|
+
async handleGroupStory(content, jid) {
|
|
338
|
+
const s = content.groupStatusMessage;
|
|
671
339
|
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
upload: this.waUploadToServer
|
|
340
|
+
// Mode 1: raw relay langsung
|
|
341
|
+
if (s.raw) {
|
|
342
|
+
return await this.relayMessage(jid, s.raw, {
|
|
343
|
+
messageId: this.bail.generateMessageID()
|
|
677
344
|
});
|
|
678
345
|
}
|
|
679
346
|
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
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
|
|
355
|
+
let innerMessage;
|
|
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 } : {})
|
|
684
365
|
}
|
|
685
|
-
}
|
|
686
|
-
|
|
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;
|
|
423
|
+
} else {
|
|
424
|
+
// Fallback: generate via generateWAMessageContent
|
|
425
|
+
innerMessage = await this.bail.generateWAMessageContent(s, { upload: this.waUploadToServer });
|
|
426
|
+
}
|
|
687
427
|
|
|
688
|
-
return await this.relayMessage(jid,
|
|
689
|
-
|
|
690
|
-
});
|
|
428
|
+
return await this.relayMessage(jid, {
|
|
429
|
+
groupStatusMessageV2: { message: innerMessage }
|
|
430
|
+
}, { messageId: this.bail.generateMessageID() });
|
|
691
431
|
}
|
|
692
432
|
}
|
|
693
433
|
|