wa-multi-mongodb 3.9.10 → 3.10.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.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/Messaging/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAqB,MAAM,SAAS,CAAC;AAGnD,OAAO,EACL,cAAc,EACd,gBAAgB,EAChB,aAAa,EACb,eAAe,EACf,2BAA2B,EAC5B,MAAM,UAAU,CAAC;AAOlB,eAAO,MAAM,eAAe,GAAU,4CAMnC,gBAAgB,KAAG,OAAO,CAAC,KAAK,CAAC,cAAc,GAAG,SAAS,CA2H7D,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,0BAA0B,GAAU,sDAO9C,2BAA2B,KAAG,OAAO,CAAC,KAAK,CAAC,cAAc,GAAG,SAAS,CAiJxE,CAAC;AAaF,eAAO,MAAM,SAAS,GAAU,wEAS7B,cAAc,KAAG,OAAO,CAAC,KAAK,CAAC,cAAc,GAAG,SAAS,CAgL3D,CAAC;AAEF,eAAO,MAAM,aAAa,GAAU,6CAMjC,IAAI,CAAC,cAAc,EAAE,MAAM,CAAC,KAAG,OAAO,CAAC,KAAK,CAAC,cAAc,GAAG,SAAS,CA2GzE,CAAC;AAEF,eAAO,MAAM,WAAW,GAAU,6CAM/B,cAAc,KAAG,OAAO,CAAC,KAAK,CAAC,cAAc,GAAG,SAAS,CAyG3D,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,UAAU,GAAU,uCAK9B,eAAe,KAAG,OAAO,CAAC,IAAI,CAuEhC,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,WAAW,GAAU,qBAG/B,aAAa,KAAG,OAAO,CAAC,IAAI,CA6B9B,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,aAAa,GAAU,qBAGjC,aAAa,KAAG,OAAO,CAAC,IAAI,CAsC9B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/Messaging/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAqB,MAAM,SAAS,CAAC;AAGnD,OAAO,EACL,cAAc,EACd,gBAAgB,EAChB,aAAa,EACb,eAAe,EACf,2BAA2B,EAC5B,MAAM,UAAU,CAAC;AAQlB,eAAO,MAAM,eAAe,GAAU,4CAMnC,gBAAgB,KAAG,OAAO,CAAC,KAAK,CAAC,cAAc,GAAG,SAAS,CA8I7D,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,0BAA0B,GAAU,sDAO9C,2BAA2B,KAAG,OAAO,CAAC,KAAK,CAAC,cAAc,GAAG,SAAS,CAoKxE,CAAC;AAaF,eAAO,MAAM,SAAS,GAAU,wEAS7B,cAAc,KAAG,OAAO,CAAC,KAAK,CAAC,cAAc,GAAG,SAAS,CAqM3D,CAAC;AAEF,eAAO,MAAM,aAAa,GAAU,6CAMjC,IAAI,CAAC,cAAc,EAAE,MAAM,CAAC,KAAG,OAAO,CAAC,KAAK,CAAC,cAAc,GAAG,SAAS,CA6HzE,CAAC;AAEF,eAAO,MAAM,WAAW,GAAU,6CAM/B,cAAc,KAAG,OAAO,CAAC,KAAK,CAAC,cAAc,GAAG,SAAS,CA2H3D,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,UAAU,GAAU,uCAK9B,eAAe,KAAG,OAAO,CAAC,IAAI,CA4EhC,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,WAAW,GAAU,qBAG/B,aAAa,KAAG,OAAO,CAAC,IAAI,CA6B9B,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,aAAa,GAAU,qBAGjC,aAAa,KAAG,OAAO,CAAC,IAAI,CAsC9B,CAAC"}
@@ -27,6 +27,7 @@ exports.deleteMessage = exports.readMessage = exports.sendTyping = exports.sendS
27
27
  const Defaults_1 = require("../Defaults");
28
28
  const Socket_1 = require("../Socket");
29
29
  const Utils_1 = require("../Utils");
30
+ const Utils_2 = require("../Utils");
30
31
  const create_delay_1 = require("../Utils/create-delay");
31
32
  const is_exist_1 = require("../Utils/is-exist");
32
33
  const mime_1 = __importDefault(require("mime"));
