@denzy-official/baileys 1.1.9 → 1.2.1

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2025 t.me/pantatBegetar Custom Baileys
3
+ Copyright (c) 2025 Denzy ZeroDay
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
18
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
19
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
20
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,2 +1,364 @@
1
- telegram: t.me/pantatBegetar
2
- bocah kontol kang renane mati aja
1
+ # WhatsApp Baileys
2
+
3
+ <p align="center">
4
+ <img src="https://raw.githubusercontent.com/Denzy-ZeroDay/Upload/main/file_1761667786632.jpg" alt="Thumbnail" />
5
+ </p>
6
+
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
+ ## SendMessage Documentation
35
+
36
+ ### Album Message (Multiple Images)
37
+ Send multiple images in a single album message:
38
+
39
+ ```javascript
40
+ await sock.sendMessage(jid, {
41
+ albumMessage: [
42
+ { image: cihuy, caption: "Foto pertama" },
43
+ { image: { url: "URL IMAGE" }, caption: "Foto kedua" }
44
+ ]
45
+ }, { quoted: m });
46
+ ```
47
+
48
+ ### Event Message
49
+ Create and send WhatsApp event invitations:
50
+
51
+ ```javascript
52
+ await sock.sendMessage(jid, {
53
+ eventMessage: {
54
+ isCanceled: false,
55
+ name: "Hello World",
56
+ description: "yume native",
57
+ location: {
58
+ degreesLatitude: 0,
59
+ degreesLongitude: 0,
60
+ name: "rowrrrr"
61
+ },
62
+ joinLink: "https://call.whatsapp.com/video/pantatBegetar",
63
+ startTime: "1763019000",
64
+ endTime: "1763026200",
65
+ extraGuestsAllowed: false
66
+ }
67
+ }, { quoted: m });
68
+ ```
69
+
70
+ ### Poll Result Message
71
+ Display poll results with vote counts:
72
+
73
+ ```javascript
74
+ await sock.sendMessage(jid, {
75
+ pollResultMessage: {
76
+ name: "Hello World",
77
+ pollVotes: [
78
+ {
79
+ optionName: "TEST 1",
80
+ optionVoteCount: "112233"
81
+ },
82
+ {
83
+ optionName: "TEST 2",
84
+ optionVoteCount: "1"
85
+ }
86
+ ]
87
+ }
88
+ }, { quoted: m });
89
+ ```
90
+
91
+ ### Simple Interactive Message
92
+ Send basic interactive messages with copy button functionality:
93
+
94
+ ```javascript
95
+ await sock.sendMessage(jid, {
96
+ interactiveMessage: {
97
+ header: "Hello World",
98
+ title: "Hello World",
99
+ footer: "telegram: @pantatBegetar ",
100
+ buttons: [
101
+ {
102
+ name: "cta_copy",
103
+ buttonParamsJson: JSON.stringify({
104
+ display_text: "copy code",
105
+ id: "123456789",
106
+ copy_code: "ABC123XYZ"
107
+ })
108
+ }
109
+ ]
110
+ }
111
+ }, { quoted: m });
112
+ ```
113
+
114
+ ### Interactive Message with Native Flow
115
+ Send interactive messages with buttons, copy actions, and native flow features:
116
+
117
+ ```javascript
118
+ await sock.sendMessage(jid, {
119
+ interactiveMessage: {
120
+ header: "Hello World",
121
+ title: "Hello World",
122
+ footer: "telegram: @pantatBegetar",
123
+ image: { url: "https://example.com/image.jpg" },
124
+ nativeFlowMessage: {
125
+ messageParamsJson: JSON.stringify({
126
+ limited_time_offer: {
127
+ text: "idk hummmm?",
128
+ url: "https://t.me/pantatBegetar",
129
+ copy_code: "yume",
130
+ expiration_time: Date.now() * 999
131
+ },
132
+ bottom_sheet: {
133
+ in_thread_buttons_limit: 2,
134
+ divider_indices: [1, 2, 3, 4, 5, 999],
135
+ list_title: "yume native",
136
+ button_title: "yume native"
137
+ },
138
+ tap_target_configuration: {
139
+ title: " X ",
140
+ description: "bomboclard",
141
+ canonical_url: "https://t.me/pantatBegetar",
142
+ domain: "shop.example.com",
143
+ button_index: 0
144
+ }
145
+ }),
146
+ buttons: [
147
+ {
148
+ name: "single_select",
149
+ buttonParamsJson: JSON.stringify({
150
+ has_multiple_buttons: true
151
+ })
152
+ },
153
+ {
154
+ name: "call_permission_request",
155
+ buttonParamsJson: JSON.stringify({
156
+ has_multiple_buttons: true
157
+ })
158
+ },
159
+ {
160
+ name: "single_select",
161
+ buttonParamsJson: JSON.stringify({
162
+ title: "Hello World",
163
+ sections: [
164
+ {
165
+ title: "title",
166
+ highlight_label: "label",
167
+ rows: [
168
+ {
169
+ title: "@pantatBegetar",
170
+ description: "love you",
171
+ id: "row_2"
172
+ }
173
+ ]
174
+ }
175
+ ],
176
+ has_multiple_buttons: true
177
+ })
178
+ },
179
+ {
180
+ name: "cta_copy",
181
+ buttonParamsJson: JSON.stringify({
182
+ display_text: "copy code",
183
+ id: "123456789",
184
+ copy_code: "ABC123XYZ"
185
+ })
186
+ }
187
+ ]
188
+ }
189
+ }
190
+ }, { quoted: m });
191
+ ```
192
+
193
+ ### Interactive Message with Thumbnail
194
+ Send interactive messages with thumbnail image and copy button:
195
+
196
+ ```javascript
197
+ await sock.sendMessage(jid, {
198
+ interactiveMessage: {
199
+ header: "Hello World",
200
+ title: "Hello World",
201
+ footer: "telegram: @pantatBegetar",
202
+ image: { url: "https://example.com/image.jpg" },
203
+ buttons: [
204
+ {
205
+ name: "cta_copy",
206
+ buttonParamsJson: JSON.stringify({
207
+ display_text: "copy code",
208
+ id: "123456789",
209
+ copy_code: "ABC123XYZ"
210
+ })
211
+ }
212
+ ]
213
+ }
214
+ }, { quoted: m });
215
+ ```
216
+
217
+ ### Product Message
218
+ Send product catalog messages with buttons and merchant information:
219
+
220
+ ```javascript
221
+ await sock.sendMessage(jid, {
222
+ productMessage: {
223
+ title: "Produk Contoh",
224
+ description: "Ini adalah deskripsi produk",
225
+ thumbnail: { url: "https://example.com/image.jpg" },
226
+ productId: "PROD001",
227
+ retailerId: "RETAIL001",
228
+ url: "https://example.com/product",
229
+ body: "Detail produk",
230
+ footer: "Harga spesial",
231
+ priceAmount1000: 50000,
232
+ currencyCode: "USD",
233
+ buttons: [
234
+ {
235
+ name: "cta_url",
236
+ buttonParamsJson: JSON.stringify({
237
+ display_text: "Beli Sekarang",
238
+ url: "https://example.com/buy"
239
+ })
240
+ }
241
+ ]
242
+ }
243
+ }, { quoted: m });
244
+ ```
245
+
246
+ ### Interactive Message with Document Buffer
247
+ Send interactive messages with document from buffer (file system) - **Note: Documents only support buffer**:
248
+
249
+ ```javascript
250
+ await sock.sendMessage(jid, {
251
+ interactiveMessage: {
252
+ header: "Hello World",
253
+ title: "Hello World",
254
+ footer: "telegram: @pantatBegetar",
255
+ document: fs.readFileSync("./package.json"),
256
+ mimetype: "application/pdf",
257
+ fileName: "pantatBegetar.pdf",
258
+ jpegThumbnail: fs.readFileSync("./document.jpeg"),
259
+ contextInfo: {
260
+ mentionedJid: [jid],
261
+ forwardingScore: 777,
262
+ isForwarded: false
263
+ },
264
+ externalAdReply: {
265
+ title: "shenń Bot",
266
+ body: "anu team",
267
+ mediaType: 3,
268
+ thumbnailUrl: "https://example.com/image.jpg",
269
+ mediaUrl: " X ",
270
+ sourceUrl: "https://t.me/pantatBegetar",
271
+ showAdAttribution: true,
272
+ renderLargerThumbnail: false
273
+ },
274
+ buttons: [
275
+ {
276
+ name: "cta_url",
277
+ buttonParamsJson: JSON.stringify({
278
+ display_text: "Telegram",
279
+ url: "https://t.me/pantatBegetar",
280
+ merchant_url: "https://t.me/pantatBegetar"
281
+ })
282
+ }
283
+ ]
284
+ }
285
+ }, { quoted: m });
286
+ ```
287
+
288
+ ### Interactive Message with Document Buffer (Simple)
289
+ Send interactive messages with document from buffer (file system) without contextInfo and externalAdReply - **Note: Documents only support buffer**:
290
+
291
+ ```javascript
292
+ await sock.sendMessage(jid, {
293
+ interactiveMessage: {
294
+ header: "Hello World",
295
+ title: "Hello World",
296
+ footer: "telegram: @pantatBegetar",
297
+ document: fs.readFileSync("./package.json"),
298
+ mimetype: "application/pdf",
299
+ fileName: "pantatBegetar.pdf",
300
+ jpegThumbnail: fs.readFileSync("./document.jpeg"),
301
+ buttons: [
302
+ {
303
+ name: "cta_url",
304
+ buttonParamsJson: JSON.stringify({
305
+ display_text: "Telegram",
306
+ url: "https://t.me/pantatBegetar",
307
+ merchant_url: "https://t.me/pantatBegetar"
308
+ })
309
+ }
310
+ ]
311
+ }
312
+ }, { quoted: m });
313
+ ```
314
+
315
+ ### Request Payment Message
316
+ Send payment request messages with custom background and sticker:
317
+
318
+ ```javascript
319
+ let quotedType = m.quoted?.mtype || '';
320
+ let quotedContent = JSON.stringify({ [quotedType]: m.quoted }, null, 2);
321
+
322
+ await sock.sendMessage(jid, {
323
+ requestPaymentMessage: {
324
+ currency: "IDR",
325
+ amount: 10000000,
326
+ from: m.sender,
327
+ sticker: JSON.parse(quotedContent),
328
+ background: {
329
+ id: "100",
330
+ fileLength: "0",
331
+ width: 1000,
332
+ height: 1000,
333
+ mimetype: "image/webp",
334
+ placeholderArgb: 0xFF00FFFF,
335
+ textArgb: 0xFFFFFFFF,
336
+ subtextArgb: 0xFFAA00FF
337
+ }
338
+ }
339
+ }, { quoted: m });
340
+ ```
341
+
342
+ ---
343
+
344
+ ## Why Choose WhatsApp Baileys?
345
+
346
+ 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.
347
+
348
+ ---
349
+
350
+ ### Technical Notes
351
+
352
+ - Supports custom pairing codes that are stable and secure
353
+ - Fixes previous issues related to pairing and authentication
354
+ - Features interactive messages and action buttons for dynamic menu creation
355
+ - Automatic and efficient session management for long-term stability
356
+ - Compatible with the latest multi-device features from WhatsApp
357
+ - Easy to integrate and customize based on your needs
358
+ - Perfect for developing bots, customer service automation, and other communication applications
359
+
360
+ ---
361
+
362
+ 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.
363
+
364
+ **Thank you for choosing WhatsApp Baileys as your WhatsApp automation solution!**
@@ -1,3 +1,4 @@
1
+ // Baileys Denzy ZeroDay
1
2
  "use strict";
