@x4r1s3/baileys 0.0.0-stage → 1.0.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.
Files changed (185) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1245 -2
  3. package/SECURITY.md +47 -0
  4. package/WAProto/V +1 -0
  5. package/WAProto/WAProto.proto +8892 -0
  6. package/WAProto/index.d.ts +104128 -0
  7. package/WAProto/index.js +334920 -0
  8. package/assets/rolling-circle.svg +133 -0
  9. package/assets/x4r1s3-banner.svg +32 -0
  10. package/engine-requirements.js +27 -0
  11. package/lib/Builders/A2UI.js +245 -0
  12. package/lib/Builders/AIRich.js +179 -0
  13. package/lib/Builders/Button.js +108 -0
  14. package/lib/Builders/CFC.js +284 -0
  15. package/lib/Builders/Carousel.js +81 -0
  16. package/lib/Call/THIRD_PARTY_LICENSE.txt +21 -0
  17. package/lib/Call/astralena-v3.mjs +96 -0
  18. package/lib/Call/audio-feeder.mjs +201 -0
  19. package/lib/Call/audio-recorder.mjs +250 -0
  20. package/lib/Call/fetch-wasm-resources.mjs +104 -0
  21. package/lib/Call/index.mjs +707 -0
  22. package/lib/Call/relay-transport.mjs +563 -0
  23. package/lib/Call/signaling.mjs +660 -0
  24. package/lib/Call/types.mjs +17 -0
  25. package/lib/Call/video-feeder.mjs +94 -0
  26. package/lib/Call/voip-resources.mjs +259 -0
  27. package/lib/Call/wasm-engine.mjs +1372 -0
  28. package/lib/Call/worker-bootstrap.mjs +1042 -0
  29. package/lib/Defaults/ban-checker.js +56 -0
  30. package/lib/Defaults/index.js +170 -0
  31. package/lib/Signal/Group/ciphertext-message.js +23 -0
  32. package/lib/Signal/Group/group-session-builder.js +41 -0
  33. package/lib/Signal/Group/group_cipher.js +93 -0
  34. package/lib/Signal/Group/index.js +23 -0
  35. package/lib/Signal/Group/keyhelper.js +29 -0
  36. package/lib/Signal/Group/sender-chain-key.js +37 -0
  37. package/lib/Signal/Group/sender-key-distribution-message.js +74 -0
  38. package/lib/Signal/Group/sender-key-message.js +77 -0
  39. package/lib/Signal/Group/sender-key-name.js +59 -0
  40. package/lib/Signal/Group/sender-key-record.js +52 -0
  41. package/lib/Signal/Group/sender-key-state.js +95 -0
  42. package/lib/Signal/Group/sender-message-key.js +37 -0
  43. package/lib/Signal/libsignal.js +440 -0
  44. package/lib/Signal/lid-mapping.js +292 -0
  45. package/lib/Socket/Client/index.js +14 -0
  46. package/lib/Socket/Client/types.js +22 -0
  47. package/lib/Socket/Client/websocket.js +65 -0
  48. package/lib/Socket/aigroups.js +327 -0
  49. package/lib/Socket/ban-checker.js +165 -0
  50. package/lib/Socket/business.js +419 -0
  51. package/lib/Socket/chats.js +1921 -0
  52. package/lib/Socket/communities.js +443 -0
  53. package/lib/Socket/graphql.js +911 -0
  54. package/lib/Socket/groups.js +561 -0
  55. package/lib/Socket/index.js +49 -0
  56. package/lib/Socket/interactive-handler.js +612 -0
  57. package/lib/Socket/interop.js +575 -0
  58. package/lib/Socket/managed-account.js +220 -0
  59. package/lib/Socket/messages-recv.js +2193 -0
  60. package/lib/Socket/messages-send.js +4141 -0
  61. package/lib/Socket/mex.js +53 -0
  62. package/lib/Socket/newsletter.js +291 -0
  63. package/lib/Socket/privacy.js +458 -0
  64. package/lib/Socket/registration.js +440 -0
  65. package/lib/Socket/socket.js +1042 -0
  66. package/lib/Socket/status-actions.js +287 -0
  67. package/lib/Socket/username.js +241 -0
  68. package/lib/Store/index.js +16 -0
  69. package/lib/Store/make-cache-manager-store.js +101 -0
  70. package/lib/Store/make-in-memory-store.js +432 -0
  71. package/lib/Store/make-ordered-dictionary.js +90 -0
  72. package/lib/Store/object-repository.js +35 -0
  73. package/lib/Types/Auth.js +13 -0
  74. package/lib/Types/Bussines.js +13 -0
  75. package/lib/Types/Call.js +13 -0
  76. package/lib/Types/Chat.js +19 -0
  77. package/lib/Types/Contact.js +13 -0
  78. package/lib/Types/Events.js +13 -0
  79. package/lib/Types/GroupMetadata.js +13 -0
  80. package/lib/Types/Label.js +36 -0
  81. package/lib/Types/LabelAssociation.js +18 -0
  82. package/lib/Types/Message.js +30 -0
  83. package/lib/Types/Mex.js +53 -0
  84. package/lib/Types/Product.js +13 -0
  85. package/lib/Types/RichType.js +34 -0
  86. package/lib/Types/Signal.js +13 -0
  87. package/lib/Types/Socket.js +14 -0
  88. package/lib/Types/State.js +60 -0
  89. package/lib/Types/USync.js +13 -0
  90. package/lib/Types/index.js +37 -0
  91. package/lib/Utils/auth-utils.js +313 -0
  92. package/lib/Utils/ban-checker.js +48 -0
  93. package/lib/Utils/bot-capabilities.js +96 -0
  94. package/lib/Utils/bot-planning-replay.js +177 -0
  95. package/lib/Utils/browser-utils.js +40 -0
  96. package/lib/Utils/business.js +242 -0
  97. package/lib/Utils/c2582.js +147 -0
  98. package/lib/Utils/chat-utils.js +905 -0
  99. package/lib/Utils/companion-reg-client-utils.js +104 -0
  100. package/lib/Utils/consumer-application.js +114 -0
  101. package/lib/Utils/crypto.js +129 -0
  102. package/lib/Utils/decode-wa-message.js +496 -0
  103. package/lib/Utils/direct-chat-theme.js +164 -0
  104. package/lib/Utils/event-buffer.js +601 -0
  105. package/lib/Utils/experimental-proto.js +206 -0
  106. package/lib/Utils/games/miniapp.js +17 -0
  107. package/lib/Utils/games/slot-machine.js +270 -0
  108. package/lib/Utils/games/website-preview.js +306 -0
  109. package/lib/Utils/generics.js +402 -0
  110. package/lib/Utils/group-history.js +68 -0
  111. package/lib/Utils/group-wallpaper.js +168 -0
  112. package/lib/Utils/history.js +162 -0
  113. package/lib/Utils/identity-change-handler.js +60 -0
  114. package/lib/Utils/index.js +61 -0
  115. package/lib/Utils/jid-display-normalization.js +221 -0
  116. package/lib/Utils/link-preview.js +96 -0
  117. package/lib/Utils/logger.js +14 -0
  118. package/lib/Utils/lt-hash.js +19 -0
  119. package/lib/Utils/make-mutex.js +44 -0
  120. package/lib/Utils/message-composer.js +709 -0
  121. package/lib/Utils/message-inspect.js +79 -0
  122. package/lib/Utils/message-retry-manager.js +253 -0
  123. package/lib/Utils/message-security.js +167 -0
  124. package/lib/Utils/messages-media.js +1027 -0
  125. package/lib/Utils/messages.js +2467 -0
  126. package/lib/Utils/meta-ai-msmsg.js +215 -0
  127. package/lib/Utils/meta-compositing.js +239 -0
  128. package/lib/Utils/native-flow.js +158 -0
  129. package/lib/Utils/newsletter-live-update-utils.js +74 -0
  130. package/lib/Utils/newsletter-status-utils.js +152 -0
  131. package/lib/Utils/noise-handler.js +212 -0
  132. package/lib/Utils/offline-node-processor.js +51 -0
  133. package/lib/Utils/poll-manager.js +206 -0
  134. package/lib/Utils/portable-compat.js +12 -0
  135. package/lib/Utils/pre-key-manager.js +117 -0
  136. package/lib/Utils/process-message.js +610 -0
  137. package/lib/Utils/reporting-utils.js +269 -0
  138. package/lib/Utils/rich-message-utils.js +2841 -0
  139. package/lib/Utils/scheduled-message.js +107 -0
  140. package/lib/Utils/signal.js +212 -0
  141. package/lib/Utils/source-grep.js +57 -0
  142. package/lib/Utils/stanza-ack.js +49 -0
  143. package/lib/Utils/sticker-annotation.js +87 -0
  144. package/lib/Utils/sync-action-utils.js +59 -0
  145. package/lib/Utils/tc-token-utils.js +174 -0
  146. package/lib/Utils/use-multi-file-auth-state.js +132 -0
  147. package/lib/Utils/use-single-file-auth-state.js +108 -0
  148. package/lib/Utils/use-sqlite-auth-state.js +120 -0
  149. package/lib/Utils/validate-connection.js +221 -0
  150. package/lib/Utils/view-once-utils.js +218 -0
  151. package/lib/Utils/voip-rekey.js +32 -0
  152. package/lib/Utils/website-preview.js +27 -0
  153. package/lib/Utils/welcome-flow.js +228 -0
  154. package/lib/Utils/x4r1s3.js +144 -0
  155. package/lib/WABinary/constants.js +1475 -0
  156. package/lib/WABinary/decode.js +273 -0
  157. package/lib/WABinary/encode.js +231 -0
  158. package/lib/WABinary/generic-utils.js +242 -0
  159. package/lib/WABinary/index.js +17 -0
  160. package/lib/WABinary/jid-utils.js +107 -0
  161. package/lib/WABinary/types.js +13 -0
  162. package/lib/WAM/BinaryInfo.js +21 -0
  163. package/lib/WAM/constants.js +22864 -0
  164. package/lib/WAM/encode.js +161 -0
  165. package/lib/WAM/index.js +15 -0
  166. package/lib/WAUSync/Protocols/USyncBusinessProtocol.js +108 -0
  167. package/lib/WAUSync/Protocols/USyncContactProtocol.js +68 -0
  168. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +65 -0
  169. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +38 -0
  170. package/lib/WAUSync/Protocols/USyncFeatureProtocol.js +82 -0
  171. package/lib/WAUSync/Protocols/USyncPictureProtocol.js +40 -0
  172. package/lib/WAUSync/Protocols/USyncSidelistProtocol.js +37 -0
  173. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +49 -0
  174. package/lib/WAUSync/Protocols/USyncTextStatusProtocol.js +46 -0
  175. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +36 -0
  176. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +62 -0
  177. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +40 -0
  178. package/lib/WAUSync/Protocols/index.js +24 -0
  179. package/lib/WAUSync/USyncQuery.js +213 -0
  180. package/lib/WAUSync/USyncUser.js +66 -0
  181. package/lib/WAUSync/index.js +15 -0
  182. package/lib/antiban.cjs +4726 -0
  183. package/lib/index.d.ts +1895 -0
  184. package/lib/index.js +41 -0
  185. package/package.json +125 -4