@@ -53,6 +54,10 @@ const sendTextMessage = (_a) => __awaiter(void 0, void 0, void 0, function* () {
53
54
  else {
54
55
  jid = (0, Utils_1.phoneToJid)({ to, isGroup: isGroup || isGroupChat });
55
56
  }
57
+ // Validasi JID untuk memastikan format yang didukung
58
+ if (!(0, Utils_2.isValidJid)(jid)) {
59
+ throw new Error_1.WhatsappError(`Invalid JID format: ${jid}. Supported formats: @s.whatsapp.net, @lid, @g.us`);
60
+ }
56
61
  let retryCount = 0;
57
62
  const maxRetries = 3;
58
63
  const attemptSend = () => __awaiter(void 0, void 0, void 0, function* () {
@@ -69,9 +74,12 @@ const sendTextMessage = (_a) => __awaiter(void 0, void 0, void 0, function* () {
69
74
  // Beri timeout yang lebih pendek untuk grup untuk mencegah hanging
70
75
  const timeoutMs = isDestinationGroup ? 15000 : 30000;
71
76
  // Gunakan withTimeout untuk membatasi waktu operasi
72
- return yield (0, create_delay_1.withTimeout)(session.sendMessage(jid, {
77
+ const result = yield session.sendMessage(jid, {
73
78
  text: text,
74
- }, messageOptions), timeoutMs, `Pengiriman pesan ke ${jid} melebihi batas waktu ${timeoutMs / 1000} detik`);
79
+ }, messageOptions);
80
+ // Tambahkan method toJSON untuk compatibility dengan WebMessageInfo
81
+ result.toJSON = () => ({});
82
+ return yield (0, create_delay_1.withTimeout)(Promise.resolve(result), timeoutMs, `Pengiriman pesan ke ${jid} melebihi batas waktu ${timeoutMs / 1000} detik`);
75
83
  }
76
84
  catch (error) {
77
85
  console.error(`Error saat mengirim pesan (percobaan ${retryCount + 1}/${maxRetries}): ${(error === null || error === void 0 ? void 0 : error.message) || 'Unknown error'}`);
@@ -82,7 +90,6 @@ const sendTextMessage = (_a) => __awaiter(void 0, void 0, void 0, function* () {
82
90
  retryCount++;
83
91
  // Tambahkan delay lebih lama antara percobaan
84
92
  yield (0, create_delay_1.createDelay)(2000 * retryCount);
85
- console.log(`Mencoba kembali pengiriman pesan (${retryCount}/${maxRetries})...`);
86
93
  return attemptSend();
87
94
  }
88
95
  else {
@@ -96,11 +103,14 @@ const sendTextMessage = (_a) => __awaiter(void 0, void 0, void 0, function* () {
96
103
  yield (0, Socket_1.reconnect)(sessionId);
97
104
  yield (0, create_delay_1.createDelay)(3000); // Beri waktu untuk reconnect sepenuhnya
98
105
  // Coba kirim lagi setelah reconnect
99
- return yield (0, create_delay_1.withTimeout)(session.sendMessage(jid, {
106
+ const reconnectResult = yield session.sendMessage(jid, {
100
107
  text: text,
101
108
  }, {
102
109
  quoted: props.answering,
103
- }), 30000, `Pengiriman pesan setelah reconnect melebihi batas waktu`);
110
+ });
111
+ // Tambahkan method toJSON untuk compatibility dengan WebMessageInfo
112
+ reconnectResult.toJSON = () => ({});
113
+ return yield (0, create_delay_1.withTimeout)(Promise.resolve(reconnectResult), 30000, `Pengiriman pesan setelah reconnect melebihi batas waktu`);
104
114
  }
105
115
  catch (reconnectError) {
106
116
  console.error(`Gagal reconnect: ${(reconnectError === null || reconnectError === void 0 ? void 0 : reconnectError.message) || 'Unknown error'}`);
@@ -111,11 +121,14 @@ const sendTextMessage = (_a) => __awaiter(void 0, void 0, void 0, function* () {
111
121
  try {
112
122
  yield (0, create_delay_1.createDelay)(2000);
113
123
  // Untuk percobaan kedua, gunakan timeout yang lebih lama
114
- return yield (0, create_delay_1.withTimeout)(session.sendMessage(jid, {
124
+ const retryResult = yield session.sendMessage(jid, {
115
125
  text: text,
116
126
  }, {
117
127
  quoted: props.answering,
118
- }), 20000, `Percobaan kedua pengiriman pesan melebihi batas waktu`);
128
+ });
129
+ // Tambahkan method toJSON untuk compatibility dengan WebMessageInfo
130
+ retryResult.toJSON = () => ({});
131
+ return yield (0, create_delay_1.withTimeout)(Promise.resolve(retryResult), 20000, `Percobaan kedua pengiriman pesan melebihi batas waktu`);
119
132
  }
120
133
  catch (retryError) {
121
134
  console.error(`Gagal pada percobaan kedua: ${(retryError === null || retryError === void 0 ? void 0 : retryError.message) || 'Unknown error'}`);
@@ -158,6 +171,10 @@ const sendTextMessageWithMention = (_a) => __awaiter(void 0, void 0, void 0, fun
158
171
  else {
159
172
  jid = (0, Utils_1.phoneToJid)({ to, isGroup: isGroup || isGroupChat });
160
173
  }
174
+ // Validasi JID untuk memastikan format yang didukung
175
+ if (!(0, Utils_2.isValidJid)(jid)) {
176
+ throw new Error_1.WhatsappError(`Invalid JID format: ${jid}. Supported formats: @s.whatsapp.net, @lid, @g.us`);
177
+ }
161
178
  let retryCount = 0;
162
179
  const maxRetries = 3;
163
180
  const attemptSend = () => __awaiter(void 0, void 0, void 0, function* () {
@@ -182,7 +199,10 @@ const sendTextMessageWithMention = (_a) => __awaiter(void 0, void 0, void 0, fun
182
199
  messageContent.mentions = mentions;
183
200
  }
184
201
  // Gunakan withTimeout untuk membatasi waktu operasi
185
- return yield (0, create_delay_1.withTimeout)(session.sendMessage(jid, messageContent, messageOptions), timeoutMs, `Pengiriman pesan dengan mention ke ${jid} melebihi batas waktu ${timeoutMs / 1000} detik`);
202
+ const result = yield session.sendMessage(jid, messageContent, messageOptions);
203
+ // Tambahkan method toJSON untuk compatibility dengan WebMessageInfo
204
+ result.toJSON = () => ({});
205
+ return yield (0, create_delay_1.withTimeout)(Promise.resolve(result), timeoutMs, `Pengiriman pesan dengan mention ke ${jid} melebihi batas waktu ${timeoutMs / 1000} detik`);
186
206
  }
187
207
  catch (error) {
188
208
  console.error(`Error saat mengirim pesan dengan mention (percobaan ${retryCount + 1}/${maxRetries}): ${(error === null || error === void 0 ? void 0 : error.message) || 'Unknown error'}`);
@@ -193,7 +213,6 @@ const sendTextMessageWithMention = (_a) => __awaiter(void 0, void 0, void 0, fun
193
213
  retryCount++;
194
214
  // Tambahkan delay lebih lama antara percobaan
195
215
  yield (0, create_delay_1.createDelay)(2000 * retryCount);
196
- console.log(`Mencoba kembali pengiriman pesan dengan mention (${retryCount}/${maxRetries})...`);
197
216
  return attemptSend();
198
217
  }
199
218
  else {
@@ -214,9 +233,12 @@ const sendTextMessageWithMention = (_a) => __awaiter(void 0, void 0, void 0, fun
214
233
  messageContent.mentions = mentions;
215
234
  }
216
235
  // Coba kirim lagi setelah reconnect
217
- return yield (0, create_delay_1.withTimeout)(session.sendMessage(jid, messageContent, {
236
+ const reconnectResult = yield session.sendMessage(jid, messageContent, {
218
237
  quoted: props.answering,
219
- }), 30000, `Pengiriman pesan dengan mention setelah reconnect melebihi batas waktu`);
238
+ });
239
+ // Tambahkan method toJSON untuk compatibility dengan WebMessageInfo
240
+ reconnectResult.toJSON = () => ({});
241
+ return yield (0, create_delay_1.withTimeout)(Promise.resolve(reconnectResult), 30000, `Pengiriman pesan dengan mention setelah reconnect melebihi batas waktu`);
220
242
  }
221
243
  catch (reconnectError) {
222
244
  console.error(`Gagal reconnect: ${(reconnectError === null || reconnectError === void 0 ? void 0 : reconnectError.message) || 'Unknown error'}`);
@@ -234,9 +256,12 @@ const sendTextMessageWithMention = (_a) => __awaiter(void 0, void 0, void 0, fun
234
256
  messageContent.mentions = mentions;
235
257
  }
236
258
  // Untuk percobaan kedua, gunakan timeout yang lebih lama
237
- return yield (0, create_delay_1.withTimeout)(session.sendMessage(jid, messageContent, {
259
+ const retryResult = yield session.sendMessage(jid, messageContent, {
238
260
  quoted: props.answering,
239
- }), 20000, `Percobaan kedua pengiriman pesan dengan mention melebihi batas waktu`);
261
+ });
262
+ // Tambahkan method toJSON untuk compatibility dengan WebMessageInfo
263
+ retryResult.toJSON = () => ({});
264
+ return yield (0, create_delay_1.withTimeout)(Promise.resolve(retryResult), 20000, `Percobaan kedua pengiriman pesan dengan mention melebihi batas waktu`);
240
265
  }
241
266
  catch (retryError) {
242
267
  console.error(`Gagal pada percobaan kedua: ${(retryError === null || retryError === void 0 ? void 0 : retryError.message) || 'Unknown error'}`);
@@ -268,6 +293,10 @@ const sendMedia = (_a) => __awaiter(void 0, [_a], void 0, function* ({ sessionId
268
293
  else {
269
294
  jid = (0, Utils_1.phoneToJid)({ to, isGroup: isGroup || isGroupChat });
270
295
  }
296
+ // Validasi JID untuk memastikan format yang didukung
297
+ if (!(0, Utils_2.isValidJid)(jid)) {
298
+ throw new Error_1.WhatsappError(`Invalid JID format: ${jid}. Supported formats: @s.whatsapp.net, @lid, @g.us`);
299
+ }
271
300
  let retryCount = 0;
272
301
  const maxRetries = 3;
273
302
  // Helper function untuk mendapatkan message content berdasarkan tipe
@@ -354,7 +383,10 @@ const sendMedia = (_a) => __awaiter(void 0, [_a], void 0, function* ({ sessionId
354
383
  }
355
384
  // Timeout lebih lama untuk media karena ukuran file
356
385
  const timeoutMs = isDestinationGroup ? 60000 : 120000;
357
- return yield (0, create_delay_1.withTimeout)(session.sendMessage(jid, messageContent, options), timeoutMs, `Pengiriman media melebihi batas waktu ${timeoutMs / 1000} detik`);
386
+ const result = yield session.sendMessage(jid, messageContent, options);
387
+ // Tambahkan method toJSON untuk compatibility dengan WebMessageInfo
388
+ result.toJSON = () => ({});
389
+ return yield (0, create_delay_1.withTimeout)(Promise.resolve(result), timeoutMs, `Pengiriman media melebihi batas waktu ${timeoutMs / 1000} detik`);
358
390
  }
359
391
  catch (error) {
360
392
  console.error(`Error saat mengirim media (percobaan ${retryCount + 1}/${maxRetries}): ${(error === null || error === void 0 ? void 0 : error.message) || 'Unknown error'}`);
@@ -365,7 +397,6 @@ const sendMedia = (_a) => __awaiter(void 0, [_a], void 0, function* ({ sessionId
365
397
  retryCount++;
366
398
  // Tambahkan delay lebih lama antara percobaan
367
399
  yield (0, create_delay_1.createDelay)(2000 * retryCount);
368
- console.log(`Mencoba kembali pengiriman media (${retryCount}/${maxRetries})...`);
369
400
  return attemptSend();
370
401
  }
371
402
  else {
@@ -381,7 +412,11 @@ const sendMedia = (_a) => __awaiter(void 0, [_a], void 0, function* ({ sessionId
381
412
  // Siapkan content media untuk percobaan ulang
382
413
  const retryContent = getMessageContent();
383
414
  // Coba kirim lagi setelah reconnect
384
- return yield (0, create_delay_1.withTimeout)(session.sendMessage(jid, retryContent, answering ? { quoted: answering } : {}), 180000, // 3 menit untuk percobaan setelah reconnect
415
+ const reconnectOptions = answering ? { quoted: answering } : {};
416
+ const reconnectResult = yield session.sendMessage(jid, retryContent, reconnectOptions);
417
+ // Tambahkan method toJSON untuk compatibility dengan WebMessageInfo
418
+ reconnectResult.toJSON = () => ({});
419
+ return yield (0, create_delay_1.withTimeout)(Promise.resolve(reconnectResult), 180000, // 3 menit untuk percobaan setelah reconnect
385
420
  `Pengiriman media setelah reconnect melebihi batas waktu`);
386
421
  }
387
422
  catch (reconnectError) {
@@ -395,7 +430,11 @@ const sendMedia = (_a) => __awaiter(void 0, [_a], void 0, function* ({ sessionId
395
430
  // Siapkan content media untuk percobaan ulang
396
431
  const retryContent = getMessageContent();
397
432
  // Untuk percobaan kedua, gunakan timeout yang lebih lama
398
- return yield (0, create_delay_1.withTimeout)(session.sendMessage(jid, retryContent, answering ? { quoted: answering } : {}), 180000, // 3 menit untuk percobaan kedua
433
+ const retryOptions = answering ? { quoted: answering } : {};
434
+ const retryResult = yield session.sendMessage(jid, retryContent, retryOptions);
435
+ // Tambahkan method toJSON untuk compatibility dengan WebMessageInfo
436
+ retryResult.toJSON = () => ({});
437
+ return yield (0, create_delay_1.withTimeout)(Promise.resolve(retryResult), 180000, // 3 menit untuk percobaan kedua
399
438
  `Percobaan kedua pengiriman media melebihi batas waktu`);
400
439
  }
401
440
  catch (retryError) {
@@ -429,6 +468,10 @@ const sendVoiceNote = (_a) => __awaiter(void 0, void 0, void 0, function* () {
429
468
  else {
430
469
  jid = (0, Utils_1.phoneToJid)({ to, isGroup: isGroup || isGroupChat });
431
470
  }
471
+ // Validasi JID untuk memastikan format yang didukung
472
+ if (!(0, Utils_2.isValidJid)(jid)) {
473
+ throw new Error_1.WhatsappError(`Invalid JID format: ${jid}. Supported formats: @s.whatsapp.net, @lid, @g.us`);
474
+ }
432
475
  if (!media) {
433
476
  throw new Error_1.WhatsappError(`Invalid Media`);
434
477
  }
@@ -438,16 +481,20 @@ const sendVoiceNote = (_a) => __awaiter(void 0, void 0, void 0, function* () {
438
481
  var _a, _b, _c;
439
482
  try {
440
483
  // Gunakan timeout untuk mencegah hanging
441
- return yield (0, create_delay_1.withTimeout)(session.sendMessage(jid, {
484
+ const voiceOptions = {
485
+ quoted: props.answering,
486
+ };
487
+ const result = yield session.sendMessage(jid, {
442
488
  audio: typeof media == "string"
443
489
  ? {
444
490
  url: media,
445
491
  }
446
492
  : media,
447
493
  ptt: true,
448
- }, {
449
- quoted: props.answering,
450
- }), 60000, `Pengiriman voice note melebihi batas waktu`);
494
+ }, voiceOptions);
495
+ // Tambahkan method toJSON untuk compatibility dengan WebMessageInfo
496
+ result.toJSON = () => ({});
497
+ return yield (0, create_delay_1.withTimeout)(Promise.resolve(result), 60000, `Pengiriman voice note melebihi batas waktu`);
451
498
  }
452
499
  catch (error) {
453
500
  console.error(`Error saat mengirim voice note (percobaan ${retryCount + 1}/${maxRetries}): ${(error === null || error === void 0 ? void 0 : error.message) || 'Unknown error'}`);
@@ -458,7 +505,6 @@ const sendVoiceNote = (_a) => __awaiter(void 0, void 0, void 0, function* () {
458
505
  retryCount++;
459
506
  // Tambahkan delay lebih lama antara percobaan
460
507
  yield (0, create_delay_1.createDelay)(2000 * retryCount);
461
- console.log(`Mencoba kembali pengiriman voice note (${retryCount}/${maxRetries})...`);
462
508
  return attemptSend();
463
509
  }
464
510
  else {
@@ -472,16 +518,20 @@ const sendVoiceNote = (_a) => __awaiter(void 0, void 0, void 0, function* () {
472
518
  yield (0, Socket_1.reconnect)(sessionId);
473
519
  yield (0, create_delay_1.createDelay)(3000); // Beri waktu untuk reconnect sepenuhnya
474
520
  // Coba kirim lagi setelah reconnect
475
- return yield (0, create_delay_1.withTimeout)(session.sendMessage(jid, {
521
+ const reconnectVoiceOptions = {
522
+ quoted: props.answering,
523
+ };
524
+ const reconnectResult = yield session.sendMessage(jid, {
476
525
  audio: typeof media == "string"
477
526
  ? {
478
527
  url: media,
479
528
  }
480
529
  : media,
481
530
  ptt: true,
482
- }, {
483
- quoted: props.answering,
484
- }), 60000, `Pengiriman voice note setelah reconnect melebihi batas waktu`);
531
+ }, reconnectVoiceOptions);
532
+ // Tambahkan method toJSON untuk compatibility dengan WebMessageInfo
533
+ reconnectResult.toJSON = () => ({});
534
+ return yield (0, create_delay_1.withTimeout)(Promise.resolve(reconnectResult), 60000, `Pengiriman voice note setelah reconnect melebihi batas waktu`);
485
535
  }
486
536
  catch (reconnectError) {
487
537
  console.error(`Gagal reconnect: ${(reconnectError === null || reconnectError === void 0 ? void 0 : reconnectError.message) || 'Unknown error'}`);
@@ -517,6 +567,10 @@ const sendSticker = (_a) => __awaiter(void 0, void 0, void 0, function* () {
517
567
  else {
518
568
  jid = (0, Utils_1.phoneToJid)({ to, isGroup: isGroup || isGroupChat });
519
569
  }
570
+ // Validasi JID untuk memastikan format yang didukung
571
+ if (!(0, Utils_2.isValidJid)(jid)) {
572
+ throw new Error_1.WhatsappError(`Invalid JID format: ${jid}. Supported formats: @s.whatsapp.net, @lid, @g.us`);
573
+ }
520
574
  if (!media) {
521
575
  throw new Error_1.WhatsappError(`Invalid Media`);
522
576
  }
@@ -526,15 +580,19 @@ const sendSticker = (_a) => __awaiter(void 0, void 0, void 0, function* () {
526
580
  var _a, _b, _c;
527
581
  try {
528
582
  // Gunakan timeout untuk mencegah hanging
529
- return yield (0, create_delay_1.withTimeout)(session.sendMessage(jid, {
583
+ const stickerOptions = {
584
+ quoted: props.answering,
585
+ };
586
+ const result = yield session.sendMessage(jid, {
530
587
  sticker: typeof media == "string"
531
588
  ? {
532
589
  url: media,
533
590
  }
534
591
  : media,
535
- }, {
536
- quoted: props.answering,
537
- }), 60000, `Pengiriman sticker melebihi batas waktu`);
592
+ }, stickerOptions);
593
+ // Tambahkan method toJSON untuk compatibility dengan WebMessageInfo
594
+ result.toJSON = () => ({});
595
+ return yield (0, create_delay_1.withTimeout)(Promise.resolve(result), 60000, `Pengiriman sticker melebihi batas waktu`);
538
596
  }
539
597
  catch (error) {
540
598
  console.error(`Error saat mengirim sticker (percobaan ${retryCount + 1}/${maxRetries}): ${(error === null || error === void 0 ? void 0 : error.message) || 'Unknown error'}`);
@@ -545,7 +603,6 @@ const sendSticker = (_a) => __awaiter(void 0, void 0, void 0, function* () {
545
603
  retryCount++;
546
604
  // Tambahkan delay lebih lama antara percobaan
547
605
  yield (0, create_delay_1.createDelay)(2000 * retryCount);
548
- console.log(`Mencoba kembali pengiriman sticker (${retryCount}/${maxRetries})...`);
549
606
  return attemptSend();
550
607
  }
551
608
  else {
@@ -559,15 +616,19 @@ const sendSticker = (_a) => __awaiter(void 0, void 0, void 0, function* () {
559
616
  yield (0, Socket_1.reconnect)(sessionId);
560
617
  yield (0, create_delay_1.createDelay)(3000); // Beri waktu untuk reconnect sepenuhnya
561
618
  // Coba kirim lagi setelah reconnect
562
- return yield (0, create_delay_1.withTimeout)(session.sendMessage(jid, {
619
+ const reconnectStickerOptions = {
620
+ quoted: props.answering,
621
+ };
622
+ const reconnectResult = yield session.sendMessage(jid, {
563
623
  sticker: typeof media == "string"
564
624
  ? {
565
625
  url: media,
566
626
  }
567
627
  : media,
568
- }, {
569
- quoted: props.answering,
570
- }), 60000, `Pengiriman sticker setelah reconnect melebihi batas waktu`);
628
+ }, reconnectStickerOptions);
629
+ // Tambahkan method toJSON untuk compatibility dengan WebMessageInfo
630
+ reconnectResult.toJSON = () => ({});
631
+ return yield (0, create_delay_1.withTimeout)(Promise.resolve(reconnectResult), 60000, `Pengiriman sticker setelah reconnect melebihi batas waktu`);
571
632
  }
572
633
  catch (reconnectError) {
573
634
  console.error(`Gagal reconnect: ${(reconnectError === null || reconnectError === void 0 ? void 0 : reconnectError.message) || 'Unknown error'}`);
@@ -613,6 +674,10 @@ const sendTyping = (_a) => __awaiter(void 0, [_a], void 0, function* ({ sessionI
613
674
  else {
614
675
  jid = (0, Utils_1.phoneToJid)({ to, isGroup: isGroup || isGroupChat });
615
676
  }
677
+ // Validasi JID untuk memastikan format yang didukung
678
+ if (!(0, Utils_2.isValidJid)(jid)) {
679
+ throw new Error_1.WhatsappError(`Invalid JID format: ${jid}. Supported formats: @s.whatsapp.net, @lid, @g.us`);
680
+ }
616
681
  try {
617
682
  // Deteksi apakah ini grup
618
683
  const isDestinationGroup = jid.endsWith('@g.us');
@@ -2,4 +2,5 @@ export * from "./phone-to-jid";
2
2
  export * from "./is-exist";
3
3
  export * from "./create-delay";
4
4
  export * from "./group-cache";
5
+ export * from "./lid-utils";
5
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/Utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/Utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC"}
@@ -18,5 +18,6 @@ __exportStar(require("./phone-to-jid"), exports);
18
18
  __exportStar(require("./is-exist"), exports);
19
19
  __exportStar(require("./create-delay"), exports);
20
20
  __exportStar(require("./group-cache"), exports);
21
+ __exportStar(require("./lid-utils"), exports);
21
22
  // Note: setCredentialsDir & setMongoDBNames have been moved to src/Socket/index.ts
22
23
  // Please import them directly from there instead
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Fungsi untuk mendeteksi apakah sebuah JID menggunakan format PN (@s.whatsapp.net)
3
+ * @param jid JID yang akan dicek
4
+ * @returns true jika JID menggunakan format PN
5
+ */
6
+ export declare const isPnJid: (jid: string) => boolean;
7
+ /**
8
+ * Fungsi untuk mengekstrak nomor telepon dari JID (baik format @s.whatsapp.net atau @lid)
9
+ * @param jid JID yang akan diekstrak
10
+ * @returns nomor telepon tanpa suffix
11
+ */
12
+ export declare const extractPhoneNumber: (jid: string) => string;
13
+ /**
14
+ * Fungsi untuk konversi JID dari format LID ke format PN jika diperlukan
15
+ * Catatan: Fungsi ini hanya untuk kompatibilitas, karena WhatsApp sekarang mendukung kedua format
16
+ * @param jid JID yang akan dikonversi
17
+ * @returns JID dalam format yang sesuai
18
+ */
19
+ export declare const normalizeJid: (jid: string) => string;
20
+ /**
21
+ * Fungsi untuk memvalidasi format JID
22
+ * @param jid JID yang akan divalidasi
23
+ * @returns true jika JID valid
24
+ */
25
+ export declare const isValidJid: (jid: string) => boolean;
26
+ //# sourceMappingURL=lid-utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lid-utils.d.ts","sourceRoot":"","sources":["../../src/Utils/lid-utils.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,eAAO,MAAM,OAAO,GAAI,KAAK,MAAM,KAAG,OAErC,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,GAAI,KAAK,MAAM,KAAG,MAQhD,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,YAAY,GAAI,KAAK,MAAM,KAAG,MAe1C,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,UAAU,GAAI,KAAK,MAAM,KAAG,OA2BxC,CAAC"}
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isValidJid = exports.normalizeJid = exports.extractPhoneNumber = exports.isPnJid = void 0;
4
+ const Error_1 = require("../Error");
5
+ const phone_to_jid_1 = require("./phone-to-jid");
6
+ /**
7
+ * Fungsi untuk mendeteksi apakah sebuah JID menggunakan format PN (@s.whatsapp.net)
8
+ * @param jid JID yang akan dicek
9
+ * @returns true jika JID menggunakan format PN
10
+ */
11
+ const isPnJid = (jid) => {
12
+ return jid.includes("@s.whatsapp.net");
13
+ };
14
+ exports.isPnJid = isPnJid;
15
+ /**
16
+ * Fungsi untuk mengekstrak nomor telepon dari JID (baik format @s.whatsapp.net atau @lid)
17
+ * @param jid JID yang akan diekstrak
18
+ * @returns nomor telepon tanpa suffix
19
+ */
20
+ const extractPhoneNumber = (jid) => {
21
+ if (!jid)
22
+ throw new Error_1.WhatsappError('parameter "jid" is required');
23
+ // Hapus suffix @s.whatsapp.net atau @lid
24
+ const phoneNumber = jid.replace(/@(s\.whatsapp\.net|lid)$/, '');
25
+ // Hapus karakter non-digit
26
+ return phoneNumber.replace(/\D/g, '');
27
+ };
28
+ exports.extractPhoneNumber = extractPhoneNumber;
29
+ /**
30
+ * Fungsi untuk konversi JID dari format LID ke format PN jika diperlukan
31
+ * Catatan: Fungsi ini hanya untuk kompatibilitas, karena WhatsApp sekarang mendukung kedua format
32
+ * @param jid JID yang akan dikonversi
33
+ * @returns JID dalam format yang sesuai
34
+ */
35
+ const normalizeJid = (jid) => {
36
+ if (!jid)
37
+ throw new Error_1.WhatsappError('parameter "jid" is required');
38
+ // Jika sudah dalam format yang valid, kembalikan apa adanya
39
+ if ((0, phone_to_jid_1.isLidJid)(jid) || (0, exports.isPnJid)(jid) || jid.includes('@g.us') || jid.includes('@broadcast')) {
40
+ return jid;
41
+ }
42
+ // Jika hanya nomor telepon, tambahkan suffix default
43
+ const phoneNumber = jid.replace(/\D/g, '');
44
+ if (phoneNumber.length > 0) {
45
+ return `${phoneNumber}@s.whatsapp.net`;
46
+ }
47
+ throw new Error_1.WhatsappError(`Invalid JID format: ${jid}`);
48
+ };
49
+ exports.normalizeJid = normalizeJid;
50
+ /**
51
+ * Fungsi untuk memvalidasi format JID
52
+ * @param jid JID yang akan divalidasi
53
+ * @returns true jika JID valid
54
+ */
55
+ const isValidJid = (jid) => {
56
+ if (!jid)
57
+ return false;
58
+ // Validasi format @s.whatsapp.net
59
+ if ((0, exports.isPnJid)(jid)) {
60
+ const phoneNumber = (0, exports.extractPhoneNumber)(jid);
61
+ return phoneNumber.length >= 10 && phoneNumber.length <= 15;
62
+ }
63
+ // Validasi format @lid
64
+ if ((0, phone_to_jid_1.isLidJid)(jid)) {
65
+ const lidPart = jid.split('@')[0];
66
+ return lidPart.length > 0;
67
+ }
68
+ // Validasi format grup
69
+ if (jid.includes('@g.us')) {
70
+ const groupPart = jid.split('@')[0];
71
+ return groupPart.length > 0 && groupPart.includes('-');
72
+ }
73
+ // Validasi format broadcast
74
+ if (jid.includes('@broadcast')) {
75
+ return true;
76
+ }
77
+ return false;
78
+ };
79
+ exports.isValidJid = isValidJid;
@@ -1,3 +1,15 @@
1
+ /**
2
+ * Fungsi untuk mendeteksi apakah sebuah JID menggunakan format LID (@lid)
3
+ * @param jid JID yang akan dicek
4
+ * @returns true jika JID menggunakan format LID
5
+ */
6
+ export declare const isLidJid: (jid: string) => boolean;
7
+ /**
8
+ * Fungsi untuk normalisasi JID, mendukung format @s.whatsapp.net dan @lid
9
+ * @param to Nomor telepon atau JID tujuan
10
+ * @param isGroup Apakah ini adalah grup
11
+ * @returns JID yang sudah dinormalisasi
12
+ */
1
13
  export declare const phoneToJid: ({ to, isGroup, }: {
2
14
  to: string | number;
3
15
  isGroup?: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"phone-to-jid.d.ts","sourceRoot":"","sources":["../../src/Utils/phone-to-jid.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,UAAU,GAAI,kBAGxB;IACD,EAAE,EAAE,MAAM,GAAG,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,KAAG,MAaH,CAAC"}
1
+ {"version":3,"file":"phone-to-jid.d.ts","sourceRoot":"","sources":["../../src/Utils/phone-to-jid.ts"],"names":[],"mappings":"AASA;;;;GAIG;AACH,eAAO,MAAM,QAAQ,GAAI,KAAK,MAAM,KAAG,OAEtC,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,UAAU,GAAI,kBAGxB;IACD,EAAE,EAAE,MAAM,GAAG,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,KAAG,MAoBH,CAAC"}
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.phoneToJid = void 0;
6
+ exports.phoneToJid = exports.isLidJid = void 0;
7
7
  const Error_1 = require("../Error");
8
8
  const baileys_1 = __importDefault(require("baileys"));
9
9
  const isPhoneNumberValidCountry = (phone) => {
@@ -11,6 +11,21 @@ const isPhoneNumberValidCountry = (phone) => {
11
11
  return phone.startsWith(key);
12
12
  });
13
13
  };
14
+ /**
15
+ * Fungsi untuk mendeteksi apakah sebuah JID menggunakan format LID (@lid)
16
+ * @param jid JID yang akan dicek
17
+ * @returns true jika JID menggunakan format LID
18
+ */
19
+ const isLidJid = (jid) => {
20
+ return jid.includes("@lid");
21
+ };
22
+ exports.isLidJid = isLidJid;
23
+ /**
24
+ * Fungsi untuk normalisasi JID, mendukung format @s.whatsapp.net dan @lid
25
+ * @param to Nomor telepon atau JID tujuan
26
+ * @param isGroup Apakah ini adalah grup
27
+ * @returns JID yang sudah dinormalisasi
28
+ */
14
29
  const phoneToJid = ({ to, isGroup = false, }) => {
15
30
  if (!to)
16
31
  throw new Error_1.WhatsappError('parameter "to" is required');
@@ -22,8 +37,14 @@ const phoneToJid = ({ to, isGroup = false, }) => {
22
37
  }
23
38
  else {
24
39
  number = number.replace(/\s|[+]|[-]/gim, "");
25
- if (!number.includes("@s.whatsapp.net"))
40
+ // Jika sudah dalam format @lid atau @s.whatsapp.net, gunakan apa adanya
41
+ if (number.includes("@lid") || number.includes("@s.whatsapp.net")) {
42
+ // Jangan tambahkan suffix lagi
43
+ }
44
+ else {
45
+ // Default ke format @s.whatsapp.net untuk kompatibilitas
26
46
  number = number + "@s.whatsapp.net";
47
+ }
27
48
  }
28
49
  return number;
29
50
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wa-multi-mongodb",
3
- "version": "3.9.10",
3
+ "version": "3.10.1",
4
4
  "description": "Multi Session Whatsapp Library with MongoDB Integration",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -20,7 +20,7 @@
20
20
  "@types/node-cache": "^4.1.3",
21
21
  "@types/qrcode": "^1.5.5",
22
22
  "aws4": "^1.13.2",
23
- "baileys": "^6.7.21",
23
+ "baileys": "^7.0.0-rc.6",
24
24
  "dotenv": "^16.5.0",
25
25
  "link-preview-js": "^3.0.14",
26
26
  "mime": "^3.0.0",
package/readme.md CHANGED
@@ -816,7 +816,22 @@ export default WhatsAppQRComponent;
816
816
 
817
817
  ## Changelog
818
818
 
819
- ### v3.9.8 (latest)
819
+ ### v3.10.1 (latest)
820
+ - **Using Baileys New Version (7.x.x)**: Update & support function with latest baileys version
821
+ - **Added @lid Format Support**: Full support for WhatsApp's new @lid identifier format
822
+ - Updated `phoneToJid()` function to handle both @s.whatsapp.net and @lid formats
823
+ - Enhanced all message sending functions with JID validation:
824
+ - `sendTextMessage()`
825
+ - `sendTextMessageWithMention()`
826
+ - `sendMedia()`
827
+ - `sendVoiceNote()`
828
+ - `sendSticker()`
829
+ - `sendTyping()`
830
+ - No breaking changes - existing @s.whatsapp.net format continues to work
831
+ - Automatic detection and handling of @lid format to prevent 404 errors
832
+ - Added comprehensive error handling for invalid JID formats
833
+
834
+ ### v3.9.8
820
835
  ### Added
821
836
  - **New `sendTextMessageWithMention` Function**: Comprehensive mention functionality for WhatsApp messages
822
837
  - Support for mentioning single or multiple users in group chats