@ryuu-reinzz/haruka-lib 1.0.15 → 1.2.15
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/main/index.js +1 -46
- package/main/socket.js +356 -326
- package/package.json +2 -2
package/main/index.js
CHANGED
|
@@ -1,52 +1,7 @@
|
|
|
1
1
|
import addProperty from './socket.js';
|
|
2
2
|
import useSQLiteAuthState from './sqliteAuth.js';
|
|
3
3
|
|
|
4
|
-
const haruka =
|
|
5
|
-
haruka.tutorial = () => {
|
|
6
|
-
console.log(`
|
|
7
|
-
╭──────────────────────────────────────╮
|
|
8
|
-
│ @ryuu-reinzz/haruka-lib │
|
|
9
|
-
│ Small helper for WhatsApp Baileys │
|
|
10
|
-
╰──────────────────────────────────────╯
|
|
11
|
-
|
|
12
|
-
Usage:
|
|
13
|
-
haruka.extendSocketBot(socket, store, smsg, baileys)
|
|
14
|
-
→ extend socket with helper methods
|
|
15
|
-
|
|
16
|
-
haruka.useSQLiteAuthState()
|
|
17
|
-
→ SQLite-based auth state for your bot
|
|
18
|
-
|
|
19
|
-
Examples:
|
|
20
|
-
Add socket:
|
|
21
|
-
import makeWASocket, {
|
|
22
|
-
proto,
|
|
23
|
-
generateWAMessageFromContent,
|
|
24
|
-
jidDecode,
|
|
25
|
-
downloadContentFromMessage,
|
|
26
|
-
prepareWAMessageMedia,
|
|
27
|
-
generateMessageID
|
|
28
|
-
} from "baileys";
|
|
29
|
-
const conn = makeWASocket({});
|
|
30
|
-
const baileys = {
|
|
31
|
-
proto,
|
|
32
|
-
generateWAMessageFromContent,
|
|
33
|
-
jidDecode,
|
|
34
|
-
downloadContentFromMessage,
|
|
35
|
-
prepareWAMessageMedia,
|
|
36
|
-
generateMessageID
|
|
37
|
-
}
|
|
38
|
-
import haruka from "@ryuu-reinzz/haruka-lib";
|
|
39
|
-
haruka.addProperty(conn, store, smsg, baileys);
|
|
40
|
-
|
|
41
|
-
SQLite session:
|
|
42
|
-
const sessionPath = "./session"
|
|
43
|
-
if (!fs.existsSync(sessionPath)) fs.mkdirSync(sessionPath, { recursive: true });
|
|
44
|
-
const useSQLiteAuthState = haruka.useSQLiteAuthState;
|
|
45
|
-
const { state, saveCreds } = await useSQLiteAuthState(sessionPath + \"auth.db\");
|
|
46
|
-
|
|
47
|
-
Made by Ryuu
|
|
48
|
-
`)
|
|
49
|
-
}
|
|
4
|
+
const haruka = global.Haruka;
|
|
50
5
|
haruka.useSQLiteAuthState = useSQLiteAuthState;
|
|
51
6
|
haruka.addProperty = addProperty;
|
|
52
7
|
|
package/main/socket.js
CHANGED
|
@@ -14,6 +14,70 @@ const __dirname = dirname(__filename);
|
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
16
|
export default function addProperty(socket, store, smsg, baileys) {
|
|
17
|
+
const tutor = `
|
|
18
|
+
Welcome to @ryuu-reinzz/haruka-lib
|
|
19
|
+
Small helper for WhatsApp Baileys
|
|
20
|
+
|
|
21
|
+
Usage:
|
|
22
|
+
haruka.extendSocketBot(socket, store, smsg, baileys)
|
|
23
|
+
→ extend socket with helper methods
|
|
24
|
+
|
|
25
|
+
haruka.useSQLiteAuthState()
|
|
26
|
+
→ SQLite-based auth state for your bot
|
|
27
|
+
|
|
28
|
+
Examples:
|
|
29
|
+
Add socket:
|
|
30
|
+
import makeWASocket, {
|
|
31
|
+
proto,
|
|
32
|
+
generateWAMessageFromContent,
|
|
33
|
+
jidDecode,
|
|
34
|
+
downloadContentFromMessage,
|
|
35
|
+
prepareWAMessageMedia,
|
|
36
|
+
generateMessageID
|
|
37
|
+
} from "baileys";
|
|
38
|
+
const conn = makeWASocket({});
|
|
39
|
+
const baileys = {
|
|
40
|
+
proto,
|
|
41
|
+
generateWAMessageFromContent,
|
|
42
|
+
jidDecode,
|
|
43
|
+
downloadContentFromMessage,
|
|
44
|
+
prepareWAMessageMedia,
|
|
45
|
+
generateMessageID
|
|
46
|
+
}
|
|
47
|
+
import haruka from "@ryuu-reinzz/haruka-lib";
|
|
48
|
+
haruka.addProperty(conn, store, smsg, baileys);
|
|
49
|
+
|
|
50
|
+
SQLite session:
|
|
51
|
+
const sessionPath = "./session"
|
|
52
|
+
if (!fs.existsSync(sessionPath)) fs.mkdirSync(sessionPath, { recursive: true });
|
|
53
|
+
const useSQLiteAuthState = haruka.useSQLiteAuthState;
|
|
54
|
+
const { state, saveCreds } = await useSQLiteAuthState(sessionPath + \"auth.db\");
|
|
55
|
+
|
|
56
|
+
Made by Ryuu`;
|
|
57
|
+
global.Haruka = () => {
|
|
58
|
+
socket.sendMessage(
|
|
59
|
+
socket.user.jid,
|
|
60
|
+
{
|
|
61
|
+
text: tutor,
|
|
62
|
+
contextInfo: {
|
|
63
|
+
forwardingScore: 99,
|
|
64
|
+
isForwarded: true,
|
|
65
|
+
forwardedNewsletterMessageInfo: {
|
|
66
|
+
newsletterName: "𝙍͢𝙮𝙪𝙪 𝙍͢𝙚𝙞𝙣𝙯𝙯",
|
|
67
|
+
newsletterJid: "120363419382206255@newsletter"
|
|
68
|
+
},
|
|
69
|
+
externalAdReply: {
|
|
70
|
+
title: "Haruka Tutorial",
|
|
71
|
+
body: "How to use",
|
|
72
|
+
thumbnailUrl: "https://api.ryuu-dev.offc.my.id/src/assest/bot/Haruka.jpg",
|
|
73
|
+
sourceUrl: `https://whatsapp.com/channel/0029Vb49CCWJ93wO2dLDqx14`,
|
|
74
|
+
mediaType: 1,
|
|
75
|
+
renderLargerThumbnail: true,
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
}
|
|
79
|
+
);
|
|
80
|
+
}
|
|
17
81
|
const {
|
|
18
82
|
proto,
|
|
19
83
|
generateWAMessageFromContent,
|
|
@@ -155,350 +219,316 @@ Object.assign(socket, {
|
|
|
155
219
|
}
|
|
156
220
|
},
|
|
157
221
|
|
|
158
|
-
sendButton:
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
const {
|
|
164
|
-
text = "",
|
|
165
|
-
caption = "",
|
|
166
|
-
title = "",
|
|
167
|
-
footer = "",
|
|
168
|
-
buttons = [],
|
|
169
|
-
hasMediaAttachment = false,
|
|
170
|
-
image = null,
|
|
171
|
-
video = null,
|
|
172
|
-
document = null,
|
|
173
|
-
mimetype = null,
|
|
174
|
-
jpegThumbnail = null,
|
|
175
|
-
location = null,
|
|
176
|
-
product = null,
|
|
177
|
-
businessOwnerJid = null,
|
|
178
|
-
} = content;
|
|
179
|
-
|
|
180
|
-
if (!Array.isArray(buttons) || buttons.length ===
|
|
181
|
-
0) {
|
|
182
|
-
throw new Error(
|
|
183
|
-
"buttons must be a non-empty array");
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
const interactiveButtons = [];
|
|
187
|
-
|
|
188
|
-
for (let i = 0; i < buttons.length; i++) {
|
|
189
|
-
const btn = buttons[i];
|
|
190
|
-
|
|
191
|
-
if (!btn || typeof btn !== "object") {
|
|
192
|
-
throw new Error(
|
|
193
|
-
`button[${i}] must be an object`);
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
if (btn.name && btn.buttonParamsJson) {
|
|
197
|
-
interactiveButtons.push(btn);
|
|
198
|
-
continue;
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
if (btn.id || btn.text || btn.displayText) {
|
|
202
|
-
interactiveButtons.push({
|
|
203
|
-
name: "quick_reply",
|
|
204
|
-
buttonParamsJson: JSON
|
|
205
|
-
.stringify({
|
|
206
|
-
display_text: btn
|
|
207
|
-
.text || btn
|
|
208
|
-
.displayText ||
|
|
209
|
-
`Button ${i + 1}`,
|
|
210
|
-
id: btn.id ||
|
|
211
|
-
`quick_${i + 1}`,
|
|
212
|
-
}),
|
|
213
|
-
});
|
|
214
|
-
continue;
|
|
215
|
-
}
|
|
222
|
+
sendButton:
|
|
223
|
+
async (jid, content = {}, options = {}) => {
|
|
224
|
+
if (!socket.user?.id) {
|
|
225
|
+
throw new Error("User not authenticated");
|
|
226
|
+
}
|
|
216
227
|
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
228
|
+
const {
|
|
229
|
+
text = "",
|
|
230
|
+
caption = "",
|
|
231
|
+
title = "",
|
|
232
|
+
footer = "",
|
|
233
|
+
buttons = [],
|
|
234
|
+
hasMediaAttachment = false,
|
|
235
|
+
image = null,
|
|
236
|
+
video = null,
|
|
237
|
+
document = null,
|
|
238
|
+
mimetype = null,
|
|
239
|
+
jpegThumbnail = null,
|
|
240
|
+
location = null,
|
|
241
|
+
product = null,
|
|
242
|
+
businessOwnerJid = null,
|
|
243
|
+
externalAdReply = null,
|
|
244
|
+
} = content;
|
|
245
|
+
|
|
246
|
+
if (!Array.isArray(buttons) || buttons.length === 0) {
|
|
247
|
+
throw new Error("buttons must be a non-empty array");
|
|
248
|
+
}
|
|
231
249
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
250
|
+
const processedButtons = [];
|
|
251
|
+
|
|
252
|
+
for (let i = 0; i < buttons.length; i++) {
|
|
253
|
+
const btn = buttons[i];
|
|
254
|
+
|
|
255
|
+
if (!btn || typeof btn !== "object") {
|
|
256
|
+
throw new Error(`interactiveButton[${i}] must be an object`);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
if (btn.name && btn.buttonParamsJson) {
|
|
260
|
+
processedButtons.push(btn);
|
|
261
|
+
continue;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
if (btn.id || btn.text || btn.displayText) {
|
|
265
|
+
processedButtons.push({
|
|
266
|
+
name: "quick_reply",
|
|
267
|
+
buttonParamsJson: JSON.stringify({
|
|
268
|
+
display_text: btn.text || btn.displayText || `Button ${i + 1}`,
|
|
269
|
+
id: btn.id || `quick_${i + 1}`,
|
|
270
|
+
}),
|
|
271
|
+
});
|
|
272
|
+
continue;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
if (btn.buttonId && btn.buttonText?.displayText) {
|
|
276
|
+
processedButtons.push({
|
|
277
|
+
name: "quick_reply",
|
|
278
|
+
buttonParamsJson: JSON.stringify({
|
|
279
|
+
display_text: btn.buttonText.displayText,
|
|
280
|
+
id: btn.buttonId,
|
|
281
|
+
}),
|
|
282
|
+
});
|
|
283
|
+
continue;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
throw new Error(`interactiveButton[${i}] has invalid shape`);
|
|
287
|
+
}
|
|
235
288
|
|
|
236
|
-
|
|
237
|
-
if (image) {
|
|
238
|
-
const mediaInput = {};
|
|
239
|
-
if (Buffer.isBuffer(image)) {
|
|
240
|
-
mediaInput.image = image;
|
|
241
|
-
} else if (typeof image === "object" && image
|
|
242
|
-
.url) {
|
|
243
|
-
mediaInput.image = {
|
|
244
|
-
url: image.url
|
|
245
|
-
};
|
|
246
|
-
} else if (typeof image === "string") {
|
|
247
|
-
mediaInput.image = {
|
|
248
|
-
url: image
|
|
249
|
-
};
|
|
250
|
-
}
|
|
289
|
+
let messageContent = {};
|
|
251
290
|
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
.imageMessage,
|
|
262
|
-
};
|
|
263
|
-
} else if (video) {
|
|
264
|
-
const mediaInput = {};
|
|
265
|
-
if (Buffer.isBuffer(video)) {
|
|
266
|
-
mediaInput.video = video;
|
|
267
|
-
} else if (typeof video === "object" && video
|
|
268
|
-
.url) {
|
|
269
|
-
mediaInput.video = {
|
|
270
|
-
url: video.url
|
|
271
|
-
};
|
|
272
|
-
} else if (typeof video === "string") {
|
|
273
|
-
mediaInput.video = {
|
|
274
|
-
url: video
|
|
275
|
-
};
|
|
276
|
-
}
|
|
291
|
+
if (image) {
|
|
292
|
+
const mediaInput = {};
|
|
293
|
+
if (Buffer.isBuffer(image)) {
|
|
294
|
+
mediaInput.image = image;
|
|
295
|
+
} else if (typeof image === "object" && image.url) {
|
|
296
|
+
mediaInput.image = { url: image.url };
|
|
297
|
+
} else if (typeof image === "string") {
|
|
298
|
+
mediaInput.image = { url: image };
|
|
299
|
+
}
|
|
277
300
|
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
});
|
|
282
|
-
|
|
283
|
-
messageContent.header = {
|
|
284
|
-
title: title || "",
|
|
285
|
-
hasMediaAttachment: hasMediaAttachment,
|
|
286
|
-
videoMessage: preparedMedia
|
|
287
|
-
.videoMessage,
|
|
288
|
-
};
|
|
289
|
-
} else if (document) {
|
|
290
|
-
const mediaInput = {
|
|
291
|
-
document: {}
|
|
292
|
-
};
|
|
293
|
-
|
|
294
|
-
if (Buffer.isBuffer(document)) {
|
|
295
|
-
mediaInput.document = document;
|
|
296
|
-
} else if (typeof document === "object" &&
|
|
297
|
-
document.url) {
|
|
298
|
-
mediaInput.document = {
|
|
299
|
-
url: document.url
|
|
300
|
-
};
|
|
301
|
-
} else if (typeof document === "string") {
|
|
302
|
-
mediaInput.document = {
|
|
303
|
-
url: document
|
|
304
|
-
};
|
|
305
|
-
}
|
|
301
|
+
const preparedMedia = await prepareWAMessageMedia(mediaInput, {
|
|
302
|
+
upload: socket.waUploadToServer,
|
|
303
|
+
});
|
|
306
304
|
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
305
|
+
messageContent.header = {
|
|
306
|
+
title: title || "",
|
|
307
|
+
hasMediaAttachment: hasMediaAttachment || true,
|
|
308
|
+
imageMessage: preparedMedia.imageMessage,
|
|
309
|
+
};
|
|
310
|
+
} else if (video) {
|
|
311
|
+
const mediaInput = {};
|
|
312
|
+
if (Buffer.isBuffer(video)) {
|
|
313
|
+
mediaInput.video = video;
|
|
314
|
+
} else if (typeof video === "object" && video.url) {
|
|
315
|
+
mediaInput.video = { url: video.url };
|
|
316
|
+
} else if (typeof video === "string") {
|
|
317
|
+
mediaInput.video = { url: video };
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
const preparedMedia = await prepareWAMessageMedia(mediaInput, {
|
|
321
|
+
upload: socket.waUploadToServer,
|
|
322
|
+
});
|
|
313
323
|
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
324
|
+
messageContent.header = {
|
|
325
|
+
title: title || "",
|
|
326
|
+
hasMediaAttachment: hasMediaAttachment || true,
|
|
327
|
+
videoMessage: preparedMedia.videoMessage,
|
|
328
|
+
};
|
|
329
|
+
} else if (document) {
|
|
330
|
+
const mediaInput = { document: {} };
|
|
331
|
+
|
|
332
|
+
if (Buffer.isBuffer(document)) {
|
|
333
|
+
mediaInput.document = document;
|
|
334
|
+
} else if (typeof document === "object" && document.url) {
|
|
335
|
+
mediaInput.document = { url: document.url };
|
|
336
|
+
} else if (typeof document === "string") {
|
|
337
|
+
mediaInput.document = { url: document };
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
if (mimetype) {
|
|
341
|
+
if (typeof mediaInput.document === "object") {
|
|
342
|
+
mediaInput.document.mimetype = mimetype;
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
if (jpegThumbnail) {
|
|
347
|
+
if (typeof mediaInput.document === "object") {
|
|
348
|
+
if (Buffer.isBuffer(jpegThumbnail)) {
|
|
349
|
+
mediaInput.document.jpegThumbnail = jpegThumbnail;
|
|
350
|
+
} else if (typeof jpegThumbnail === "string") {
|
|
351
|
+
try {
|
|
352
|
+
const response = await fetch(jpegThumbnail);
|
|
353
|
+
const arrayBuffer = await response.arrayBuffer();
|
|
354
|
+
mediaInput.document.jpegThumbnail = Buffer.from(arrayBuffer);
|
|
355
|
+
} catch {
|
|
356
|
+
//
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
const preparedMedia = await prepareWAMessageMedia(mediaInput, {
|
|
363
|
+
upload: socket.waUploadToServer,
|
|
364
|
+
});
|
|
336
365
|
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
366
|
+
messageContent.header = {
|
|
367
|
+
title: title || "",
|
|
368
|
+
hasMediaAttachment: hasMediaAttachment || true,
|
|
369
|
+
documentMessage: preparedMedia.documentMessage,
|
|
370
|
+
};
|
|
371
|
+
} else if (location && typeof location === "object") {
|
|
372
|
+
messageContent.header = {
|
|
373
|
+
title: title || location.name || "Location",
|
|
374
|
+
hasMediaAttachment: hasMediaAttachment || false,
|
|
375
|
+
locationMessage: {
|
|
376
|
+
degreesLatitude:
|
|
377
|
+
location.degressLatitude || location.degreesLatitude || 0,
|
|
378
|
+
degreesLongitude:
|
|
379
|
+
location.degressLongitude || location.degreesLongitude || 0,
|
|
380
|
+
name: location.name || "",
|
|
381
|
+
address: location.address || "",
|
|
382
|
+
},
|
|
383
|
+
};
|
|
384
|
+
} else if (product && typeof product === "object") {
|
|
385
|
+
let productImageMessage = null;
|
|
386
|
+
if (product.productImage) {
|
|
387
|
+
const mediaInput = {};
|
|
388
|
+
if (Buffer.isBuffer(product.productImage)) {
|
|
389
|
+
mediaInput.image = product.productImage;
|
|
390
|
+
} else if (
|
|
391
|
+
typeof product.productImage === "object" &&
|
|
392
|
+
product.productImage.url
|
|
393
|
+
) {
|
|
394
|
+
mediaInput.image = {
|
|
395
|
+
url: product.productImage.url,
|
|
396
|
+
};
|
|
397
|
+
} else if (typeof product.productImage === "string") {
|
|
398
|
+
mediaInput.image = {
|
|
399
|
+
url: product.productImage,
|
|
400
|
+
};
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
const preparedMedia = await prepareWAMessageMedia(mediaInput, {
|
|
404
|
+
upload: socket.waUploadToServer,
|
|
405
|
+
});
|
|
406
|
+
productImageMessage = preparedMedia.imageMessage;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
messageContent.header = {
|
|
410
|
+
title: title || product.title || "Product",
|
|
411
|
+
hasMediaAttachment: hasMediaAttachment || false,
|
|
412
|
+
productMessage: {
|
|
413
|
+
product: {
|
|
414
|
+
productImage: productImageMessage,
|
|
415
|
+
productId: product.productId || "",
|
|
416
|
+
title: product.title || "",
|
|
417
|
+
description: product.description || "",
|
|
418
|
+
currencyCode: product.currencyCode || "USD",
|
|
419
|
+
priceAmount1000: parseInt(product.priceAmount1000) || 0,
|
|
420
|
+
retailerId: product.retailerId || "",
|
|
421
|
+
url: product.url || "",
|
|
422
|
+
productImageCount: product.productImageCount || 1,
|
|
423
|
+
},
|
|
424
|
+
businessOwnerJid:
|
|
425
|
+
businessOwnerJid || product.businessOwnerJid || socket.user.id,
|
|
426
|
+
},
|
|
427
|
+
};
|
|
428
|
+
} else if (title) {
|
|
429
|
+
messageContent.header = {
|
|
430
|
+
title: title,
|
|
431
|
+
hasMediaAttachment: false,
|
|
432
|
+
};
|
|
433
|
+
}
|
|
385
434
|
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
mediaInput, {
|
|
389
|
-
upload: socket.waUploadToServer,
|
|
390
|
-
});
|
|
391
|
-
productImageMessage = preparedMedia
|
|
392
|
-
.imageMessage;
|
|
393
|
-
}
|
|
435
|
+
const hasMedia = !!(image || video || document || location || product);
|
|
436
|
+
const bodyText = hasMedia ? caption : text || caption;
|
|
394
437
|
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
hasMediaAttachment: hasMediaAttachment,
|
|
399
|
-
productMessage: {
|
|
400
|
-
product: {
|
|
401
|
-
productImage: productImageMessage,
|
|
402
|
-
productId: product.productId ||
|
|
403
|
-
"",
|
|
404
|
-
title: product.title || "",
|
|
405
|
-
description: product
|
|
406
|
-
.description || "",
|
|
407
|
-
currencyCode: product
|
|
408
|
-
.currencyCode || "USD",
|
|
409
|
-
priceAmount1000: parseInt(
|
|
410
|
-
product.priceAmount1000
|
|
411
|
-
) || 0,
|
|
412
|
-
retailerId: product
|
|
413
|
-
.retailerId || "",
|
|
414
|
-
url: product.url || "",
|
|
415
|
-
productImageCount: product
|
|
416
|
-
.productImageCount || 1,
|
|
417
|
-
},
|
|
418
|
-
businessOwnerJid: businessOwnerJid ||
|
|
419
|
-
product.businessOwnerJid || socket
|
|
420
|
-
.user.id,
|
|
421
|
-
},
|
|
422
|
-
};
|
|
423
|
-
} else if (title) {
|
|
424
|
-
messageContent.header = {
|
|
425
|
-
title: title,
|
|
426
|
-
hasMediaAttachment: false,
|
|
427
|
-
};
|
|
428
|
-
}
|
|
438
|
+
if (bodyText) {
|
|
439
|
+
messageContent.body = { text: bodyText };
|
|
440
|
+
}
|
|
429
441
|
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
caption;
|
|
442
|
+
if (footer) {
|
|
443
|
+
messageContent.footer = { text: footer };
|
|
444
|
+
}
|
|
434
445
|
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
};
|
|
439
|
-
}
|
|
446
|
+
messageContent.nativeFlowMessage = {
|
|
447
|
+
buttons: processedButtons,
|
|
448
|
+
};
|
|
440
449
|
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
450
|
+
if (externalAdReply && typeof externalAdReply === "object") {
|
|
451
|
+
messageContent.contextInfo = {
|
|
452
|
+
externalAdReply: {
|
|
453
|
+
title: externalAdReply.title || "",
|
|
454
|
+
body: externalAdReply.body || "",
|
|
455
|
+
mediaType: externalAdReply.mediaType || 1,
|
|
456
|
+
sourceUrl: externalAdReply.sourceUrl || externalAdReply.url || "",
|
|
457
|
+
thumbnailUrl:
|
|
458
|
+
externalAdReply.thumbnailUrl || externalAdReply.thumbnail || "",
|
|
459
|
+
renderLargerThumbnail: externalAdReply.renderLargerThumbnail || false,
|
|
460
|
+
showAdAttribution: externalAdReply.showAdAttribution !== false,
|
|
461
|
+
containsAutoReply: externalAdReply.containsAutoReply || false,
|
|
462
|
+
...(externalAdReply.mediaUrl && {
|
|
463
|
+
mediaUrl: externalAdReply.mediaUrl,
|
|
464
|
+
}),
|
|
465
|
+
...(externalAdReply.thumbnail &&
|
|
466
|
+
Buffer.isBuffer(externalAdReply.thumbnail) && {
|
|
467
|
+
thumbnail: externalAdReply.thumbnail,
|
|
468
|
+
}),
|
|
469
|
+
...(externalAdReply.jpegThumbnail && {
|
|
470
|
+
jpegThumbnail: externalAdReply.jpegThumbnail,
|
|
471
|
+
}),
|
|
472
|
+
},
|
|
473
|
+
...(options.mentionedJid && {
|
|
474
|
+
mentionedJid: options.mentionedJid,
|
|
475
|
+
}),
|
|
476
|
+
};
|
|
477
|
+
} else if (options.mentionedJid) {
|
|
478
|
+
messageContent.contextInfo = {
|
|
479
|
+
mentionedJid: options.mentionedJid,
|
|
480
|
+
};
|
|
481
|
+
}
|
|
446
482
|
|
|
447
|
-
|
|
448
|
-
buttons: interactiveButtons,
|
|
449
|
-
};
|
|
483
|
+
const payload = proto.Message.InteractiveMessage.create(messageContent);
|
|
450
484
|
|
|
451
|
-
|
|
452
|
-
|
|
485
|
+
const msg = generateWAMessageFromContent(
|
|
486
|
+
jid,
|
|
487
|
+
{
|
|
488
|
+
viewOnceMessage: {
|
|
489
|
+
message: {
|
|
490
|
+
interactiveMessage: payload,
|
|
491
|
+
},
|
|
492
|
+
},
|
|
493
|
+
},
|
|
494
|
+
{
|
|
495
|
+
userJid: socket.user.id,
|
|
496
|
+
quoted: options?.quoted || null,
|
|
497
|
+
}
|
|
498
|
+
);
|
|
453
499
|
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
attrs: {
|
|
479
|
-
v: "9",
|
|
480
|
-
name: "mixed",
|
|
481
|
-
},
|
|
482
|
-
}, ],
|
|
483
|
-
}, ],
|
|
484
|
-
}, ];
|
|
485
|
-
|
|
486
|
-
if (!isGroup) {
|
|
487
|
-
additionalNodes.push({
|
|
488
|
-
tag: "bot",
|
|
489
|
-
attrs: {
|
|
490
|
-
biz_bot: "1"
|
|
491
|
-
},
|
|
492
|
-
});
|
|
493
|
-
}
|
|
500
|
+
const additionalNodes = [
|
|
501
|
+
{
|
|
502
|
+
tag: "biz",
|
|
503
|
+
attrs: {},
|
|
504
|
+
content: [
|
|
505
|
+
{
|
|
506
|
+
tag: "interactive",
|
|
507
|
+
attrs: {
|
|
508
|
+
type: "native_flow",
|
|
509
|
+
v: "1",
|
|
510
|
+
},
|
|
511
|
+
content: [
|
|
512
|
+
{
|
|
513
|
+
tag: "native_flow",
|
|
514
|
+
attrs: {
|
|
515
|
+
v: "9",
|
|
516
|
+
name: "mixed",
|
|
517
|
+
},
|
|
518
|
+
},
|
|
519
|
+
],
|
|
520
|
+
},
|
|
521
|
+
],
|
|
522
|
+
},
|
|
523
|
+
];
|
|
494
524
|
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
525
|
+
await socket.relayMessage(jid, msg.message, {
|
|
526
|
+
messageId: msg.key.id,
|
|
527
|
+
additionalNodes,
|
|
528
|
+
});
|
|
499
529
|
|
|
500
|
-
|
|
501
|
-
|
|
530
|
+
return msg;
|
|
531
|
+
},
|
|
502
532
|
sendAlbum: async (jid, items = [], options = {}) => {
|
|
503
533
|
if (!socket.user?.id) {
|
|
504
534
|
throw new Error("User not authenticated");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ryuu-reinzz/haruka-lib",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.15",
|
|
4
4
|
"description": "Library extra for bot WhatsApp",
|
|
5
5
|
"main": "main/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -17,6 +17,6 @@
|
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"better-sqlite3": "^12.5.0",
|
|
19
19
|
"node-fetch": "^2.6.1",
|
|
20
|
-
"wa-sticker-formatter": "
|
|
20
|
+
"wa-sticker-formatter": "4.4.4"
|
|
21
21
|
}
|
|
22
22
|
}
|