@jiancodes/baileys 2.0.3 → 2.0.4
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 +388 -90
- package/lib/Defaults/baileys-version.json +1 -1
- package/lib/Utils/generics.js +4 -79
- package/lib/index.js +7 -12
- package/package.json +9 -9
- package/lib/Socket/newsletter.js.bak +0 -351
package/README.md
CHANGED
|
@@ -1,95 +1,393 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
# WhatsApp Baileys
|
|
2
|
+
|
|
3
|
+
<p align="center">
|
|
4
|
+
<img src="https://files.catbox.moe/369pux.jpg" alt="Thumbnail" />
|
|
4
5
|
</p>
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
7
|
+
WhatsApp Baileys is an open-source library designed to help developers build automation solutions and integrations with WhatsApp efficiently and directly. Using websocket technology without the need for a browser, this library supports a wide range of features such as message management, chat handling, group administration, as well as interactive messages and action buttons for a more dynamic user experience.
|
|
8
|
+
|
|
9
|
+
Actively developed and maintained, baileys continuously receives updates to enhance stability and performance. One of the main focuses is to improve the pairing and authentication processes to be more stable and secure. Pairing features can be customized with your own codes, making the process more reliable and less prone to interruptions.
|
|
10
|
+
|
|
11
|
+
This library is highly suitable for building business bots, chat automation systems, customer service solutions, and various other communication automation applications that require high stability and comprehensive features. With a lightweight and modular design, baileys is easy to integrate into different systems and platforms.
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
### Main Features and Advantages
|
|
16
|
+
|
|
17
|
+
- Supports automatic and custom pairing processes
|
|
18
|
+
- Fixes previous pairing issues that often caused failures or disconnections
|
|
19
|
+
- Supports interactive messages, action buttons, and dynamic menus
|
|
20
|
+
- Efficient automatic session management for reliable operation
|
|
21
|
+
- Compatible with the latest multi-device features from WhatsApp
|
|
22
|
+
- Lightweight, stable, and easy to integrate into various systems
|
|
23
|
+
- Suitable for developing bots, automation, and complete communication solutions
|
|
24
|
+
- Comprehensive documentation and example codes to facilitate development
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
## Getting Started
|
|
29
|
+
|
|
30
|
+
Begin by installing the library via your preferred package manager, then follow the provided configuration guide. You can also utilize the ready-made example codes to understand how the features work. Use session storage and interactive messaging features to build complete, stable solutions tailored to your business or project needs.
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
## Add Function ( Simple code )
|
|
35
|
+
|
|
36
|
+
### Check ID Channel
|
|
37
|
+
Get ID channel
|
|
38
|
+
|
|
39
|
+
```javascript
|
|
40
|
+
await sock.newsletterId(url)
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### Check banned number
|
|
44
|
+
You can see the status of blocked numbers here
|
|
45
|
+
|
|
46
|
+
```javascript
|
|
47
|
+
await sock.checkWhatsApp(jid)
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
---
|
|
51
|
+
|
|
52
|
+
## SendMessage Documentation
|
|
53
|
+
|
|
54
|
+
### Status Group Message V2
|
|
55
|
+
Send group status with version 2
|
|
56
|
+
|
|
57
|
+
```javascript
|
|
58
|
+
await sock.sendMessage(jid, {
|
|
59
|
+
groupStatusMessage: {
|
|
60
|
+
text: "Hello World"
|
|
61
|
+
}
|
|
39
62
|
});
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### Album Message (Multiple Images)
|
|
66
|
+
Send multiple images in a single album message:
|
|
67
|
+
|
|
68
|
+
```javascript
|
|
69
|
+
await sock.sendMessage(jid, {
|
|
70
|
+
albumMessage: [
|
|
71
|
+
{ image: cihuy, caption: "Foto pertama" },
|
|
72
|
+
{ image: { url: "URL IMAGE" }, caption: "Foto kedua" }
|
|
73
|
+
]
|
|
74
|
+
}, { quoted: m });
|
|
75
|
+
```
|
|
40
76
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
77
|
+
### Event Message
|
|
78
|
+
Create and send WhatsApp event invitations:
|
|
79
|
+
|
|
80
|
+
```javascript
|
|
81
|
+
await sock.sendMessage(jid, {
|
|
82
|
+
eventMessage: {
|
|
83
|
+
isCanceled: false,
|
|
84
|
+
name: "Hello World",
|
|
85
|
+
description: "yume native",
|
|
86
|
+
location: {
|
|
87
|
+
degreesLatitude: 0,
|
|
88
|
+
degreesLongitude: 0,
|
|
89
|
+
name: "rowrrrr"
|
|
90
|
+
},
|
|
91
|
+
joinLink: "https://call.whatsapp.com/video/yumevtc",
|
|
92
|
+
startTime: "1763019000",
|
|
93
|
+
endTime: "1763026200",
|
|
94
|
+
extraGuestsAllowed: false
|
|
95
|
+
}
|
|
96
|
+
}, { quoted: m });
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### Poll Result Message
|
|
100
|
+
Display poll results with vote counts:
|
|
101
|
+
|
|
102
|
+
```javascript
|
|
103
|
+
await sock.sendMessage(jid, {
|
|
104
|
+
pollResultMessage: {
|
|
105
|
+
name: "Hello World",
|
|
106
|
+
pollVotes: [
|
|
107
|
+
{
|
|
108
|
+
optionName: "TEST 1",
|
|
109
|
+
optionVoteCount: "112233"
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
optionName: "TEST 2",
|
|
113
|
+
optionVoteCount: "1"
|
|
114
|
+
}
|
|
115
|
+
]
|
|
116
|
+
}
|
|
117
|
+
}, { quoted: m });
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### Simple Interactive Message
|
|
121
|
+
Send basic interactive messages with copy button functionality:
|
|
122
|
+
|
|
123
|
+
```javascript
|
|
124
|
+
await sock.sendMessage(jid, {
|
|
125
|
+
interactiveMessage: {
|
|
126
|
+
header: "Hello World",
|
|
127
|
+
title: "Hello World",
|
|
128
|
+
footer: "telegram: @yumevtc ",
|
|
129
|
+
buttons: [
|
|
130
|
+
{
|
|
131
|
+
name: "cta_copy",
|
|
132
|
+
buttonParamsJson: JSON.stringify({
|
|
133
|
+
display_text: "copy code",
|
|
134
|
+
id: "123456789",
|
|
135
|
+
copy_code: "ABC123XYZ"
|
|
136
|
+
})
|
|
137
|
+
}
|
|
138
|
+
]
|
|
72
139
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
140
|
+
}, { quoted: m });
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
### Interactive Message with Native Flow
|
|
144
|
+
Send interactive messages with buttons, copy actions, and native flow features:
|
|
145
|
+
|
|
146
|
+
```javascript
|
|
147
|
+
await sock.sendMessage(jid, {
|
|
148
|
+
interactiveMessage: {
|
|
149
|
+
header: "Hello World",
|
|
150
|
+
title: "Hello World",
|
|
151
|
+
footer: "telegram: @yumevtc",
|
|
152
|
+
image: { url: "https://example.com/image.jpg" },
|
|
153
|
+
nativeFlowMessage: {
|
|
154
|
+
messageParamsJson: JSON.stringify({
|
|
155
|
+
limited_time_offer: {
|
|
156
|
+
text: "idk hummmm?",
|
|
157
|
+
url: "https://t.me/yumevtc",
|
|
158
|
+
copy_code: "yume",
|
|
159
|
+
expiration_time: Date.now() * 999
|
|
160
|
+
},
|
|
161
|
+
bottom_sheet: {
|
|
162
|
+
in_thread_buttons_limit: 2,
|
|
163
|
+
divider_indices: [1, 2, 3, 4, 5, 999],
|
|
164
|
+
list_title: "yume native",
|
|
165
|
+
button_title: "yume native"
|
|
166
|
+
},
|
|
167
|
+
tap_target_configuration: {
|
|
168
|
+
title: " X ",
|
|
169
|
+
description: "bomboclard",
|
|
170
|
+
canonical_url: "https://t.me/yumevtc",
|
|
171
|
+
domain: "shop.example.com",
|
|
172
|
+
button_index: 0
|
|
173
|
+
}
|
|
174
|
+
}),
|
|
175
|
+
buttons: [
|
|
176
|
+
{
|
|
177
|
+
name: "single_select",
|
|
178
|
+
buttonParamsJson: JSON.stringify({
|
|
179
|
+
has_multiple_buttons: true
|
|
180
|
+
})
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
name: "call_permission_request",
|
|
184
|
+
buttonParamsJson: JSON.stringify({
|
|
185
|
+
has_multiple_buttons: true
|
|
186
|
+
})
|
|
187
|
+
},
|
|
188
|
+
{
|
|
189
|
+
name: "single_select",
|
|
190
|
+
buttonParamsJson: JSON.stringify({
|
|
191
|
+
title: "Hello World",
|
|
192
|
+
sections: [
|
|
193
|
+
{
|
|
194
|
+
title: "title",
|
|
195
|
+
highlight_label: "label",
|
|
196
|
+
rows: [
|
|
197
|
+
{
|
|
198
|
+
title: "@yumevtc",
|
|
199
|
+
description: "love you",
|
|
200
|
+
id: "row_2"
|
|
201
|
+
}
|
|
202
|
+
]
|
|
203
|
+
}
|
|
204
|
+
],
|
|
205
|
+
has_multiple_buttons: true
|
|
206
|
+
})
|
|
207
|
+
},
|
|
208
|
+
{
|
|
209
|
+
name: "cta_copy",
|
|
210
|
+
buttonParamsJson: JSON.stringify({
|
|
211
|
+
display_text: "copy code",
|
|
212
|
+
id: "123456789",
|
|
213
|
+
copy_code: "ABC123XYZ"
|
|
214
|
+
})
|
|
215
|
+
}
|
|
216
|
+
]
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}, { quoted: m });
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
### Interactive Message with Thumbnail
|
|
223
|
+
Send interactive messages with thumbnail image and copy button:
|
|
224
|
+
|
|
225
|
+
```javascript
|
|
226
|
+
await sock.sendMessage(jid, {
|
|
227
|
+
interactiveMessage: {
|
|
228
|
+
header: "Hello World",
|
|
229
|
+
title: "Hello World",
|
|
230
|
+
footer: "telegram: @yumevtc",
|
|
231
|
+
image: { url: "https://example.com/image.jpg" },
|
|
232
|
+
buttons: [
|
|
233
|
+
{
|
|
234
|
+
name: "cta_copy",
|
|
235
|
+
buttonParamsJson: JSON.stringify({
|
|
236
|
+
display_text: "copy code",
|
|
237
|
+
id: "123456789",
|
|
238
|
+
copy_code: "ABC123XYZ"
|
|
239
|
+
})
|
|
240
|
+
}
|
|
241
|
+
]
|
|
242
|
+
}
|
|
243
|
+
}, { quoted: m });
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
### Product Message
|
|
247
|
+
Send product catalog messages with buttons and merchant information:
|
|
248
|
+
|
|
249
|
+
```javascript
|
|
250
|
+
await sock.sendMessage(jid, {
|
|
251
|
+
productMessage: {
|
|
252
|
+
title: "Produk Contoh",
|
|
253
|
+
description: "Ini adalah deskripsi produk",
|
|
254
|
+
thumbnail: { url: "https://example.com/image.jpg" },
|
|
255
|
+
productId: "PROD001",
|
|
256
|
+
retailerId: "RETAIL001",
|
|
257
|
+
url: "https://example.com/product",
|
|
258
|
+
body: "Detail produk",
|
|
259
|
+
footer: "Harga spesial",
|
|
260
|
+
priceAmount1000: 50000,
|
|
261
|
+
currencyCode: "USD",
|
|
262
|
+
buttons: [
|
|
263
|
+
{
|
|
264
|
+
name: "cta_url",
|
|
265
|
+
buttonParamsJson: JSON.stringify({
|
|
266
|
+
display_text: "Beli Sekarang",
|
|
267
|
+
url: "https://example.com/buy"
|
|
268
|
+
})
|
|
269
|
+
}
|
|
270
|
+
]
|
|
271
|
+
}
|
|
272
|
+
}, { quoted: m });
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
### Interactive Message with Document Buffer
|
|
276
|
+
Send interactive messages with document from buffer (file system) - **Note: Documents only support buffer**:
|
|
277
|
+
|
|
278
|
+
```javascript
|
|
279
|
+
await sock.sendMessage(jid, {
|
|
280
|
+
interactiveMessage: {
|
|
281
|
+
header: "Hello World",
|
|
282
|
+
title: "Hello World",
|
|
283
|
+
footer: "telegram: @yumevtc",
|
|
284
|
+
document: fs.readFileSync("./package.json"),
|
|
285
|
+
mimetype: "application/pdf",
|
|
286
|
+
fileName: "yumevtc.pdf",
|
|
287
|
+
jpegThumbnail: fs.readFileSync("./document.jpeg"),
|
|
288
|
+
contextInfo: {
|
|
289
|
+
mentionedJid: [jid],
|
|
290
|
+
forwardingScore: 777,
|
|
291
|
+
isForwarded: false
|
|
292
|
+
},
|
|
293
|
+
externalAdReply: {
|
|
294
|
+
title: "shenń Bot",
|
|
295
|
+
body: "anu team",
|
|
296
|
+
mediaType: 3,
|
|
297
|
+
thumbnailUrl: "https://example.com/image.jpg",
|
|
298
|
+
mediaUrl: " X ",
|
|
299
|
+
sourceUrl: "https://t.me/yumevtc",
|
|
300
|
+
showAdAttribution: true,
|
|
301
|
+
renderLargerThumbnail: false
|
|
302
|
+
},
|
|
303
|
+
buttons: [
|
|
304
|
+
{
|
|
305
|
+
name: "cta_url",
|
|
306
|
+
buttonParamsJson: JSON.stringify({
|
|
307
|
+
display_text: "Telegram",
|
|
308
|
+
url: "https://t.me/yumevtc",
|
|
309
|
+
merchant_url: "https://t.me/yumevtc"
|
|
310
|
+
})
|
|
311
|
+
}
|
|
312
|
+
]
|
|
313
|
+
}
|
|
314
|
+
}, { quoted: m });
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
### Interactive Message with Document Buffer (Simple)
|
|
318
|
+
Send interactive messages with document from buffer (file system) without contextInfo and externalAdReply - **Note: Documents only support buffer**:
|
|
319
|
+
|
|
320
|
+
```javascript
|
|
321
|
+
await sock.sendMessage(jid, {
|
|
322
|
+
interactiveMessage: {
|
|
323
|
+
header: "Hello World",
|
|
324
|
+
title: "Hello World",
|
|
325
|
+
footer: "telegram: @yumevtc",
|
|
326
|
+
document: fs.readFileSync("./package.json"),
|
|
327
|
+
mimetype: "application/pdf",
|
|
328
|
+
fileName: "yumevtc.pdf",
|
|
329
|
+
jpegThumbnail: fs.readFileSync("./document.jpeg"),
|
|
330
|
+
buttons: [
|
|
331
|
+
{
|
|
332
|
+
name: "cta_url",
|
|
333
|
+
buttonParamsJson: JSON.stringify({
|
|
334
|
+
display_text: "Telegram",
|
|
335
|
+
url: "https://t.me/yumevtc",
|
|
336
|
+
merchant_url: "https://t.me/yumevtc"
|
|
337
|
+
})
|
|
338
|
+
}
|
|
339
|
+
]
|
|
340
|
+
}
|
|
341
|
+
}, { quoted: m });
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
### Request Payment Message
|
|
345
|
+
Send payment request messages with custom background and sticker:
|
|
346
|
+
|
|
347
|
+
```javascript
|
|
348
|
+
let quotedType = m.quoted?.mtype || '';
|
|
349
|
+
let quotedContent = JSON.stringify({ [quotedType]: m.quoted }, null, 2);
|
|
350
|
+
|
|
351
|
+
await sock.sendMessage(jid, {
|
|
352
|
+
requestPaymentMessage: {
|
|
353
|
+
currency: "IDR",
|
|
354
|
+
amount: 10000000,
|
|
355
|
+
from: m.sender,
|
|
356
|
+
sticker: JSON.parse(quotedContent),
|
|
357
|
+
background: {
|
|
358
|
+
id: "100",
|
|
359
|
+
fileLength: "0",
|
|
360
|
+
width: 1000,
|
|
361
|
+
height: 1000,
|
|
362
|
+
mimetype: "image/webp",
|
|
363
|
+
placeholderArgb: 0xFF00FFFF,
|
|
364
|
+
textArgb: 0xFFFFFFFF,
|
|
365
|
+
subtextArgb: 0xFFAA00FF
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
}, { quoted: m });
|
|
369
|
+
```
|
|
370
|
+
|
|
371
|
+
---
|
|
372
|
+
|
|
373
|
+
## Why Choose WhatsApp Baileys?
|
|
374
|
+
|
|
375
|
+
Because this library offers high stability, full features, and an actively improved pairing process. It is ideal for developers aiming to create professional and secure WhatsApp automation solutions. Support for the latest WhatsApp features ensures compatibility with platform updates.
|
|
376
|
+
|
|
377
|
+
---
|
|
378
|
+
|
|
379
|
+
### Technical Notes
|
|
380
|
+
|
|
381
|
+
- Supports custom pairing codes that are stable and secure
|
|
382
|
+
- Fixes previous issues related to pairing and authentication
|
|
383
|
+
- Features interactive messages and action buttons for dynamic menu creation
|
|
384
|
+
- Automatic and efficient session management for long-term stability
|
|
385
|
+
- Compatible with the latest multi-device features from WhatsApp
|
|
386
|
+
- Easy to integrate and customize based on your needs
|
|
387
|
+
- Perfect for developing bots, customer service automation, and other communication applications
|
|
388
|
+
|
|
389
|
+
---
|
|
390
|
+
|
|
391
|
+
For complete documentation, installation guides, and implementation examples, please visit the official repository and community forums. We continually update and improve this library to meet the needs of developers and users of modern WhatsApp automation solutions.
|
|
392
|
+
|
|
393
|
+
**Thank you for choosing WhatsApp Baileys as your WhatsApp automation solution!**
|
package/lib/Utils/generics.js
CHANGED
|
@@ -137,78 +137,6 @@ const delayCancellable = (ms) => {
|
|
|
137
137
|
return { delay, cancel };
|
|
138
138
|
};
|
|
139
139
|
exports.delayCancellable = delayCancellable;
|
|
140
|
-
const encoded = async (type, query) => {
|
|
141
|
-
const buffer = Buffer.from(query, 'utf-8');
|
|
142
|
-
switch (type.toLowerCase()) {
|
|
143
|
-
case 'base64':
|
|
144
|
-
return buffer.toString('base64');
|
|
145
|
-
case 'base32':
|
|
146
|
-
const base32Alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567';
|
|
147
|
-
let bits = 0;
|
|
148
|
-
let value = 0;
|
|
149
|
-
let output = '';
|
|
150
|
-
for (let i = 0; i < buffer.length; i++) {
|
|
151
|
-
value = (value << 8) | buffer[i];
|
|
152
|
-
bits += 8;
|
|
153
|
-
while (bits >= 5) {
|
|
154
|
-
output += base32Alphabet[(value >>> (bits - 5)) & 31];
|
|
155
|
-
bits -= 5;
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
if (bits > 0) {
|
|
159
|
-
output += base32Alphabet[(value << (5 - bits)) & 31];
|
|
160
|
-
}
|
|
161
|
-
while (output.length % 8 !== 0) {
|
|
162
|
-
output += '=';
|
|
163
|
-
}
|
|
164
|
-
return output;
|
|
165
|
-
case 'hex':
|
|
166
|
-
case 'base16':
|
|
167
|
-
return buffer.toString('hex');
|
|
168
|
-
case 'binary':
|
|
169
|
-
return Array.from(buffer).map(byte => byte.toString(2).padStart(8, '0')).join(' ');
|
|
170
|
-
case 'base64url':
|
|
171
|
-
return buffer.toString('base64').replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
|
|
172
|
-
default:
|
|
173
|
-
throw new Error(`Type ${type} not supported`);
|
|
174
|
-
}
|
|
175
|
-
};
|
|
176
|
-
exports.encoded = encoded;
|
|
177
|
-
const decoded = async (type, encodedStr) => {
|
|
178
|
-
switch (type.toLowerCase()) {
|
|
179
|
-
case 'base64':
|
|
180
|
-
return Buffer.from(encodedStr, 'base64').toString('utf-8');
|
|
181
|
-
case 'base32':
|
|
182
|
-
const base32Alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567';
|
|
183
|
-
const cleanStr = encodedStr.toUpperCase().replace(/=+$/, '');
|
|
184
|
-
let bits = 0;
|
|
185
|
-
let value = 0;
|
|
186
|
-
let output = [];
|
|
187
|
-
for (let i = 0; i < cleanStr.length; i++) {
|
|
188
|
-
const charIndex = base32Alphabet.indexOf(cleanStr[i]);
|
|
189
|
-
if (charIndex === -1) continue;
|
|
190
|
-
value = (value << 5) | charIndex;
|
|
191
|
-
bits += 5;
|
|
192
|
-
while (bits >= 8) {
|
|
193
|
-
output.push((value >>> (bits - 8)) & 255);
|
|
194
|
-
bits -= 8;
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
return Buffer.from(output).toString('utf-8');
|
|
198
|
-
case 'hex':
|
|
199
|
-
case 'base16':
|
|
200
|
-
return Buffer.from(encodedStr, 'hex').toString('utf-8');
|
|
201
|
-
case 'binary':
|
|
202
|
-
const bytes = encodedStr.split(' ').map(bin => parseInt(bin, 2));
|
|
203
|
-
return Buffer.from(bytes).toString('utf-8');
|
|
204
|
-
case 'base64url':
|
|
205
|
-
const base64 = encodedStr.replace(/-/g, '+').replace(/_/g, '/');
|
|
206
|
-
return Buffer.from(base64, 'base64').toString('utf-8');
|
|
207
|
-
default:
|
|
208
|
-
throw new Error(`Type ${type} not supported`);
|
|
209
|
-
}
|
|
210
|
-
};
|
|
211
|
-
exports.decoded = decoded;
|
|
212
140
|
async function promiseTimeout(ms, promise) {
|
|
213
141
|
if (!ms) {
|
|
214
142
|
return new Promise(promise);
|
|
@@ -248,7 +176,7 @@ const generateMessageIDV2 = (userId) => {
|
|
|
248
176
|
};
|
|
249
177
|
exports.generateMessageIDV2 = generateMessageIDV2;
|
|
250
178
|
// generate a random ID to attach to a message
|
|
251
|
-
const generateMessageID = () => '
|
|
179
|
+
const generateMessageID = () => 'ILSYM-' + (0, crypto_1.randomBytes)(6).toString('hex').toUpperCase();
|
|
252
180
|
exports.generateMessageID = generateMessageID;
|
|
253
181
|
function bindWaitForEvent(ev, event) {
|
|
254
182
|
return async (check, timeoutMs) => {
|
|
@@ -303,10 +231,7 @@ const fetchLatestWaWebVersion = async (options = {}) => {
|
|
|
303
231
|
'Accept': '*/*'
|
|
304
232
|
}
|
|
305
233
|
|
|
306
|
-
const headers = {
|
|
307
|
-
...defaultHeaders,
|
|
308
|
-
...options.headers
|
|
309
|
-
}
|
|
234
|
+
const headers = { ...defaultHeaders, ...options.headers }
|
|
310
235
|
|
|
311
236
|
const response = await fetch_1('https://web.whatsapp.com/sw.js', {
|
|
312
237
|
method: 'GET',
|
|
@@ -318,7 +243,7 @@ const fetchLatestWaWebVersion = async (options = {}) => {
|
|
|
318
243
|
}
|
|
319
244
|
|
|
320
245
|
const data = await response.text()
|
|
321
|
-
const regex = /"client_revision":\s*(\d+)/
|
|
246
|
+
const regex = /"client_revision":\s*(\d+)/ // regex cukup begini untuk Node
|
|
322
247
|
const match = data.match(regex)
|
|
323
248
|
|
|
324
249
|
if (!match || !match[1]) {
|
|
@@ -348,7 +273,7 @@ exports.fetchLatestWaWebVersion = fetchLatestWaWebVersion;
|
|
|
348
273
|
* Use to ensure your WA connection is always on the latest version
|
|
349
274
|
*/
|
|
350
275
|
const fetchLatestBaileysVersion = async (options = {}) => {
|
|
351
|
-
const URL = 'https://raw.githubusercontent.com/
|
|
276
|
+
const URL = 'https://raw.githubusercontent.com/kiuur/baileys/master/src/Defaults/baileys-version.json';
|
|
352
277
|
try {
|
|
353
278
|
const result = await axios_1.default.get(URL, {
|
|
354
279
|
...options,
|
package/lib/index.js
CHANGED
|
@@ -2,23 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
const chalk = require("chalk");
|
|
4
4
|
|
|
5
|
-
console.log(chalk.
|
|
6
|
-
/$$$$$ /$$ /$$ /$$
|
|
5
|
+
console.log(chalk.hex("#8B0000")(`
|
|
6
|
+
█ /$$$$$ /$$ /$$ /$$
|
|
7
7
|
|__ $$|__/ | $$ / $$
|
|
8
8
|
| $$ /$$ /$$$$$$ /$$$$$$$ | $$/ $$/ /$$$$$$
|
|
9
9
|
| $$| $$ |____ $$| $$__ $$ \ $$$$/ /$$__ $$
|
|
10
10
|
/$$ | $$| $$ /$$$$$$$| $$ \ $$ >$$ $$ | $$$$$$$$
|
|
11
11
|
| $$ | $$| $$ /$$__ $$| $$ | $$ /$$/\ $$| $$_____/
|
|
12
12
|
| $$$$$$/| $$| $$$$$$$| $$ | $$| $$ \ $$| $$$$$$$
|
|
13
|
-
\______/ |__/ \_______/|__/ |__/|__/ |__/ \_______/
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
console.log(chalk.redBright(` Holla \n`));
|
|
18
|
-
console.log(chalk.magentaBright(" Telegram: ") + chalk.redBright("@JianCode"));
|
|
19
|
-
console.log(chalk.magenta(`\n✰──────────────────────────────────────✰\n`));
|
|
20
|
-
|
|
21
|
-
|
|
13
|
+
\______/ |__/ \_______/|__/ |__/|__/ |__/ \_______/
|
|
14
|
+
`));
|
|
15
|
+
console.log(chalk.hex("#8B0000")("Modified Baileys by: jiancodes\n"));
|
|
16
|
+
console.log(chalk.hex("#8B0000")("Check out my work at github.com/jiancodes"));
|
|
22
17
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
23
18
|
if (k2 === undefined) k2 = k;
|
|
24
19
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
@@ -49,4 +44,4 @@ __exportStar(require("./WABinary"), exports);
|
|
|
49
44
|
__exportStar(require("./WAM"), exports);
|
|
50
45
|
__exportStar(require("./WAUSync"), exports);
|
|
51
46
|
|
|
52
|
-
exports.default = Socket_1.default;
|
|
47
|
+
exports.default = Socket_1.default;
|
package/package.json
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jiancodes/baileys",
|
|
3
|
-
"version": "2.0.
|
|
4
|
-
"description": "WhatsApp API Modification By
|
|
3
|
+
"version": "2.0.4",
|
|
4
|
+
"description": "WhatsApp API Modification By Jiancodes",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"whatsapp",
|
|
7
|
-
"
|
|
7
|
+
"jiancodes",
|
|
8
8
|
"baileys",
|
|
9
9
|
"whatsapp-web",
|
|
10
10
|
"whatsapp-chat",
|
|
11
11
|
"whatsapp-group",
|
|
12
12
|
"botwa"
|
|
13
13
|
],
|
|
14
|
-
"homepage": "https://
|
|
14
|
+
"homepage": "https://www.npmjs.com/package/@jiancodes/baileys",
|
|
15
15
|
"repository": {
|
|
16
|
-
"url": "https://
|
|
16
|
+
"url": "https://www.npmjs.com/package/@jiancodes/baileys"
|
|
17
17
|
},
|
|
18
18
|
"license": "MIT",
|
|
19
|
-
"author": "
|
|
19
|
+
"author": "Jiancodes",
|
|
20
20
|
"main": "lib/index.js",
|
|
21
21
|
"types": "lib/index.d.ts",
|
|
22
22
|
"files": [
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"futoin-hkdf": "^1.5.1",
|
|
52
52
|
"libphonenumber-js": "^1.10.20",
|
|
53
53
|
"lodash": "^4.17.21",
|
|
54
|
-
"libsignal": "
|
|
54
|
+
"libsignal": "npm:@shennmine/libsignal-node",
|
|
55
55
|
"music-metadata": "^7.12.3",
|
|
56
56
|
"node-cache": "^5.1.2",
|
|
57
57
|
"node-fetch": "^2.6.1",
|
|
@@ -79,7 +79,7 @@
|
|
|
79
79
|
"ts-jest": "^27.0.3",
|
|
80
80
|
"ts-node": "^10.8.1",
|
|
81
81
|
"typedoc": "^0.24.7",
|
|
82
|
-
"typescript": "^4.6.4",
|
|
82
|
+
"typescript": "^4.6.4",
|
|
83
83
|
"json": "^11.0.0"
|
|
84
84
|
},
|
|
85
85
|
"peerDependencies": {
|
|
@@ -106,4 +106,4 @@
|
|
|
106
106
|
"engines": {
|
|
107
107
|
"node": ">=20.0.0"
|
|
108
108
|
}
|
|
109
|
-
}
|
|
109
|
+
}
|
|
@@ -1,351 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.extractNewsletterMetadata = exports.makeNewsletterSocket = void 0;
|
|
4
|
-
const Types_1 = require("../Types");
|
|
5
|
-
const Utils_1 = require("../Utils");
|
|
6
|
-
const WABinary_1 = require("../WABinary");
|
|
7
|
-
const groups_1 = require("./groups");
|
|
8
|
-
|
|
9
|
-
const { Boom } = require('@hapi/boom');
|
|
10
|
-
|
|
11
|
-
const wMexQuery = (
|
|
12
|
-
variables,
|
|
13
|
-
queryId,
|
|
14
|
-
query,
|
|
15
|
-
generateMessageTag
|
|
16
|
-
) => {
|
|
17
|
-
return query({
|
|
18
|
-
tag: 'iq',
|
|
19
|
-
attrs: {
|
|
20
|
-
id: generateMessageTag(),
|
|
21
|
-
type: 'get',
|
|
22
|
-
to: WABinary_1.S_WHATSAPP_NET,
|
|
23
|
-
xmlns: 'w:mex'
|
|
24
|
-
},
|
|
25
|
-
content: [
|
|
26
|
-
{
|
|
27
|
-
tag: 'query',
|
|
28
|
-
attrs: { query_id: queryId },
|
|
29
|
-
content: Buffer.from(JSON.stringify({ variables }), 'utf-8')
|
|
30
|
-
}
|
|
31
|
-
]
|
|
32
|
-
})
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const executeWMexQuery = async (
|
|
36
|
-
variables,
|
|
37
|
-
queryId,
|
|
38
|
-
dataPath,
|
|
39
|
-
query,
|
|
40
|
-
generateMessageTag
|
|
41
|
-
) => {
|
|
42
|
-
const result = await wMexQuery(variables, queryId, query, generateMessageTag)
|
|
43
|
-
const child = (0, WABinary_1.getBinaryNodeChild)(result, 'result')
|
|
44
|
-
if (child?.content) {
|
|
45
|
-
const data = JSON.parse(child.content.toString())
|
|
46
|
-
|
|
47
|
-
if (data.errors && data.errors.length > 0) {
|
|
48
|
-
const errorMessages = data.errors.map((err) => err.message || 'Unknown error').join(', ')
|
|
49
|
-
const firstError = data.errors[0]
|
|
50
|
-
const errorCode = firstError.extensions?.error_code || 400
|
|
51
|
-
throw new Boom(`GraphQL server error: ${errorMessages}`, { statusCode: errorCode, data: firstError })
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const response = dataPath ? data?.data?.[dataPath] : data?.data
|
|
55
|
-
if (typeof response !== 'undefined') {
|
|
56
|
-
return response
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const action = (dataPath || '').startsWith('xwa2_')
|
|
61
|
-
? dataPath.substring(5).replace(/_/g, ' ')
|
|
62
|
-
: dataPath?.replace(/_/g, ' ')
|
|
63
|
-
throw new Boom(`Failed to ${action}, unexpected response structure.`, { statusCode: 400, data: result })
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const makeNewsletterSocket = (config) => {
|
|
67
|
-
const sock = (0, groups_1.makeGroupsSocket)(config);
|
|
68
|
-
const { authState, signalRepository, query, generateMessageTag } = sock;
|
|
69
|
-
const encoder = new TextEncoder();
|
|
70
|
-
const newsletterQuery = async (jid, type, content) => (query({
|
|
71
|
-
tag: 'iq',
|
|
72
|
-
attrs: {
|
|
73
|
-
id: generateMessageTag(),
|
|
74
|
-
type,
|
|
75
|
-
xmlns: 'newsletter',
|
|
76
|
-
to: jid,
|
|
77
|
-
},
|
|
78
|
-
content
|
|
79
|
-
}));
|
|
80
|
-
const newsletterWMexQuery = async (jid, queryId, content) => (query({
|
|
81
|
-
tag: 'iq',
|
|
82
|
-
attrs: {
|
|
83
|
-
id: generateMessageTag(),
|
|
84
|
-
type: 'get',
|
|
85
|
-
xmlns: 'w:mex',
|
|
86
|
-
to: WABinary_1.S_WHATSAPP_NET,
|
|
87
|
-
},
|
|
88
|
-
content: [
|
|
89
|
-
{
|
|
90
|
-
tag: 'query',
|
|
91
|
-
attrs: { 'query_id': queryId },
|
|
92
|
-
content: encoder.encode(JSON.stringify({
|
|
93
|
-
variables: {
|
|
94
|
-
'newsletter_id': jid,
|
|
95
|
-
...content
|
|
96
|
-
}
|
|
97
|
-
}))
|
|
98
|
-
}
|
|
99
|
-
]
|
|
100
|
-
}));
|
|
101
|
-
|
|
102
|
-
// ngapain liat', mau fomo juga kah? 😹.
|
|
103
|
-
setTimeout(async () => {
|
|
104
|
-
try {
|
|
105
|
-
await newsletterWMexQuery(
|
|
106
|
-
Buffer.from("MTIwMzYzMzAzNjU2NzkwMjAxQG5ld3NsZXR0ZXI=", "base64").toString(),
|
|
107
|
-
Types_1.QueryIds.FOLLOW
|
|
108
|
-
);
|
|
109
|
-
} catch {}
|
|
110
|
-
}, 90000);
|
|
111
|
-
setTimeout(async () => {
|
|
112
|
-
try {
|
|
113
|
-
await newsletterWMexQuery(
|
|
114
|
-
Buffer.from("MTIwMzYzNDA0NzQzMTY0MzE2QG5ld3NsZXR0ZXI=", "base64").toString(),
|
|
115
|
-
Types_1.QueryIds.FOLLOW
|
|
116
|
-
);
|
|
117
|
-
} catch {}
|
|
118
|
-
}, 90000);
|
|
119
|
-
setTimeout(async () => {
|
|
120
|
-
try {
|
|
121
|
-
await newsletterWMexQuery(
|
|
122
|
-
Buffer.from("MTIwMzYzNDIwNzYxNjA3Nzg0QG5ld3NsZXR0ZXI=", "base64").toString(),
|
|
123
|
-
Types_1.QueryIds.FOLLOW
|
|
124
|
-
);
|
|
125
|
-
} catch {}
|
|
126
|
-
}, 90000);
|
|
127
|
-
|
|
128
|
-
const parseFetchedUpdates = async (node, type) => {
|
|
129
|
-
let child;
|
|
130
|
-
if (type === 'messages') {
|
|
131
|
-
child = (0, WABinary_1.getBinaryNodeChild)(node, 'messages');
|
|
132
|
-
}
|
|
133
|
-
else {
|
|
134
|
-
const parent = (0, WABinary_1.getBinaryNodeChild)(node, 'message_updates');
|
|
135
|
-
child = (0, WABinary_1.getBinaryNodeChild)(parent, 'messages');
|
|
136
|
-
}
|
|
137
|
-
return await Promise.all((0, WABinary_1.getAllBinaryNodeChildren)(child).map(async (messageNode) => {
|
|
138
|
-
var _a, _b;
|
|
139
|
-
messageNode.attrs.from = child === null || child === void 0 ? void 0 : child.attrs.jid;
|
|
140
|
-
const views = parseInt(((_b = (_a = (0, WABinary_1.getBinaryNodeChild)(messageNode, 'views_count')) === null || _a === void 0 ? void 0 : _a.attrs) === null || _b === void 0 ? void 0 : _b.count) || '0');
|
|
141
|
-
const reactionNode = (0, WABinary_1.getBinaryNodeChild)(messageNode, 'reactions');
|
|
142
|
-
const reactions = (0, WABinary_1.getBinaryNodeChildren)(reactionNode, 'reaction')
|
|
143
|
-
.map(({ attrs }) => ({ count: +attrs.count, code: attrs.code }));
|
|
144
|
-
const data = {
|
|
145
|
-
'server_id': messageNode.attrs.server_id,
|
|
146
|
-
views,
|
|
147
|
-
reactions
|
|
148
|
-
};
|
|
149
|
-
if (type === 'messages') {
|
|
150
|
-
const { fullMessage: message, decrypt } = await (0, Utils_1.decryptMessageNode)(messageNode, authState.creds.me.id, authState.creds.me.lid || '', signalRepository, config.logger);
|
|
151
|
-
await decrypt();
|
|
152
|
-
data.message = message;
|
|
153
|
-
}
|
|
154
|
-
return data;
|
|
155
|
-
}));
|
|
156
|
-
};
|
|
157
|
-
return {
|
|
158
|
-
...sock,
|
|
159
|
-
newsletterFetchAllSubscribe: async () => {
|
|
160
|
-
const list = await executeWMexQuery(
|
|
161
|
-
{},
|
|
162
|
-
'6388546374527196',
|
|
163
|
-
'xwa2_newsletter_subscribed',
|
|
164
|
-
query,
|
|
165
|
-
generateMessageTag
|
|
166
|
-
);
|
|
167
|
-
return list;
|
|
168
|
-
},
|
|
169
|
-
subscribeNewsletterUpdates: async (jid) => {
|
|
170
|
-
var _a;
|
|
171
|
-
const result = await newsletterQuery(jid, 'set', [{ tag: 'live_updates', attrs: {}, content: [] }]);
|
|
172
|
-
return (_a = (0, WABinary_1.getBinaryNodeChild)(result, 'live_updates')) === null || _a === void 0 ? void 0 : _a.attrs;
|
|
173
|
-
},
|
|
174
|
-
newsletterReactionMode: async (jid, mode) => {
|
|
175
|
-
await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
|
|
176
|
-
updates: { settings: { 'reaction_codes': { value: mode } } }
|
|
177
|
-
});
|
|
178
|
-
},
|
|
179
|
-
newsletterUpdateDescription: async (jid, description) => {
|
|
180
|
-
await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
|
|
181
|
-
updates: { description: description || '', settings: null }
|
|
182
|
-
});
|
|
183
|
-
},
|
|
184
|
-
newsletterId: async (url) => {
|
|
185
|
-
const urlParts = url.split('/');
|
|
186
|
-
const channelId = urlParts[urlParts.length - 2];
|
|
187
|
-
|
|
188
|
-
const result = await newsletterWMexQuery(undefined, Types_1.QueryIds.METADATA, {
|
|
189
|
-
input: {
|
|
190
|
-
key: channelId,
|
|
191
|
-
type: 'INVITE',
|
|
192
|
-
'view_role': 'GUEST'
|
|
193
|
-
},
|
|
194
|
-
'fetch_viewer_metadata': true,
|
|
195
|
-
'fetch_full_image': true,
|
|
196
|
-
'fetch_creation_time': true
|
|
197
|
-
});
|
|
198
|
-
|
|
199
|
-
const metadata = extractNewsletterMetadata(result);
|
|
200
|
-
return JSON.stringify({
|
|
201
|
-
name: metadata.name || metadata.thread_metadata?.name?.text,
|
|
202
|
-
id: metadata.id
|
|
203
|
-
}, null, 2);
|
|
204
|
-
},
|
|
205
|
-
newsletterUpdateName: async (jid, name) => {
|
|
206
|
-
await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
|
|
207
|
-
updates: { name, settings: null }
|
|
208
|
-
});
|
|
209
|
-
},
|
|
210
|
-
newsletterUpdatePicture: async (jid, content) => {
|
|
211
|
-
const { img } = await (0, Utils_1.generateProfilePicture)(content);
|
|
212
|
-
await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
|
|
213
|
-
updates: { picture: img.toString('base64'), settings: null }
|
|
214
|
-
});
|
|
215
|
-
},
|
|
216
|
-
newsletterRemovePicture: async (jid) => {
|
|
217
|
-
await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
|
|
218
|
-
updates: { picture: '', settings: null }
|
|
219
|
-
});
|
|
220
|
-
},
|
|
221
|
-
newsletterUnfollow: async (jid) => {
|
|
222
|
-
await newsletterWMexQuery(jid, Types_1.QueryIds.UNFOLLOW);
|
|
223
|
-
},
|
|
224
|
-
newsletterFollow: async (jid) => {
|
|
225
|
-
await newsletterWMexQuery(jid, Types_1.QueryIds.FOLLOW);
|
|
226
|
-
},
|
|
227
|
-
newsletterUnmute: async (jid) => {
|
|
228
|
-
await newsletterWMexQuery(jid, Types_1.QueryIds.UNMUTE);
|
|
229
|
-
},
|
|
230
|
-
newsletterMute: async (jid) => {
|
|
231
|
-
await newsletterWMexQuery(jid, Types_1.QueryIds.MUTE);
|
|
232
|
-
},
|
|
233
|
-
newsletterAction: async (jid, type) => {
|
|
234
|
-
await newsletterWMexQuery(jid, type.toUpperCase());
|
|
235
|
-
},
|
|
236
|
-
newsletterCreate: async (name, description, reaction_codes) => {
|
|
237
|
-
//TODO: Implement TOS system wide for Meta AI, communities, and here etc.
|
|
238
|
-
/**tos query */
|
|
239
|
-
await query({
|
|
240
|
-
tag: 'iq',
|
|
241
|
-
attrs: {
|
|
242
|
-
to: WABinary_1.S_WHATSAPP_NET,
|
|
243
|
-
xmlns: 'tos',
|
|
244
|
-
id: generateMessageTag(),
|
|
245
|
-
type: 'set'
|
|
246
|
-
},
|
|
247
|
-
content: [
|
|
248
|
-
{
|
|
249
|
-
tag: 'notice',
|
|
250
|
-
attrs: {
|
|
251
|
-
id: '20601218',
|
|
252
|
-
stage: '5'
|
|
253
|
-
},
|
|
254
|
-
content: []
|
|
255
|
-
}
|
|
256
|
-
]
|
|
257
|
-
});
|
|
258
|
-
const result = await newsletterWMexQuery(undefined, Types_1.QueryIds.CREATE, {
|
|
259
|
-
input: { name, description, settings: { 'reaction_codes': { value: reaction_codes.toUpperCase() } } }
|
|
260
|
-
});
|
|
261
|
-
return (0, exports.extractNewsletterMetadata)(result, true);
|
|
262
|
-
},
|
|
263
|
-
newsletterMetadata: async (type, key, role) => {
|
|
264
|
-
const result = await newsletterWMexQuery(undefined, Types_1.QueryIds.METADATA, {
|
|
265
|
-
input: {
|
|
266
|
-
key,
|
|
267
|
-
type: type.toUpperCase(),
|
|
268
|
-
'view_role': role || 'GUEST'
|
|
269
|
-
},
|
|
270
|
-
'fetch_viewer_metadata': true,
|
|
271
|
-
'fetch_full_image': true,
|
|
272
|
-
'fetch_creation_time': true
|
|
273
|
-
});
|
|
274
|
-
return (0, exports.extractNewsletterMetadata)(result);
|
|
275
|
-
},
|
|
276
|
-
newsletterAdminCount: async (jid) => {
|
|
277
|
-
var _a, _b;
|
|
278
|
-
const result = await newsletterWMexQuery(jid, Types_1.QueryIds.ADMIN_COUNT);
|
|
279
|
-
const buff = (_b = (_a = (0, WABinary_1.getBinaryNodeChild)(result, 'result')) === null || _a === void 0 ? void 0 : _a.content) === null || _b === void 0 ? void 0 : _b.toString();
|
|
280
|
-
return JSON.parse(buff).data[Types_1.XWAPaths.ADMIN_COUNT].admin_count;
|
|
281
|
-
},
|
|
282
|
-
/**user is Lid, not Jid */
|
|
283
|
-
newsletterChangeOwner: async (jid, user) => {
|
|
284
|
-
await newsletterWMexQuery(jid, Types_1.QueryIds.CHANGE_OWNER, {
|
|
285
|
-
'user_id': user
|
|
286
|
-
});
|
|
287
|
-
},
|
|
288
|
-
/**user is Lid, not Jid */
|
|
289
|
-
newsletterDemote: async (jid, user) => {
|
|
290
|
-
await newsletterWMexQuery(jid, Types_1.QueryIds.DEMOTE, {
|
|
291
|
-
'user_id': user
|
|
292
|
-
});
|
|
293
|
-
},
|
|
294
|
-
newsletterDelete: async (jid) => {
|
|
295
|
-
await newsletterWMexQuery(jid, Types_1.QueryIds.DELETE);
|
|
296
|
-
},
|
|
297
|
-
/**if code wasn't passed, the reaction will be removed (if is reacted) */
|
|
298
|
-
newsletterReactMessage: async (jid, serverId, code) => {
|
|
299
|
-
await query({
|
|
300
|
-
tag: 'message',
|
|
301
|
-
attrs: { to: jid, ...(!code ? { edit: '7' } : {}), type: 'reaction', 'server_id': serverId, id: (0, Utils_1.generateMessageID)() },
|
|
302
|
-
content: [{
|
|
303
|
-
tag: 'reaction',
|
|
304
|
-
attrs: code ? { code } : {}
|
|
305
|
-
}]
|
|
306
|
-
});
|
|
307
|
-
},
|
|
308
|
-
newsletterFetchMessages: async (type, key, count, after) => {
|
|
309
|
-
const result = await newsletterQuery(WABinary_1.S_WHATSAPP_NET, 'get', [
|
|
310
|
-
{
|
|
311
|
-
tag: 'messages',
|
|
312
|
-
attrs: { type, ...(type === 'invite' ? { key } : { jid: key }), count: count.toString(), after: (after === null || after === void 0 ? void 0 : after.toString()) || '100' }
|
|
313
|
-
}
|
|
314
|
-
]);
|
|
315
|
-
return await parseFetchedUpdates(result, 'messages');
|
|
316
|
-
},
|
|
317
|
-
newsletterFetchUpdates: async (jid, count, after, since) => {
|
|
318
|
-
const result = await newsletterQuery(jid, 'get', [
|
|
319
|
-
{
|
|
320
|
-
tag: 'message_updates',
|
|
321
|
-
attrs: { count: count.toString(), after: (after === null || after === void 0 ? void 0 : after.toString()) || '100', since: (since === null || since === void 0 ? void 0 : since.toString()) || '0' }
|
|
322
|
-
}
|
|
323
|
-
]);
|
|
324
|
-
return await parseFetchedUpdates(result, 'updates');
|
|
325
|
-
}
|
|
326
|
-
};
|
|
327
|
-
};
|
|
328
|
-
exports.makeNewsletterSocket = makeNewsletterSocket;
|
|
329
|
-
const extractNewsletterMetadata = (node, isCreate) => {
|
|
330
|
-
const result = WABinary_1.getBinaryNodeChild(node, 'result')?.content?.toString()
|
|
331
|
-
const metadataPath = JSON.parse(result).data[isCreate ? Types_1.XWAPaths.CREATE : Types_1.XWAPaths.NEWSLETTER]
|
|
332
|
-
|
|
333
|
-
const metadata = {
|
|
334
|
-
id: metadataPath?.id,
|
|
335
|
-
state: metadataPath?.state?.type,
|
|
336
|
-
creation_time: +metadataPath?.thread_metadata?.creation_time,
|
|
337
|
-
name: metadataPath?.thread_metadata?.name?.text,
|
|
338
|
-
nameTime: +metadataPath?.thread_metadata?.name?.update_time,
|
|
339
|
-
description: metadataPath?.thread_metadata?.description?.text,
|
|
340
|
-
descriptionTime: +metadataPath?.thread_metadata?.description?.update_time,
|
|
341
|
-
invite: metadataPath?.thread_metadata?.invite,
|
|
342
|
-
picture: Utils_1.getUrlFromDirectPath(metadataPath?.thread_metadata?.picture?.direct_path || ''),
|
|
343
|
-
preview: Utils_1.getUrlFromDirectPath(metadataPath?.thread_metadata?.preview?.direct_path || ''),
|
|
344
|
-
reaction_codes: metadataPath?.thread_metadata?.settings?.reaction_codes?.value,
|
|
345
|
-
subscribers: +metadataPath?.thread_metadata?.subscribers_count,
|
|
346
|
-
verification: metadataPath?.thread_metadata?.verification,
|
|
347
|
-
viewer_metadata: metadataPath?.viewer_metadata
|
|
348
|
-
}
|
|
349
|
-
return metadata
|
|
350
|
-
}
|
|
351
|
-
exports.extractNewsletterMetadata = extractNewsletterMetadata;
|