2
3
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
4
  return (mod && mod.__esModule) ? mod : { "default": mod };
@@ -327,7 +327,7 @@ class kikyy {
327
327
  newsletterName: `WhatsApp`,
328
328
  contentType: 1,
329
329
  timestamp: new Date().toISOString(),
330
- senderName: "kikyy dugonggg",
330
+ senderName: "Denzy dugonggg",
331
331
  content: "Text Message",
332
332
  priority: "high",
333
333
  status: "sent",
@@ -1,3 +1,5 @@
1
+ // Telegram: t.me/pantatBegetar
2
+
1
3
  "use strict";
2
4
  Object.defineProperty(exports, "__esModule", { value: true });
3
5
  exports.makeSocket = void 0;
@@ -10,39 +12,30 @@ const Defaults_1 = require("../Defaults");
10
12
  const Types_1 = require("../Types");
11
13
  const Utils_1 = require("../Utils");
12
14
  const WABinary_1 = require("../WABinary");
13
- const Client_1 = require("./Client");
14
- /**
15
- * Connects to WA servers and performs:
16
- * - simple queries (no retry mechanism, wait for connection establishment)
17
- * - listen to messages and emit events
18
- * - query phone connection
19
- */
15
+ const Client_1 = require("./Client");
20
16
  const makeSocket = (config) => {
21
17
  var _a, _b;
22
18
  const { waWebSocketUrl, connectTimeoutMs, logger, keepAliveIntervalMs, browser, auth: authState, printQRInTerminal, defaultQueryTimeoutMs, transactionOpts, qrTimeout, makeSignalRepository, } = config;
23
- let url = typeof waWebSocketUrl === 'string' ? new url_1.URL(waWebSocketUrl) : waWebSocketUrl;
24
- config.mobile = config.mobile || url.protocol === 'tcp:';
25
- if (config.mobile && url.protocol !== 'tcp:') {
26
- url = new url_1.URL(`tcp://${Defaults_1.MOBILE_ENDPOINT}:${Defaults_1.MOBILE_PORT}`);
19
+ const url = typeof waWebSocketUrl === 'string' ? new url_1.URL(waWebSocketUrl) : waWebSocketUrl;
20
+ if (config.mobile || url.protocol === 'tcp:') {
21
+ throw new boom_1.Boom('Mobile API is not supported anymore', {
22
+ statusCode: Types_1.DisconnectReason.loggedOut
23
+ });
27
24
  }
28
- if (!config.mobile && url.protocol === 'wss' && ((_a = authState === null || authState === void 0 ? void 0 : authState.creds) === null || _a === void 0 ? void 0 : _a.routingInfo)) {
25
+ if (url.protocol === 'wss' && ((_a = authState === null || authState === void 0 ? void 0 : authState.creds) === null || _a === void 0 ? void 0 : _a.routingInfo)) {
29
26
  url.searchParams.append('ED', authState.creds.routingInfo.toString('base64url'));
30
27
  }
31
- const ws = config.socket ? config.socket : config.mobile ? new Client_1.MobileSocketClient(url, config) : new Client_1.WebSocketClient(url, config);
28
+ const ws = new Client_1.WebSocketClient(url, config);
32
29
  ws.connect();
33
- const ev = (0, Utils_1.makeEventBuffer)(logger);
34
- /** ephemeral key pair used to encrypt/decrypt communication. Unique for each connection */
30
+ const ev = (0, Utils_1.makeEventBuffer)(logger);
35
31
  const ephemeralKeyPair = Utils_1.Curve.generateKeyPair();
36
- /** WA noise protocol wrapper */
37
32
  const noise = (0, Utils_1.makeNoiseHandler)({
38
33
  keyPair: ephemeralKeyPair,
39
- NOISE_HEADER: config.mobile ? Defaults_1.MOBILE_NOISE_HEADER : Defaults_1.NOISE_WA_HEADER,
40
- mobile: config.mobile,
34
+ NOISE_HEADER: Defaults_1.NOISE_WA_HEADER,
41
35
  logger,
42
36
  routingInfo: (_b = authState === null || authState === void 0 ? void 0 : authState.creds) === null || _b === void 0 ? void 0 : _b.routingInfo
43
37
  });
44
38
  const { creds } = authState;
45
- // add transaction capability
46
39
  const keys = (0, Utils_1.addTransactionCapability)(authState.keys, logger, transactionOpts);
47
40
  const signalRepository = makeSignalRepository({ creds, keys });
48
41
  let lastDateRecv;
@@ -53,7 +46,6 @@ const makeSocket = (config) => {
53
46
  const uqTagId = (0, Utils_1.generateMdTagPrefix)();
54
47
  const generateMessageTag = () => `${uqTagId}${epoch++}`;
55
48
  const sendPromise = (0, util_1.promisify)(ws.send);
56
- /** send a raw buffer */
57
49
  const sendRawMessage = async (data) => {
58
50
  if (!ws.isOpen) {
59
51
  throw new boom_1.Boom('Connection Closed', { statusCode: Types_1.DisconnectReason.connectionClosed });
@@ -68,20 +60,34 @@ const makeSocket = (config) => {
68
60
  reject(error);
69
61
  }
70
62
  });
71
- };
72
- /** send a binary node */
63
+ };
73
64
  const sendNode = (frame) => {
74
65
  if (logger.level === 'trace') {
75
66
  logger.trace({ xml: (0, WABinary_1.binaryNodeToString)(frame), msg: 'xml send' });
76
67
  }
77
68
  const buff = (0, WABinary_1.encodeBinaryNode)(frame);
78
69
  return sendRawMessage(buff);
79
- };
80
- /** log & process any unexpected errors */
70
+ };
81
71
  const onUnexpectedError = (err, msg) => {
82
72
  logger.error({ err }, `unexpected error in '${msg}'`);
73
+ const message = (err && ((err.stack || err.message) || String(err))).toLowerCase();
74
+ if (message.includes('bad mac') || (message.includes('mac') && message.includes('invalid'))) {
75
+ try {
76
+ uploadPreKeysToServerIfRequired(true)
77
+ .catch(e => logger.warn({ e }, 'failed to re-upload prekeys after bad mac'));
78
+ }
79
+ catch (_e) {
80
+ }
81
+ }
82
+
83
+ if (message.includes('429') || message.includes('rate limit')) {
84
+ const wait = Math.min(30000, (config.backoffDelayMs || 5000));
85
+ logger.info({ wait }, 'backing off due to rate limit');
86
+ setTimeout(() => {
87
+ }, wait);
88
+ }
83
89
  };
84
- /** await the next incoming message */
90
+
85
91
  const awaitNextMessage = async (sendMsg) => {
86
92
  if (!ws.isOpen) {
87
93
  throw new boom_1.Boom('Connection Closed', {
@@ -106,47 +112,45 @@ const makeSocket = (config) => {
106
112
  sendRawMessage(sendMsg).catch(onClose);
107
113
  }
108
114
  return result;
109
- };
110
- /**
111
- * Wait for a message with a certain tag to be received
112
- * @param msgId the message tag to await
113
- * @param timeoutMs timeout after which the promise will reject
114
- */
115
+ };
116
+
115
117
  const waitForMessage = async (msgId, timeoutMs = defaultQueryTimeoutMs) => {
116
118
  let onRecv;
117
119
  let onErr;
118
120
  try {
119
- return await (0, Utils_1.promiseTimeout)(timeoutMs, (resolve, reject) => {
121
+ const result = await (0, Utils_1.promiseTimeout)(timeoutMs, (resolve, reject) => {
120
122
  onRecv = resolve;
121
123
  onErr = err => {
122
124
  reject(err || new boom_1.Boom('Connection Closed', { statusCode: Types_1.DisconnectReason.connectionClosed }));
123
125
  };
124
126
  ws.on(`TAG:${msgId}`, onRecv);
125
- ws.on('close', onErr); // if the socket closes, you'll never receive the message
127
+ ws.on('close', onErr);
126
128
  ws.off('error', onErr);
127
129
  });
130
+ return result;
128
131
  }
129
132
  finally {
130
133
  ws.off(`TAG:${msgId}`, onRecv);
131
- ws.off('close', onErr); // if the socket closes, you'll never receive the message
134
+ ws.off('close', onErr);
132
135
  ws.off('error', onErr);
133
136
  }
134
137
  };
135
- /** send a query, and wait for its response. auto-generates message ID if not provided */
138
+
136
139
  const query = async (node, timeoutMs) => {
137
140
  if (!node.attrs.id) {
138
141
  node.attrs.id = generateMessageTag();
139
142
  }
140
143
  const msgId = node.attrs.id;
141
- const wait = waitForMessage(msgId, timeoutMs);
142
- await sendNode(node);
143
- const result = await wait;
144
+ const [result] = await Promise.all([
145
+ waitForMessage(msgId, timeoutMs),
146
+ sendNode(node)
147
+ ]);
144
148
  if ('tag' in result) {
145
149
  (0, WABinary_1.assertNodeErrorFree)(result);
146
150
  }
147
151
  return result;
148
152
  };
149
- /** connection handshake */
153
+
150
154
  const validateConnection = async () => {
151
155
  let helloMsg = {
152
156
  clientHello: { ephemeral: ephemeralKeyPair.public }
@@ -157,12 +161,9 @@ const makeSocket = (config) => {
157
161
  const result = await awaitNextMessage(init);
158
162
  const handshake = WAProto_1.proto.HandshakeMessage.decode(result);
159
163
  logger.trace({ handshake }, 'handshake recv from WA');
160
- const keyEnc = noise.processHandshake(handshake, creds.noiseKey);
164
+ const keyEnc = await noise.processHandshake(handshake, creds.noiseKey);
161
165
  let node;
162
- if (config.mobile) {
163
- node = (0, Utils_1.generateMobileNode)(config);
164
- }
165
- else if (!creds.me) {
166
+ if (!creds.me) {
166
167
  node = (0, Utils_1.generateRegistrationNode)(creds, config);
167
168
  logger.info({ node }, 'not logged in, attempting registration...');
168
169
  }
@@ -232,11 +233,11 @@ const makeSocket = (config) => {
232
233
  const l0 = frame.tag;
233
234
  const l1 = frame.attrs || {};
234
235
  const l2 = Array.isArray(frame.content) ? (_a = frame.content[0]) === null || _a === void 0 ? void 0 : _a.tag : '';
235
- Object.keys(l1).forEach(key => {
236
+ for (const key of Object.keys(l1)) {
236
237
  anyTriggered = ws.emit(`${Defaults_1.DEF_CALLBACK_PREFIX}${l0},${key}:${l1[key]},${l2}`, frame) || anyTriggered;
237
238
  anyTriggered = ws.emit(`${Defaults_1.DEF_CALLBACK_PREFIX}${l0},${key}:${l1[key]}`, frame) || anyTriggered;
238
239
  anyTriggered = ws.emit(`${Defaults_1.DEF_CALLBACK_PREFIX}${l0},${key}`, frame) || anyTriggered;
239
- });
240
+ }
240
241
  anyTriggered = ws.emit(`${Defaults_1.DEF_CALLBACK_PREFIX}${l0},,${l2}`, frame) || anyTriggered;
241
242
  anyTriggered = ws.emit(`${Defaults_1.DEF_CALLBACK_PREFIX}${l0}`, frame) || anyTriggered;
242
243
  if (!anyTriggered && logger.level === 'debug') {
@@ -300,15 +301,12 @@ const makeSocket = (config) => {
300
301
  lastDateRecv = new Date();
301
302
  }
302
303
  const diff = Date.now() - lastDateRecv.getTime();
303
- /*
304
- check if it's been a suspicious amount of time since the server responded with our last seen
305
- it could be that the network is down
306
- */
304
+
307
305
  if (diff > keepAliveIntervalMs + 5000) {
308
306
  end(new boom_1.Boom('Connection was lost', { statusCode: Types_1.DisconnectReason.connectionLost }));
309
307
  }
310
308
  else if (ws.isOpen) {
311
- // if its all good, send a keep alive request
309
+
312
310
  query({
313
311
  tag: 'iq',
314
312
  attrs: {
@@ -327,7 +325,7 @@ const makeSocket = (config) => {
327
325
  logger.warn('keep alive called when WS not open');
328
326
  }
329
327
  }, keepAliveIntervalMs));
330
- /** i have no idea why this exists. pls enlighten me */
328
+
331
329
  const sendPassiveIq = (tag) => (query({
332
330
  tag: 'iq',
333
331
  attrs: {
@@ -339,7 +337,7 @@ const makeSocket = (config) => {
339
337
  { tag, attrs: {} }
340
338
  ]
341
339
  }));
342
- /** logout & invalidate connection */
340
+
343
341
  const logout = async (msg) => {
344
342
  var _a;
345
343
  const jid = (_a = authState.creds.me) === null || _a === void 0 ? void 0 : _a.id;
@@ -365,11 +363,8 @@ const makeSocket = (config) => {
365
363
  }
366
364
  end(new boom_1.Boom(msg || 'Intentional Logout', { statusCode: Types_1.DisconnectReason.loggedOut }));
367
365
  };
368
- /** This method was created by snowi, and implemented by KyuuRzy */
369
366
 
370
- /** hey bro, if you delete this text */
371
- /** you are the most cursed human being who likes to claim other people's property 😹🙌🏻 */
372
- const requestPairingCode = async (phoneNumber, pairKey = "DENZYMOD") => {
367
+ const requestPairingCode = async (phoneNumber, pairKey) => {
373
368
  if (pairKey) {
374
369
  authState.creds.pairingCode = pairKey.toUpperCase();
375
370
  } else {
@@ -431,12 +426,11 @@ const makeSocket = (config) => {
431
426
  });
432
427
 
433
428
  return authState.creds.pairingCode;
434
- };
435
-
429
+ }
436
430
  async function generatePairingKey() {
437
431
  const salt = (0, crypto_1.randomBytes)(32);
438
432
  const randomIv = (0, crypto_1.randomBytes)(16);
439
- const key = (0, Utils_1.derivePairingCodeKey)(authState.creds.pairingCode, salt);
433
+ const key = await (0, Utils_1.derivePairingCodeKey)(authState.creds.pairingCode, salt);
440
434
  const ciphered = (0, Utils_1.aesEncryptCTR)(authState.creds.pairingEphemeralKeyPair.public, key, randomIv);
441
435
  return Buffer.concat([salt, randomIv, ciphered]);
442
436
  }
@@ -469,9 +463,9 @@ const makeSocket = (config) => {
469
463
  });
470
464
  ws.on('error', mapWebSocketError(end));
471
465
  ws.on('close', () => end(new boom_1.Boom('Connection Terminated', { statusCode: Types_1.DisconnectReason.connectionClosed })));
472
- // the server terminated the connection
466
+
473
467
  ws.on('CB:xmlstreamend', () => end(new boom_1.Boom('Connection Terminated by Server', { statusCode: Types_1.DisconnectReason.connectionClosed })));
474
- // QR gen
468
+
475
469
  ws.on('CB:iq,type:set,pair-device', async (stanza) => {
476
470
  const iq = {
477
471
  tag: 'iq',
@@ -505,8 +499,7 @@ const makeSocket = (config) => {
505
499
  };
506
500
  genPairQR();
507
501
  });
508
- // device paired for the first time
509
- // if device pairs successfully, the server asks to restart the connection
502
+
510
503
  ws.on('CB:iq,,pair-success', async (stanza) => {
511
504
  logger.debug('pair success recv');
512
505
  try {
@@ -521,14 +514,21 @@ const makeSocket = (config) => {
521
514
  end(error);
522
515
  }
523
516
  });
524
- // login complete
517
+
525
518
  ws.on('CB:success', async (node) => {
526
- await uploadPreKeysToServerIfRequired();
527
- await sendPassiveIq('active');
528
- logger.info('opened connection to WA');
529
- clearTimeout(qrTimer); // will never happen in all likelyhood -- but just in case WA sends success on first try
530
- ev.emit('creds.update', { me: { ...authState.creds.me, lid: node.attrs.lid } });
531
- ev.emit('connection.update', { connection: 'open' });
519
+ try {
520
+ await uploadPreKeysToServerIfRequired();
521
+ await sendPassiveIq('active');
522
+ logger.info('opened connection to WA');
523
+ clearTimeout(qrTimer);
524
+
525
+ ev.emit('creds.update', { me: { ...authState.creds.me, lid: node.attrs.lid } });
526
+ ev.emit('connection.update', { connection: 'open' });
527
+ }
528
+ catch (err) {
529
+ logger.error({ err }, 'error opening connection');
530
+ end(err);
531
+ }
532
532
  });
533
533
  ws.on('CB:stream:error', (node) => {
534
534
  logger.error({ node }, 'stream errored out');
@@ -543,25 +543,33 @@ const makeSocket = (config) => {
543
543
  ws.on('CB:ib,,downgrade_webclient', () => {
544
544
  end(new boom_1.Boom('Multi-device beta not joined', { statusCode: Types_1.DisconnectReason.multideviceMismatch }));
545
545
  });
546
+ ws.on('CB:ib,,offline_preview', (node) => {
547
+ logger.info('offline preview received', JSON.stringify(node));
548
+ sendNode({
549
+ tag: 'ib',
550
+ attrs: {},
551
+ content: [{ tag: 'offline_batch', attrs: { count: '100' } }]
552
+ });
553
+ });
546
554
  ws.on('CB:ib,,edge_routing', (node) => {
547
555
  const edgeRoutingNode = (0, WABinary_1.getBinaryNodeChild)(node, 'edge_routing');
548
556
  const routingInfo = (0, WABinary_1.getBinaryNodeChild)(edgeRoutingNode, 'routing_info');
549
557
  if (routingInfo === null || routingInfo === void 0 ? void 0 : routingInfo.content) {
550
558
  authState.creds.routingInfo = Buffer.from(routingInfo === null || routingInfo === void 0 ? void 0 : routingInfo.content);
559
+ ev.emit('creds.update', authState.creds);
551
560
  }
552
561
  });
553
562
  let didStartBuffer = false;
554
563
  process.nextTick(() => {
555
564
  var _a;
556
565
  if ((_a = creds.me) === null || _a === void 0 ? void 0 : _a.id) {
557
- // start buffering important events
558
- // if we're logged in
566
+
559
567
  ev.buffer();
560
568
  didStartBuffer = true;
561
569
  }
562
570
  ev.emit('connection.update', { connection: 'connecting', receivedPendingNotifications: false, qr: undefined });
563
571
  });
564
- // called when all offline notifs are handled
572
+
565
573
  ws.on('CB:ib,,offline', (node) => {
566
574
  const child = (0, WABinary_1.getBinaryNodeChild)(node, 'offline');
567
575
  const offlineNotifs = +((child === null || child === void 0 ? void 0 : child.attrs.count) || 0);
@@ -572,7 +580,7 @@ const makeSocket = (config) => {
572
580
  }
573
581
  ev.emit('connection.update', { receivedPendingNotifications: true });
574
582
  });
575
- // update credentials when required
583
+
576
584
  ev.on('creds.update', update => {
577
585
  var _a, _b;
578
586
  const name = (_a = update.me) === null || _a === void 0 ? void 0 : _a.name;
@@ -596,7 +604,10 @@ const makeSocket = (config) => {
596
604
  type: 'md',
597
605
  ws,
598
606
  ev,
599
- authState: { creds, keys },
607
+ authState: {
608
+ creds,
609
+ keys
610
+ },
600
611
  signalRepository,
601
612
  get user() {
602
613
  return authState.creds.me;
@@ -613,16 +624,13 @@ const makeSocket = (config) => {
613
624
  uploadPreKeys,
614
625
  uploadPreKeysToServerIfRequired,
615
626
  requestPairingCode,
616
- /** Waits for the connection to WA to reach a state */
627
+
617
628
  waitForConnectionUpdate: (0, Utils_1.bindWaitForConnectionUpdate)(ev),
618
629
  sendWAMBuffer,
619
630
  };
620
631
  };
621
632
  exports.makeSocket = makeSocket;
622
- /**
623
- * map the websocket error to the right type
624
- * so it can be retried by the caller
625
- * */
633
+
626
634
  function mapWebSocketError(handler) {
627
635
  return (error) => {
628
636
  handler(new boom_1.Boom(`WebSocket Error (${error === null || error === void 0 ? void 0 : error.message})`, { statusCode: (0, Utils_1.getCodeFromWSError)(error), data: error }));
@@ -174,7 +174,7 @@ const generateMessageIDV2 = (userId) => {
174
174
  };
175
175
  exports.generateMessageIDV2 = generateMessageIDV2;
176
176
  // generate a random ID to attach to a message
177
- const generateMessageID = () => 'ILSYM-' + (0, crypto_1.randomBytes)(6).toString('hex').toUpperCase();
177
+ const generateMessageID = () => 'DENZY-ZERODAY-' + (0, crypto_1.randomBytes)(6).toString('hex').toUpperCase();
178
178
  exports.generateMessageID = generateMessageID;
179
179
  function bindWaitForEvent(ev, event) {
180
180
  return async (check, timeoutMs) => {
@@ -216,11 +216,7 @@ const printQRIfNecessaryListener = (ev, logger) => {
216
216
  }
217
217
  });
218
218
  };
219
- exports.printQRIfNecessaryListener = printQRIfNecessaryListener;
220
- /**
221
- * utility that fetches latest baileys version from the master branch.
222
- * Use to ensure your WA connection is always on the latest version
223
- */
219
+ exports.printQRIfNecessaryListener = printQRIfNecessaryListener;
224
220
  const fetchLatestWaWebVersion = async (options = {}) => {
225
221
  try {
226
222
  const defaultHeaders = {
@@ -241,7 +237,7 @@ const fetchLatestWaWebVersion = async (options = {}) => {
241
237
  }
242
238
 
243
239
  const data = await response.text()
244
- const regex = /"client_revision":\s*(\d+)/ // regex cukup begini untuk Node
240
+ const regex = /"client_revision":\s*(\d+)/
245
241
  const match = data.match(regex)
246
242
 
247
243
  if (!match || !match[1]) {
@@ -266,12 +262,9 @@ const fetchLatestWaWebVersion = async (options = {}) => {
266
262
  }
267
263
  }
268
264
  exports.fetchLatestWaWebVersion = fetchLatestWaWebVersion;
269
- /**
270
- * utility that fetches latest baileys version from the master branch.
271
- * Use to ensure your WA connection is always on the latest version
272
- */
265
+
273
266
  const fetchLatestBaileysVersion = async (options = {}) => {
274
- const URL = 'https://raw.githubusercontent.com/kiuur/bails/master/src/Defaults/baileys-version.json';
267
+ const URL = 'https://raw.githubusercontent.com/Denzy-ZeroDay/baileys/master/src/Defaults/baileys-version.json';
275
268
  try {
276
269
  const result = await axios_1.default.get(URL, {
277
270
  ...options,
@@ -291,7 +284,7 @@ const fetchLatestBaileysVersion = async (options = {}) => {
291
284
  }
292
285
  };
293
286
  exports.fetchLatestBaileysVersion = fetchLatestBaileysVersion;
294
- /** unique message tag prefix for MD clients */
287
+
295
288
  const generateMdTagPrefix = () => {
296
289
  const bytes = (0, crypto_1.randomBytes)(4);
297
290
  return `${bytes.readUInt16BE()}.${bytes.readUInt16BE(2)}-`;
@@ -301,11 +294,7 @@ const STATUS_MAP = {
301
294
  'played': WAProto_1.proto.WebMessageInfo.Status.PLAYED,
302
295
  'read': WAProto_1.proto.WebMessageInfo.Status.READ,
303
296
  'read-self': WAProto_1.proto.WebMessageInfo.Status.READ
304
- };
305
- /**
306
- * Given a type of receipt, returns what the new status of the message should be
307
- * @param type type from receipt
308
- */
297
+ };
309
298
  const getStatusFromReceiptType = (type) => {
310
299
  const status = STATUS_MAP[type];
311
300
  if (typeof type === 'undefined') {
@@ -316,11 +305,7 @@ const getStatusFromReceiptType = (type) => {
316
305
  exports.getStatusFromReceiptType = getStatusFromReceiptType;
317
306
  const CODE_MAP = {
318
307
  conflict: Types_1.DisconnectReason.connectionReplaced
319
- };
320
- /**
321
- * Stream errors generally provide a reason, map that to a baileys DisconnectReason
322
- * @param reason the string reason given, eg. "conflict"
323
- */
308
+ };
324
309
  const getErrorCodeFromStreamError = (node) => {
325
310
  const [reasonNode] = (0, WABinary_1.getAllBinaryNodeChildren)(node);
326
311
  let reason = (reasonNode === null || reasonNode === void 0 ? void 0 : reasonNode.tag) || 'unknown';
@@ -378,11 +363,8 @@ const getCodeFromWSError = (error) => {
378
363
  }
379
364
  return statusCode;
380
365
  };
381
- exports.getCodeFromWSError = getCodeFromWSError;
382
- /**
383
- * Is the given platform WA business
384
- * @param platform AuthenticationCreds.platform
385
- */
366
+ exports.getCodeFromWSError = getCodeFromWSError;
367
+
386
368
  const isWABusinessPlatform = (platform) => {
387
369
  return platform === 'smbi' || platform === 'smba';
388
370
  };
@@ -105,9 +105,9 @@ const prepareWAMessageMedia = async (message, options) => {
105
105
  }
106
106
  ],
107
107
  newsletter: {
108
- newsletterJid: "120363420249672073@newsletter",
108
+ newsletterJid: "120363402308105961@newsletter",
109
109
  serverMessageId: 0,
110
- newsletterName: "kyuu ilysm",
110
+ newsletterName: "Denzy ZeroDay",
111
111
  contentType: "UPDATE",
112
112
  }
113
113
  }
package/package.json CHANGED
@@ -1,19 +1,18 @@
1
1
  {
2
2
  "name": "@denzy-official/baileys",
3
- "version": "1.1.9",
3
+ "version": "1.2.1",
4
4
  "description": "Baileys Custom Denzy-ZeroDay",
5
5
  "keywords": [
6
- "Denzy ZeroDay",
7
- "Costum",
8
- "Baileys",
9
- "whatsapp",
10
- "whatsapp-api",
11
- "whatsapp-web",
12
- "whatsapp-bot",
13
- "automation",
14
- "multi-device",
15
- "Denzy Team Smz"
16
- ],
6
+ "whatsapp",
7
+ "awa-subaru",
8
+ "baileys",
9
+ "whatsapp-web",
10
+ "whatsapp-chat",
11
+ "whatsapp-group",
12
+ "whatsapp-api",
13
+ "botwa",
14
+ "Denzy ZeroDay"
15
+ ],
17
16
  "homepage": "https://www.npmjs.com/package/@denzy-official/baileys",
18
17
  "repository": {
19
18
  "url": "https://www.npmjs.com/package/@denzy-official/baileys"