wa-multi-mongodb 3.10.2 → 3.10.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.
Files changed (85) hide show
  1. package/dist/Defaults/index.js +4 -9
  2. package/dist/Error/index.js +1 -5
  3. package/dist/Messaging/index.d.ts +1 -1
  4. package/dist/Messaging/index.js +123 -137
  5. package/dist/Profile/index.d.ts +1 -1
  6. package/dist/Profile/index.js +6 -10
  7. package/dist/Socket/index.d.ts +160 -1
  8. package/dist/Socket/index.d.ts.map +1 -1
  9. package/dist/Socket/index.js +462 -200
  10. package/dist/Types/index.d.ts +21 -0
  11. package/dist/Types/index.d.ts.map +1 -1
  12. package/dist/Types/index.js +1 -2
  13. package/dist/Types/profile.js +1 -2
  14. package/dist/Utils/create-delay.js +2 -7
  15. package/dist/Utils/error.js +1 -4
  16. package/dist/Utils/group-cache.js +8 -15
  17. package/dist/Utils/index.d.ts +5 -5
  18. package/dist/Utils/index.js +5 -21
  19. package/dist/Utils/is-exist.d.ts +1 -1
  20. package/dist/Utils/is-exist.js +7 -10
  21. package/dist/Utils/lid-utils.js +13 -20
  22. package/dist/Utils/message-status.d.ts +1 -1
  23. package/dist/Utils/message-status.js +7 -11
  24. package/dist/Utils/mongo-auth-state.js +10 -13
  25. package/dist/Utils/phone-to-jid.js +6 -14
  26. package/dist/Utils/save-media.d.ts +1 -1
  27. package/dist/Utils/save-media.js +16 -26
  28. package/dist/cjs/Defaults/index.d.ts +21 -0
  29. package/dist/cjs/Defaults/index.d.ts.map +1 -0
  30. package/dist/cjs/Defaults/index.js +31 -0
  31. package/dist/cjs/Error/index.d.ts +5 -0
  32. package/dist/cjs/Error/index.d.ts.map +1 -0
  33. package/dist/cjs/Error/index.js +14 -0
  34. package/dist/cjs/Messaging/index.d.ts +45 -0
  35. package/dist/cjs/Messaging/index.d.ts.map +1 -0
  36. package/dist/cjs/Messaging/index.js +784 -0
  37. package/dist/cjs/Profile/index.d.ts +9 -0
  38. package/dist/cjs/Profile/index.d.ts.map +1 -0
  39. package/dist/cjs/Profile/index.js +34 -0
  40. package/dist/cjs/Socket/index.d.ts +264 -0
  41. package/dist/cjs/Socket/index.d.ts.map +1 -0
  42. package/dist/cjs/Socket/index.js +1210 -0
  43. package/dist/cjs/Types/index.d.ts +95 -0
  44. package/dist/cjs/Types/index.d.ts.map +1 -0
  45. package/dist/cjs/Types/index.js +2 -0
  46. package/dist/cjs/Types/profile.d.ts +5 -0
  47. package/dist/cjs/Types/profile.d.ts.map +1 -0
  48. package/dist/cjs/Types/profile.js +2 -0
  49. package/dist/cjs/Utils/create-delay.d.ts +17 -0
  50. package/dist/cjs/Utils/create-delay.d.ts.map +1 -0
  51. package/dist/cjs/Utils/create-delay.js +38 -0
  52. package/dist/cjs/Utils/error.d.ts +4 -0
  53. package/dist/cjs/Utils/error.d.ts.map +1 -0
  54. package/dist/cjs/Utils/error.js +8 -0
  55. package/dist/cjs/Utils/group-cache.d.ts +23 -0
  56. package/dist/cjs/Utils/group-cache.d.ts.map +1 -0
  57. package/dist/cjs/Utils/group-cache.js +176 -0
  58. package/dist/cjs/Utils/index.d.ts +6 -0
  59. package/dist/cjs/Utils/index.d.ts.map +1 -0
  60. package/dist/cjs/Utils/index.js +23 -0
  61. package/dist/cjs/Utils/is-exist.d.ts +6 -0
  62. package/dist/cjs/Utils/is-exist.d.ts.map +1 -0
  63. package/dist/cjs/Utils/is-exist.js +53 -0
  64. package/dist/cjs/Utils/lid-utils.d.ts +26 -0
  65. package/dist/cjs/Utils/lid-utils.d.ts.map +1 -0
  66. package/dist/cjs/Utils/lid-utils.js +81 -0
  67. package/dist/cjs/Utils/message-status.d.ts +4 -0
  68. package/dist/cjs/Utils/message-status.d.ts.map +1 -0
  69. package/dist/cjs/Utils/message-status.js +18 -0
  70. package/dist/cjs/Utils/mongo-auth-state.d.ts +15 -0
  71. package/dist/cjs/Utils/mongo-auth-state.d.ts.map +1 -0
  72. package/dist/cjs/Utils/mongo-auth-state.js +109 -0
  73. package/dist/cjs/Utils/phone-to-jid.d.ts +17 -0
  74. package/dist/cjs/Utils/phone-to-jid.d.ts.map +1 -0
  75. package/dist/cjs/Utils/phone-to-jid.js +51 -0
  76. package/dist/cjs/Utils/save-media.d.ts +6 -0
  77. package/dist/cjs/Utils/save-media.d.ts.map +1 -0
  78. package/dist/cjs/Utils/save-media.js +55 -0
  79. package/dist/cjs/index.d.ts +8 -0
  80. package/dist/cjs/index.d.ts.map +1 -0
  81. package/dist/cjs/index.js +46 -0
  82. package/dist/index.d.ts +6 -6
  83. package/dist/index.js +7 -46
  84. package/package.json +57 -42
  85. package/readme.md +170 -3
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
2
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
3
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -19,24 +18,19 @@ var __rest = (this && this.__rest) || function (s, e) {
19
18
  }
20
19
  return t;
21
20
  };
