@aldy11/baileys 0.0.0-stage → 2.0.2

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 (100) hide show
  1. package/LICENSE +23 -0
  2. package/README.md +270 -2
  3. package/WAProto/index.d.ts +15933 -0
  4. package/WAProto/index.js +115857 -0
  5. package/index.d.ts +129 -0
  6. package/lib/Defaults/baileys-version.json +3 -0
  7. package/lib/Defaults/index.js +120 -0
  8. package/lib/Signal/Group/ciphertext-message.js +15 -0
  9. package/lib/Signal/Group/group-session-builder.js +64 -0
  10. package/lib/Signal/Group/group_cipher.js +96 -0
  11. package/lib/Signal/Group/index.js +57 -0
  12. package/lib/Signal/Group/keyhelper.js +55 -0
  13. package/lib/Signal/Group/queue-job.js +57 -0
  14. package/lib/Signal/Group/sender-chain-key.js +34 -0
  15. package/lib/Signal/Group/sender-key-distribution-message.js +66 -0
  16. package/lib/Signal/Group/sender-key-message.js +69 -0
  17. package/lib/Signal/Group/sender-key-name.js +51 -0
  18. package/lib/Signal/Group/sender-key-record.js +53 -0
  19. package/lib/Signal/Group/sender-key-state.js +99 -0
  20. package/lib/Signal/Group/sender-message-key.js +29 -0
  21. package/lib/Signal/libsignal.js +218 -0
  22. package/lib/Socket/Client/index.js +18 -0
  23. package/lib/Socket/Client/types.js +13 -0
  24. package/lib/Socket/Client/websocket.js +72 -0
  25. package/lib/Socket/business.js +260 -0
  26. package/lib/Socket/chats.js +996 -0
  27. package/lib/Socket/groups.js +332 -0
  28. package/lib/Socket/index.js +10 -0
  29. package/lib/Socket/messages-recv.js +1134 -0
  30. package/lib/Socket/messages-send.js +1087 -0
  31. package/lib/Socket/newsletter.js +251 -0
  32. package/lib/Socket/socket.js +716 -0
  33. package/lib/Socket/usync.js +70 -0
  34. package/lib/Store/index.js +8 -0
  35. package/lib/Store/make-in-memory-store.js +439 -0
  36. package/lib/Store/make-ordered-dictionary.js +81 -0
  37. package/lib/Store/object-repository.js +27 -0
  38. package/lib/Types/Auth.js +2 -0
  39. package/lib/Types/Call.js +2 -0
  40. package/lib/Types/Chat.js +4 -0
  41. package/lib/Types/Contact.js +2 -0
  42. package/lib/Types/Events.js +2 -0
  43. package/lib/Types/GroupMetadata.js +2 -0
  44. package/lib/Types/Label.js +27 -0
  45. package/lib/Types/LabelAssociation.js +9 -0
  46. package/lib/Types/Message.js +7 -0
  47. package/lib/Types/Newsletter.js +18 -0
  48. package/lib/Types/Product.js +2 -0
  49. package/lib/Types/Signal.js +2 -0
  50. package/lib/Types/Socket.js +2 -0
  51. package/lib/Types/State.js +2 -0
  52. package/lib/Types/USync.js +2 -0
  53. package/lib/Types/index.js +42 -0
  54. package/lib/Utils/auth-utils.js +199 -0
  55. package/lib/Utils/browser-utils.js +67 -0
  56. package/lib/Utils/business.js +234 -0
  57. package/lib/Utils/chat-utils.js +730 -0
  58. package/lib/Utils/crypto.js +193 -0
  59. package/lib/Utils/decode-wa-message.js +218 -0
  60. package/lib/Utils/event-buffer.js +518 -0
  61. package/lib/Utils/event-stream.js +63 -0
  62. package/lib/Utils/generics.js +438 -0
  63. package/lib/Utils/history.js +94 -0
  64. package/lib/Utils/index.js +36 -0
  65. package/lib/Utils/link-preview.js +126 -0
  66. package/lib/Utils/logger.js +7 -0
  67. package/lib/Utils/lt-hash.js +51 -0
  68. package/lib/Utils/make-mutex.js +43 -0
  69. package/lib/Utils/message-retry-manager.js +185 -0
  70. package/lib/Utils/messages-media.js +879 -0
  71. package/lib/Utils/messages.js +2212 -0
  72. package/lib/Utils/noise-handler.js +150 -0
  73. package/lib/Utils/power-features.js +416 -0
  74. package/lib/Utils/process-message.js +385 -0
  75. package/lib/Utils/signal.js +186 -0
  76. package/lib/Utils/use-multi-file-auth-state.js +124 -0
  77. package/lib/Utils/validate-connection.js +234 -0
  78. package/lib/WABinary/constants.js +1303 -0
  79. package/lib/WABinary/decode.js +265 -0
  80. package/lib/WABinary/encode.js +250 -0
  81. package/lib/WABinary/generic-utils.js +110 -0
  82. package/lib/WABinary/index.js +21 -0
  83. package/lib/WABinary/jid-utils.js +85 -0
  84. package/lib/WABinary/types.js +2 -0
  85. package/lib/WAM/BinaryInfo.js +13 -0
  86. package/lib/WAM/constants.js +15350 -0
  87. package/lib/WAM/encode.js +155 -0
  88. package/lib/WAM/index.js +19 -0
  89. package/lib/WAUSync/Protocols/USyncContactProtocol.js +32 -0
  90. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +57 -0
  91. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +30 -0
  92. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +42 -0
  93. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +53 -0
  94. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +24 -0
  95. package/lib/WAUSync/Protocols/index.js +20 -0
  96. package/lib/WAUSync/USyncQuery.js +89 -0
  97. package/lib/WAUSync/USyncUser.js +26 -0
  98. package/lib/WAUSync/index.js +19 -0
  99. package/lib/index.js +48 -0
  100. package/package.json +50 -4
