@ryuu-reinzz/haruka-lib 1.1.0-beta.1 → 1.2.16

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 ryuu-reinzz
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,21 +1,18 @@
1
- # Package Docs
1
+ ### Haruka Library
2
+ <p align="center">
3
+ <img src="https://api.ryuu-dev.offc.my.id/src/assest/bot/Haruka.jpg" width="400" alt="Haruka-Lib">
2
4
 
3
- **@ryuu-reinzz/haruka-lib**
4
5
 
5
- ![Thumbnail](https://api.ryuu-dev.offc.my.id/src/assest/bot/Haruka.jpg)
6
+ <b>Powerful & Lightweight WhatsApp Bot Library Extension</b>
7
+ </p>
6
8
 
7
- ---
8
-
9
- ## Daftar Fitur
10
-
11
- ### How to Use
12
- **Deskripsi:** Contoh penggunaan Haruka Library dengan Baileys.
13
-
14
- **Contoh:**
15
- ```javascript
16
- //how to use:
17
- //npm i @ryuu-reinzz/haruka-lib@1.0.9
9
+ # How to use
10
+ ``` bash
11
+ npm install @ryuu-reinzz/haruka-lib@1.0.15
12
+ ```
18
13
 
14
+ *how to use it in JavaScript:*
15
+ ``` javascript
19
16
  import haruka from "@ryuu-reinzz/haruka-lib";
20
17
  import makeWASocket, {
21
18
  proto,
@@ -41,67 +38,64 @@ const conn = makeWASocket({});
41
38
  haruka.addProperty(conn, store, smsg, property);
42
39
  ```
43
40
 
41
+ ## 1. Send Button
42
+ *Digunakan untuk mengirim button message ke WhatsApp jika baileys bawaan tidak mendukung*
44
43
 
45
-
46
- ---
47
- ##List Feature
48
- #1. sendOrder
49
-
50
- Deskripsi: Mengirim pesan orderan palsu yang bisa bebas thumbnail.
51
-
52
- Contoh:
53
44
  ``` javascript
54
- conn.sendOrder(
55
- m.chat,
56
- {
57
- orderId: "ORDER-" + Date.now(),
58
- thumbnail: global.thumbnail,
59
- itemCount: 15,
60
- status: 1,
61
- surface: 1,
62
- orderTitle: "Premium Subscription",
63
- message: "Zahlea botz",
64
- sellerJid: conn.user.jid,
65
- totalAmount1000: 500000000,
66
- totalCurrencyCode: "IDR"
67
- },
68
- {
69
- quoted: m,
70
- mentions: [m.sender]
71
- }
72
- );
45
+ conn.sendButton(m.chat, {
46
+ caption: "Haruka here!",
47
+ image: { url: global.thumbnail },
48
+ footer: global.ownername,
49
+ buttons: [
50
+ {
51
+ name: "cta_url",
52
+ buttonParamsJson: JSON.stringify({
53
+ display_text: "View Link",
54
+ url: global.thumbnail
55
+ })
56
+ }
57
+ ]
58
+ });
73
59
  ```
74
- Example:
75
- ![example](https://api.ryuu-dev.offc.my.id/src/assest/Haruhime/sendOrder.jpg)
76
-
77
-
60
+ Hasil Output:
61
+ <img src="https://api.ryuu-dev.offc.my.id/src/assest/Haruhime/sendButton.jpg" width="300" />
78
62
 
79
- ---
63
+ ## 2. Send Order
64
+ *Digunakan untuk membuat tampilan pesanan profesional atau sekedar prank orderan.*
80
65
 
81
- #2. sendAlbum
66
+ ``` javascript
67
+ conn.sendOrder(m.chat, {
68
+ orderId: "ORDER-" + Date.now(),
69
+ thumbnail: global.thumbnail,
70
+ itemCount: 15,
71
+ status: 1,
72
+ surface: 1,
73
+ orderTitle: "Premium Subscription",
74
+ message: "Zahlea botz",
75
+ sellerJid: conn.user.jid,
76
+ totalAmount1000: 500000000,
77
+ totalCurrencyCode: "IDR"
78
+ }, { quoted: m, mentions: [m.sender] });
79
+ ```
80
+ Hasil Output:
81
+ <img src="https://api.ryuu-dev.offc.my.id/src/assest/Haruhime/sendOrder.jpg" width="300" />
82
82
 
83
- Deskripsi: Mengirim pesan berupa beberapa gambar sekaligus.
83
+ ## 3. Send Album
84
+ *Cocok untuk mengirim katalog produk atau galeri foto tanpa memenuhi chat.*
84
85
 
85
- Contoh:
86
86
  ``` javascript
87
87
  conn.sendAlbum(m.chat, [
88
88
  { image: { url: global.thumbnail }, caption: "Gambar 1" },
89
89
  { image: { url: global.thumbnail }, caption: "Gambar 2" },
90
90
  { image: fs.readFileSync("./image.jpg"), caption: "Stiker lucu" }
91
- ], { quoted: m });
92
- ```
93
- Example:
94
- ![example](https://api.ryuu-dev.offc.my.id/src/assest/Haruhime/sendAlbum.jpg)
91
+ ], { quoted: m });
92
+ ```
93
+ Hasil Output:
94
+ <img src="https://api.ryuu-dev.offc.my.id/src/assest/Haruhime/sendAlbum.jpg" width="300" />
95
95
 
96
+ ## 4. Send Card (Carousel)
97
+ *Fitur tercanggih untuk membuat menu bot yang bisa digeser (slide) ke samping.*
96
98
 
97
-
98
- ---
99
-
100
- #3. sendCard
101
-
102
- Deskripsi: Mengirim pesan seperti kartu dan bisa memiliki button.
103
-
104
- Contoh:
105
99
  ``` javascript
106
100
  conn.sendCard(m.chat, {
107
101
  text: "Bot Thumbnail",
@@ -112,74 +106,36 @@ conn.sendCard(m.chat, {
112
106
  {
113
107
  image: global.thumbnail,
114
108
  caption: "Thumbnail 1",
115
- source: global.thumbnail,
116
- buttons: [
117
- {
118
- name: "cta_url",
119
- buttonParamsJson: JSON.stringify({
120
- display_text: "Lihat Gambar 1",
121
- url: global.thumbnail
122
- })
123
- }
124
- ]
125
- },
126
- {
127
- image: global.thumbnail,
128
- caption: "Thumbnail 2",
129
- source: global.thumbnail,
130
- buttons: [
131
- {
132
- name: "cta_url",
133
- buttonParamsJson: JSON.stringify({
134
- display_text: "Lihat Gambar 2",
135
- url: global.thumbnail2
136
- })
137
- }
138
- ]
109
+ buttons: [{ name: "cta_url", buttonParamsJson: JSON.stringify({ display_text: "Visit", url: "https://google.com" }) }]
139
110
  }
140
111
  ]
141
112
  });
142
113
  ```
143
- Example:
144
- ![example](https://api.ryuu-dev.offc.my.id/src/assest/Haruhime/sendCard.jpg)
145
-
114
+ ## Hasil Output:
115
+ <img src="https://api.ryuu-dev.offc.my.id/src/assest/Haruhime/sendCard.jpg" width="300" />
146
116
 
147
- ---
117
+ ## 5. Custom Sticker
118
+ *Buat stiker langsung dengan identitas bot kamu sendiri.*
148
119
 
149
- #4. sendSticker
150
-
151
- Deskripsi: Mengirim pesan yang bisa bebas custom packname dan author.
152
-
153
- Contoh:
154
120
  ``` javascript
155
121
  conn.sendSticker(m.chat, {
156
122
  sticker: "./stiker/apa-woi.webp",
157
- packname: global.packaname,
158
- author: global.author
123
+ packname: "Haruka Bot",
124
+ author: "@ryuu-reinzz"
159
125
  });
160
126
  ```
161
- Example:
162
- ![example](https://api.ryuu-dev.offc.my.id/src/assest/Haruhime/sendSticker.jpg)
163
-
127
+ ## Hasil Output:
128
+ <img src="https://api.ryuu-dev.offc.my.id/src/assest/Haruhime/sendSticker.jpg" width="200" />
164
129
 
130
+ ## 6. ID Mapping (LID to PN and PN to LID)
131
+ *Mencari LID atau Phone Number*
165
132
 
166
- ---
133
+ ``` javascript
134
+ // Mencari LID dari nomor HP
135
+ await conn.getLidFromPN(m, "6288246552068@s.whatsapp.net");
167
136
 
168
- #5. Search Lid and PN
169
-
170
- Deskripsi: Mencari Lid dan PN.
171
-
172
- Contoh:
173
- ``` javascript
174
- > conn.getLidFromPN(
175
- m,
176
- "6288246552068@s.whatsapp.net"
177
- );
178
- or
179
- > conn.getPNFromLid(
180
- m,
181
- "129459441135829@lid"
182
- );
137
+ // Mencari nomor HP dari LID
138
+ await conn.getPNFromLid(m, "129459441135829@lid");
183
139
  ```
184
- Example:
185
- ![example](https://api.ryuu-dev.offc.my.id/src/assest/Haruhime/mapping.jpg)
140
+ ### Hasil Output:
141
+ <img src="https://api.ryuu-dev.offc.my.id/src/assest/Haruhime/mapping.jpg" width="300" />
package/main/index.js CHANGED
@@ -1,51 +1,9 @@
1
- import addProperty from './socket.js';
2
- import useSQLiteAuthState from './sqliteAuth.js';
1
+ import { addProperty } from "./socket.js";
2
+ import useSQLiteAuthState from "./sqliteAuth.js";
3
3
 
4
- const haruka = {}
5
- haruka.tutorial = console.log(`
6
- ╭──────────────────────────────────────╮
7
- │ @ryuu-reinzz/haruka-lib │
8
- │ Small helper for WhatsApp Baileys │
9
- ╰──────────────────────────────────────╯
10
-
11
- Usage:
12
- haruka.extendSocketBot(socket, store, smsg, baileys)
13
- → extend socket with helper methods
14
-
15
- haruka.useSQLiteAuthState()
16
- → SQLite-based auth state for your bot
17
-
18
- Examples:
19
- Add socket:
20
- import makeWASocket, {
21
- proto,
22
- generateWAMessageFromContent,
23
- jidDecode,
24
- downloadContentFromMessage,
25
- prepareWAMessageMedia,
26
- generateMessageID
27
- } from "baileys";
28
- const conn = makeWASocket({});
29
- const baileys = {
30
- proto,
31
- generateWAMessageFromContent,
32
- jidDecode,
33
- downloadContentFromMessage,
34
- prepareWAMessageMedia,
35
- generateMessageID
36
- }
37
- import haruka from "@ryuu-reinzz/haruka-lib";
38
- haruka.extendSocketBot(conn, store, smsg, baileys);
39
-
40
- SQLite session:
41
- const sessionPath = "./session"
42
- if (!fs.existsSync(sessionPath)) fs.mkdirSync(sessionPath, { recursive: true });
43
- const useSQLiteAuthState = haruka.useSQLiteAuthState;
44
- const { state, saveCreds } = await useSQLiteAuthState(sessionPath + \"auth.db\");
45
-
46
- Made by Ryuu
47
- `);
48
- haruka.useSQLiteAuthState = useSQLiteAuthState;
49
- haruka.addProperty = addProperty;
4
+ const haruka = {
5
+ addProperty,
6
+ useSQLiteAuthState
7
+ };
50
8
 
51
9
  export default haruka;
package/main/socket.js CHANGED
@@ -14,6 +14,68 @@ 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
+ socket.sendMessage(
58
+ socket.user.jid,
59
+ {
60
+ text: tutor,
61
+ contextInfo: {
62
+ forwardingScore: 99,
63
+ isForwarded: true,
64
+ forwardedNewsletterMessageInfo: {
65
+ newsletterName: "𝙍͢𝙮𝙪𝙪 𝙍͢𝙚𝙞𝙣𝙯𝙯",
66
+ newsletterJid: "120363419382206255@newsletter"
67
+ },
68
+ externalAdReply: {
69
+ title: "Haruka Tutorial",
70
+ body: "How to use",
71
+ thumbnailUrl: "https://api.ryuu-dev.offc.my.id/src/assest/bot/Haruka.jpg",
72
+ sourceUrl: `https://whatsapp.com/channel/0029Vb49CCWJ93wO2dLDqx14`,
73
+ mediaType: 1,
74
+ renderLargerThumbnail: true,
75
+ },
76
+ },
77
+ }
78
+ );
17
79
  const {
18
80
  proto,
19
81
  generateWAMessageFromContent,
@@ -155,350 +217,316 @@ Object.assign(socket, {
155
217
  }
156
218
  },
157
219
 
158
- sendButton: async (jid, content = {}, options = {}) => {
159
- if (!socket.user?.id) {
160
- throw new Error("User not authenticated");
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
- }
220
+ sendButton:
221
+ async (jid, content = {}, options = {}) => {
222
+ if (!socket.user?.id) {
223
+ throw new Error("User not authenticated");
224
+ }
216
225
 
217
- if (btn.buttonId && btn.buttonText
218
- ?.displayText) {
219
- interactiveButtons.push({
220
- name: "quick_reply",
221
- buttonParamsJson: JSON
222
- .stringify({
223
- display_text: btn
224
- .buttonText
225
- .displayText,
226
- id: btn.buttonId,
227
- }),
228
- });
229
- continue;
230
- }
226
+ const {
227
+ text = "",
228
+ caption = "",
229
+ title = "",
230
+ footer = "",
231
+ buttons = [],
232
+ hasMediaAttachment = false,
233
+ image = null,
234
+ video = null,
235
+ document = null,
236
+ mimetype = null,
237
+ jpegThumbnail = null,
238
+ location = null,
239
+ product = null,
240
+ businessOwnerJid = null,
241
+ externalAdReply = null,
242
+ } = content;
243
+
244
+ if (!Array.isArray(buttons) || buttons.length === 0) {
245
+ throw new Error("buttons must be a non-empty array");
246
+ }
231
247
 
232
- throw new Error(
233
- `button[${i}] has invalid shape`);
234
- }
248
+ const processedButtons = [];
249
+
250
+ for (let i = 0; i < buttons.length; i++) {
251
+ const btn = buttons[i];
252
+
253
+ if (!btn || typeof btn !== "object") {
254
+ throw new Error(`interactiveButton[${i}] must be an object`);
255
+ }
256
+
257
+ if (btn.name && btn.buttonParamsJson) {
258
+ processedButtons.push(btn);
259
+ continue;
260
+ }
261
+
262
+ if (btn.id || btn.text || btn.displayText) {
263
+ processedButtons.push({
264
+ name: "quick_reply",
265
+ buttonParamsJson: JSON.stringify({
266
+ display_text: btn.text || btn.displayText || `Button ${i + 1}`,
267
+ id: btn.id || `quick_${i + 1}`,
268
+ }),
269
+ });
270
+ continue;
271
+ }
272
+
273
+ if (btn.buttonId && btn.buttonText?.displayText) {
274
+ processedButtons.push({
275
+ name: "quick_reply",
276
+ buttonParamsJson: JSON.stringify({
277
+ display_text: btn.buttonText.displayText,
278
+ id: btn.buttonId,
279
+ }),
280
+ });
281
+ continue;
282
+ }
283
+
284
+ throw new Error(`interactiveButton[${i}] has invalid shape`);
285
+ }
235
286
 
236
- let messageContent = {};
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
- }
287
+ let messageContent = {};
251
288
 
252
- const preparedMedia =
253
- await prepareWAMessageMedia(mediaInput, {
254
- upload: socket.waUploadToServer,
255
- });
256
-
257
- messageContent.header = {
258
- title: title || "",
259
- hasMediaAttachment: hasMediaAttachment,
260
- imageMessage: preparedMedia
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
- }
289
+ if (image) {
290
+ const mediaInput = {};
291
+ if (Buffer.isBuffer(image)) {
292
+ mediaInput.image = image;
293
+ } else if (typeof image === "object" && image.url) {
294
+ mediaInput.image = { url: image.url };
295
+ } else if (typeof image === "string") {
296
+ mediaInput.image = { url: image };
297
+ }
277
298
 
278
- const preparedMedia =
279
- await prepareWAMessageMedia(mediaInput, {
280
- upload: socket.waUploadToServer,
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
- }
299
+ const preparedMedia = await prepareWAMessageMedia(mediaInput, {
300
+ upload: socket.waUploadToServer,
301
+ });
306
302
 
307
- if (mimetype) {
308
- if (typeof mediaInput.document ===
309
- "object") {
310
- mediaInput.document.mimetype = mimetype;
311
- }
312
- }
303
+ messageContent.header = {
304
+ title: title || "",
305
+ hasMediaAttachment: hasMediaAttachment || true,
306
+ imageMessage: preparedMedia.imageMessage,
307
+ };
308
+ } else if (video) {
309
+ const mediaInput = {};
310
+ if (Buffer.isBuffer(video)) {
311
+ mediaInput.video = video;
312
+ } else if (typeof video === "object" && video.url) {
313
+ mediaInput.video = { url: video.url };
314
+ } else if (typeof video === "string") {
315
+ mediaInput.video = { url: video };
316
+ }
317
+
318
+ const preparedMedia = await prepareWAMessageMedia(mediaInput, {
319
+ upload: socket.waUploadToServer,
320
+ });
313
321
 
314
- if (jpegThumbnail) {
315
- if (typeof mediaInput.document ===
316
- "object") {
317
- if (Buffer.isBuffer(jpegThumbnail)) {
318
- mediaInput.document.jpegThumbnail =
319
- jpegThumbnail;
320
- } else if (typeof jpegThumbnail ===
321
- "string") {
322
- try {
323
- const response = await fetch(
324
- jpegThumbnail);
325
- const arrayBuffer =
326
- await response
327
- .arrayBuffer();
328
- mediaInput.document
329
- .jpegThumbnail = Buffer
330
- .from(arrayBuffer);
331
- } catch {
332
- }
333
- }
334
- }
335
- }
322
+ messageContent.header = {
323
+ title: title || "",
324
+ hasMediaAttachment: hasMediaAttachment || true,
325
+ videoMessage: preparedMedia.videoMessage,
326
+ };
327
+ } else if (document) {
328
+ const mediaInput = { document: {} };
329
+
330
+ if (Buffer.isBuffer(document)) {
331
+ mediaInput.document = document;
332
+ } else if (typeof document === "object" && document.url) {
333
+ mediaInput.document = { url: document.url };
334
+ } else if (typeof document === "string") {
335
+ mediaInput.document = { url: document };
336
+ }
337
+
338
+ if (mimetype) {
339
+ if (typeof mediaInput.document === "object") {
340
+ mediaInput.document.mimetype = mimetype;
341
+ }
342
+ }
343
+
344
+ if (jpegThumbnail) {
345
+ if (typeof mediaInput.document === "object") {
346
+ if (Buffer.isBuffer(jpegThumbnail)) {
347
+ mediaInput.document.jpegThumbnail = jpegThumbnail;
348
+ } else if (typeof jpegThumbnail === "string") {
349
+ try {
350
+ const response = await fetch(jpegThumbnail);
351
+ const arrayBuffer = await response.arrayBuffer();
352
+ mediaInput.document.jpegThumbnail = Buffer.from(arrayBuffer);
353
+ } catch {
354
+ //
355
+ }
356
+ }
357
+ }
358
+ }
359
+
360
+ const preparedMedia = await prepareWAMessageMedia(mediaInput, {
361
+ upload: socket.waUploadToServer,
362
+ });
336
363
 
337
- const preparedMedia =
338
- await prepareWAMessageMedia(mediaInput, {
339
- upload: socket.waUploadToServer,
340
- });
341
-
342
- messageContent.header = {
343
- title: title || "",
344
- hasMediaAttachment: hasMediaAttachment,
345
- documentMessage: preparedMedia
346
- .documentMessage,
347
- };
348
- } else if (location && typeof location ===
349
- "object") {
350
- messageContent.header = {
351
- title: title || location.name ||
352
- "Location",
353
- hasMediaAttachment: hasMediaAttachment,
354
- locationMessage: {
355
- degreesLatitude: location
356
- .degressLatitude || location
357
- .degreesLatitude || 0,
358
- degreesLongitude: location
359
- .degressLongitude || location
360
- .degreesLongitude || 0,
361
- name: location.name || "",
362
- address: location.address || "",
363
- },
364
- };
365
- } else if (product && typeof product === "object") {
366
- let productImageMessage = null;
367
- if (product.productImage) {
368
- const mediaInput = {};
369
- if (Buffer.isBuffer(product.productImage)) {
370
- mediaInput.image = product.productImage;
371
- } else if (
372
- typeof product.productImage ===
373
- "object" &&
374
- product.productImage.url
375
- ) {
376
- mediaInput.image = {
377
- url: product.productImage.url,
378
- };
379
- } else if (typeof product.productImage ===
380
- "string") {
381
- mediaInput.image = {
382
- url: product.productImage,
383
- };
384
- }
364
+ messageContent.header = {
365
+ title: title || "",
366
+ hasMediaAttachment: hasMediaAttachment || true,
367
+ documentMessage: preparedMedia.documentMessage,
368
+ };
369
+ } else if (location && typeof location === "object") {
370
+ messageContent.header = {
371
+ title: title || location.name || "Location",
372
+ hasMediaAttachment: hasMediaAttachment || false,
373
+ locationMessage: {
374
+ degreesLatitude:
375
+ location.degressLatitude || location.degreesLatitude || 0,
376
+ degreesLongitude:
377
+ location.degressLongitude || location.degreesLongitude || 0,
378
+ name: location.name || "",
379
+ address: location.address || "",
380
+ },
381
+ };
382
+ } else if (product && typeof product === "object") {
383
+ let productImageMessage = null;
384
+ if (product.productImage) {
385
+ const mediaInput = {};
386
+ if (Buffer.isBuffer(product.productImage)) {
387
+ mediaInput.image = product.productImage;
388
+ } else if (
389
+ typeof product.productImage === "object" &&
390
+ product.productImage.url
391
+ ) {
392
+ mediaInput.image = {
393
+ url: product.productImage.url,
394
+ };
395
+ } else if (typeof product.productImage === "string") {
396
+ mediaInput.image = {
397
+ url: product.productImage,
398
+ };
399
+ }
400
+
401
+ const preparedMedia = await prepareWAMessageMedia(mediaInput, {
402
+ upload: socket.waUploadToServer,
403
+ });
404
+ productImageMessage = preparedMedia.imageMessage;
405
+ }
406
+
407
+ messageContent.header = {
408
+ title: title || product.title || "Product",
409
+ hasMediaAttachment: hasMediaAttachment || false,
410
+ productMessage: {
411
+ product: {
412
+ productImage: productImageMessage,
413
+ productId: product.productId || "",
414
+ title: product.title || "",
415
+ description: product.description || "",
416
+ currencyCode: product.currencyCode || "USD",
417
+ priceAmount1000: parseInt(product.priceAmount1000) || 0,
418
+ retailerId: product.retailerId || "",
419
+ url: product.url || "",
420
+ productImageCount: product.productImageCount || 1,
421
+ },
422
+ businessOwnerJid:
423
+ businessOwnerJid || product.businessOwnerJid || socket.user.id,
424
+ },
425
+ };
426
+ } else if (title) {
427
+ messageContent.header = {
428
+ title: title,
429
+ hasMediaAttachment: false,
430
+ };
431
+ }
385
432
 
386
- const preparedMedia =
387
- await prepareWAMessageMedia(
388
- mediaInput, {
389
- upload: socket.waUploadToServer,
390
- });
391
- productImageMessage = preparedMedia
392
- .imageMessage;
393
- }
433
+ const hasMedia = !!(image || video || document || location || product);
434
+ const bodyText = hasMedia ? caption : text || caption;
394
435
 
395
- messageContent.header = {
396
- title: title || product.title ||
397
- "Product",
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
- }
436
+ if (bodyText) {
437
+ messageContent.body = { text: bodyText };
438
+ }
429
439
 
430
- const hasMedia = !!(image || video || document ||
431
- location || product);
432
- const bodyText = hasMedia ? caption : text ||
433
- caption;
440
+ if (footer) {
441
+ messageContent.footer = { text: footer };
442
+ }
434
443
 
435
- if (bodyText) {
436
- messageContent.body = {
437
- text: bodyText
438
- };
439
- }
444
+ messageContent.nativeFlowMessage = {
445
+ buttons: processedButtons,
446
+ };
440
447
 
441
- if (footer) {
442
- messageContent.footer = {
443
- text: footer
444
- };
445
- }
448
+ if (externalAdReply && typeof externalAdReply === "object") {
449
+ messageContent.contextInfo = {
450
+ externalAdReply: {
451
+ title: externalAdReply.title || "",
452
+ body: externalAdReply.body || "",
453
+ mediaType: externalAdReply.mediaType || 1,
454
+ sourceUrl: externalAdReply.sourceUrl || externalAdReply.url || "",
455
+ thumbnailUrl:
456
+ externalAdReply.thumbnailUrl || externalAdReply.thumbnail || "",
457
+ renderLargerThumbnail: externalAdReply.renderLargerThumbnail || false,
458
+ showAdAttribution: externalAdReply.showAdAttribution !== false,
459
+ containsAutoReply: externalAdReply.containsAutoReply || false,
460
+ ...(externalAdReply.mediaUrl && {
461
+ mediaUrl: externalAdReply.mediaUrl,
462
+ }),
463
+ ...(externalAdReply.thumbnail &&
464
+ Buffer.isBuffer(externalAdReply.thumbnail) && {
465
+ thumbnail: externalAdReply.thumbnail,
466
+ }),
467
+ ...(externalAdReply.jpegThumbnail && {
468
+ jpegThumbnail: externalAdReply.jpegThumbnail,
469
+ }),
470
+ },
471
+ ...(options.mentionedJid && {
472
+ mentionedJid: options.mentionedJid,
473
+ }),
474
+ };
475
+ } else if (options.mentionedJid) {
476
+ messageContent.contextInfo = {
477
+ mentionedJid: options.mentionedJid,
478
+ };
479
+ }
446
480
 
447
- messageContent.nativeFlowMessage = {
448
- buttons: interactiveButtons,
449
- };
481
+ const payload = proto.Message.InteractiveMessage.create(messageContent);
450
482
 
451
- const payload = proto.Message.InteractiveMessage
452
- .create(messageContent);
483
+ const msg = generateWAMessageFromContent(
484
+ jid,
485
+ {
486
+ viewOnceMessage: {
487
+ message: {
488
+ interactiveMessage: payload,
489
+ },
490
+ },
491
+ },
492
+ {
493
+ userJid: socket.user.id,
494
+ quoted: options?.quoted || null,
495
+ }
496
+ );
453
497
 
454
- const msg = generateWAMessageFromContent(
455
- jid, {
456
- viewOnceMessage: {
457
- message: {
458
- interactiveMessage: payload,
459
- },
460
- },
461
- }, {
462
- userJid: socket.user.id,
463
- quoted: options?.quoted || null,
464
- }
465
- );
466
- const isGroup = jid.endsWith("@g.us");
467
- const additionalNodes = [{
468
- tag: "biz",
469
- attrs: {},
470
- content: [{
471
- tag: "interactive",
472
- attrs: {
473
- type: "native_flow",
474
- v: "1",
475
- },
476
- content: [{
477
- tag: "native_flow",
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
- }
498
+ const additionalNodes = [
499
+ {
500
+ tag: "biz",
501
+ attrs: {},
502
+ content: [
503
+ {
504
+ tag: "interactive",
505
+ attrs: {
506
+ type: "native_flow",
507
+ v: "1",
508
+ },
509
+ content: [
510
+ {
511
+ tag: "native_flow",
512
+ attrs: {
513
+ v: "9",
514
+ name: "mixed",
515
+ },
516
+ },
517
+ ],
518
+ },
519
+ ],
520
+ },
521
+ ];
494
522
 
495
- await socket.relayMessage(jid, msg.message, {
496
- messageId: msg.key.id,
497
- additionalNodes,
498
- });
523
+ await socket.relayMessage(jid, msg.message, {
524
+ messageId: msg.key.id,
525
+ additionalNodes,
526
+ });
499
527
 
500
- return msg;
501
- },
528
+ return msg;
529
+ },
502
530
  sendAlbum: async (jid, items = [], options = {}) => {
503
531
  if (!socket.user?.id) {
504
532
  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.1.0-beta.1",
3
+ "version": "1.2.16",
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": "^4.4.4"
20
+ "wa-sticker-formatter": "4.4.4"
21
21
  }
22
22
  }