22
- var __importDefault = (this && this.__importDefault) || function (mod) {
23
- return (mod && mod.__esModule) ? mod : { "default": mod };
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.deleteMessage = exports.readMessage = exports.sendTyping = exports.sendSticker = exports.sendVoiceNote = exports.sendMedia = exports.sendTextMessageWithMention = exports.sendTextMessage = void 0;
27
- const Defaults_1 = require("../Defaults");
28
- const Socket_1 = require("../Socket");
29
- const Utils_1 = require("../Utils");
30
- const Utils_2 = require("../Utils");
31
- const create_delay_1 = require("../Utils/create-delay");
32
- const is_exist_1 = require("../Utils/is-exist");
33
- const mime_1 = __importDefault(require("mime"));
34
- const Error_1 = require("../Error");
35
- const sendTextMessage = (_a) => __awaiter(void 0, void 0, void 0, function* () {
21
+ import { Messages } from "../Defaults/index.js";
22
+ import { getSession, reconnect } from "../Socket/index.js";
23
+ import { phoneToJid } from "../Utils/index.js";
24
+ import { isValidJid } from "../Utils/index.js";
25
+ import { createDelay, withTimeout } from "../Utils/create-delay.js";
26
+ import { isExist } from "../Utils/is-exist.js";
27
+ import mime from "mime";
28
+ import { WhatsappError } from "../Error/index.js";
29
+ export const sendTextMessage = (_a) => __awaiter(void 0, void 0, void 0, function* () {
36
30
  var { sessionId, to, text = "", isGroup = false } = _a, props = __rest(_a, ["sessionId", "to", "text", "isGroup"]);
37
- const session = (0, Socket_1.getSession)(sessionId);
31
+ const session = getSession(sessionId);
38
32
  if (!session)
39
- throw new Error_1.WhatsappError(Defaults_1.Messages.sessionNotFound(sessionId));
33
+ throw new WhatsappError(Messages.sessionNotFound(sessionId));
40
34
  // Deteksi otomatis apakah ini adalah grup berdasarkan format JID
41
35
  const toStr = to.toString();
42
36
  const isGroupChat = toStr.includes('@g.us');
@@ -52,11 +46,11 @@ const sendTextMessage = (_a) => __awaiter(void 0, void 0, void 0, function* () {
52
46
  }
53
47
  }
54
48
  else {
55
- jid = (0, Utils_1.phoneToJid)({ to, isGroup: isGroup || isGroupChat });
49
+ jid = phoneToJid({ to, isGroup: isGroup || isGroupChat });
56
50
  }
57
51
  // 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`);
52
+ if (!isValidJid(jid)) {
53
+ throw new WhatsappError(`Invalid JID format: ${jid}. Supported formats: @s.whatsapp.net, @lid, @g.us`);
60
54
  }
61
55
  let retryCount = 0;
62
56
  const maxRetries = 3;
@@ -70,7 +64,7 @@ const sendTextMessage = (_a) => __awaiter(void 0, void 0, void 0, function* () {
70
64
  // Konfirmasi sekali lagi apakah ini grup berdasarkan format JID setelah konversi
71
65
  const isDestinationGroup = jid.endsWith('@g.us');
72
66
  // Gunakan waktu jeda untuk memastikan koneksi siap
73
- yield (0, create_delay_1.createDelay)(500);
67
+ yield createDelay(500);
74
68
  // Beri timeout yang lebih pendek untuk grup untuk mencegah hanging
75
69
  const timeoutMs = isDestinationGroup ? 15000 : 30000;
76
70
  // Gunakan withTimeout untuk membatasi waktu operasi
@@ -79,7 +73,7 @@ const sendTextMessage = (_a) => __awaiter(void 0, void 0, void 0, function* () {
79
73
  }, messageOptions);
80
74
  // Tambahkan method toJSON untuk compatibility dengan WebMessageInfo
81
75
  result.toJSON = () => ({});
82
- return yield (0, create_delay_1.withTimeout)(Promise.resolve(result), timeoutMs, `Pengiriman pesan ke ${jid} melebihi batas waktu ${timeoutMs / 1000} detik`);
76
+ return yield withTimeout(Promise.resolve(result), timeoutMs, `Pengiriman pesan ke ${jid} melebihi batas waktu ${timeoutMs / 1000} detik`);
83
77
  }
84
78
  catch (error) {
85
79
  console.error(`Error saat mengirim pesan (percobaan ${retryCount + 1}/${maxRetries}): ${(error === null || error === void 0 ? void 0 : error.message) || 'Unknown error'}`);
@@ -89,19 +83,19 @@ const sendTextMessage = (_a) => __awaiter(void 0, void 0, void 0, function* () {
89
83
  if (retryCount < maxRetries) {
90
84
  retryCount++;
91
85
  // Tambahkan delay lebih lama antara percobaan
92
- yield (0, create_delay_1.createDelay)(2000 * retryCount);
86
+ yield createDelay(2000 * retryCount);
93
87
  return attemptSend();
94
88
  }
95
89
  else {
96
90
  console.error('Batas maksimum percobaan ulang tercapai');
97
- throw new Error_1.WhatsappError(`Gagal mengirim pesan ke grup dengan channel pengumuman setelah ${maxRetries} kali percobaan`);
91
+ throw new WhatsappError(`Gagal mengirim pesan ke grup dengan channel pengumuman setelah ${maxRetries} kali percobaan`);
98
92
  }
99
93
  }
100
94
  // Jika koneksi tertutup, coba reconnect
101
95
  if ((_c = error === null || error === void 0 ? void 0 : error.message) === null || _c === void 0 ? void 0 : _c.includes('Connection Closed')) {
102
96
  try {
103
- yield (0, Socket_1.reconnect)(sessionId);
104
- yield (0, create_delay_1.createDelay)(3000); // Beri waktu untuk reconnect sepenuhnya
97
+ yield reconnect(sessionId);
98
+ yield createDelay(3000); // Beri waktu untuk reconnect sepenuhnya
105
99
  // Coba kirim lagi setelah reconnect
106
100
  const reconnectResult = yield session.sendMessage(jid, {
107
101
  text: text,
@@ -110,16 +104,16 @@ const sendTextMessage = (_a) => __awaiter(void 0, void 0, void 0, function* () {
110
104
  });
111
105
  // Tambahkan method toJSON untuk compatibility dengan WebMessageInfo
112
106
  reconnectResult.toJSON = () => ({});
113
- return yield (0, create_delay_1.withTimeout)(Promise.resolve(reconnectResult), 30000, `Pengiriman pesan setelah reconnect melebihi batas waktu`);
107
+ return yield withTimeout(Promise.resolve(reconnectResult), 30000, `Pengiriman pesan setelah reconnect melebihi batas waktu`);
114
108
  }
115
109
  catch (reconnectError) {
116
110
  console.error(`Gagal reconnect: ${(reconnectError === null || reconnectError === void 0 ? void 0 : reconnectError.message) || 'Unknown error'}`);
117
- throw new Error_1.WhatsappError(`Koneksi terputus dan gagal reconnect: ${(reconnectError === null || reconnectError === void 0 ? void 0 : reconnectError.message) || 'Unknown error'}`);
111
+ throw new WhatsappError(`Koneksi terputus dan gagal reconnect: ${(reconnectError === null || reconnectError === void 0 ? void 0 : reconnectError.message) || 'Unknown error'}`);
118
112
  }
119
113
  }
120
114
  // Jika ada error timeout atau error lain, coba lagi sekali dengan delay lebih lama
121
115
  try {
122
- yield (0, create_delay_1.createDelay)(2000);
116
+ yield createDelay(2000);
123
117
  // Untuk percobaan kedua, gunakan timeout yang lebih lama
124
118
  const retryResult = yield session.sendMessage(jid, {
125
119
  text: text,
@@ -128,17 +122,16 @@ const sendTextMessage = (_a) => __awaiter(void 0, void 0, void 0, function* () {
128
122
  });
129
123
  // Tambahkan method toJSON untuk compatibility dengan WebMessageInfo
130
124
  retryResult.toJSON = () => ({});
131
- return yield (0, create_delay_1.withTimeout)(Promise.resolve(retryResult), 20000, `Percobaan kedua pengiriman pesan melebihi batas waktu`);
125
+ return yield withTimeout(Promise.resolve(retryResult), 20000, `Percobaan kedua pengiriman pesan melebihi batas waktu`);
132
126
  }
133
127
  catch (retryError) {
134
128
  console.error(`Gagal pada percobaan kedua: ${(retryError === null || retryError === void 0 ? void 0 : retryError.message) || 'Unknown error'}`);
135
- throw new Error_1.WhatsappError(`Gagal mengirim pesan: ${(retryError === null || retryError === void 0 ? void 0 : retryError.message) || 'Unknown error'}`);
129
+ throw new WhatsappError(`Gagal mengirim pesan: ${(retryError === null || retryError === void 0 ? void 0 : retryError.message) || 'Unknown error'}`);
136
130
  }
137
131
  }
138
132
  });
139
133
  return attemptSend();
140
134
  });
141
- exports.sendTextMessage = sendTextMessage;
142
135
  /**
143
136
  * Kirim pesan teks dengan mention
144
137
  *
@@ -149,11 +142,11 @@ exports.sendTextMessage = sendTextMessage;
149
142
  * @param isGroup - Apakah ini adalah grup
150
143
  * @param props - Properti tambahan seperti answering
151
144
  */
152
- const sendTextMessageWithMention = (_a) => __awaiter(void 0, void 0, void 0, function* () {
145
+ export const sendTextMessageWithMention = (_a) => __awaiter(void 0, void 0, void 0, function* () {
153
146
  var { sessionId, to, text = "", mentions = [], isGroup = false } = _a, props = __rest(_a, ["sessionId", "to", "text", "mentions", "isGroup"]);
154
- const session = (0, Socket_1.getSession)(sessionId);
147
+ const session = getSession(sessionId);
155
148
  if (!session)
156
- throw new Error_1.WhatsappError(Defaults_1.Messages.sessionNotFound(sessionId));
149
+ throw new WhatsappError(Messages.sessionNotFound(sessionId));
157
150
  // Deteksi otomatis apakah ini adalah grup berdasarkan format JID
158
151
  const toStr = to.toString();
159
152
  const isGroupChat = toStr.includes('@g.us');
@@ -169,11 +162,11 @@ const sendTextMessageWithMention = (_a) => __awaiter(void 0, void 0, void 0, fun
169
162
  }
170
163
  }
171
164
  else {
172
- jid = (0, Utils_1.phoneToJid)({ to, isGroup: isGroup || isGroupChat });
165
+ jid = phoneToJid({ to, isGroup: isGroup || isGroupChat });
173
166
  }
174
167
  // 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`);
168
+ if (!isValidJid(jid)) {
169
+ throw new WhatsappError(`Invalid JID format: ${jid}. Supported formats: @s.whatsapp.net, @lid, @g.us`);
177
170
  }
178
171
  let retryCount = 0;
179
172
  const maxRetries = 3;
@@ -187,7 +180,7 @@ const sendTextMessageWithMention = (_a) => __awaiter(void 0, void 0, void 0, fun
187
180
  // Konfirmasi sekali lagi apakah ini grup berdasarkan format JID setelah konversi
188
181
  const isDestinationGroup = jid.endsWith('@g.us');
189
182
  // Gunakan waktu jeda untuk memastikan koneksi siap
190
- yield (0, create_delay_1.createDelay)(500);
183
+ yield createDelay(500);
191
184
  // Beri timeout yang lebih pendek untuk grup untuk mencegah hanging
192
185
  const timeoutMs = isDestinationGroup ? 15000 : 30000;
193
186
  // Persiapkan pesan dengan mention jika ada
@@ -202,7 +195,7 @@ const sendTextMessageWithMention = (_a) => __awaiter(void 0, void 0, void 0, fun
202
195
  const result = yield session.sendMessage(jid, messageContent, messageOptions);
203
196
  // Tambahkan method toJSON untuk compatibility dengan WebMessageInfo
204
197
  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`);
198
+ return yield withTimeout(Promise.resolve(result), timeoutMs, `Pengiriman pesan dengan mention ke ${jid} melebihi batas waktu ${timeoutMs / 1000} detik`);
206
199
  }
207
200
  catch (error) {
208
201
  console.error(`Error saat mengirim pesan dengan mention (percobaan ${retryCount + 1}/${maxRetries}): ${(error === null || error === void 0 ? void 0 : error.message) || 'Unknown error'}`);
@@ -212,19 +205,19 @@ const sendTextMessageWithMention = (_a) => __awaiter(void 0, void 0, void 0, fun
212
205
  if (retryCount < maxRetries) {
213
206
  retryCount++;
214
207
  // Tambahkan delay lebih lama antara percobaan
215
- yield (0, create_delay_1.createDelay)(2000 * retryCount);
208
+ yield createDelay(2000 * retryCount);
216
209
  return attemptSend();
217
210
  }
218
211
  else {
219
212
  console.error('Batas maksimum percobaan ulang tercapai');
220
- throw new Error_1.WhatsappError(`Gagal mengirim pesan dengan mention ke grup dengan channel pengumuman setelah ${maxRetries} kali percobaan`);
213
+ throw new WhatsappError(`Gagal mengirim pesan dengan mention ke grup dengan channel pengumuman setelah ${maxRetries} kali percobaan`);
221
214
  }
222
215
  }
223
216
  // Jika koneksi tertutup, coba reconnect
224
217
  if ((_c = error === null || error === void 0 ? void 0 : error.message) === null || _c === void 0 ? void 0 : _c.includes('Connection Closed')) {
225
218
  try {
226
- yield (0, Socket_1.reconnect)(sessionId);
227
- yield (0, create_delay_1.createDelay)(3000); // Beri waktu untuk reconnect sepenuhnya
219
+ yield reconnect(sessionId);
220
+ yield createDelay(3000); // Beri waktu untuk reconnect sepenuhnya
228
221
  // Persiapkan pesan dengan mention untuk reconnect
229
222
  const messageContent = {
230
223
  text: text,
@@ -238,16 +231,16 @@ const sendTextMessageWithMention = (_a) => __awaiter(void 0, void 0, void 0, fun
238
231
  });
239
232
  // Tambahkan method toJSON untuk compatibility dengan WebMessageInfo
240
233
  reconnectResult.toJSON = () => ({});
241
- return yield (0, create_delay_1.withTimeout)(Promise.resolve(reconnectResult), 30000, `Pengiriman pesan dengan mention setelah reconnect melebihi batas waktu`);
234
+ return yield withTimeout(Promise.resolve(reconnectResult), 30000, `Pengiriman pesan dengan mention setelah reconnect melebihi batas waktu`);
242
235
  }
243
236
  catch (reconnectError) {
244
237
  console.error(`Gagal reconnect: ${(reconnectError === null || reconnectError === void 0 ? void 0 : reconnectError.message) || 'Unknown error'}`);
245
- throw new Error_1.WhatsappError(`Koneksi terputus dan gagal reconnect: ${(reconnectError === null || reconnectError === void 0 ? void 0 : reconnectError.message) || 'Unknown error'}`);
238
+ throw new WhatsappError(`Koneksi terputus dan gagal reconnect: ${(reconnectError === null || reconnectError === void 0 ? void 0 : reconnectError.message) || 'Unknown error'}`);
246
239
  }
247
240
  }
248
241
  // Jika ada error timeout atau error lain, coba lagi sekali dengan delay lebih lama
249
242
  try {
250
- yield (0, create_delay_1.createDelay)(2000);
243
+ yield createDelay(2000);
251
244
  // Persiapkan pesan dengan mention untuk percobaan kedua
252
245
  const messageContent = {
253
246
  text: text,
@@ -261,21 +254,20 @@ const sendTextMessageWithMention = (_a) => __awaiter(void 0, void 0, void 0, fun
261
254
  });
262
255
  // Tambahkan method toJSON untuk compatibility dengan WebMessageInfo
263
256
  retryResult.toJSON = () => ({});
264
- return yield (0, create_delay_1.withTimeout)(Promise.resolve(retryResult), 20000, `Percobaan kedua pengiriman pesan dengan mention melebihi batas waktu`);
257
+ return yield withTimeout(Promise.resolve(retryResult), 20000, `Percobaan kedua pengiriman pesan dengan mention melebihi batas waktu`);
265
258
  }
266
259
  catch (retryError) {
267
260
  console.error(`Gagal pada percobaan kedua: ${(retryError === null || retryError === void 0 ? void 0 : retryError.message) || 'Unknown error'}`);
268
- throw new Error_1.WhatsappError(`Gagal mengirim pesan dengan mention: ${(retryError === null || retryError === void 0 ? void 0 : retryError.message) || 'Unknown error'}`);
261
+ throw new WhatsappError(`Gagal mengirim pesan dengan mention: ${(retryError === null || retryError === void 0 ? void 0 : retryError.message) || 'Unknown error'}`);
269
262
  }
270
263
  }
271
264
  });
272
265
  return attemptSend();
273
266
  });
274
- exports.sendTextMessageWithMention = sendTextMessageWithMention;
275
- const sendMedia = (_a) => __awaiter(void 0, [_a], void 0, function* ({ sessionId, to, media, type, caption = "", fileName, isGroup = false, answering, }) {
276
- const session = (0, Socket_1.getSession)(sessionId);
267
+ export const sendMedia = (_a) => __awaiter(void 0, [_a], void 0, function* ({ sessionId, to, media, type, caption = "", fileName, isGroup = false, answering, }) {
268
+ const session = getSession(sessionId);
277
269
  if (!session)
278
- throw new Error_1.WhatsappError(Defaults_1.Messages.sessionNotFound(sessionId));
270
+ throw new WhatsappError(Messages.sessionNotFound(sessionId));
279
271
  // Deteksi otomatis apakah ini adalah grup berdasarkan format JID
280
272
  const toStr = to.toString();
281
273
  const isGroupChat = toStr.includes('@g.us');
@@ -291,19 +283,19 @@ const sendMedia = (_a) => __awaiter(void 0, [_a], void 0, function* ({ sessionId
291
283
  }
292
284
  }
293
285
  else {
294
- jid = (0, Utils_1.phoneToJid)({ to, isGroup: isGroup || isGroupChat });
286
+ jid = phoneToJid({ to, isGroup: isGroup || isGroupChat });
295
287
  }
296
288
  // 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`);
289
+ if (!isValidJid(jid)) {
290
+ throw new WhatsappError(`Invalid JID format: ${jid}. Supported formats: @s.whatsapp.net, @lid, @g.us`);
299
291
  }
300
292
  let retryCount = 0;
301
293
  const maxRetries = 3;
302
294
  // Helper function untuk mendapatkan message content berdasarkan tipe
303
295
  function getMessageContent() {
304
- const processedMedia = (0, is_exist_1.isExist)(media);
296
+ const processedMedia = isExist(media);
305
297
  const content = {};
306
- const fileMimeType = mime_1.default.getType(typeof media === 'string' ? media : (fileName || '')) || 'application/octet-stream';
298
+ const fileMimeType = mime.getType(typeof media === 'string' ? media : (fileName || '')) || 'application/octet-stream';
307
299
  switch (type) {
308
300
  case "image":
309
301
  content.image = processedMedia;
@@ -335,7 +327,7 @@ const sendMedia = (_a) => __awaiter(void 0, [_a], void 0, function* ({ sessionId
335
327
  const attemptSend = () => __awaiter(void 0, void 0, void 0, function* () {
336
328
  var _a, _b, _c;
337
329
  try {
338
- const mimeType = mime_1.default.getType(typeof media === 'string' ? media : (fileName || '')) || 'application/octet-stream';
330
+ const mimeType = mime.getType(typeof media === 'string' ? media : (fileName || '')) || 'application/octet-stream';
339
331
  if (!mimeType && type !== 'image' && type !== 'video')
340
332
  throw new Error("Cannot get file mimetype!");
341
333
  const messageContent = {};
@@ -343,9 +335,9 @@ const sendMedia = (_a) => __awaiter(void 0, [_a], void 0, function* ({ sessionId
343
335
  // Konfirmasi sekali lagi apakah ini grup berdasarkan format JID setelah konversi
344
336
  const isDestinationGroup = jid.endsWith('@g.us');
345
337
  // Tunda sejenak untuk memastikan koneksi stabil
346
- yield (0, create_delay_1.createDelay)(500);
338
+ yield createDelay(500);
347
339
  // Persiapkan media dengan isExist
348
- const processedMedia = (0, is_exist_1.isExist)(media);
340
+ const processedMedia = isExist(media);
349
341
  switch (type) {
350
342
  case "image":
351
343
  messageContent.image = processedMedia;
@@ -386,7 +378,7 @@ const sendMedia = (_a) => __awaiter(void 0, [_a], void 0, function* ({ sessionId
386
378
  const result = yield session.sendMessage(jid, messageContent, options);
387
379
  // Tambahkan method toJSON untuk compatibility dengan WebMessageInfo
388
380
  result.toJSON = () => ({});
389
- return yield (0, create_delay_1.withTimeout)(Promise.resolve(result), timeoutMs, `Pengiriman media melebihi batas waktu ${timeoutMs / 1000} detik`);
381
+ return yield withTimeout(Promise.resolve(result), timeoutMs, `Pengiriman media melebihi batas waktu ${timeoutMs / 1000} detik`);
390
382
  }
391
383
  catch (error) {
392
384
  console.error(`Error saat mengirim media (percobaan ${retryCount + 1}/${maxRetries}): ${(error === null || error === void 0 ? void 0 : error.message) || 'Unknown error'}`);
@@ -396,19 +388,19 @@ const sendMedia = (_a) => __awaiter(void 0, [_a], void 0, function* ({ sessionId
396
388
  if (retryCount < maxRetries) {
397
389
  retryCount++;
398
390
  // Tambahkan delay lebih lama antara percobaan
399
- yield (0, create_delay_1.createDelay)(2000 * retryCount);
391
+ yield createDelay(2000 * retryCount);
400
392
  return attemptSend();
401
393
  }
402
394
  else {
403
395
  console.error('Batas maksimum percobaan ulang tercapai');
404
- throw new Error_1.WhatsappError(`Gagal mengirim media ke grup dengan channel pengumuman setelah ${maxRetries} kali percobaan`);
396
+ throw new WhatsappError(`Gagal mengirim media ke grup dengan channel pengumuman setelah ${maxRetries} kali percobaan`);
405
397
  }
406
398
  }
407
399
  // Jika koneksi tertutup, coba reconnect
408
400
  if ((_c = error === null || error === void 0 ? void 0 : error.message) === null || _c === void 0 ? void 0 : _c.includes('Connection Closed')) {
409
401
  try {
410
- yield (0, Socket_1.reconnect)(sessionId);
411
- yield (0, create_delay_1.createDelay)(3000); // Beri waktu untuk reconnect sepenuhnya
402
+ yield reconnect(sessionId);
403
+ yield createDelay(3000); // Beri waktu untuk reconnect sepenuhnya
412
404
  // Siapkan content media untuk percobaan ulang
413
405
  const retryContent = getMessageContent();
414
406
  // Coba kirim lagi setelah reconnect
@@ -416,17 +408,17 @@ const sendMedia = (_a) => __awaiter(void 0, [_a], void 0, function* ({ sessionId
416
408
  const reconnectResult = yield session.sendMessage(jid, retryContent, reconnectOptions);
417
409
  // Tambahkan method toJSON untuk compatibility dengan WebMessageInfo
418
410
  reconnectResult.toJSON = () => ({});
419
- return yield (0, create_delay_1.withTimeout)(Promise.resolve(reconnectResult), 180000, // 3 menit untuk percobaan setelah reconnect
411
+ return yield withTimeout(Promise.resolve(reconnectResult), 180000, // 3 menit untuk percobaan setelah reconnect
420
412
  `Pengiriman media setelah reconnect melebihi batas waktu`);
421
413
  }
422
414
  catch (reconnectError) {
423
415
  console.error(`Gagal reconnect: ${(reconnectError === null || reconnectError === void 0 ? void 0 : reconnectError.message) || 'Unknown error'}`);
424
- throw new Error_1.WhatsappError(`Koneksi terputus dan gagal reconnect: ${(reconnectError === null || reconnectError === void 0 ? void 0 : reconnectError.message) || 'Unknown error'}`);
416
+ throw new WhatsappError(`Koneksi terputus dan gagal reconnect: ${(reconnectError === null || reconnectError === void 0 ? void 0 : reconnectError.message) || 'Unknown error'}`);
425
417
  }
426
418
  }
427
419
  // Untuk error timeout atau error lain, coba lagi dengan timeout lebih lama
428
420
  try {
429
- yield (0, create_delay_1.createDelay)(3000);
421
+ yield createDelay(3000);
430
422
  // Siapkan content media untuk percobaan ulang
431
423
  const retryContent = getMessageContent();
432
424
  // Untuk percobaan kedua, gunakan timeout yang lebih lama
@@ -434,23 +426,22 @@ const sendMedia = (_a) => __awaiter(void 0, [_a], void 0, function* ({ sessionId
434
426
  const retryResult = yield session.sendMessage(jid, retryContent, retryOptions);
435
427
  // Tambahkan method toJSON untuk compatibility dengan WebMessageInfo
436
428
  retryResult.toJSON = () => ({});
437
- return yield (0, create_delay_1.withTimeout)(Promise.resolve(retryResult), 180000, // 3 menit untuk percobaan kedua
429
+ return yield withTimeout(Promise.resolve(retryResult), 180000, // 3 menit untuk percobaan kedua
438
430
  `Percobaan kedua pengiriman media melebihi batas waktu`);
439
431
  }
440
432
  catch (retryError) {
441
433
  console.error(`Gagal pada percobaan kedua: ${(retryError === null || retryError === void 0 ? void 0 : retryError.message) || 'Unknown error'}`);
442
- throw new Error_1.WhatsappError(`Gagal mengirim media: ${(retryError === null || retryError === void 0 ? void 0 : retryError.message) || 'Unknown error'}`);
434
+ throw new WhatsappError(`Gagal mengirim media: ${(retryError === null || retryError === void 0 ? void 0 : retryError.message) || 'Unknown error'}`);
443
435
  }
444
436
  }
445
437
  });
446
438
  return attemptSend();
447
439
  });
448
- exports.sendMedia = sendMedia;
449
- const sendVoiceNote = (_a) => __awaiter(void 0, void 0, void 0, function* () {
440
+ export const sendVoiceNote = (_a) => __awaiter(void 0, void 0, void 0, function* () {
450
441
  var { sessionId, to, isGroup = false, media } = _a, props = __rest(_a, ["sessionId", "to", "isGroup", "media"]);
451
- const session = (0, Socket_1.getSession)(sessionId);
442
+ const session = getSession(sessionId);
452
443
  if (!session)
453
- throw new Error_1.WhatsappError(Defaults_1.Messages.sessionNotFound(sessionId));
444
+ throw new WhatsappError(Messages.sessionNotFound(sessionId));
454
445
  // Deteksi otomatis apakah ini adalah grup berdasarkan format JID
455
446
  const toStr = to.toString();
456
447
  const isGroupChat = toStr.includes('@g.us');
@@ -466,14 +457,14 @@ const sendVoiceNote = (_a) => __awaiter(void 0, void 0, void 0, function* () {
466
457
  }
467
458
  }
468
459
  else {
469
- jid = (0, Utils_1.phoneToJid)({ to, isGroup: isGroup || isGroupChat });
460
+ jid = phoneToJid({ to, isGroup: isGroup || isGroupChat });
470
461
  }
471
462
  // 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`);
463
+ if (!isValidJid(jid)) {
464
+ throw new WhatsappError(`Invalid JID format: ${jid}. Supported formats: @s.whatsapp.net, @lid, @g.us`);
474
465
  }
475
466
  if (!media) {
476
- throw new Error_1.WhatsappError(`Invalid Media`);
467
+ throw new WhatsappError(`Invalid Media`);
477
468
  }
478
469
  let retryCount = 0;
479
470
  const maxRetries = 3;
@@ -494,7 +485,7 @@ const sendVoiceNote = (_a) => __awaiter(void 0, void 0, void 0, function* () {
494
485
  }, voiceOptions);
495
486
  // Tambahkan method toJSON untuk compatibility dengan WebMessageInfo
496
487
  result.toJSON = () => ({});
497
- return yield (0, create_delay_1.withTimeout)(Promise.resolve(result), 60000, `Pengiriman voice note melebihi batas waktu`);
488
+ return yield withTimeout(Promise.resolve(result), 60000, `Pengiriman voice note melebihi batas waktu`);
498
489
  }
499
490
  catch (error) {
500
491
  console.error(`Error saat mengirim voice note (percobaan ${retryCount + 1}/${maxRetries}): ${(error === null || error === void 0 ? void 0 : error.message) || 'Unknown error'}`);
@@ -504,19 +495,19 @@ const sendVoiceNote = (_a) => __awaiter(void 0, void 0, void 0, function* () {
504
495
  if (retryCount < maxRetries) {
505
496
  retryCount++;
506
497
  // Tambahkan delay lebih lama antara percobaan
507
- yield (0, create_delay_1.createDelay)(2000 * retryCount);
498
+ yield createDelay(2000 * retryCount);
508
499
  return attemptSend();
509
500
  }
510
501
  else {
511
502
  console.error('Batas maksimum percobaan ulang tercapai');
512
- throw new Error_1.WhatsappError(`Gagal mengirim voice note ke grup dengan channel pengumuman setelah ${maxRetries} kali percobaan`);
503
+ throw new WhatsappError(`Gagal mengirim voice note ke grup dengan channel pengumuman setelah ${maxRetries} kali percobaan`);
513
504
  }
514
505
  }
515
506
  // Jika koneksi tertutup, coba reconnect
516
507
  if ((_c = error === null || error === void 0 ? void 0 : error.message) === null || _c === void 0 ? void 0 : _c.includes('Connection Closed')) {
517
508
  try {
518
- yield (0, Socket_1.reconnect)(sessionId);
519
- yield (0, create_delay_1.createDelay)(3000); // Beri waktu untuk reconnect sepenuhnya
509
+ yield reconnect(sessionId);
510
+ yield createDelay(3000); // Beri waktu untuk reconnect sepenuhnya
520
511
  // Coba kirim lagi setelah reconnect
521
512
  const reconnectVoiceOptions = {
522
513
  quoted: props.answering,
@@ -531,25 +522,24 @@ const sendVoiceNote = (_a) => __awaiter(void 0, void 0, void 0, function* () {
531
522
  }, reconnectVoiceOptions);
532
523
  // Tambahkan method toJSON untuk compatibility dengan WebMessageInfo
533
524
  reconnectResult.toJSON = () => ({});
534
- return yield (0, create_delay_1.withTimeout)(Promise.resolve(reconnectResult), 60000, `Pengiriman voice note setelah reconnect melebihi batas waktu`);
525
+ return yield withTimeout(Promise.resolve(reconnectResult), 60000, `Pengiriman voice note setelah reconnect melebihi batas waktu`);
535
526
  }
536
527
  catch (reconnectError) {
537
528
  console.error(`Gagal reconnect: ${(reconnectError === null || reconnectError === void 0 ? void 0 : reconnectError.message) || 'Unknown error'}`);
538
- throw new Error_1.WhatsappError(`Koneksi terputus dan gagal reconnect: ${(reconnectError === null || reconnectError === void 0 ? void 0 : reconnectError.message) || 'Unknown error'}`);
529
+ throw new WhatsappError(`Koneksi terputus dan gagal reconnect: ${(reconnectError === null || reconnectError === void 0 ? void 0 : reconnectError.message) || 'Unknown error'}`);
539
530
  }
540
531
  }
541
532
  // Re-throw error jika bukan masalah koneksi atau reconnect gagal
542
- throw new Error_1.WhatsappError(`Gagal mengirim voice note: ${(error === null || error === void 0 ? void 0 : error.message) || 'Unknown error'}`);
533
+ throw new WhatsappError(`Gagal mengirim voice note: ${(error === null || error === void 0 ? void 0 : error.message) || 'Unknown error'}`);
543
534
  }
544
535
  });
545
536
  return attemptSend();
546
537
  });
547
- exports.sendVoiceNote = sendVoiceNote;
548
- const sendSticker = (_a) => __awaiter(void 0, void 0, void 0, function* () {
538
+ export const sendSticker = (_a) => __awaiter(void 0, void 0, void 0, function* () {
549
539
  var { sessionId, to, isGroup, media } = _a, props = __rest(_a, ["sessionId", "to", "isGroup", "media"]);
550
- const session = (0, Socket_1.getSession)(sessionId);
540
+ const session = getSession(sessionId);
551
541
  if (!session)
552
- throw new Error_1.WhatsappError(Defaults_1.Messages.sessionNotFound(sessionId));
542
+ throw new WhatsappError(Messages.sessionNotFound(sessionId));
553
543
  // Deteksi otomatis apakah ini adalah grup berdasarkan format JID
554
544
  const toStr = to.toString();
555
545
  const isGroupChat = toStr.includes('@g.us');
@@ -565,14 +555,14 @@ const sendSticker = (_a) => __awaiter(void 0, void 0, void 0, function* () {
565
555
  }
566
556
  }
567
557
  else {
568
- jid = (0, Utils_1.phoneToJid)({ to, isGroup: isGroup || isGroupChat });
558
+ jid = phoneToJid({ to, isGroup: isGroup || isGroupChat });
569
559
  }
570
560
  // 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`);
561
+ if (!isValidJid(jid)) {
562
+ throw new WhatsappError(`Invalid JID format: ${jid}. Supported formats: @s.whatsapp.net, @lid, @g.us`);
573
563
  }
574
564
  if (!media) {
575
- throw new Error_1.WhatsappError(`Invalid Media`);
565
+ throw new WhatsappError(`Invalid Media`);
576
566
  }
577
567
  let retryCount = 0;
578
568
  const maxRetries = 3;
@@ -592,7 +582,7 @@ const sendSticker = (_a) => __awaiter(void 0, void 0, void 0, function* () {
592
582
  }, stickerOptions);
593
583
  // Tambahkan method toJSON untuk compatibility dengan WebMessageInfo
594
584
  result.toJSON = () => ({});
595
- return yield (0, create_delay_1.withTimeout)(Promise.resolve(result), 60000, `Pengiriman sticker melebihi batas waktu`);
585
+ return yield withTimeout(Promise.resolve(result), 60000, `Pengiriman sticker melebihi batas waktu`);
596
586
  }
597
587
  catch (error) {
598
588
  console.error(`Error saat mengirim sticker (percobaan ${retryCount + 1}/${maxRetries}): ${(error === null || error === void 0 ? void 0 : error.message) || 'Unknown error'}`);
@@ -602,19 +592,19 @@ const sendSticker = (_a) => __awaiter(void 0, void 0, void 0, function* () {
602
592
  if (retryCount < maxRetries) {
603
593
  retryCount++;
604
594
  // Tambahkan delay lebih lama antara percobaan
605
- yield (0, create_delay_1.createDelay)(2000 * retryCount);
595
+ yield createDelay(2000 * retryCount);
606
596
  return attemptSend();
607
597
  }
608
598
  else {
609
599
  console.error('Batas maksimum percobaan ulang tercapai');
610
- throw new Error_1.WhatsappError(`Gagal mengirim sticker ke grup dengan channel pengumuman setelah ${maxRetries} kali percobaan`);
600
+ throw new WhatsappError(`Gagal mengirim sticker ke grup dengan channel pengumuman setelah ${maxRetries} kali percobaan`);
611
601
  }
612
602
  }
613
603
  // Jika koneksi tertutup, coba reconnect
614
604
  if ((_c = error === null || error === void 0 ? void 0 : error.message) === null || _c === void 0 ? void 0 : _c.includes('Connection Closed')) {
615
605
  try {
616
- yield (0, Socket_1.reconnect)(sessionId);
617
- yield (0, create_delay_1.createDelay)(3000); // Beri waktu untuk reconnect sepenuhnya
606
+ yield reconnect(sessionId);
607
+ yield createDelay(3000); // Beri waktu untuk reconnect sepenuhnya
618
608
  // Coba kirim lagi setelah reconnect
619
609
  const reconnectStickerOptions = {
620
610
  quoted: props.answering,
@@ -628,20 +618,19 @@ const sendSticker = (_a) => __awaiter(void 0, void 0, void 0, function* () {
628
618
  }, reconnectStickerOptions);
629
619
  // Tambahkan method toJSON untuk compatibility dengan WebMessageInfo
630
620
  reconnectResult.toJSON = () => ({});
631
- return yield (0, create_delay_1.withTimeout)(Promise.resolve(reconnectResult), 60000, `Pengiriman sticker setelah reconnect melebihi batas waktu`);
621
+ return yield withTimeout(Promise.resolve(reconnectResult), 60000, `Pengiriman sticker setelah reconnect melebihi batas waktu`);
632
622
  }
633
623
  catch (reconnectError) {
634
624
  console.error(`Gagal reconnect: ${(reconnectError === null || reconnectError === void 0 ? void 0 : reconnectError.message) || 'Unknown error'}`);
635
- throw new Error_1.WhatsappError(`Koneksi terputus dan gagal reconnect: ${(reconnectError === null || reconnectError === void 0 ? void 0 : reconnectError.message) || 'Unknown error'}`);
625
+ throw new WhatsappError(`Koneksi terputus dan gagal reconnect: ${(reconnectError === null || reconnectError === void 0 ? void 0 : reconnectError.message) || 'Unknown error'}`);
636
626
  }
637
627
  }
638
628
  // Re-throw error jika bukan masalah koneksi atau reconnect gagal
639
- throw new Error_1.WhatsappError(`Gagal mengirim sticker: ${(error === null || error === void 0 ? void 0 : error.message) || 'Unknown error'}`);
629
+ throw new WhatsappError(`Gagal mengirim sticker: ${(error === null || error === void 0 ? void 0 : error.message) || 'Unknown error'}`);
640
630
  }
641
631
  });
642
632
  return attemptSend();
643
633
  });
644
- exports.sendSticker = sendSticker;
645
634
  /**
646
635
  * Give typing effect to target
647
636
  *
@@ -652,11 +641,11 @@ exports.sendSticker = sendSticker;
652
641
  * @param duration - Duration in miliseconds typing effect will appear
653
642
  * @param isGroup - Whether the chat is a group
654
643
  */
655
- const sendTyping = (_a) => __awaiter(void 0, [_a], void 0, function* ({ sessionId, to, duration, isGroup, }) {
644
+ export const sendTyping = (_a) => __awaiter(void 0, [_a], void 0, function* ({ sessionId, to, duration, isGroup, }) {
656
645
  var _b;
657
- const session = (0, Socket_1.getSession)(sessionId);
646
+ const session = getSession(sessionId);
658
647
  if (!session)
659
- throw new Error_1.WhatsappError(Defaults_1.Messages.sessionNotFound(sessionId));
648
+ throw new WhatsappError(Messages.sessionNotFound(sessionId));
660
649
  // Deteksi otomatis apakah ini adalah grup berdasarkan format JID
661
650
  const toStr = to.toString();
662
651
  const isGroupChat = toStr.includes('@g.us');
@@ -672,35 +661,35 @@ const sendTyping = (_a) => __awaiter(void 0, [_a], void 0, function* ({ sessionI
672
661
  }
673
662
  }
674
663
  else {
675
- jid = (0, Utils_1.phoneToJid)({ to, isGroup: isGroup || isGroupChat });
664
+ jid = phoneToJid({ to, isGroup: isGroup || isGroupChat });
676
665
  }
677
666
  // 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`);
667
+ if (!isValidJid(jid)) {
668
+ throw new WhatsappError(`Invalid JID format: ${jid}. Supported formats: @s.whatsapp.net, @lid, @g.us`);
680
669
  }
681
670
  try {
682
671
  // Deteksi apakah ini grup
683
672
  const isDestinationGroup = jid.endsWith('@g.us');
684
673
  const timeoutMs = isDestinationGroup ? 5000 : 10000;
685
674
  // Kirim status mengetik dengan timeout
686
- yield (0, create_delay_1.withTimeout)(session.sendPresenceUpdate("composing", jid), timeoutMs, `Timeout saat mengirim status mengetik`);
675
+ yield withTimeout(session.sendPresenceUpdate("composing", jid), timeoutMs, `Timeout saat mengirim status mengetik`);
687
676
  // Tunggu durasi yang ditentukan
688
- yield (0, create_delay_1.createDelay)(duration);
677
+ yield createDelay(duration);
689
678
  // Setelah durasi, atur kembali status
690
- yield (0, create_delay_1.withTimeout)(session.sendPresenceUpdate("paused", jid), timeoutMs, `Timeout saat menghentikan status mengetik`);
679
+ yield withTimeout(session.sendPresenceUpdate("paused", jid), timeoutMs, `Timeout saat menghentikan status mengetik`);
691
680
  }
692
681
  catch (error) {
693
682
  // Jika koneksi tertutup, coba reconnect
694
683
  if ((_b = error === null || error === void 0 ? void 0 : error.message) === null || _b === void 0 ? void 0 : _b.includes('Connection Closed')) {
695
684
  try {
696
- yield (0, Socket_1.reconnect)(sessionId);
697
- yield (0, create_delay_1.createDelay)(2000); // Beri waktu untuk reconnect sepenuhnya
685
+ yield reconnect(sessionId);
686
+ yield createDelay(2000); // Beri waktu untuk reconnect sepenuhnya
698
687
  // Setelah reconnect, coba kirim status mengetik lagi
699
688
  const isDestinationGroup = jid.endsWith('@g.us');
700
689
  const timeoutMs = isDestinationGroup ? 5000 : 10000;
701
- yield (0, create_delay_1.withTimeout)(session.sendPresenceUpdate("composing", jid), timeoutMs, `Timeout saat mengirim status mengetik setelah reconnect`);
702
- yield (0, create_delay_1.createDelay)(duration);
703
- yield (0, create_delay_1.withTimeout)(session.sendPresenceUpdate("paused", jid), timeoutMs, `Timeout saat menghentikan status mengetik setelah reconnect`);
690
+ yield withTimeout(session.sendPresenceUpdate("composing", jid), timeoutMs, `Timeout saat mengirim status mengetik setelah reconnect`);
691
+ yield createDelay(duration);
692
+ yield withTimeout(session.sendPresenceUpdate("paused", jid), timeoutMs, `Timeout saat menghentikan status mengetik setelah reconnect`);
704
693
  }
705
694
  catch (reconnectError) {
706
695
  // Tidak melempar error agar aplikasi tetap berjalan
@@ -708,30 +697,29 @@ const sendTyping = (_a) => __awaiter(void 0, [_a], void 0, function* ({ sessionI
708
697
  }
709
698
  }
710
699
  });
711
- exports.sendTyping = sendTyping;
712
700
  /**
713
701
  * Mark message as read
714
702
  *
715
703
  * @param sessionId - Session ID
716
704
  * @param key - Message key to mark as read
717
705
  */
718
- const readMessage = (_a) => __awaiter(void 0, [_a], void 0, function* ({ sessionId, key, }) {
706
+ export const readMessage = (_a) => __awaiter(void 0, [_a], void 0, function* ({ sessionId, key, }) {
719
707
  var _b;
720
- const session = (0, Socket_1.getSession)(sessionId);
708
+ const session = getSession(sessionId);
721
709
  if (!session)
722
- throw new Error_1.WhatsappError(Defaults_1.Messages.sessionNotFound(sessionId));
710
+ throw new WhatsappError(Messages.sessionNotFound(sessionId));
723
711
  try {
724
712
  // Terapkan timeout untuk mencegah hanging
725
- yield (0, create_delay_1.withTimeout)(session.readMessages([key]), 10000, "Timeout saat menandai pesan sebagai telah dibaca");
713
+ yield withTimeout(session.readMessages([key]), 10000, "Timeout saat menandai pesan sebagai telah dibaca");
726
714
  }
727
715
  catch (error) {
728
716
  // Jika koneksi tertutup, coba reconnect
729
717
  if ((_b = error === null || error === void 0 ? void 0 : error.message) === null || _b === void 0 ? void 0 : _b.includes('Connection Closed')) {
730
718
  try {
731
- yield (0, Socket_1.reconnect)(sessionId);
732
- yield (0, create_delay_1.createDelay)(2000); // Beri waktu untuk reconnect sepenuhnya
719
+ yield reconnect(sessionId);
720
+ yield createDelay(2000); // Beri waktu untuk reconnect sepenuhnya
733
721
  // Setelah reconnect, coba tandai dibaca lagi
734
- yield (0, create_delay_1.withTimeout)(session.readMessages([key]), 10000, "Timeout saat menandai pesan sebagai telah dibaca setelah reconnect");
722
+ yield withTimeout(session.readMessages([key]), 10000, "Timeout saat menandai pesan sebagai telah dibaca setelah reconnect");
735
723
  }
736
724
  catch (reconnectError) {
737
725
  // Tidak melempar error agar aplikasi tetap berjalan
@@ -739,7 +727,6 @@ const readMessage = (_a) => __awaiter(void 0, [_a], void 0, function* ({ session
739
727
  }
740
728
  }
741
729
  });
742
- exports.readMessage = readMessage;
743
730
  /**
744
731
  * Menghapus pesan yang telah dikirim
745
732
  *
@@ -748,14 +735,14 @@ exports.readMessage = readMessage;
748
735
  * @param sessionId - Session ID
749
736
  * @param key - Message key dari pesan yang akan dihapus
750
737
  */
751
- const deleteMessage = (_a) => __awaiter(void 0, [_a], void 0, function* ({ sessionId, key, }) {
738
+ export const deleteMessage = (_a) => __awaiter(void 0, [_a], void 0, function* ({ sessionId, key, }) {
752
739
  var _b;
753
- const session = (0, Socket_1.getSession)(sessionId);
740
+ const session = getSession(sessionId);
754
741
  if (!session)
755
- throw new Error_1.WhatsappError(Defaults_1.Messages.sessionNotFound(sessionId));
742
+ throw new WhatsappError(Messages.sessionNotFound(sessionId));
756
743
  try {
757
744
  // Hapus pesan dengan timeout untuk mencegah hanging
758
- yield (0, create_delay_1.withTimeout)(session.sendMessage(key.remoteJid, {
745
+ yield withTimeout(session.sendMessage(key.remoteJid, {
759
746
  delete: key
760
747
  }), 10000, "Timeout saat menghapus pesan");
761
748
  }
@@ -764,21 +751,20 @@ const deleteMessage = (_a) => __awaiter(void 0, [_a], void 0, function* ({ sessi
764
751
  // Jika koneksi tertutup, coba reconnect
765
752
  if ((_b = error === null || error === void 0 ? void 0 : error.message) === null || _b === void 0 ? void 0 : _b.includes('Connection Closed')) {
766
753
  try {
767
- yield (0, Socket_1.reconnect)(sessionId);
768
- yield (0, create_delay_1.createDelay)(2000); // Beri waktu untuk reconnect sepenuhnya
754
+ yield reconnect(sessionId);
755
+ yield createDelay(2000); // Beri waktu untuk reconnect sepenuhnya
769
756
  // Coba hapus lagi setelah reconnect
770
- yield (0, create_delay_1.withTimeout)(session.sendMessage(key.remoteJid, {
757
+ yield withTimeout(session.sendMessage(key.remoteJid, {
771
758
  delete: key
772
759
  }), 10000, "Timeout saat menghapus pesan setelah reconnect");
773
760
  }
774
761
  catch (reconnectError) {
775
762
  console.error(`Gagal reconnect atau menghapus pesan: ${(reconnectError === null || reconnectError === void 0 ? void 0 : reconnectError.message) || 'Unknown error'}`);
776
- throw new Error_1.WhatsappError(`Gagal menghapus pesan: ${(reconnectError === null || reconnectError === void 0 ? void 0 : reconnectError.message) || 'Unknown error'}`);
763
+ throw new WhatsappError(`Gagal menghapus pesan: ${(reconnectError === null || reconnectError === void 0 ? void 0 : reconnectError.message) || 'Unknown error'}`);
777
764
  }
778
765
  }
779
766
  else {
780
- throw new Error_1.WhatsappError(`Gagal menghapus pesan: ${(error === null || error === void 0 ? void 0 : error.message) || 'Unknown error'}`);
767
+ throw new WhatsappError(`Gagal menghapus pesan: ${(error === null || error === void 0 ? void 0 : error.message) || 'Unknown error'}`);
781
768
  }
782
769
  }
783
770
  });
784
- exports.deleteMessage = deleteMessage;