@zelynskybail/baileys 0.0.0-stage → 2.6.28
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.
- package/BUILD_STATUS.md +21 -0
- package/CHANGELOG.md +17 -0
- package/LICENSE +21 -0
- package/NOTICE.md +9 -0
- package/README.md +165 -2
- package/THANKS.md +7 -0
- package/THIRD_PARTY_NOTICES.md +8 -0
- package/WAProto/GenerateStatics.sh +3 -0
- package/WAProto/WAProto.proto +6035 -0
- package/WAProto/fix-imports.js +81 -0
- package/WAProto/index.d.ts +2 -0
- package/WAProto/index.js +132326 -0
- package/lib/Builders/advanced.d.ts +14 -0
- package/lib/Builders/advanced.js +142 -0
- package/lib/Builders/group-status.d.ts +9 -0
- package/lib/Builders/group-status.js +19 -0
- package/lib/Builders/index.d.ts +62 -0
- package/lib/Builders/index.js +242 -0
- package/lib/Defaults/index.d.ts +74 -0
- package/lib/Defaults/index.js +136 -0
- package/lib/Modded/MessageBuilder.js +3222 -0
- package/lib/Modded/message_builder.d.ts +43 -0
- package/lib/Modded/message_builder.js +2 -0
- package/lib/Signal/Group/ciphertext-message.d.ts +10 -0
- package/lib/Signal/Group/ciphertext-message.js +11 -0
- package/lib/Signal/Group/group-session-builder.d.ts +15 -0
- package/lib/Signal/Group/group-session-builder.js +29 -0
- package/lib/Signal/Group/group_cipher.d.ts +17 -0
- package/lib/Signal/Group/group_cipher.js +81 -0
- package/lib/Signal/Group/index.d.ts +12 -0
- package/lib/Signal/Group/index.js +11 -0
- package/lib/Signal/Group/keyhelper.d.ts +11 -0
- package/lib/Signal/Group/keyhelper.js +17 -0
- package/lib/Signal/Group/sender-chain-key.d.ts +14 -0
- package/lib/Signal/Group/sender-chain-key.js +25 -0
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +17 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +62 -0
- package/lib/Signal/Group/sender-key-message.d.ts +19 -0
- package/lib/Signal/Group/sender-key-message.js +65 -0
- package/lib/Signal/Group/sender-key-name.d.ts +18 -0
- package/lib/Signal/Group/sender-key-name.js +47 -0
- package/lib/Signal/Group/sender-key-record.d.ts +31 -0
- package/lib/Signal/Group/sender-key-record.js +40 -0
- package/lib/Signal/Group/sender-key-state.d.ts +39 -0
- package/lib/Signal/Group/sender-key-state.js +83 -0
- package/lib/Signal/Group/sender-message-key.d.ts +12 -0
- package/lib/Signal/Group/sender-message-key.js +25 -0
- package/lib/Signal/libsignal.d.ts +5 -0
- package/lib/Signal/libsignal.js +402 -0
- package/lib/Signal/lid-mapping.d.ts +19 -0
- package/lib/Signal/lid-mapping.js +270 -0
- package/lib/Socket/Client/index.d.ts +3 -0
- package/lib/Socket/Client/index.js +2 -0
- package/lib/Socket/Client/types.d.ts +16 -0
- package/lib/Socket/Client/types.js +10 -0
- package/lib/Socket/Client/websocket.d.ts +13 -0
- package/lib/Socket/Client/websocket.js +53 -0
- package/lib/Socket/business.d.ts +536 -0
- package/lib/Socket/business.js +421 -0
- package/lib/Socket/chats.d.ts +111 -0
- package/lib/Socket/chats.js +990 -0
- package/lib/Socket/communities.d.ts +645 -0
- package/lib/Socket/communities.js +430 -0
- package/lib/Socket/dugong.d.ts +130 -0
- package/lib/Socket/dugong.js +767 -0
- package/lib/Socket/groups.d.ts +150 -0
- package/lib/Socket/groups.js +326 -0
- package/lib/Socket/index.d.ts +657 -0
- package/lib/Socket/index.js +26 -0
- package/lib/Socket/messages-recv.d.ts +238 -0
- package/lib/Socket/messages-recv.js +1307 -0
- package/lib/Socket/messages-send.d.ts +579 -0
- package/lib/Socket/messages-send.js +1594 -0
- package/lib/Socket/mex.d.ts +3 -0
- package/lib/Socket/mex.js +47 -0
- package/lib/Socket/newsletter.d.ts +177 -0
- package/lib/Socket/newsletter.js +314 -0
- package/lib/Socket/socket.d.ts +55 -0
- package/lib/Socket/socket.js +935 -0
- package/lib/Types/Auth.d.ts +116 -0
- package/lib/Types/Auth.js +1 -0
- package/lib/Types/Bussines.d.ts +37 -0
- package/lib/Types/Bussines.js +1 -0
- package/lib/Types/Call.d.ts +15 -0
- package/lib/Types/Call.js +1 -0
- package/lib/Types/Chat.d.ts +123 -0
- package/lib/Types/Chat.js +7 -0
- package/lib/Types/Contact.d.ts +24 -0
- package/lib/Types/Contact.js +1 -0
- package/lib/Types/Events.d.ts +237 -0
- package/lib/Types/Events.js +1 -0
- package/lib/Types/GroupMetadata.d.ts +68 -0
- package/lib/Types/GroupMetadata.js +1 -0
- package/lib/Types/Label.d.ts +47 -0
- package/lib/Types/Label.js +24 -0
- package/lib/Types/LabelAssociation.d.ts +30 -0
- package/lib/Types/LabelAssociation.js +6 -0
- package/lib/Types/Message.d.ts +422 -0
- package/lib/Types/Message.js +10 -0
- package/lib/Types/Newsletter.d.ts +135 -0
- package/lib/Types/Newsletter.js +30 -0
- package/lib/Types/Product.d.ts +79 -0
- package/lib/Types/Product.js +1 -0
- package/lib/Types/Signal.d.ts +76 -0
- package/lib/Types/Signal.js +1 -0
- package/lib/Types/Socket.d.ts +154 -0
- package/lib/Types/Socket.js +2 -0
- package/lib/Types/State.d.ts +39 -0
- package/lib/Types/State.js +12 -0
- package/lib/Types/USync.d.ts +26 -0
- package/lib/Types/USync.js +1 -0
- package/lib/Types/index.d.ts +66 -0
- package/lib/Types/index.js +32 -0
- package/lib/Utils/auth-utils.d.ts +19 -0
- package/lib/Utils/auth-utils.js +289 -0
- package/lib/Utils/browser-utils.d.ts +4 -0
- package/lib/Utils/browser-utils.js +27 -0
- package/lib/Utils/business.d.ts +23 -0
- package/lib/Utils/business.js +230 -0
- package/lib/Utils/chat-utils.d.ts +70 -0
- package/lib/Utils/chat-utils.js +811 -0
- package/lib/Utils/crypto.d.ts +37 -0
- package/lib/Utils/crypto.js +117 -0
- package/lib/Utils/decode-wa-message.d.ts +48 -0
- package/lib/Utils/decode-wa-message.js +282 -0
- package/lib/Utils/event-buffer.d.ts +34 -0
- package/lib/Utils/event-buffer.js +573 -0
- package/lib/Utils/generics.d.ts +91 -0
- package/lib/Utils/generics.js +383 -0
- package/lib/Utils/history.d.ts +22 -0
- package/lib/Utils/history.js +130 -0
- package/lib/Utils/identity-change-handler.d.ts +37 -0
- package/lib/Utils/identity-change-handler.js +48 -0
- package/lib/Utils/index.d.ts +24 -0
- package/lib/Utils/index.js +24 -0
- package/lib/Utils/link-preview.d.ts +21 -0
- package/lib/Utils/link-preview.js +84 -0
- package/lib/Utils/logger.d.ts +13 -0
- package/lib/Utils/logger.js +2 -0
- package/lib/Utils/lt-hash.d.ts +8 -0
- package/lib/Utils/lt-hash.js +7 -0
- package/lib/Utils/make-mutex.d.ts +9 -0
- package/lib/Utils/make-mutex.js +32 -0
- package/lib/Utils/message-retry-manager.d.ts +110 -0
- package/lib/Utils/message-retry-manager.js +224 -0
- package/lib/Utils/message-tools.d.ts +31 -0
- package/lib/Utils/message-tools.js +182 -0
- package/lib/Utils/messages-media.d.ts +130 -0
- package/lib/Utils/messages-media.js +781 -0
- package/lib/Utils/messages.d.ts +91 -0
- package/lib/Utils/messages.js +1239 -0
- package/lib/Utils/noise-handler.d.ts +20 -0
- package/lib/Utils/noise-handler.js +200 -0
- package/lib/Utils/offline-node-processor.d.ts +17 -0
- package/lib/Utils/offline-node-processor.js +68 -0
- package/lib/Utils/performance.d.ts +3 -0
- package/lib/Utils/performance.js +35 -0
- package/lib/Utils/pre-key-manager.d.ts +28 -0
- package/lib/Utils/pre-key-manager.js +105 -0
- package/lib/Utils/process-message.d.ts +60 -0
- package/lib/Utils/process-message.js +527 -0
- package/lib/Utils/reporting-utils.d.ts +11 -0
- package/lib/Utils/reporting-utils.js +257 -0
- package/lib/Utils/rich-messages.d.ts +277 -0
- package/lib/Utils/rich-messages.js +1143 -0
- package/lib/Utils/signal.d.ts +34 -0
- package/lib/Utils/signal.js +158 -0
- package/lib/Utils/stanza-ack.d.ts +11 -0
- package/lib/Utils/stanza-ack.js +37 -0
- package/lib/Utils/sticker-pack.d.ts +10 -0
- package/lib/Utils/sticker-pack.js +111 -0
- package/lib/Utils/sync-action-utils.d.ts +19 -0
- package/lib/Utils/sync-action-utils.js +47 -0
- package/lib/Utils/tc-token-utils.d.ts +12 -0
- package/lib/Utils/tc-token-utils.js +17 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts +13 -0
- package/lib/Utils/use-multi-file-auth-state.js +120 -0
- package/lib/Utils/validate-connection.d.ts +11 -0
- package/lib/Utils/validate-connection.js +199 -0
- package/lib/VoIP/index.d.ts +18 -0
- package/lib/VoIP/index.js +81 -0
- package/lib/WABinary/constants.d.ts +28 -0
- package/lib/WABinary/constants.js +1300 -0
- package/lib/WABinary/decode.d.ts +7 -0
- package/lib/WABinary/decode.js +261 -0
- package/lib/WABinary/encode.d.ts +3 -0
- package/lib/WABinary/encode.js +219 -0
- package/lib/WABinary/generic-utils.d.ts +17 -0
- package/lib/WABinary/generic-utils.js +190 -0
- package/lib/WABinary/index.d.ts +6 -0
- package/lib/WABinary/index.js +5 -0
- package/lib/WABinary/jid-utils.d.ts +48 -0
- package/lib/WABinary/jid-utils.js +95 -0
- package/lib/WABinary/types.d.ts +19 -0
- package/lib/WABinary/types.js +1 -0
- package/lib/WAM/BinaryInfo.d.ts +9 -0
- package/lib/WAM/BinaryInfo.js +9 -0
- package/lib/WAM/constants.d.ts +40 -0
- package/lib/WAM/constants.js +22852 -0
- package/lib/WAM/encode.d.ts +3 -0
- package/lib/WAM/encode.js +149 -0
- package/lib/WAM/index.d.ts +4 -0
- package/lib/WAM/index.js +3 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +10 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +28 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +23 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +53 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +13 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +26 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +13 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +37 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +26 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +50 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +10 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +28 -0
- package/lib/WAUSync/Protocols/index.d.ts +5 -0
- package/lib/WAUSync/Protocols/index.js +4 -0
- package/lib/WAUSync/USyncQuery.d.ts +29 -0
- package/lib/WAUSync/USyncQuery.js +93 -0
- package/lib/WAUSync/USyncUser.d.ts +13 -0
- package/lib/WAUSync/USyncUser.js +22 -0
- package/lib/WAUSync/index.d.ts +4 -0
- package/lib/WAUSync/index.js +3 -0
- package/lib/index.d.ts +14 -0
- package/lib/index.js +14 -0
- package/package.json +128 -4
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { mkdir, readFile, rename, writeFile } from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { randomUUID } from 'node:crypto';
|
|
4
|
+
|
|
5
|
+
const getText = (message) => {
|
|
6
|
+
if (!message || typeof message !== 'object') return '';
|
|
7
|
+
const seen = new Set();
|
|
8
|
+
const visit = (value) => {
|
|
9
|
+
if (!value || typeof value !== 'object' || seen.has(value)) return '';
|
|
10
|
+
seen.add(value);
|
|
11
|
+
if (typeof value.conversation === 'string') return value.conversation;
|
|
12
|
+
for (const key of ['text', 'caption', 'contentText', 'selectedDisplayText']) {
|
|
13
|
+
if (typeof value[key] === 'string') return value[key];
|
|
14
|
+
}
|
|
15
|
+
for (const [key, child] of Object.entries(value)) {
|
|
16
|
+
if (key === 'contextInfo' || key === 'messageContextInfo') continue;
|
|
17
|
+
if (child && typeof child === 'object') {
|
|
18
|
+
const result = visit(child);
|
|
19
|
+
if (result) return result;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return '';
|
|
23
|
+
};
|
|
24
|
+
return visit(message);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const makeKey = (key) => `${key?.remoteJid ?? ''}|${key?.id ?? ''}`;
|
|
28
|
+
|
|
29
|
+
/** In-memory message index with bounded storage and query helpers. */
|
|
30
|
+
export class MessageSearch {
|
|
31
|
+
constructor({ maxEntries = 10000 } = {}) {
|
|
32
|
+
if (!Number.isInteger(maxEntries) || maxEntries < 1) throw new RangeError('maxEntries must be a positive integer.');
|
|
33
|
+
this.maxEntries = maxEntries;
|
|
34
|
+
this.messages = new Map();
|
|
35
|
+
this.bindings = [];
|
|
36
|
+
}
|
|
37
|
+
index(message) {
|
|
38
|
+
if (!message?.key?.id || !message?.key?.remoteJid) return false;
|
|
39
|
+
const key = makeKey(message.key);
|
|
40
|
+
this.messages.delete(key);
|
|
41
|
+
this.messages.set(key, {
|
|
42
|
+
key: structuredClone(message.key),
|
|
43
|
+
message,
|
|
44
|
+
text: getText(message.message).toLocaleLowerCase(),
|
|
45
|
+
timestamp: Number(message.messageTimestamp ?? Date.now() / 1000),
|
|
46
|
+
});
|
|
47
|
+
while (this.messages.size > this.maxEntries) this.messages.delete(this.messages.keys().next().value);
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
bind(sock) {
|
|
51
|
+
if (!sock?.ev?.on) throw new TypeError('A Baileys socket event emitter is required.');
|
|
52
|
+
const upsert = ({ messages = [] } = {}) => { for (const message of messages) this.index(message); };
|
|
53
|
+
const update = (updates = []) => {
|
|
54
|
+
for (const item of updates) {
|
|
55
|
+
const key = makeKey(item.key);
|
|
56
|
+
const old = this.messages.get(key);
|
|
57
|
+
if (old && item.update?.message) this.index({ ...old.message, message: item.update.message });
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
const remove = ({ keys = [] } = {}) => { for (const key of keys) this.remove(key); };
|
|
61
|
+
sock.ev.on('messages.upsert', upsert);
|
|
62
|
+
sock.ev.on('messages.update', update);
|
|
63
|
+
sock.ev.on('messages.delete', remove);
|
|
64
|
+
this.bindings.push(() => {
|
|
65
|
+
sock.ev.off?.('messages.upsert', upsert);
|
|
66
|
+
sock.ev.off?.('messages.update', update);
|
|
67
|
+
sock.ev.off?.('messages.delete', remove);
|
|
68
|
+
});
|
|
69
|
+
return this;
|
|
70
|
+
}
|
|
71
|
+
get(key) { return this.messages.get(makeKey(key))?.message; }
|
|
72
|
+
remove(key) { return this.messages.delete(makeKey(key)); }
|
|
73
|
+
search(query, { jid, fromMe, limit = 50, caseSensitive = false } = {}) {
|
|
74
|
+
const needle = String(query ?? '').trim();
|
|
75
|
+
if (!needle) return [];
|
|
76
|
+
if (!Number.isInteger(limit) || limit < 1) throw new RangeError('limit must be a positive integer.');
|
|
77
|
+
const q = caseSensitive ? needle : needle.toLocaleLowerCase();
|
|
78
|
+
const results = [];
|
|
79
|
+
for (const entry of [...this.messages.values()].reverse()) {
|
|
80
|
+
if (jid && entry.key.remoteJid !== jid) continue;
|
|
81
|
+
if (fromMe !== undefined && Boolean(entry.key.fromMe) !== Boolean(fromMe)) continue;
|
|
82
|
+
const content = caseSensitive ? getText(entry.message.message) : entry.text;
|
|
83
|
+
if (content.includes(q)) results.push(entry.message);
|
|
84
|
+
if (results.length >= limit) break;
|
|
85
|
+
}
|
|
86
|
+
return results;
|
|
87
|
+
}
|
|
88
|
+
clear() { this.messages.clear(); }
|
|
89
|
+
stop() { for (const unbind of this.bindings.splice(0)) unbind(); return this; }
|
|
90
|
+
get size() { return this.messages.size; }
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** Observe revoke/delete events and retrieve cached message content for an app callback. */
|
|
94
|
+
export class AntiDeleteManager {
|
|
95
|
+
constructor({ sock, messageSearch, getMessage, onDelete, onError = (error) => console.error('[ZelynskyBail:AntiDelete]', error) } = {}) {
|
|
96
|
+
if (!sock?.ev?.on) throw new TypeError('A Baileys socket is required.');
|
|
97
|
+
this.sock = sock;
|
|
98
|
+
this.messageSearch = messageSearch;
|
|
99
|
+
this.getMessage = getMessage;
|
|
100
|
+
this.onDelete = onDelete;
|
|
101
|
+
this.onError = onError;
|
|
102
|
+
this.started = false;
|
|
103
|
+
this.listener = ({ keys = [] } = {}) => {
|
|
104
|
+
void this.#handle(keys).catch((error) => {
|
|
105
|
+
try { this.onError?.(error); } catch {}
|
|
106
|
+
});
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
start() {
|
|
110
|
+
if (!this.started) {
|
|
111
|
+
this.sock.ev.on('messages.delete', this.listener);
|
|
112
|
+
this.started = true;
|
|
113
|
+
}
|
|
114
|
+
return this;
|
|
115
|
+
}
|
|
116
|
+
async #handle(keys) {
|
|
117
|
+
for (const key of keys) {
|
|
118
|
+
let message;
|
|
119
|
+
try {
|
|
120
|
+
message = this.messageSearch?.get(key) ?? await this.getMessage?.(key.remoteJid, key.id);
|
|
121
|
+
} catch (error) {
|
|
122
|
+
try { await this.onDelete?.({ key, message: undefined, error }); }
|
|
123
|
+
catch (callbackError) { this.onError?.(callbackError); }
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
try { await this.onDelete?.({ key, message }); }
|
|
127
|
+
catch (error) { this.onError?.(error); }
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
stop() {
|
|
131
|
+
if (this.started) this.sock.ev.off?.('messages.delete', this.listener);
|
|
132
|
+
this.started = false;
|
|
133
|
+
return this;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** Atomic JSON-backed key/value store. Suitable for small metadata, not media blobs. */
|
|
138
|
+
export class PersistentStore {
|
|
139
|
+
constructor(filePath, { pretty = false } = {}) {
|
|
140
|
+
if (!filePath || typeof filePath !== 'string') throw new TypeError('A file path is required.');
|
|
141
|
+
this.filePath = path.resolve(filePath);
|
|
142
|
+
this.pretty = pretty;
|
|
143
|
+
this.data = new Map();
|
|
144
|
+
this.writeQueue = Promise.resolve();
|
|
145
|
+
this.opened = false;
|
|
146
|
+
}
|
|
147
|
+
async open() {
|
|
148
|
+
if (this.opened) return this;
|
|
149
|
+
try {
|
|
150
|
+
const parsed = JSON.parse(await readFile(this.filePath, 'utf8'));
|
|
151
|
+
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) throw new TypeError('Store file must contain a JSON object.');
|
|
152
|
+
this.data = new Map(Object.entries(parsed));
|
|
153
|
+
} catch (error) {
|
|
154
|
+
if (error.code !== 'ENOENT') throw error;
|
|
155
|
+
}
|
|
156
|
+
this.opened = true;
|
|
157
|
+
return this;
|
|
158
|
+
}
|
|
159
|
+
#assertOpen() { if (!this.opened) throw new Error('Call await store.open() before using the store.'); }
|
|
160
|
+
get(key) { this.#assertOpen(); return this.data.get(String(key)); }
|
|
161
|
+
has(key) { this.#assertOpen(); return this.data.has(String(key)); }
|
|
162
|
+
keys() { this.#assertOpen(); return [...this.data.keys()]; }
|
|
163
|
+
entries() { this.#assertOpen(); return [...this.data.entries()]; }
|
|
164
|
+
async set(key, value) { this.#assertOpen(); this.data.set(String(key), value); await this.flush(); return this; }
|
|
165
|
+
async delete(key) { this.#assertOpen(); const changed = this.data.delete(String(key)); if (changed) await this.flush(); return changed; }
|
|
166
|
+
async clear() { this.#assertOpen(); this.data.clear(); await this.flush(); }
|
|
167
|
+
flush() {
|
|
168
|
+
this.#assertOpen();
|
|
169
|
+
const snapshot = Object.fromEntries(this.data);
|
|
170
|
+
const serialized = JSON.stringify(snapshot, null, this.pretty ? 2 : 0);
|
|
171
|
+
this.writeQueue = this.writeQueue.then(async () => {
|
|
172
|
+
await mkdir(path.dirname(this.filePath), { recursive: true });
|
|
173
|
+
const temp = `${this.filePath}.${process.pid}.${randomUUID()}.tmp`;
|
|
174
|
+
await writeFile(temp, serialized, { mode: 0o600 });
|
|
175
|
+
await rename(temp, this.filePath);
|
|
176
|
+
});
|
|
177
|
+
return this.writeQueue;
|
|
178
|
+
}
|
|
179
|
+
async close() { if (this.opened) await this.flush(); this.opened = false; }
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export const extractMessageText = getText;
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { Boom } from '@hapi/boom';
|
|
2
|
+
import type { Agent } from 'https';
|
|
3
|
+
import { Readable } from 'stream';
|
|
4
|
+
import { URL } from 'url';
|
|
5
|
+
import { proto } from '../../WAProto/index.js';
|
|
6
|
+
import { type MediaType } from '../Defaults/index.js';
|
|
7
|
+
import type { DownloadableMessage, MediaConnInfo, MediaDecryptionKeyInfo, SocketConfig, WAMediaUpload, WAMediaUploadFunction, WAMessageContent, WAMessageKey } from '../Types/index.js';
|
|
8
|
+
import { type BinaryNode } from '../WABinary/index.js';
|
|
9
|
+
import type { ILogger } from './logger.js';
|
|
10
|
+
export declare const hkdfInfoKey: (type: MediaType) => string;
|
|
11
|
+
export declare const getRawMediaUploadData: (media: WAMediaUpload, mediaType: MediaType, logger?: ILogger) => Promise<{
|
|
12
|
+
filePath: string;
|
|
13
|
+
fileSha256: Buffer;
|
|
14
|
+
fileLength: number;
|
|
15
|
+
}>;
|
|
16
|
+
/** generates all the keys required to encrypt/decrypt & sign a media message */
|
|
17
|
+
export declare function getMediaKeys(buffer: Uint8Array | string | null | undefined, mediaType: MediaType): Promise<MediaDecryptionKeyInfo>;
|
|
18
|
+
export declare const extractImageThumb: (bufferOrFilePath: Readable | Buffer | string, width?: number) => Promise<{
|
|
19
|
+
buffer: any;
|
|
20
|
+
original: {
|
|
21
|
+
width: any;
|
|
22
|
+
height: any;
|
|
23
|
+
};
|
|
24
|
+
}>;
|
|
25
|
+
export declare const encodeBase64EncodedStringForUpload: (b64: string) => string;
|
|
26
|
+
export declare const generateProfilePicture: (mediaUpload: WAMediaUpload, dimensions?: {
|
|
27
|
+
width: number;
|
|
28
|
+
height: number;
|
|
29
|
+
}) => Promise<{
|
|
30
|
+
img: Buffer;
|
|
31
|
+
}>;
|
|
32
|
+
/** gets the SHA256 of the given media message */
|
|
33
|
+
export declare const mediaMessageSHA256B64: (message: WAMessageContent) => string | null | undefined;
|
|
34
|
+
export declare function getAudioDuration(buffer: Buffer | string | Readable): Promise<number | undefined>;
|
|
35
|
+
/**
|
|
36
|
+
referenced from and modifying https://github.com/wppconnect-team/wa-js/blob/main/src/chat/functions/prepareAudioWaveform.ts
|
|
37
|
+
*/
|
|
38
|
+
export declare function getAudioWaveform(buffer: Buffer | string | Readable, logger?: ILogger): Promise<Uint8Array<ArrayBuffer> | undefined>;
|
|
39
|
+
export declare const toReadable: (buffer: Buffer) => Readable;
|
|
40
|
+
export declare const toBuffer: (stream: Readable) => Promise<Buffer>;
|
|
41
|
+
export declare const getStream: (item: WAMediaUpload, opts?: RequestInit & {
|
|
42
|
+
maxContentLength?: number;
|
|
43
|
+
}) => Promise<{
|
|
44
|
+
readonly stream: Readable;
|
|
45
|
+
readonly type: "buffer";
|
|
46
|
+
} | {
|
|
47
|
+
readonly stream: Readable;
|
|
48
|
+
readonly type: "readable";
|
|
49
|
+
} | {
|
|
50
|
+
readonly stream: any;
|
|
51
|
+
readonly type: "remote";
|
|
52
|
+
} | {
|
|
53
|
+
readonly stream: import("fs").ReadStream;
|
|
54
|
+
readonly type: "file";
|
|
55
|
+
}>;
|
|
56
|
+
/** generates a thumbnail for a given media, if required */
|
|
57
|
+
export declare function generateThumbnail(file: string, mediaType: 'video' | 'image', options: {
|
|
58
|
+
logger?: ILogger;
|
|
59
|
+
}): Promise<{
|
|
60
|
+
thumbnail: string | undefined;
|
|
61
|
+
originalImageDimensions: {
|
|
62
|
+
width: number;
|
|
63
|
+
height: number;
|
|
64
|
+
} | undefined;
|
|
65
|
+
}>;
|
|
66
|
+
export declare const getHttpStream: (url: string | URL, options?: RequestInit & {
|
|
67
|
+
isStream?: true;
|
|
68
|
+
}) => Promise<any>;
|
|
69
|
+
type EncryptedStreamOptions = {
|
|
70
|
+
saveOriginalFileIfRequired?: boolean;
|
|
71
|
+
logger?: ILogger;
|
|
72
|
+
opts?: RequestInit;
|
|
73
|
+
};
|
|
74
|
+
export declare const encryptedStream: (media: WAMediaUpload, mediaType: MediaType, { logger, saveOriginalFileIfRequired, opts }?: EncryptedStreamOptions) => Promise<{
|
|
75
|
+
mediaKey: Buffer;
|
|
76
|
+
originalFilePath: string | undefined;
|
|
77
|
+
encFilePath: string;
|
|
78
|
+
mac: Buffer;
|
|
79
|
+
fileEncSha256: Buffer;
|
|
80
|
+
fileSha256: Buffer;
|
|
81
|
+
fileLength: number;
|
|
82
|
+
}>;
|
|
83
|
+
export type MediaDownloadOptions = {
|
|
84
|
+
startByte?: number;
|
|
85
|
+
endByte?: number;
|
|
86
|
+
options?: RequestInit;
|
|
87
|
+
};
|
|
88
|
+
export declare const getUrlFromDirectPath: (directPath: string) => string;
|
|
89
|
+
export declare const downloadContentFromMessage: ({ mediaKey, directPath, url }: DownloadableMessage, type: MediaType, opts?: MediaDownloadOptions) => Promise<any>;
|
|
90
|
+
/**
|
|
91
|
+
* Decrypts and downloads an AES256-CBC encrypted file given the keys.
|
|
92
|
+
* Assumes the SHA256 of the plaintext is appended to the end of the ciphertext
|
|
93
|
+
* */
|
|
94
|
+
export declare const downloadEncryptedContent: (downloadUrl: string, { cipherKey, iv }: MediaDecryptionKeyInfo, { startByte, endByte, options }?: MediaDownloadOptions) => Promise<any>;
|
|
95
|
+
export declare function extensionForMediaMessage(message: WAMessageContent): string;
|
|
96
|
+
type MediaUploadResult = {
|
|
97
|
+
url?: string;
|
|
98
|
+
direct_path?: string;
|
|
99
|
+
meta_hmac?: string;
|
|
100
|
+
ts?: number;
|
|
101
|
+
fbid?: number;
|
|
102
|
+
};
|
|
103
|
+
export type UploadParams = {
|
|
104
|
+
url: string;
|
|
105
|
+
filePath: string;
|
|
106
|
+
headers: Record<string, string>;
|
|
107
|
+
timeoutMs?: number;
|
|
108
|
+
agent?: Agent;
|
|
109
|
+
};
|
|
110
|
+
export declare const uploadWithNodeHttp: ({ url, filePath, headers, timeoutMs, agent }: UploadParams, redirectCount?: number) => Promise<MediaUploadResult | undefined>;
|
|
111
|
+
export declare const getWAUploadToServer: ({ customUploadHosts, fetchAgent, logger, options }: SocketConfig, refreshMediaConn: (force: boolean) => Promise<MediaConnInfo>) => WAMediaUploadFunction;
|
|
112
|
+
/**
|
|
113
|
+
* Generate a binary node that will request the phone to re-upload the media & return the newly uploaded URL
|
|
114
|
+
*/
|
|
115
|
+
export declare const encryptMediaRetryRequest: (key: WAMessageKey, mediaKey: Buffer | Uint8Array, meId: string) => BinaryNode;
|
|
116
|
+
export declare const decodeMediaRetryNode: (node: BinaryNode) => {
|
|
117
|
+
key: WAMessageKey;
|
|
118
|
+
media?: {
|
|
119
|
+
ciphertext: Uint8Array;
|
|
120
|
+
iv: Uint8Array;
|
|
121
|
+
};
|
|
122
|
+
error?: Boom;
|
|
123
|
+
};
|
|
124
|
+
export declare const decryptMediaRetryData: ({ ciphertext, iv }: {
|
|
125
|
+
ciphertext: Uint8Array;
|
|
126
|
+
iv: Uint8Array;
|
|
127
|
+
}, mediaKey: Uint8Array, msgId: string) => proto.MediaRetryNotification;
|
|
128
|
+
export declare const getStatusCodeForMediaRetry: (code: number) => 200 | 412 | 404 | 418;
|
|
129
|
+
export {};
|
|
130
|
+
//# sourceMappingURL=messages-media.d.ts.map
|