wa-multi-mongodb 3.9.4 → 3.9.5

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.
@@ -22,4 +22,13 @@ export declare const sendTyping: ({ sessionId, to, duration, isGroup, }: SendTyp
22
22
  * @param key - Message key to mark as read
23
23
  */
24
24
  export declare const readMessage: ({ sessionId, key, }: SendReadTypes) => Promise<void>;
25
+ /**
26
+ * Menghapus pesan yang telah dikirim
27
+ *
28
+ * Dapat digunakan untuk menghapus pesan bot sendiri atau menghapus pesan orang lain (jika bot adalah admin di grup)
29
+ *
30
+ * @param sessionId - Session ID
31
+ * @param key - Message key dari pesan yang akan dihapus
32
+ */
33
+ export declare const deleteMessage: ({ sessionId, key, }: SendReadTypes) => Promise<void>;
25
34
  //# sourceMappingURL=index.d.ts.map
@@ -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,EAChB,MAAM,UAAU,CAAC;AAOlB,eAAO,MAAM,eAAe,GAAU,4CAMnC,gBAAgB,KAAG,OAAO,CAAC,KAAK,CAAC,cAAc,GAAG,SAAS,CA2H7D,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"}
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,EAChB,MAAM,UAAU,CAAC;AAOlB,eAAO,MAAM,eAAe,GAAU,4CAMnC,gBAAgB,KAAG,OAAO,CAAC,KAAK,CAAC,cAAc,GAAG,SAAS,CA2H7D,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"}
@@ -23,7 +23,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
23
23
  return (mod && mod.__esModule) ? mod : { "default": mod };
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.readMessage = exports.sendTyping = exports.sendSticker = exports.sendVoiceNote = exports.sendMedia = exports.sendTextMessage = void 0;
26
+ exports.deleteMessage = exports.readMessage = exports.sendTyping = exports.sendSticker = exports.sendVoiceNote = exports.sendMedia = exports.sendTextMessage = void 0;
27
27
  const Defaults_1 = require("../Defaults");
28
28
  const Socket_1 = require("../Socket");
29
29
  const Utils_1 = require("../Utils");
@@ -554,3 +554,45 @@ const readMessage = (_a) => __awaiter(void 0, [_a], void 0, function* ({ session
554
554
  }
555
555
  });
556
556
  exports.readMessage = readMessage;
557
+ /**
558
+ * Menghapus pesan yang telah dikirim
559
+ *
560
+ * Dapat digunakan untuk menghapus pesan bot sendiri atau menghapus pesan orang lain (jika bot adalah admin di grup)
561
+ *
562
+ * @param sessionId - Session ID
563
+ * @param key - Message key dari pesan yang akan dihapus
564
+ */
565
+ const deleteMessage = (_a) => __awaiter(void 0, [_a], void 0, function* ({ sessionId, key, }) {
566
+ var _b;
567
+ const session = (0, Socket_1.getSession)(sessionId);
568
+ if (!session)
569
+ throw new Error_1.WhatsappError(Defaults_1.Messages.sessionNotFound(sessionId));
570
+ try {
571
+ // Hapus pesan dengan timeout untuk mencegah hanging
572
+ yield (0, create_delay_1.withTimeout)(session.sendMessage(key.remoteJid, {
573
+ delete: key
574
+ }), 10000, "Timeout saat menghapus pesan");
575
+ }
576
+ catch (error) {
577
+ console.error(`Error saat menghapus pesan: ${(error === null || error === void 0 ? void 0 : error.message) || 'Unknown error'}`);
578
+ // Jika koneksi tertutup, coba reconnect
579
+ if ((_b = error === null || error === void 0 ? void 0 : error.message) === null || _b === void 0 ? void 0 : _b.includes('Connection Closed')) {
580
+ try {
581
+ yield (0, Socket_1.reconnect)(sessionId);
582
+ yield (0, create_delay_1.createDelay)(2000); // Beri waktu untuk reconnect sepenuhnya
583
+ // Coba hapus lagi setelah reconnect
584
+ yield (0, create_delay_1.withTimeout)(session.sendMessage(key.remoteJid, {
585
+ delete: key
586
+ }), 10000, "Timeout saat menghapus pesan setelah reconnect");
587
+ }
588
+ catch (reconnectError) {
589
+ console.error(`Gagal reconnect atau menghapus pesan: ${(reconnectError === null || reconnectError === void 0 ? void 0 : reconnectError.message) || 'Unknown error'}`);
590
+ throw new Error_1.WhatsappError(`Gagal menghapus pesan: ${(reconnectError === null || reconnectError === void 0 ? void 0 : reconnectError.message) || 'Unknown error'}`);
591
+ }
592
+ }
593
+ else {
594
+ throw new Error_1.WhatsappError(`Gagal menghapus pesan: ${(error === null || error === void 0 ? void 0 : error.message) || 'Unknown error'}`);
595
+ }
596
+ }
597
+ });
598
+ exports.deleteMessage = deleteMessage;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wa-multi-mongodb",
3
- "version": "3.9.4",
3
+ "version": "3.9.5",
4
4
  "description": "Multi Session Whatsapp Library with MongoDB Integration",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/readme.md CHANGED
@@ -18,6 +18,7 @@ Built on [Baileys](https://github.com/WhiskeySockets/Baileys) Library.
18
18
  - Automatic retry for failed message deliveries
19
19
  - Automatic group chat detection (v3.9.0+)
20
20
  - Hybrid caching system for group metadata (v3.9.4+)
21
+ - Message deletion for self and others (v3.9.5+)
21
22
 
22
23
  ## Installation
23
24
 
@@ -178,6 +179,42 @@ await whatsapp.sendTyping({
178
179
  duration: 3000, // milliseconds
179
180
  // isGroup parameter is optional (v3.9.0+)
180
181
  });
182
+
183
+ // Delete message (v3.9.5+)
184
+ // Delete own message for everyone
185
+ await whatsapp.deleteMessage({
186
+ sessionId: "mysession",
187
+ key: messageObject.key, // message key from received or sent message
188
+ });
189
+
190
+ // Delete someone else's message (requires admin permissions in groups)
191
+ await whatsapp.deleteMessage({
192
+ sessionId: "mysession",
193
+ key: {
194
+ remoteJid: "120363152682073800@g.us", // group ID with @g.us
195
+ fromMe: false,
196
+ id: "MESSAGE_ID",
197
+ participant: "SENDER_JID" // required for group messages
198
+ }
199
+ });
200
+
201
+ // Auto-delete message after delay (helper function example)
202
+ function autoDeleteMessage(sessionId, message, delayMs = 3000) {
203
+ setTimeout(async () => {
204
+ try {
205
+ await whatsapp.deleteMessage({
206
+ sessionId: sessionId,
207
+ key: message.key
208
+ });
209
+ } catch (error) {
210
+ console.error("Error auto-deleting message:", error);
211
+ }
212
+ }, delayMs);
213
+ }
214
+
215
+ // Usage: Auto-delete a sent message after 5 seconds
216
+ const sentMsg = await whatsapp.sendTextMessage({/*...*/});
217
+ autoDeleteMessage("mysession", sentMsg, 5000);
181
218
  ```
182
219
 
183
220
  ### Event Listeners
@@ -492,7 +529,12 @@ startApp().catch(err => {
492
529
 
493
530
  ## Changelog
494
531
 
495
- ### v3.9.4 (current)
532
+ ### v3.9.5 (current)
533
+ - New `deleteMessage()` function for deleting messages
534
+ - Support for deleting both own messages and others' messages (requires admin permissions in groups)
535
+ - Auto-delete message utility function example
536
+
537
+ ### v3.9.4
496
538
  - Updated baileys dependency to v6.7.18
497
539
  - Added hybrid caching system for group metadata (NodeCache + MongoDB)
498
540
  - Improved group operations performance with automatic caching