@@ -0,0 +1,150 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.makeNoiseHandler = void 0;
4
+ const boom_1 = require("@hapi/boom");
5
+ const WAProto_1 = require("../../WAProto");
6
+ const Defaults_1 = require("../Defaults");
7
+ const WABinary_1 = require("../WABinary");
8
+ const crypto_1 = require("./crypto");
9
+ const generateIV = (counter) => {
10
+ const iv = new ArrayBuffer(12);
11
+ new DataView(iv).setUint32(8, counter);
12
+ return new Uint8Array(iv);
13
+ };
14
+ const makeNoiseHandler = ({ keyPair: { private: privateKey, public: publicKey }, NOISE_HEADER, logger, routingInfo }) => {
15
+ logger = logger.child({ class: 'ns' });
16
+ const authenticate = (data) => {
17
+ if (!isFinished) {
18
+ hash = (0, crypto_1.sha256)(Buffer.concat([hash, data]));
19
+ }
20
+ };
21
+ const encrypt = (plaintext) => {
22
+ const result = (0, crypto_1.aesEncryptGCM)(plaintext, encKey, generateIV(writeCounter), hash);
23
+ writeCounter += 1;
24
+ authenticate(result);
25
+ return result;
26
+ };
27
+ const decrypt = (ciphertext) => {
28
+ // before the handshake is finished, we use the same counter
29
+ // after handshake, the counters are different
30
+ const iv = generateIV(isFinished ? readCounter : writeCounter);
31
+ const result = (0, crypto_1.aesDecryptGCM)(ciphertext, decKey, iv, hash);
32
+ if (isFinished) {
33
+ readCounter += 1;
34
+ }
35
+ else {
36
+ writeCounter += 1;
37
+ }
38
+ authenticate(ciphertext);
39
+ return result;
40
+ };
41
+ const localHKDF = async (data) => {
42
+ const key = await (0, crypto_1.hkdf)(Buffer.from(data), 64, { salt, info: '' });
43
+ return [key.slice(0, 32), key.slice(32)];
44
+ };
45
+ const mixIntoKey = async (data) => {
46
+ const [write, read] = await localHKDF(data);
47
+ salt = write;
48
+ encKey = read;
49
+ decKey = read;
50
+ readCounter = 0;
51
+ writeCounter = 0;
52
+ };
53
+ const finishInit = async () => {
54
+ const [write, read] = await localHKDF(new Uint8Array(0));
55
+ encKey = write;
56
+ decKey = read;
57
+ hash = Buffer.from([]);
58
+ readCounter = 0;
59
+ writeCounter = 0;
60
+ isFinished = true;
61
+ };
62
+ const data = Buffer.from(Defaults_1.NOISE_MODE);
63
+ let hash = data.byteLength === 32 ? data : (0, crypto_1.sha256)(data);
64
+ let salt = hash;
65
+ let encKey = hash;
66
+ let decKey = hash;
67
+ let readCounter = 0;
68
+ let writeCounter = 0;
69
+ let isFinished = false;
70
+ let sentIntro = false;
71
+ let inBytes = Buffer.alloc(0);
72
+ authenticate(NOISE_HEADER);
73
+ authenticate(publicKey);
74
+ return {
75
+ encrypt,
76
+ decrypt,
77
+ authenticate,
78
+ mixIntoKey,
79
+ finishInit,
80
+ processHandshake: async ({ serverHello }, noiseKey) => {
81
+ authenticate(serverHello.ephemeral);
82
+ await mixIntoKey(crypto_1.Curve.sharedKey(privateKey, serverHello.ephemeral));
83
+ const decStaticContent = decrypt(serverHello.static);
84
+ await mixIntoKey(crypto_1.Curve.sharedKey(privateKey, decStaticContent));
85
+ const certDecoded = decrypt(serverHello.payload);
86
+ const { intermediate: certIntermediate } = WAProto_1.proto.CertChain.decode(certDecoded);
87
+ const { issuerSerial } = WAProto_1.proto.CertChain.NoiseCertificate.Details.decode(certIntermediate.details);
88
+ if (issuerSerial !== Defaults_1.WA_CERT_DETAILS.SERIAL) {
89
+ throw new boom_1.Boom('certification match failed', { statusCode: 400 });
90
+ }
91
+ const keyEnc = encrypt(noiseKey.public);
92
+ await mixIntoKey(crypto_1.Curve.sharedKey(noiseKey.private, serverHello.ephemeral));
93
+ return keyEnc;
94
+ },
95
+ encodeFrame: (data) => {
96
+ if (isFinished) {
97
+ data = encrypt(data);
98
+ }
99
+ let header;
100
+ if (routingInfo) {
101
+ header = Buffer.alloc(7);
102
+ header.write('ED', 0, 'utf8');
103
+ header.writeUint8(0, 2);
104
+ header.writeUint8(1, 3);
105
+ header.writeUint8(routingInfo.byteLength >> 16, 4);
106
+ header.writeUint16BE(routingInfo.byteLength & 65535, 5);
107
+ header = Buffer.concat([header, routingInfo, NOISE_HEADER]);
108
+ }
109
+ else {
110
+ header = Buffer.from(NOISE_HEADER);
111
+ }
112
+ const introSize = sentIntro ? 0 : header.length;
113
+ const frame = Buffer.alloc(introSize + 3 + data.byteLength);
114
+ if (!sentIntro) {
115
+ frame.set(header);
116
+ sentIntro = true;
117
+ }
118
+ frame.writeUInt8(data.byteLength >> 16, introSize);
119
+ frame.writeUInt16BE(65535 & data.byteLength, introSize + 1);
120
+ frame.set(data, introSize + 3);
121
+ return frame;
122
+ },
123
+ decodeFrame: async (newData, onFrame) => {
124
+ var _a;
125
+ // the binary protocol uses its own framing mechanism
126
+ // on top of the WS frames
127
+ // so we get this data and separate out the frames
128
+ const getBytesSize = () => {
129
+ if (inBytes.length >= 3) {
130
+ return (inBytes.readUInt8() << 16) | inBytes.readUInt16BE(1);
131
+ }
132
+ };
133
+ inBytes = Buffer.concat([inBytes, newData]);
134
+ logger.trace(`recv ${newData.length} bytes, total recv ${inBytes.length} bytes`);
135
+ let size = getBytesSize();
136
+ while (size && inBytes.length >= size + 3) {
137
+ let frame = inBytes.slice(3, size + 3);
138
+ inBytes = inBytes.slice(size + 3);
139
+ if (isFinished) {
140
+ const result = decrypt(frame);
141
+ frame = await (0, WABinary_1.decodeBinaryNode)(result);
142
+ }
143
+ logger.trace({ msg: (_a = frame === null || frame === void 0 ? void 0 : frame.attrs) === null || _a === void 0 ? void 0 : _a.id }, 'recv frame');
144
+ onFrame(frame);
145
+ size = getBytesSize();
146
+ }
147
+ }
148
+ };
149
+ };
150
+ exports.makeNoiseHandler = makeNoiseHandler;
@@ -0,0 +1,416 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.sendInteractiveMenu = exports.extractRevokeInfo = exports.isRevokeMessage = exports.isViewOnceMessage = exports.sendVoiceNote = exports.keepMessage = exports.deleteForEveryone = exports.unpinMessage = exports.pinMessage = exports.editMessage = exports.sendStatus = exports.cleanForward = exports.sendFakeQuote = exports.tagAll = exports.sendGhostMention = exports.downloadViewOnce = exports.extractViewOnce = void 0;
4
+
5
+ const messages_media_1 = require("./messages-media");
6
+ const messages_1 = require("./messages");
7
+
8
+ /**
9
+ * Mengekstrak media dari pesan Sekali Lihat (View Once),
10
+ * baik pesan langsung, dari contextInfo, maupun dari pesan quoted/reply.
11
+ * @param msg Objek pesan WAMessage atau protobuf Message
12
+ */
13
+ const extractViewOnce = (msg) => {
14
+ if (!msg) return null;
15
+ const inner = msg.message || msg;
16
+
17
+ const viewOnceMsg = (inner === null || inner === void 0 ? void 0 : inner.viewOnceMessage) ? inner.viewOnceMessage.message :
18
+ (inner === null || inner === void 0 ? void 0 : inner.viewOnceMessageV2) ? inner.viewOnceMessageV2.message :
19
+ (inner === null || inner === void 0 ? void 0 : inner.viewOnceMessageV2Extension) ? inner.viewOnceMessageV2Extension.message : null;
20
+
21
+ let target = viewOnceMsg || inner;
22
+ let isViewOnce = !!viewOnceMsg;
23
+ let mediaType = null;
24
+ let media = null;
25
+
26
+ if (target === null || target === void 0 ? void 0 : target.imageMessage) {
27
+ mediaType = 'image';
28
+ media = target.imageMessage;
29
+ if (target.imageMessage.viewOnce) isViewOnce = true;
30
+ } else if (target === null || target === void 0 ? void 0 : target.videoMessage) {
31
+ mediaType = 'video';
32
+ media = target.videoMessage;
33
+ if (target.videoMessage.viewOnce) isViewOnce = true;
34
+ } else if (target === null || target === void 0 ? void 0 : target.audioMessage) {
35
+ mediaType = 'audio';
36
+ media = target.audioMessage;
37
+ if (target.audioMessage.viewOnce) isViewOnce = true;
38
+ }
39
+
40
+ if (!media) {
41
+ // Periksa quotedMessage jika ada
42
+ const quoted = (inner === null || inner === void 0 ? void 0 : inner.extendedTextMessage) && inner.extendedTextMessage.contextInfo ?
43
+ inner.extendedTextMessage.contextInfo.quotedMessage : null;
44
+ if (quoted) {
45
+ return (0, exports.extractViewOnce)(quoted);
46
+ }
47
+ return null;
48
+ }
49
+
50
+ return {
51
+ mediaType,
52
+ mediaMessage: media,
53
+ caption: media.caption || '',
54
+ mimetype: media.mimetype,
55
+ isViewOnce
56
+ };
57
+ };
58
+ exports.extractViewOnce = extractViewOnce;
59
+
60
+ /**
61
+ * Mengunduh buffer file dari pesan Sekali Lihat (View Once) secara instan.
62
+ * @param msg Objek pesan WAMessage atau protobuf Message
63
+ * @param options Opsi axios atau media stream
64
+ * @returns Promise<Buffer> Buffer biner file media asli
65
+ */
66
+ const downloadViewOnce = async (msg, options = {}) => {
67
+ const extracted = (0, exports.extractViewOnce)(msg);
68
+ if (!extracted) {
69
+ throw new Error('Tidak ditemukan media sekali lihat (view-once) pada pesan ini.');
70
+ }
71
+ const { mediaMessage, mediaType } = extracted;
72
+ const stream = await (0, messages_media_1.downloadContentFromMessage)(mediaMessage, mediaType, options);
73
+ return await (0, messages_media_1.toBuffer)(stream);
74
+ };
75
+ exports.downloadViewOnce = downloadViewOnce;
76
+
77
+ /**
78
+ * Mengirim pesan dengan Mention Tersembunyi (Ghost Mention).
79
+ * Notifikasi mention berbunyi di target tanpa memunculkan tag @nomor di teks pesan.
80
+ */
81
+ const sendGhostMention = async (sock, jid, text, mentions = [], options = {}) => {
82
+ return await sock.sendMessage(jid, {
83
+ text,
84
+ mentions
85
+ }, options);
86
+ };
87
+ exports.sendGhostMention = sendGhostMention;
88
+
89
+ /**
90
+ * Men-tag seluruh anggota grup secara otomatis.
91
+ * @param sock Socket instance
92
+ * @param groupId JID grup
93
+ * @param text Teks pesan pengumuman
94
+ * @param options Opsi (ghost: true untuk invisible tag, ghost: false untuk visible tag)
95
+ */
96
+ const tagAll = async (sock, groupId, text = '', options = {}) => {
97
+ const meta = await sock.groupMetadata(groupId);
98
+ const participants = meta.participants.map(p => p.id);
99
+ const isGhost = options.ghost !== false;
100
+ let messageText = text;
101
+ if (!isGhost) {
102
+ const mentionText = participants.map(p => `@${p.split('@')[0]}`).join(' ');
103
+ messageText = `${text ? text + '\n\n' : ''}${mentionText}`;
104
+ }
105
+ return await sock.sendMessage(groupId, {
106
+ text: messageText,
107
+ mentions: participants
108
+ }, options);
109
+ };
110
+ exports.tagAll = tagAll;
111
+
112
+ /**
113
+ * Membuat dan mengirim balasan/quote palsu (Fake Quote) dari nomor, teks, dan nama mana pun.
114
+ */
115
+ const sendFakeQuote = async (sock, jid, text, fakeOpts = {}, options = {}) => {
116
+ const {
117
+ sender = '0@s.whatsapp.net',
118
+ text: quotedText = '',
119
+ pushName = 'WhatsApp',
120
+ isVerified = false,
121
+ keyId = 'FAKE_' + Date.now()
122
+ } = fakeOpts;
123
+
124
+ const fakeQuotedMessage = {
125
+ key: {
126
+ remoteJid: jid,
127
+ fromMe: false,
128
+ id: keyId,
129
+ participant: sender
130
+ },
131
+ message: {
132
+ conversation: quotedText
133
+ },
134
+ pushName
135
+ };
136
+
137
+ return await sock.sendMessage(jid, {
138
+ text,
139
+ contextInfo: {
140
+ mentionedJid: fakeOpts.mentions || [],
141
+ forwardingScore: isVerified ? 999 : 0,
142
+ isForwarded: isVerified,
143
+ ...(options.contextInfo || {})
144
+ }
145
+ }, {
146
+ quoted: fakeQuotedMessage,
147
+ ...options
148
+ });
149
+ };
150
+ exports.sendFakeQuote = sendFakeQuote;
151
+
152
+ /**
153
+ * Meneruskan (forward) pesan apa pun tanpa label "Diteruskan" (Clean Forward).
154
+ */
155
+ const cleanForward = async (sock, jid, message, options = {}) => {
156
+ const rawContent = message.message || message;
157
+ const normalized = (0, messages_1.normalizeMessageContent)(rawContent);
158
+ const cloned = JSON.parse(JSON.stringify(normalized));
159
+ const [msgType] = Object.keys(cloned);
160
+ if (cloned[msgType] && cloned[msgType].contextInfo) {
161
+ cloned[msgType].contextInfo.isForwarded = false;
162
+ cloned[msgType].contextInfo.forwardingScore = 0;
163
+ delete cloned[msgType].contextInfo.forwardedAiBotMessageInfo;
164
+ delete cloned[msgType].contextInfo.forwardOrigin;
165
+ }
166
+ return await sock.sendMessage(jid, {
167
+ forward: { key: message.key, message: cloned },
168
+ contextInfo: {
169
+ isForwarded: false,
170
+ forwardingScore: 0
171
+ }
172
+ }, options);
173
+ };
174
+ exports.cleanForward = cleanForward;
175
+
176
+ /**
177
+ * Mengunggah status / story WhatsApp HD dengan opsi warna background & font custom.
178
+ */
179
+ const sendStatus = async (sock, content, options = {}) => {
180
+ const statusJid = 'status@broadcast';
181
+ let msgContent = {};
182
+ if (typeof content === 'string') {
183
+ msgContent = {
184
+ text: content,
185
+ backgroundColor: options.backgroundArgb || 0xff1e1e2f,
186
+ font: options.font || 1
187
+ };
188
+ } else if (content.text) {
189
+ msgContent = {
190
+ text: content.text,
191
+ backgroundColor: content.backgroundArgb || options.backgroundArgb || 0xff1e1e2f,
192
+ font: content.font || options.font || 1
193
+ };
194
+ } else if (content.image) {
195
+ msgContent = {
196
+ image: content.image,
197
+ caption: content.caption || ''
198
+ };
199
+ } else if (content.video) {
200
+ msgContent = {
201
+ video: content.video,
202
+ caption: content.caption || ''
203
+ };
204
+ }
205
+ return await sock.sendMessage(statusJid, msgContent, {
206
+ statusJidList: options.statusJidList,
207
+ ...options
208
+ });
209
+ };
210
+ exports.sendStatus = sendStatus;
211
+
212
+ /**
213
+ * Mengedit pesan yang sudah terkirim sebelumnya.
214
+ */
215
+ const editMessage = async (sock, jid, key, newText, options = {}) => {
216
+ return await sock.sendMessage(jid, {
217
+ text: newText,
218
+ edit: key
219
+ }, options);
220
+ };
221
+ exports.editMessage = editMessage;
222
+
223
+ /**
224
+ * Menyematkan pesan (Pin) di obrolan dengan durasi kustom (dalam detik).
225
+ */
226
+ const pinMessage = async (sock, jid, key, durationInSeconds = 86400, options = {}) => {
227
+ return await sock.sendMessage(jid, {
228
+ pin: {
229
+ key,
230
+ type: 1, // 1 = PIN
231
+ time: durationInSeconds
232
+ }
233
+ }, options);
234
+ };
235
+ exports.pinMessage = pinMessage;
236
+
237
+ /**
238
+ * Melepas sematan pesan (Unpin) di obrolan.
239
+ */
240
+ const unpinMessage = async (sock, jid, key, options = {}) => {
241
+ return await sock.sendMessage(jid, {
242
+ pin: {
243
+ key,
244
+ type: 2 // 2 = UNPIN
245
+ }
246
+ }, options);
247
+ };
248
+ exports.unpinMessage = unpinMessage;
249
+
250
+ /**
251
+ * Menghapus pesan untuk semua orang (Delete for Everyone / Revoke).
252
+ */
253
+ const deleteForEveryone = async (sock, jid, key, options = {}) => {
254
+ return await sock.sendMessage(jid, {
255
+ delete: key
256
+ }, options);
257
+ };
258
+ exports.deleteForEveryone = deleteForEveryone;
259
+
260
+ /**
261
+ * Menahan pesan agar tidak hilang pada chat disappearing mode (Keep in Chat).
262
+ */
263
+ const keepMessage = async (sock, jid, key, keep = true, options = {}) => {
264
+ return await sock.sendMessage(jid, {
265
+ keep: key,
266
+ type: keep ? 1 : 2
267
+ }, options);
268
+ };
269
+ exports.keepMessage = keepMessage;
270
+
271
+ /**
272
+ * Mengirim file audio apapun (Buffer / URL / Stream) sebagai Voice Note WhatsApp (PTT / Voice Note dengan gelombang suara).
273
+ * Di WhatsApp biasa, file audio yang dikirim akan menjadi pemutar file MP3 biasa.
274
+ */
275
+ const sendVoiceNote = async (sock, jid, audio, options = {}) => {
276
+ return await sock.sendMessage(jid, {
277
+ audio,
278
+ mimetype: 'audio/mp4; codecs=opus',
279
+ ptt: true,
280
+ waveform: options.waveform || new Uint8Array([0, 99, 0, 99, 0, 99, 0, 99])
281
+ }, options);
282
+ };
283
+ exports.sendVoiceNote = sendVoiceNote;
284
+
285
+ /**
286
+ * Memeriksa apakah suatu pesan adalah pesan Sekali Lihat (View-Once).
287
+ */
288
+ const isViewOnceMessage = (msg) => {
289
+ const extracted = (0, exports.extractViewOnce)(msg);
290
+ return Boolean(extracted && extracted.isViewOnce);
291
+ };
292
+ exports.isViewOnceMessage = isViewOnceMessage;
293
+
294
+ /**
295
+ * Memeriksa apakah pesan masuk merupakan event penarikan / pembatalan pesan oleh pengirim (Anti-Delete Helper).
296
+ */
297
+ const isRevokeMessage = (msg) => {
298
+ var _a, _b, _c;
299
+ const protoMsg = ((_a = msg === null || msg === void 0 ? void 0 : msg.message) === null || _a === void 0 ? void 0 : _a.protocolMessage) ||
300
+ ((_c = (_b = msg === null || msg === void 0 ? void 0 : msg.message) === null || _b === void 0 ? void 0 : _b.ephemeralMessage) === null || _c === void 0 ? void 0 : _c.message.protocolMessage);
301
+ return (protoMsg === null || protoMsg === void 0 ? void 0 : protoMsg.type) === 0 || (protoMsg === null || protoMsg === void 0 ? void 0 : protoMsg.type) === 'REVOKE';
302
+ };
303
+ exports.isRevokeMessage = isRevokeMessage;
304
+
305
+ /**
306
+ * Mengekstrak kunci pesan yang ditarik dari pesan revoke (Anti-Delete Helper).
307
+ */
308
+ const extractRevokeInfo = (msg) => {
309
+ var _a, _b, _c;
310
+ if (!(0, exports.isRevokeMessage)(msg)) return null;
311
+ const protoMsg = ((_a = msg === null || msg === void 0 ? void 0 : msg.message) === null || _a === void 0 ? void 0 : _a.protocolMessage) ||
312
+ ((_c = (_b = msg === null || msg === void 0 ? void 0 : msg.message) === null || _b === void 0 ? void 0 : _b.ephemeralMessage) === null || _c === void 0 ? void 0 : _c.message.protocolMessage);
313
+ return {
314
+ targetKey: protoMsg.key,
315
+ revokedAt: msg.messageTimestamp
316
+ };
317
+ };
318
+ exports.extractRevokeInfo = extractRevokeInfo;
319
+
320
+ /**
321
+ * Mengirim pesan Menu / Card Interaktif dengan Gambar Header, Title, Subtitle, Body, Footer, dan Tombol Native Flow.
322
+ * Persis seperti tampilan menu WhatsApp modern (noxleyss style).
323
+ */
324
+ const sendInteractiveMenu = async (sock, jid, menuData = {}, options = {}) => {
325
+ var _a;
326
+ const {
327
+ image,
328
+ title = 'noxXza',
329
+ subtitle = 'Indonesia',
330
+ body = 'Teks menu',
331
+ footer = '© noxXza.exe',
332
+ buttons = [
333
+ {
334
+ name: 'quick_reply',
335
+ buttonParamsJson: JSON.stringify({ display_text: '☰ menu', id: '.menu' })
336
+ },
337
+ {
338
+ name: 'cta_url',
339
+ buttonParamsJson: JSON.stringify({ display_text: '⌕ script', url: 'https://github.com' })
340
+ }
341
+ ]
342
+ } = menuData;
343
+
344
+ let headerData = {
345
+ title,
346
+ subtitle,
347
+ hasMediaAttachment: false
348
+ };
349
+
350
+ if (image) {
351
+ try {
352
+ let imageInput = image;
353
+ if (typeof image === 'string' && !image.startsWith('http://') && !image.startsWith('https://')) {
354
+ const fs = require('fs');
355
+ if (fs.existsSync(image)) {
356
+ imageInput = fs.readFileSync(image);
357
+ }
358
+ }
359
+ if (typeof sock.waUploadToServer === 'function') {
360
+ const media = await (0, messages_1.prepareWAMessageMedia)(
361
+ { image: imageInput },
362
+ { upload: sock.waUploadToServer }
363
+ );
364
+ headerData = {
365
+ title,
366
+ subtitle,
367
+ hasMediaAttachment: true,
368
+ imageMessage: media.imageMessage
369
+ };
370
+ }
371
+ } catch (mediaErr) {
372
+ headerData = {
373
+ title,
374
+ subtitle,
375
+ hasMediaAttachment: false
376
+ };
377
+ }
378
+ }
379
+
380
+ const WAProto_1 = require("../../WAProto");
381
+ const interactiveMsg = {
382
+ viewOnceMessage: {
383
+ message: {
384
+ messageContextInfo: {
385
+ deviceListMetadata: {},
386
+ deviceListMetadataVersion: 2
387
+ },
388
+ interactiveMessage: WAProto_1.proto.Message.InteractiveMessage.create({
389
+ header: headerData,
390
+ body: {
391
+ text: body
392
+ },
393
+ footer: {
394
+ text: footer
395
+ },
396
+ nativeFlowMessage: {
397
+ buttons: buttons
398
+ }
399
+ })
400
+ }
401
+ }
402
+ };
403
+
404
+ const fullMsg = (0, messages_1.generateWAMessageFromContent)(jid, interactiveMsg, {
405
+ userJid: (_a = sock.user) === null || _a === void 0 ? void 0 : _a.id,
406
+ ...options
407
+ });
408
+
409
+ await sock.relayMessage(jid, fullMsg.message, {
410
+ messageId: fullMsg.key.id,
411
+ ...options
412
+ });
413
+
414
+ return fullMsg;
415
+ };
416
+ exports.sendInteractiveMenu = sendInteractiveMenu;