gifted-baileys 1.5.0 → 1.5.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.
- package/LICENSE +1 -1
- package/README.md +1429 -684
- package/WAProto/WAProto.proto +969 -88
- package/WAProto/index.d.ts +13199 -1260
- package/WAProto/index.js +124901 -74525
- package/lib/Defaults/baileys-version.json +1 -1
- package/lib/Defaults/index.d.ts +2 -2
- package/lib/Defaults/index.js +6 -5
- package/lib/Defaults/phonenumber-mcc.json +221 -221
- package/lib/Signal/libsignal.js +18 -9
- package/lib/Socket/Client/abstract-socket-client.d.ts +0 -2
- package/lib/Socket/Client/index.d.ts +2 -3
- package/lib/Socket/Client/index.js +2 -3
- package/lib/Socket/Client/mobile-socket-client.d.ts +0 -1
- package/lib/Socket/Client/types.d.ts +17 -0
- package/lib/Socket/Client/types.js +13 -0
- package/lib/Socket/Client/{web-socket-client.d.ts → websocket.d.ts} +1 -1
- package/lib/Socket/Client/{web-socket-client.js → websocket.js} +2 -2
- package/lib/Socket/business.d.ts +64 -29
- package/lib/Socket/business.js +1 -0
- package/lib/Socket/chats.d.ts +10 -8
- package/lib/Socket/chats.js +114 -97
- package/lib/Socket/groups.d.ts +10 -8
- package/lib/Socket/groups.js +4 -2
- package/lib/Socket/index.d.ts +70 -35
- package/lib/Socket/messages-recv.d.ts +63 -29
- package/lib/Socket/messages-recv.js +374 -155
- package/lib/Socket/messages-send.d.ts +48 -12
- package/lib/Socket/messages-send.js +445 -87
- package/lib/Socket/newsletter.d.ts +132 -0
- package/lib/Socket/newsletter.js +236 -0
- package/lib/Socket/registration.d.ts +73 -41
- package/lib/Socket/registration.js +7 -7
- package/lib/Socket/socket.d.ts +2 -0
- package/lib/Socket/socket.js +56 -15
- package/lib/Socket/usync.d.ts +37 -0
- package/lib/Socket/usync.js +70 -0
- package/lib/Store/make-cache-manager-store.d.ts +2 -1
- package/lib/Store/make-in-memory-store.d.ts +2 -1
- package/lib/Store/make-in-memory-store.js +40 -46
- package/lib/Store/make-ordered-dictionary.d.ts +1 -1
- package/lib/Types/Auth.d.ts +2 -1
- package/lib/Types/Call.d.ts +1 -1
- package/lib/Types/Chat.d.ts +12 -7
- package/lib/Types/Events.d.ts +17 -2
- package/lib/Types/GroupMetadata.d.ts +6 -2
- package/lib/Types/Label.d.ts +11 -0
- package/lib/Types/Label.js +1 -1
- package/lib/Types/LabelAssociation.js +1 -1
- package/lib/Types/Message.d.ts +184 -12
- package/lib/Types/Newsletter.d.ts +92 -0
- package/lib/Types/Newsletter.js +32 -0
- package/lib/Types/Socket.d.ts +7 -2
- package/lib/Types/USync.d.ts +25 -0
- package/lib/Types/USync.js +2 -0
- package/lib/Types/index.d.ts +10 -0
- package/lib/Types/index.js +2 -1
- package/lib/Utils/auth-utils.js +5 -3
- package/lib/Utils/business.d.ts +1 -1
- package/lib/Utils/business.js +2 -2
- package/lib/Utils/chat-utils.d.ts +11 -12
- package/lib/Utils/chat-utils.js +41 -20
- package/lib/Utils/crypto.d.ts +15 -16
- package/lib/Utils/crypto.js +35 -23
- package/lib/Utils/decode-wa-message.d.ts +17 -0
- package/lib/Utils/decode-wa-message.js +65 -13
- package/lib/Utils/generics.d.ts +11 -17
- package/lib/Utils/generics.js +47 -13
- package/lib/Utils/history.d.ts +6 -2
- package/lib/Utils/history.js +3 -0
- package/lib/Utils/link-preview.js +1 -1
- package/lib/Utils/logger.d.ts +1 -3
- package/lib/Utils/make-mutex.d.ts +2 -2
- package/lib/Utils/messages-media.d.ts +31 -25
- package/lib/Utils/messages-media.js +95 -53
- package/lib/Utils/messages.d.ts +2 -1
- package/lib/Utils/messages.js +515 -34
- package/lib/Utils/noise-handler.d.ts +6 -6
- package/lib/Utils/noise-handler.js +16 -3
- package/lib/Utils/process-message.js +4 -3
- package/lib/Utils/signal.d.ts +2 -1
- package/lib/Utils/signal.js +11 -19
- package/lib/Utils/use-multi-file-auth-state.js +11 -3
- package/lib/Utils/validate-connection.js +16 -2
- package/lib/WABinary/decode.d.ts +1 -2
- package/lib/WABinary/decode.js +17 -7
- package/lib/WABinary/encode.d.ts +1 -2
- package/lib/WABinary/encode.js +33 -17
- package/lib/WABinary/generic-utils.d.ts +2 -3
- package/lib/WABinary/generic-utils.js +2 -2
- package/lib/WABinary/jid-utils.d.ts +4 -2
- package/lib/WABinary/jid-utils.js +4 -1
- package/lib/WAM/BinaryInfo.d.ts +8 -0
- package/lib/WAM/BinaryInfo.js +13 -0
- package/lib/WAM/constants.d.ts +38 -0
- package/lib/WAM/constants.js +15350 -0
- package/lib/WAM/encode.d.ts +2 -0
- package/lib/WAM/encode.js +155 -0
- package/lib/WAM/index.d.ts +3 -0
- package/lib/WAM/index.js +19 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +9 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +32 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +22 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +57 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +30 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +42 -0
- package/lib/WAUSync/Protocols/index.d.ts +4 -0
- package/lib/WAUSync/Protocols/index.js +20 -0
- package/lib/WAUSync/USyncQuery.d.ts +26 -0
- package/lib/WAUSync/USyncQuery.js +79 -0
- package/lib/WAUSync/USyncUser.d.ts +10 -0
- package/lib/WAUSync/USyncUser.js +22 -0
- package/lib/WAUSync/index.d.ts +3 -0
- package/lib/WAUSync/index.js +19 -0
- package/lib/gifted +1 -0
- package/lib/index.js +2 -0
- package/package.json +10 -7
- package/lib/index.d.ts +0 -10
package/lib/Utils/generics.js
CHANGED
|
@@ -3,7 +3,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.isWABusinessPlatform = exports.getCodeFromWSError = exports.getCallStatusFromNode = exports.getErrorCodeFromStreamError = exports.getStatusFromReceiptType = exports.generateMdTagPrefix = exports.fetchLatestWaWebVersion = exports.fetchLatestBaileysVersion = exports.printQRIfNecessaryListener = exports.bindWaitForConnectionUpdate = exports.generateMessageID = exports.generateMessageIDV2 = exports.delayCancellable = exports.delay = exports.debouncedTimeout = exports.unixTimestampSeconds = exports.toNumber = exports.encodeBigEndian = exports.generateRegistrationId = exports.encodeWAMessage = exports.unpadRandomMax16 = exports.writeRandomPadMax16 = exports.getKeyAuthor = exports.BufferJSON = exports.getPlatformId = exports.Browsers = void 0;
|
|
7
|
+
exports.promiseTimeout = promiseTimeout;
|
|
8
|
+
exports.bindWaitForEvent = bindWaitForEvent;
|
|
9
|
+
exports.trimUndefined = trimUndefined;
|
|
10
|
+
exports.bytesToCrockford = bytesToCrockford;
|
|
7
11
|
const boom_1 = require("@hapi/boom");
|
|
8
12
|
const axios_1 = __importDefault(require("axios"));
|
|
9
13
|
const crypto_1 = require("crypto");
|
|
@@ -12,20 +16,37 @@ const WAProto_1 = require("../../WAProto");
|
|
|
12
16
|
const baileys_version_json_1 = require("../Defaults/baileys-version.json");
|
|
13
17
|
const Types_1 = require("../Types");
|
|
14
18
|
const WABinary_1 = require("../WABinary");
|
|
19
|
+
const COMPANION_PLATFORM_MAP = {
|
|
20
|
+
'Chrome': '49',
|
|
21
|
+
'Edge': '50',
|
|
22
|
+
'Firefox': '51',
|
|
23
|
+
'Opera': '53',
|
|
24
|
+
'Safari': '54'
|
|
25
|
+
};
|
|
15
26
|
const PLATFORM_MAP = {
|
|
16
27
|
'aix': 'AIX',
|
|
17
28
|
'darwin': 'Mac OS',
|
|
18
29
|
'win32': 'Windows',
|
|
19
|
-
'android': 'Android'
|
|
30
|
+
'android': 'Android',
|
|
31
|
+
'freebsd': 'FreeBSD',
|
|
32
|
+
'openbsd': 'OpenBSD',
|
|
33
|
+
'sunos': 'Solaris'
|
|
20
34
|
};
|
|
21
35
|
exports.Browsers = {
|
|
22
|
-
ubuntu: browser => ['Ubuntu', browser, '
|
|
23
|
-
macOS: browser => ['Mac OS', browser, '
|
|
24
|
-
baileys: browser => ['Baileys', browser, '
|
|
25
|
-
windows: browser => ['Windows', browser, '10.0.
|
|
36
|
+
ubuntu: (browser) => ['Ubuntu', browser, '22.04.4'],
|
|
37
|
+
macOS: (browser) => ['Mac OS', browser, '14.4.1'],
|
|
38
|
+
baileys: (browser) => ['Baileys', browser, '6.5.0'],
|
|
39
|
+
windows: (browser) => ['Windows', browser, '10.0.22631'],
|
|
40
|
+
iOS: (browser) => ['iOS', browser, '18.2'],
|
|
41
|
+
linux: (browser) => ['Linux', browser, '6.12.6'],
|
|
26
42
|
/** The appropriate browser based on your OS & release */
|
|
27
|
-
appropriate: browser => [PLATFORM_MAP[(0, os_1.platform)()] || 'Ubuntu', browser, (0, os_1.release)()]
|
|
43
|
+
appropriate: (browser) => [PLATFORM_MAP[(0, os_1.platform)()] || 'Ubuntu', browser, (0, os_1.release)()]
|
|
44
|
+
};
|
|
45
|
+
const getPlatformId = (browser) => {
|
|
46
|
+
const platformType = WAProto_1.proto.DeviceProps.PlatformType[browser.toUpperCase()];
|
|
47
|
+
return platformType ? platformType.toString().charCodeAt(0).toString() : '49'; //chrome
|
|
28
48
|
};
|
|
49
|
+
exports.getPlatformId = getPlatformId;
|
|
29
50
|
exports.BufferJSON = {
|
|
30
51
|
replacer: (k, value) => {
|
|
31
52
|
if (Buffer.isBuffer(value) || value instanceof Uint8Array || (value === null || value === void 0 ? void 0 : value.type) === 'Buffer') {
|
|
@@ -146,9 +167,24 @@ async function promiseTimeout(ms, promise) {
|
|
|
146
167
|
.finally(cancel);
|
|
147
168
|
return p;
|
|
148
169
|
}
|
|
149
|
-
|
|
170
|
+
const generateMessageIDV2 = (userId) => {
|
|
171
|
+
const data = Buffer.alloc(8 + 20 + 16);
|
|
172
|
+
data.writeBigUInt64BE(BigInt(Math.floor(Date.now() / 1000)));
|
|
173
|
+
if (userId) {
|
|
174
|
+
const id = (0, WABinary_1.jidDecode)(userId);
|
|
175
|
+
if (id === null || id === void 0 ? void 0 : id.user) {
|
|
176
|
+
data.write(id.user, 8);
|
|
177
|
+
data.write('@c.us', 8 + id.user.length);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
const random = (0, crypto_1.randomBytes)(16);
|
|
181
|
+
random.copy(data, 28);
|
|
182
|
+
const hash = (0, crypto_1.createHash)('sha256').update(data).digest();
|
|
183
|
+
return 'FTG-' + hash.toString('hex').toUpperCase().substring(0, 18);
|
|
184
|
+
};
|
|
185
|
+
exports.generateMessageIDV2 = generateMessageIDV2;
|
|
150
186
|
// generate a random ID to attach to a message
|
|
151
|
-
const generateMessageID = () => (0, crypto_1.randomBytes)(
|
|
187
|
+
const generateMessageID = () => 'FTG-' + (0, crypto_1.randomBytes)(6).toString('hex').toUpperCase();
|
|
152
188
|
exports.generateMessageID = generateMessageID;
|
|
153
189
|
function bindWaitForEvent(ev, event) {
|
|
154
190
|
return async (check, timeoutMs) => {
|
|
@@ -175,7 +211,6 @@ function bindWaitForEvent(ev, event) {
|
|
|
175
211
|
}));
|
|
176
212
|
};
|
|
177
213
|
}
|
|
178
|
-
exports.bindWaitForEvent = bindWaitForEvent;
|
|
179
214
|
const bindWaitForConnectionUpdate = (ev) => bindWaitForEvent(ev, 'connection.update');
|
|
180
215
|
exports.bindWaitForConnectionUpdate = bindWaitForConnectionUpdate;
|
|
181
216
|
const printQRIfNecessaryListener = (ev, logger) => {
|
|
@@ -296,7 +331,8 @@ const getCallStatusFromNode = ({ tag, attrs }) => {
|
|
|
296
331
|
status = 'timeout';
|
|
297
332
|
}
|
|
298
333
|
else {
|
|
299
|
-
|
|
334
|
+
//fired when accepted/rejected/timeout/caller hangs up
|
|
335
|
+
status = 'terminate';
|
|
300
336
|
}
|
|
301
337
|
break;
|
|
302
338
|
case 'reject':
|
|
@@ -345,7 +381,6 @@ function trimUndefined(obj) {
|
|
|
345
381
|
}
|
|
346
382
|
return obj;
|
|
347
383
|
}
|
|
348
|
-
exports.trimUndefined = trimUndefined;
|
|
349
384
|
const CROCKFORD_CHARACTERS = '123456789ABCDEFGHJKLMNPQRSTVWXYZ';
|
|
350
385
|
function bytesToCrockford(buffer) {
|
|
351
386
|
let value = 0;
|
|
@@ -364,4 +399,3 @@ function bytesToCrockford(buffer) {
|
|
|
364
399
|
}
|
|
365
400
|
return crockford.join('');
|
|
366
401
|
}
|
|
367
|
-
exports.bytesToCrockford = bytesToCrockford;
|
package/lib/Utils/history.d.ts
CHANGED
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
import { AxiosRequestConfig } from 'axios';
|
|
2
2
|
import { proto } from '../../WAProto';
|
|
3
3
|
import { Chat, Contact } from '../Types';
|
|
4
|
-
export declare const downloadHistory: (msg: proto.Message.IHistorySyncNotification, options: AxiosRequestConfig<
|
|
4
|
+
export declare const downloadHistory: (msg: proto.Message.IHistorySyncNotification, options: AxiosRequestConfig<{}>) => Promise<proto.HistorySync>;
|
|
5
5
|
export declare const processHistoryMessage: (item: proto.IHistorySync) => {
|
|
6
6
|
chats: Chat[];
|
|
7
7
|
contacts: Contact[];
|
|
8
8
|
messages: proto.IWebMessageInfo[];
|
|
9
|
+
syncType: proto.HistorySync.HistorySyncType;
|
|
10
|
+
progress: number | null | undefined;
|
|
9
11
|
};
|
|
10
|
-
export declare const downloadAndProcessHistorySyncNotification: (msg: proto.Message.IHistorySyncNotification, options: AxiosRequestConfig<
|
|
12
|
+
export declare const downloadAndProcessHistorySyncNotification: (msg: proto.Message.IHistorySyncNotification, options: AxiosRequestConfig<{}>) => Promise<{
|
|
11
13
|
chats: Chat[];
|
|
12
14
|
contacts: Contact[];
|
|
13
15
|
messages: proto.IWebMessageInfo[];
|
|
16
|
+
syncType: proto.HistorySync.HistorySyncType;
|
|
17
|
+
progress: number | null | undefined;
|
|
14
18
|
}>;
|
|
15
19
|
export declare const getHistoryMsg: (message: proto.IMessage) => proto.Message.IHistorySyncNotification | null | undefined;
|
package/lib/Utils/history.js
CHANGED
|
@@ -32,6 +32,7 @@ const processHistoryMessage = (item) => {
|
|
|
32
32
|
case WAProto_1.proto.HistorySync.HistorySyncType.INITIAL_BOOTSTRAP:
|
|
33
33
|
case WAProto_1.proto.HistorySync.HistorySyncType.RECENT:
|
|
34
34
|
case WAProto_1.proto.HistorySync.HistorySyncType.FULL:
|
|
35
|
+
case WAProto_1.proto.HistorySync.HistorySyncType.ON_DEMAND:
|
|
35
36
|
for (const chat of item.conversations) {
|
|
36
37
|
contacts.push({ id: chat.id, name: chat.name || undefined });
|
|
37
38
|
const msgs = chat.messages || [];
|
|
@@ -74,6 +75,8 @@ const processHistoryMessage = (item) => {
|
|
|
74
75
|
chats,
|
|
75
76
|
contacts,
|
|
76
77
|
messages,
|
|
78
|
+
syncType: item.syncType,
|
|
79
|
+
progress: item.progress
|
|
77
80
|
};
|
|
78
81
|
};
|
|
79
82
|
exports.processHistoryMessage = processHistoryMessage;
|
|
@@ -32,7 +32,7 @@ const getUrlInfo = async (text, opts = {
|
|
|
32
32
|
}
|
|
33
33
|
const info = await getLinkPreview(previewLink, {
|
|
34
34
|
...opts.fetchOpts,
|
|
35
|
-
followRedirects: '
|
|
35
|
+
followRedirects: 'follow',
|
|
36
36
|
handleRedirects: (baseURL, forwardedURL) => {
|
|
37
37
|
const urlObj = new URL(baseURL);
|
|
38
38
|
const forwardedURLObj = new URL(forwardedURL);
|
package/lib/Utils/logger.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export declare const makeMutex: () => {
|
|
2
|
-
mutex<T>(code: () => T |
|
|
2
|
+
mutex<T>(code: () => Promise<T> | T): Promise<T>;
|
|
3
3
|
};
|
|
4
4
|
export type Mutex = ReturnType<typeof makeMutex>;
|
|
5
5
|
export declare const makeKeyedMutex: () => {
|
|
6
|
-
mutex<T>(key: string, task: () => T |
|
|
6
|
+
mutex<T>(key: string, task: () => Promise<T> | T): Promise<T>;
|
|
7
7
|
};
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
/// <reference types="node" />
|
|
3
|
-
/// <reference types="node" />
|
|
4
1
|
import { Boom } from '@hapi/boom';
|
|
5
2
|
import { AxiosRequestConfig } from 'axios';
|
|
6
3
|
import type { Logger } from 'pino';
|
|
7
|
-
import { Readable
|
|
4
|
+
import { Readable } from 'stream';
|
|
8
5
|
import { URL } from 'url';
|
|
9
6
|
import { proto } from '../../WAProto';
|
|
10
7
|
import { DownloadableMessage, MediaConnInfo, MediaDecryptionKeyInfo, MediaType, SocketConfig, WAMediaUpload, WAMediaUploadFunction, WAMessageContent } from '../Types';
|
|
@@ -13,10 +10,10 @@ export declare const hkdfInfoKey: (type: MediaType) => string;
|
|
|
13
10
|
/** generates all the keys required to encrypt/decrypt & sign a media message */
|
|
14
11
|
export declare function getMediaKeys(buffer: Uint8Array | string | null | undefined, mediaType: MediaType): MediaDecryptionKeyInfo;
|
|
15
12
|
export declare const extractImageThumb: (bufferOrFilePath: Readable | Buffer | string, width?: number) => Promise<{
|
|
16
|
-
buffer:
|
|
13
|
+
buffer: any;
|
|
17
14
|
original: {
|
|
18
|
-
width:
|
|
19
|
-
height:
|
|
15
|
+
width: any;
|
|
16
|
+
height: any;
|
|
20
17
|
};
|
|
21
18
|
}>;
|
|
22
19
|
export declare const encodeBase64EncodedStringForUpload: (b64: string) => string;
|
|
@@ -24,25 +21,25 @@ export declare const generateProfilePicture: (mediaUpload: WAMediaUpload) => Pro
|
|
|
24
21
|
img: Buffer;
|
|
25
22
|
}>;
|
|
26
23
|
/** gets the SHA256 of the given media message */
|
|
27
|
-
export declare const mediaMessageSHA256B64: (message: WAMessageContent) =>
|
|
28
|
-
export declare function getAudioDuration(buffer: Buffer | string | Readable): Promise<
|
|
24
|
+
export declare const mediaMessageSHA256B64: (message: WAMessageContent) => any;
|
|
25
|
+
export declare function getAudioDuration(buffer: Buffer | string | Readable): Promise<any>;
|
|
29
26
|
/**
|
|
30
27
|
referenced from and modifying https://github.com/wppconnect-team/wa-js/blob/main/src/chat/functions/prepareAudioWaveform.ts
|
|
31
28
|
*/
|
|
32
|
-
export declare function getAudioWaveform(buffer: Buffer | string | Readable, logger?: Logger): Promise<Uint8Array | undefined>;
|
|
33
|
-
export declare const toReadable: (buffer: Buffer) =>
|
|
34
|
-
export declare const toBuffer: (stream: Readable) => Promise<
|
|
29
|
+
export declare function getAudioWaveform(buffer: Buffer | string | Readable, logger?: Logger): Promise<Uint8Array<ArrayBuffer> | undefined>;
|
|
30
|
+
export declare const toReadable: (buffer: Buffer) => any;
|
|
31
|
+
export declare const toBuffer: (stream: Readable) => Promise<any>;
|
|
35
32
|
export declare const getStream: (item: WAMediaUpload, opts?: AxiosRequestConfig) => Promise<{
|
|
36
|
-
readonly stream:
|
|
33
|
+
readonly stream: any;
|
|
37
34
|
readonly type: "buffer";
|
|
38
35
|
} | {
|
|
39
|
-
readonly stream:
|
|
36
|
+
readonly stream: any;
|
|
40
37
|
readonly type: "readable";
|
|
41
38
|
} | {
|
|
42
39
|
readonly stream: Readable;
|
|
43
40
|
readonly type: "remote";
|
|
44
41
|
} | {
|
|
45
|
-
readonly stream:
|
|
42
|
+
readonly stream: any;
|
|
46
43
|
readonly type: "file";
|
|
47
44
|
}>;
|
|
48
45
|
/** generates a thumbnail for a given media, if required */
|
|
@@ -63,13 +60,22 @@ type EncryptedStreamOptions = {
|
|
|
63
60
|
logger?: Logger;
|
|
64
61
|
opts?: AxiosRequestConfig;
|
|
65
62
|
};
|
|
63
|
+
export declare const prepareStream: (media: WAMediaUpload, mediaType: MediaType, { logger, saveOriginalFileIfRequired, opts }?: EncryptedStreamOptions) => Promise<{
|
|
64
|
+
mediaKey: undefined;
|
|
65
|
+
encWriteStream: any;
|
|
66
|
+
fileLength: any;
|
|
67
|
+
fileSha256: any;
|
|
68
|
+
fileEncSha256: undefined;
|
|
69
|
+
bodyPath: string | undefined;
|
|
70
|
+
didSaveToTmpPath: boolean;
|
|
71
|
+
}>;
|
|
66
72
|
export declare const encryptedStream: (media: WAMediaUpload, mediaType: MediaType, { logger, saveOriginalFileIfRequired, opts }?: EncryptedStreamOptions) => Promise<{
|
|
67
|
-
mediaKey:
|
|
68
|
-
encWriteStream:
|
|
73
|
+
mediaKey: any;
|
|
74
|
+
encWriteStream: any;
|
|
69
75
|
bodyPath: string | undefined;
|
|
70
|
-
mac:
|
|
71
|
-
fileEncSha256:
|
|
72
|
-
fileSha256:
|
|
76
|
+
mac: any;
|
|
77
|
+
fileEncSha256: any;
|
|
78
|
+
fileSha256: any;
|
|
73
79
|
fileLength: number;
|
|
74
80
|
didSaveToTmpPath: boolean;
|
|
75
81
|
}>;
|
|
@@ -79,12 +85,12 @@ export type MediaDownloadOptions = {
|
|
|
79
85
|
options?: AxiosRequestConfig<any>;
|
|
80
86
|
};
|
|
81
87
|
export declare const getUrlFromDirectPath: (directPath: string) => string;
|
|
82
|
-
export declare const downloadContentFromMessage: ({ mediaKey, directPath, url }: DownloadableMessage, type: MediaType, opts?: MediaDownloadOptions) => Promise<
|
|
88
|
+
export declare const downloadContentFromMessage: ({ mediaKey, directPath, url }: DownloadableMessage, type: MediaType, opts?: MediaDownloadOptions) => Promise<any>;
|
|
83
89
|
/**
|
|
84
90
|
* Decrypts and downloads an AES256-CBC encrypted file given the keys.
|
|
85
91
|
* Assumes the SHA256 of the plaintext is appended to the end of the ciphertext
|
|
86
92
|
* */
|
|
87
|
-
export declare const downloadEncryptedContent: (downloadUrl: string, { cipherKey, iv }: MediaDecryptionKeyInfo, { startByte, endByte, options }?: MediaDownloadOptions) => Promise<
|
|
93
|
+
export declare const downloadEncryptedContent: (downloadUrl: string, { cipherKey, iv }: MediaDecryptionKeyInfo, { startByte, endByte, options }?: MediaDownloadOptions) => Promise<any>;
|
|
88
94
|
export declare function extensionForMediaMessage(message: WAMessageContent): string;
|
|
89
95
|
export declare const getWAUploadToServer: ({ customUploadHosts, fetchAgent, logger, options }: SocketConfig, refreshMediaConn: (force: boolean) => Promise<MediaConnInfo>) => WAMediaUploadFunction;
|
|
90
96
|
/**
|
|
@@ -92,12 +98,12 @@ export declare const getWAUploadToServer: ({ customUploadHosts, fetchAgent, logg
|
|
|
92
98
|
*/
|
|
93
99
|
export declare const encryptMediaRetryRequest: (key: proto.IMessageKey, mediaKey: Buffer | Uint8Array, meId: string) => BinaryNode;
|
|
94
100
|
export declare const decodeMediaRetryNode: (node: BinaryNode) => {
|
|
95
|
-
key:
|
|
101
|
+
key: import("../Types").WAMessageKey;
|
|
96
102
|
media?: {
|
|
97
103
|
ciphertext: Uint8Array;
|
|
98
104
|
iv: Uint8Array;
|
|
99
|
-
}
|
|
100
|
-
error?: Boom
|
|
105
|
+
};
|
|
106
|
+
error?: Boom;
|
|
101
107
|
};
|
|
102
108
|
export declare const decryptMediaRetryData: ({ ciphertext, iv }: {
|
|
103
109
|
ciphertext: Uint8Array;
|
|
@@ -15,15 +15,30 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
25
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.getStatusCodeForMediaRetry = exports.decryptMediaRetryData = exports.decodeMediaRetryNode = exports.encryptMediaRetryRequest = exports.getWAUploadToServer = exports.
|
|
36
|
+
exports.getStatusCodeForMediaRetry = exports.decryptMediaRetryData = exports.decodeMediaRetryNode = exports.encryptMediaRetryRequest = exports.getWAUploadToServer = exports.downloadEncryptedContent = exports.downloadContentFromMessage = exports.getUrlFromDirectPath = exports.encryptedStream = exports.prepareStream = exports.getHttpStream = exports.getStream = exports.toBuffer = exports.toReadable = exports.mediaMessageSHA256B64 = exports.generateProfilePicture = exports.encodeBase64EncodedStringForUpload = exports.extractImageThumb = exports.hkdfInfoKey = void 0;
|
|
37
|
+
exports.getMediaKeys = getMediaKeys;
|
|
38
|
+
exports.getAudioDuration = getAudioDuration;
|
|
39
|
+
exports.getAudioWaveform = getAudioWaveform;
|
|
40
|
+
exports.generateThumbnail = generateThumbnail;
|
|
41
|
+
exports.extensionForMediaMessage = extensionForMediaMessage;
|
|
27
42
|
const boom_1 = require("@hapi/boom");
|
|
28
43
|
const child_process_1 = require("child_process");
|
|
29
44
|
const Crypto = __importStar(require("crypto"));
|
|
@@ -81,7 +96,6 @@ function getMediaKeys(buffer, mediaType) {
|
|
|
81
96
|
macKey: expandedMediaKey.slice(48, 80),
|
|
82
97
|
};
|
|
83
98
|
}
|
|
84
|
-
exports.getMediaKeys = getMediaKeys;
|
|
85
99
|
/** Extracts video thumb using FFMPEG */
|
|
86
100
|
const extractVideoThumb = async (path, destPath, time, size) => new Promise((resolve, reject) => {
|
|
87
101
|
const cmd = `ffmpeg -ss ${time} -i ${path} -y -vf scale=${size.width}:-1 -vframes 1 -f image2 ${destPath}`;
|
|
@@ -142,42 +156,23 @@ const encodeBase64EncodedStringForUpload = (b64) => (encodeURIComponent(b64
|
|
|
142
156
|
.replace(/\=+$/, '')));
|
|
143
157
|
exports.encodeBase64EncodedStringForUpload = encodeBase64EncodedStringForUpload;
|
|
144
158
|
const generateProfilePicture = async (mediaUpload) => {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
else if ('url' in mediaUpload) {
|
|
151
|
-
bufferOrFilePath = mediaUpload.url.toString();
|
|
152
|
-
}
|
|
153
|
-
else {
|
|
154
|
-
bufferOrFilePath = await (0, exports.toBuffer)(mediaUpload.stream);
|
|
155
|
-
}
|
|
156
|
-
const lib = await getImageProcessingLibrary();
|
|
159
|
+
const bufferOrFilePath = Buffer.isBuffer(mediaUpload)
|
|
160
|
+
? mediaUpload
|
|
161
|
+
: typeof mediaUpload === 'object' && 'url' in mediaUpload
|
|
162
|
+
? mediaUpload.url.toString()
|
|
163
|
+
: await (0, exports.toBuffer)(mediaUpload.stream);
|
|
157
164
|
let img;
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
const { read, MIME_JPEG, RESIZE_BILINEAR } = lib.jimp;
|
|
168
|
-
const jimp = await read(bufferOrFilePath);
|
|
169
|
-
const min = Math.min(jimp.getWidth(), jimp.getHeight());
|
|
170
|
-
const cropped = jimp.crop(0, 0, min, min);
|
|
171
|
-
img = cropped
|
|
172
|
-
.quality(50)
|
|
173
|
-
.resize(640, 640, RESIZE_BILINEAR)
|
|
174
|
-
.getBufferAsync(MIME_JPEG);
|
|
175
|
-
}
|
|
176
|
-
else {
|
|
177
|
-
throw new boom_1.Boom('No image processing library available');
|
|
178
|
-
}
|
|
165
|
+
const { read, MIME_JPEG, AUTO } = require('jimp');
|
|
166
|
+
const jimp = await read(bufferOrFilePath);
|
|
167
|
+
const min = jimp.getWidth();
|
|
168
|
+
const max = jimp.getHeight();
|
|
169
|
+
const cropped = jimp.crop(0, 0, min, max);
|
|
170
|
+
img = cropped
|
|
171
|
+
.quality(100)
|
|
172
|
+
.scaleToFit(720, 720, AUTO)
|
|
173
|
+
.getBufferAsync(MIME_JPEG);
|
|
179
174
|
return {
|
|
180
|
-
img: await img
|
|
175
|
+
img: await img
|
|
181
176
|
};
|
|
182
177
|
};
|
|
183
178
|
exports.generateProfilePicture = generateProfilePicture;
|
|
@@ -207,7 +202,6 @@ async function getAudioDuration(buffer) {
|
|
|
207
202
|
}
|
|
208
203
|
return metadata.format.duration;
|
|
209
204
|
}
|
|
210
|
-
exports.getAudioDuration = getAudioDuration;
|
|
211
205
|
/**
|
|
212
206
|
referenced from and modifying https://github.com/wppconnect-team/wa-js/blob/main/src/chat/functions/prepareAudioWaveform.ts
|
|
213
207
|
*/
|
|
@@ -249,7 +243,6 @@ async function getAudioWaveform(buffer, logger) {
|
|
|
249
243
|
logger === null || logger === void 0 ? void 0 : logger.debug('Failed to generate waveform: ' + e);
|
|
250
244
|
}
|
|
251
245
|
}
|
|
252
|
-
exports.getAudioWaveform = getAudioWaveform;
|
|
253
246
|
const toReadable = (buffer) => {
|
|
254
247
|
const readable = new stream_1.Readable({ read: () => { } });
|
|
255
248
|
readable.push(buffer);
|
|
@@ -311,13 +304,56 @@ async function generateThumbnail(file, mediaType, options) {
|
|
|
311
304
|
originalImageDimensions
|
|
312
305
|
};
|
|
313
306
|
}
|
|
314
|
-
exports.generateThumbnail = generateThumbnail;
|
|
315
307
|
const getHttpStream = async (url, options = {}) => {
|
|
316
308
|
const { default: axios } = await import('axios');
|
|
317
309
|
const fetched = await axios.get(url.toString(), { ...options, responseType: 'stream' });
|
|
318
310
|
return fetched.data;
|
|
319
311
|
};
|
|
320
312
|
exports.getHttpStream = getHttpStream;
|
|
313
|
+
const prepareStream = async (media, mediaType, { logger, saveOriginalFileIfRequired, opts } = {}) => {
|
|
314
|
+
const { stream, type } = await (0, exports.getStream)(media, opts);
|
|
315
|
+
logger === null || logger === void 0 ? void 0 : logger.debug('fetched media stream');
|
|
316
|
+
let bodyPath;
|
|
317
|
+
let didSaveToTmpPath = false;
|
|
318
|
+
try {
|
|
319
|
+
const buffer = await (0, exports.toBuffer)(stream);
|
|
320
|
+
if (type === 'file') {
|
|
321
|
+
bodyPath = media.url;
|
|
322
|
+
}
|
|
323
|
+
else if (saveOriginalFileIfRequired) {
|
|
324
|
+
bodyPath = (0, path_1.join)(getTmpFilesDirectory(), mediaType + (0, generics_1.generateMessageID)());
|
|
325
|
+
(0, fs_1.writeFileSync)(bodyPath, buffer);
|
|
326
|
+
didSaveToTmpPath = true;
|
|
327
|
+
}
|
|
328
|
+
const fileLength = buffer.length;
|
|
329
|
+
const fileSha256 = Crypto.createHash('sha256').update(buffer).digest();
|
|
330
|
+
stream === null || stream === void 0 ? void 0 : stream.destroy();
|
|
331
|
+
logger === null || logger === void 0 ? void 0 : logger.debug('prepare stream data successfully');
|
|
332
|
+
return {
|
|
333
|
+
mediaKey: undefined,
|
|
334
|
+
encWriteStream: buffer,
|
|
335
|
+
fileLength,
|
|
336
|
+
fileSha256,
|
|
337
|
+
fileEncSha256: undefined,
|
|
338
|
+
bodyPath,
|
|
339
|
+
didSaveToTmpPath
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
catch (error) {
|
|
343
|
+
// destroy all streams with error
|
|
344
|
+
stream.destroy();
|
|
345
|
+
if (didSaveToTmpPath) {
|
|
346
|
+
try {
|
|
347
|
+
await fs_1.promises.unlink(bodyPath);
|
|
348
|
+
}
|
|
349
|
+
catch (err) {
|
|
350
|
+
logger === null || logger === void 0 ? void 0 : logger.error({ err }, 'failed to save to tmp path');
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
throw error;
|
|
354
|
+
}
|
|
355
|
+
};
|
|
356
|
+
exports.prepareStream = prepareStream;
|
|
321
357
|
const encryptedStream = async (media, mediaType, { logger, saveOriginalFileIfRequired, opts } = {}) => {
|
|
322
358
|
const { stream, type } = await (0, exports.getStream)(media, opts);
|
|
323
359
|
logger === null || logger === void 0 ? void 0 : logger.debug('fetched media stream');
|
|
@@ -521,9 +557,8 @@ function extensionForMediaMessage(message) {
|
|
|
521
557
|
}
|
|
522
558
|
return extension;
|
|
523
559
|
}
|
|
524
|
-
exports.extensionForMediaMessage = extensionForMediaMessage;
|
|
525
560
|
const getWAUploadToServer = ({ customUploadHosts, fetchAgent, logger, options }, refreshMediaConn) => {
|
|
526
|
-
return async (stream, { mediaType, fileEncSha256B64, timeoutMs }) => {
|
|
561
|
+
return async (stream, { mediaType, fileEncSha256B64, newsletter, timeoutMs }) => {
|
|
527
562
|
var _a, _b;
|
|
528
563
|
const { default: axios } = await import('axios');
|
|
529
564
|
// send a query JSON to obtain the url & auth token to upload our media
|
|
@@ -531,15 +566,21 @@ const getWAUploadToServer = ({ customUploadHosts, fetchAgent, logger, options },
|
|
|
531
566
|
let urls;
|
|
532
567
|
const hosts = [...customUploadHosts, ...uploadInfo.hosts];
|
|
533
568
|
const chunks = [];
|
|
534
|
-
|
|
535
|
-
|
|
569
|
+
if (!Buffer.isBuffer(stream)) {
|
|
570
|
+
for await (const chunk of stream) {
|
|
571
|
+
chunks.push(chunk);
|
|
572
|
+
}
|
|
536
573
|
}
|
|
537
|
-
const reqBody = Buffer.concat(chunks);
|
|
574
|
+
const reqBody = Buffer.isBuffer(stream) ? stream : Buffer.concat(chunks);
|
|
538
575
|
fileEncSha256B64 = (0, exports.encodeBase64EncodedStringForUpload)(fileEncSha256B64);
|
|
576
|
+
let media = Defaults_1.MEDIA_PATH_MAP[mediaType];
|
|
577
|
+
if (newsletter) {
|
|
578
|
+
media = media === null || media === void 0 ? void 0 : media.replace('/mms/', '/newsletter/newsletter-');
|
|
579
|
+
}
|
|
539
580
|
for (const { hostname, maxContentLengthBytes } of hosts) {
|
|
540
581
|
logger.debug(`uploading to "${hostname}"`);
|
|
541
582
|
const auth = encodeURIComponent(uploadInfo.auth); // the auth token
|
|
542
|
-
const url = `https://${hostname}${
|
|
583
|
+
const url = `https://${hostname}${media}/${fileEncSha256B64}?auth=${auth}&token=${fileEncSha256B64}`;
|
|
543
584
|
let result;
|
|
544
585
|
try {
|
|
545
586
|
if (maxContentLengthBytes && reqBody.length > maxContentLengthBytes) {
|
|
@@ -562,7 +603,8 @@ const getWAUploadToServer = ({ customUploadHosts, fetchAgent, logger, options },
|
|
|
562
603
|
if ((result === null || result === void 0 ? void 0 : result.url) || (result === null || result === void 0 ? void 0 : result.directPath)) {
|
|
563
604
|
urls = {
|
|
564
605
|
mediaUrl: result.url,
|
|
565
|
-
directPath: result.direct_path
|
|
606
|
+
directPath: result.direct_path,
|
|
607
|
+
handle: result.handle
|
|
566
608
|
};
|
|
567
609
|
break;
|
|
568
610
|
}
|
package/lib/Utils/messages.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
/// <reference types="node" />
|
|
3
3
|
import { Logger } from 'pino';
|
|
4
|
+
import { type Transform } from 'stream';
|
|
4
5
|
import { proto } from '../../WAProto';
|
|
5
6
|
import { AnyMediaMessageContent, AnyMessageContent, MediaGenerationOptions, MessageContentGenerationOptions, MessageGenerationOptions, MessageGenerationOptionsFromContent, MessageUserReceipt, WAMessage, WAMessageContent, WAProto } from '../Types';
|
|
6
7
|
import { MediaDownloadOptions } from './messages-media';
|
|
@@ -70,7 +71,7 @@ type DownloadMediaMessageContext = {
|
|
|
70
71
|
/**
|
|
71
72
|
* Downloads the given message. Throws an error if it's not a media message
|
|
72
73
|
*/
|
|
73
|
-
export declare const downloadMediaMessage: (message: WAMessage, type:
|
|
74
|
+
export declare const downloadMediaMessage: <Type extends "stream" | "buffer">(message: WAMessage, type: Type, options: MediaDownloadOptions, ctx?: DownloadMediaMessageContext) => Promise<Type extends "buffer" ? Buffer : Transform>;
|
|
74
75
|
/** Checks whether the given message is a media message; if it is returns the inner content */
|
|
75
76
|
export declare const assertMediaContent: (content: proto.IMessage | null | undefined) => proto.Message.IVideoMessage | proto.Message.IImageMessage | proto.Message.IAudioMessage | proto.Message.IDocumentMessage | proto.Message.IStickerMessage;
|
|
76
77
|
export {};
|