@@ -0,0 +1,228 @@
1
+ /**
2
+ * @X4R1S3
3
+ *
4
+ * File: lib/Utils/welcome-flow.js
5
+ * About: Welcome flow module for the X4R1S3 WhatsApp protocol client.
6
+ * Important exports: createWelcomeFlow
7
+ * Directions: Import the listed exports and preserve protocol, validation, and compatibility invariants when modifying.
8
+ *
9
+ * Copyright and attribution notice.
10
+ * Do not copy, reproduce, redistribute, modify, or create derivative works
11
+ * from this source without explicit written permission.
12
+ */
13
+ /**
14
+ * Lia@Changes [WIP]
15
+ * Welcome Flow — Meta Business-style startup template.
16
+ *
17
+ * Fires automatically on first message from any new contact.
18
+ * Sends a fully configurable greeting with interactive FAQ buttons,
19
+ * exactly like Meta Business account welcome templates.
20
+ *
21
+ * Tracks seen JIDs in memory + optional persistent JSON file so the
22
+ * greeting fires ONCE per contact — never on repeat messages.
23
+ *
24
+ * Usage:
25
+ * const welcome = createWelcomeFlow(sock, config)
26
+ * welcome.listen() // start listening
27
+ * welcome.stop() // stop listening
28
+ * welcome.reset(jid) // force re-greet a contact
29
+ * welcome.resetAll() // clear all seen contacts
30
+ *
31
+ * If you use or copy this code, please credit @X4R1S3/bailey.
32
+ */
33
+
34
+ import { readFileSync, writeFileSync, existsSync } from 'fs';
35
+ import { isJidGroup, isJidNewsletter, isJidBroadcast, jidNormalizedUser } from '../WABinary/index.js';
36
+ import { delay } from './generics.js';
37
+
38
+ // ─── Defaults ────────────────────────────────────────────────────────────────
39
+
40
+ const DEFAULT_CONFIG = {
41
+ greeting: '👋 Welcome! How can I help you today?',
42
+ footer: 'Powered by @X4R1S3/bailey',
43
+ buttonText: '📋 Choose an option',
44
+ faqs: [
45
+ { id: 'faq_1', title: '📦 Track my order', description: 'Check order status' },
46
+ { id: 'faq_2', title: '💳 Billing & payments', description: 'Payment issues & invoices' },
47
+ { id: 'faq_3', title: '🛠️ Technical support', description: 'Get help with a problem' },
48
+ { id: 'faq_4', title: '📞 Talk to a human', description: 'Connect with support staff' },
49
+ ],
50
+ sectionTitle: 'How can we help?',
51
+ typingDelayMs: 1200, // simulate typing before greeting appears
52
+ persistPath: null, // set to a file path to persist seen JIDs across restarts
53
+ ignoreGroups: true, // don't fire in group chats
54
+ ignoreNewsletter: true, // don't fire for newsletter messages
55
+ ignoreBroadcast: true, // don't fire for broadcast messages
56
+ onGreet: null, // async (jid, message) => {} — called after greeting sent
57
+ onFaqReply: null, // async (jid, faqId, message) => {} — called when user picks a FAQ
58
+ };
59
+
60
+ // ─── Persistent seen-JID store ───────────────────────────────────────────────
61
+
62
+ const createSeenStore = (persistPath) => {
63
+ const seen = new Set();
64
+
65
+ // Load from file if path given and file exists
66
+ if (persistPath && existsSync(persistPath)) {
67
+ try {
68
+ const data = JSON.parse(readFileSync(persistPath, 'utf8'));
69
+ if (Array.isArray(data)) data.forEach(jid => seen.add(jid));
70
+ } catch (_) {}
71
+ }
72
+
73
+ const save = () => {
74
+ if (!persistPath) return;
75
+ try {
76
+ writeFileSync(persistPath, JSON.stringify([...seen]), 'utf8');
77
+ } catch (_) {}
78
+ };
79
+
80
+ return {
81
+ has: (jid) => seen.has(jid),
82
+ add: (jid) => { seen.add(jid); save(); },
83
+ delete: (jid) => { seen.delete(jid); save(); },
84
+ clear: () => { seen.clear(); save(); }
85
+ };
86
+ };
87
+
88
+ // ─── Build the welcome interactive list message ───────────────────────────────
89
+
90
+ const buildWelcomeMessage = (config, quotedMsg = null) => {
91
+ const { greeting, footer, buttonText, faqs, sectionTitle } = config;
92
+
93
+ const content = {
94
+ text: greeting,
95
+ footer,
96
+ buttonText,
97
+ sections: [
98
+ {
99
+ title: sectionTitle,
100
+ rows: faqs.map(faq => ({
101
+ title: faq.title,
102
+ description: faq.description || '',
103
+ rowId: faq.id
104
+ }))
105
+ }
106
+ ]
107
+ };
108
+
109
+ if (quotedMsg) {
110
+ content.quoted = quotedMsg;
111
+ }
112
+
113
+ return content;
114
+ };
115
+
116
+ // ─── Main factory ─────────────────────────────────────────────────────────────
117
+
118
+ /**
119
+ * createWelcomeFlow — attach a Meta Business-style welcome template to a socket.
120
+ *
121
+ * @param {object} sock - Baileys socket
122
+ * @param {object} config - Partial config — merges with DEFAULT_CONFIG
123
+ * @returns {{ listen, stop, reset, resetAll }}
124
+ */
125
+ export const createWelcomeFlow = (sock, config = {}) => {
126
+ const cfg = { ...DEFAULT_CONFIG, ...config };
127
+ const seen = createSeenStore(cfg.persistPath);
128
+
129
+ // ── FAQ reply handler — called when user selects a list option ────────────
130
+ const handleFaqReply = async (msg) => {
131
+ if (typeof cfg.onFaqReply !== 'function') return;
132
+ const reply = msg.message?.listResponseMessage;
133
+ if (!reply) return;
134
+ const faqId = reply.singleSelectReply?.selectedRowId;
135
+ const jid = jidNormalizedUser(msg.key.remoteJid);
136
+ if (faqId) {
137
+ await cfg.onFaqReply(jid, faqId, msg);
138
+ }
139
+ };
140
+
141
+ // ── First-message handler ─────────────────────────────────────────────────
142
+ const handleMessage = async ({ messages, type }) => {
143
+ if (type !== 'notify') return;
144
+
145
+ for (const msg of messages) {
146
+ try {
147
+ const jid = msg.key?.remoteJid;
148
+ if (!jid || msg.key?.fromMe) continue;
149
+
150
+ // Skip ignored JID types
151
+ if (cfg.ignoreGroups && isJidGroup(jid)) continue;
152
+ if (cfg.ignoreNewsletter && isJidNewsletter(jid)) continue;
153
+ if (cfg.ignoreBroadcast && isJidBroadcast(jid)) continue;
154
+
155
+ const normalizedJid = jidNormalizedUser(jid);
156
+
157
+ // Check if it's a FAQ reply first
158
+ if (msg.message?.listResponseMessage) {
159
+ await handleFaqReply(msg);
160
+ continue;
161
+ }
162
+
163
+ // Already greeted this contact — skip
164
+ if (seen.has(normalizedJid)) continue;
165
+
166
+ // Mark as seen immediately to prevent race conditions
167
+ seen.add(normalizedJid);
168
+
169
+ // Simulate typing before the greeting
170
+ if (cfg.typingDelayMs > 0) {
171
+ await sock.sendPresenceUpdate('composing', jid);
172
+ await delay(cfg.typingDelayMs);
173
+ await sock.sendPresenceUpdate('paused', jid);
174
+ }
175
+
176
+ // Send the configured welcome message.
177
+ await sock.sendMessage(jid, buildWelcomeMessage(cfg, msg));
178
+
179
+ // Fire onGreet callback if provided
180
+ if (typeof cfg.onGreet === 'function') {
181
+ await cfg.onGreet(normalizedJid, msg).catch(() => {});
182
+ }
183
+ } catch (_) {}
184
+ }
185
+ };
186
+
187
+ // ── Public API ────────────────────────────────────────────────────────────
188
+ return {
189
+ /**
190
+ * Start listening for new contacts.
191
+ */
192
+ listen() {
193
+ sock.ev.on('messages.upsert', handleMessage);
194
+ },
195
+
196
+ /**
197
+ * Stop listening.
198
+ */
199
+ stop() {
200
+ sock.ev.off('messages.upsert', handleMessage);
201
+ },
202
+
203
+ /**
204
+ * Force re-greet a specific contact next time they message.
205
+ * @param {string} jid
206
+ */
207
+ reset(jid) {
208
+ seen.delete(jidNormalizedUser(jid));
209
+ },
210
+
211
+ /**
212
+ * Clear all seen contacts — everyone gets re-greeted.
213
+ */
214
+ resetAll() {
215
+ seen.clear();
216
+ },
217
+
218
+ /**
219
+ * Check if a contact has already been greeted.
220
+ * @param {string} jid
221
+ * @returns {boolean}
222
+ */
223
+ hasGreeted(jid) {
224
+ return seen.has(jidNormalizedUser(jid));
225
+ }
226
+ };
227
+ };
228
+
@@ -0,0 +1,144 @@
1
+ import { proto } from '../../WAProto/index.js';
2
+ import { jidDecode } from '../WABinary/jid-utils.js';
3
+
4
+ const supportedDestinationServers = new Set([
5
+ 'c.us',
6
+ 's.whatsapp.net',
7
+ 'lid',
8
+ 'hosted',
9
+ 'hosted.lid',
10
+ 'g.us'
11
+ ]);
12
+
13
+ const getTargetId = target => {
14
+ const targetId = typeof target === 'string'
15
+ ? target
16
+ : (target?.id || target?.stanzaId);
17
+
18
+ if (targetId === undefined || targetId === null || targetId === '') {
19
+ throw new Error('Missing message id to vanish');
20
+ }
21
+ if (typeof targetId !== 'string' || targetId.length > 256 || targetId.trim() !== targetId || /[\s\u0000-\u001f\u007f]/u.test(targetId)) {
22
+ throw new Error('Invalid target message id');
23
+ }
24
+ return targetId;
25
+ };
26
+
27
+ const isValidDestinationJid = jid => {
28
+ if (typeof jid !== 'string' || jid.length > 256 || jid.trim() !== jid || /[\s\u0000-\u001f\u007f]/u.test(jid)) {
29
+ return false;
30
+ }
31
+
32
+ const decoded = jidDecode(jid);
33
+ return Boolean(
34
+ decoded?.user &&
35
+ /^[A-Za-z0-9][A-Za-z0-9._:-]*$/u.test(jid.slice(0, jid.indexOf('@'))) &&
36
+ supportedDestinationServers.has(decoded.server)
37
+ );
38
+ };
39
+
40
+ const isMessageId = value => typeof value === 'string' && value.length > 0 && value.length <= 256 && value.trim() === value && !/[\s\u0000-\u001f\u007f]/u.test(value);
41
+
42
+ const groupStatusMessage = () => ({
43
+ groupStatusMessageV2: {
44
+ message: {
45
+ extendedTextMessage: {
46
+ text: '',
47
+ contextInfo: {
48
+ isGroupStatus: true
49
+ }
50
+ }
51
+ }
52
+ }
53
+ });
54
+
55
+ /**
56
+ * Relay the experimental X4R1S3 protocol sequence for a target message.
57
+ * The connection's network methods are called directly, making the helper
58
+ * straightforward to exercise with mocks and safe to use with a socket.
59
+ */
60
+ export const X4R1S3 = async (conn, jid, target) => {
61
+ if (!isValidDestinationJid(jid)) {
62
+ throw new Error('Invalid destination JID for X4R1S3');
63
+ }
64
+ const targetId = getTargetId(target);
65
+ if (!conn || typeof conn.relayMessage !== 'function' || typeof conn.sendMessage !== 'function') {
66
+ throw new TypeError('X4R1S3 requires a connection with relayMessage and sendMessage methods');
67
+ }
68
+
69
+ const temporaryIds = [];
70
+ let relayError;
71
+ let relaysSucceeded = false;
72
+
73
+ try {
74
+ const tempId = await conn.relayMessage(jid, groupStatusMessage(), {});
75
+ if (!isMessageId(tempId)) {
76
+ throw new Error('X4R1S3 first relay did not return a valid temporary message id');
77
+ }
78
+ temporaryIds.push(tempId);
79
+
80
+ const tempId2 = await conn.relayMessage(jid, {
81
+ protocolMessage: {
82
+ key: {
83
+ jid,
84
+ fromMe: true,
85
+ id: tempId
86
+ },
87
+ type: proto.Message.ProtocolMessage.Type.MESSAGE_EDIT,
88
+ editedMessage: groupStatusMessage()
89
+ }
90
+ }, {
91
+ messageId: targetId
92
+ });
93
+ if (!isMessageId(tempId2)) {
94
+ throw new Error('X4R1S3 second relay did not return a valid temporary message id');
95
+ }
96
+ temporaryIds.push(tempId2);
97
+ relaysSucceeded = true;
98
+ }
99
+ catch (error) {
100
+ relayError = error;
101
+ }
102
+
103
+ if (relaysSucceeded) {
104
+ await new Promise(resolve => setTimeout(resolve, 100));
105
+ }
106
+
107
+ const cleanupResults = await Promise.allSettled(temporaryIds.map(id => Promise.resolve().then(() => conn.sendMessage(jid, {
108
+ delete: {
109
+ remoteJid: jid,
110
+ id,
111
+ fromMe: true
112
+ }
113
+ }))));
114
+ const cleanupErrors = cleanupResults
115
+ .filter(result => result.status === 'rejected')
116
+ .map(result => result.reason);
117
+
118
+ if (relayError) {
119
+ if (cleanupErrors.length > 0) {
120
+ throw new AggregateError(
121
+ [relayError, ...cleanupErrors],
122
+ 'X4R1S3 relay failed and temporary-message cleanup also failed',
123
+ { cause: relayError }
124
+ );
125
+ }
126
+ throw relayError;
127
+ }
128
+ if (cleanupErrors.length > 0) {
129
+ throw new AggregateError(
130
+ cleanupErrors,
131
+ 'X4R1S3 protocol relays succeeded but temporary-message cleanup failed'
132
+ );
133
+ }
134
+
135
+ return {
136
+ key: {
137
+ remoteJid: jid,
138
+ id: targetId
139
+ },
140
+ status: 'vanished'
141
+ };
142
+ };
143
+
144
+ export default X4R1S3;