@d0v3riz/baileys 6.3.0 → 6.4.0
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/README.md +6 -5
- package/WAProto/WAProto.proto +58 -24
- package/WAProto/index.d.ts +649 -410
- package/WAProto/index.js +1632 -985
- package/WASignalGroup/group_cipher.js +38 -24
- package/WASignalGroup/queue_job.js +69 -0
- package/WASignalGroup/sender_key_record.js +4 -2
- package/lib/Defaults/baileys-version.json +1 -1
- package/lib/Defaults/index.js +1 -1
- package/lib/Socket/Client/abstract-socket-client.d.ts +1 -0
- package/lib/Socket/business.d.ts +5 -3
- package/lib/Socket/chats.d.ts +6 -5
- package/lib/Socket/groups.d.ts +4 -2
- package/lib/Socket/groups.js +1 -1
- package/lib/Socket/index.d.ts +9 -7
- package/lib/Socket/messages-recv.d.ts +6 -3
- package/lib/Socket/messages-recv.js +79 -3
- package/lib/Socket/messages-send.d.ts +4 -2
- package/lib/Socket/messages-send.js +17 -8
- package/lib/Socket/registration.d.ts +6 -4
- package/lib/Socket/socket.d.ts +4 -3
- package/lib/Socket/socket.js +69 -9
- package/lib/Store/make-in-memory-store.d.ts +2 -2
- package/lib/Types/Auth.d.ts +19 -17
- package/lib/Types/Call.d.ts +2 -2
- package/lib/Types/Chat.d.ts +13 -13
- package/lib/Types/Events.d.ts +3 -3
- package/lib/Types/GroupMetadata.d.ts +4 -2
- package/lib/Types/LabelAssociation.d.ts +2 -2
- package/lib/Types/Message.d.ts +57 -45
- package/lib/Types/Product.d.ts +14 -14
- package/lib/Types/Signal.d.ts +10 -10
- package/lib/Types/Socket.d.ts +5 -4
- package/lib/Types/State.d.ts +2 -2
- package/lib/Types/index.d.ts +5 -5
- package/lib/Utils/auth-utils.js +3 -1
- package/lib/Utils/chat-utils.d.ts +4 -4
- package/lib/Utils/crypto.d.ts +3 -0
- package/lib/Utils/crypto.js +15 -1
- package/lib/Utils/event-buffer.d.ts +2 -2
- package/lib/Utils/event-buffer.js +3 -3
- package/lib/Utils/generics.d.ts +7 -6
- package/lib/Utils/generics.js +25 -27
- package/lib/Utils/link-preview.d.ts +1 -1
- package/lib/Utils/link-preview.js +1 -24
- package/lib/Utils/make-mutex.d.ts +1 -1
- package/lib/Utils/messages-media.d.ts +9 -3
- package/lib/Utils/messages-media.js +54 -6
- package/lib/Utils/messages.d.ts +6 -5
- package/lib/Utils/messages.js +37 -7
- package/lib/Utils/process-message.d.ts +2 -2
- package/lib/Utils/validate-connection.js +1 -2
- package/lib/WABinary/jid-utils.d.ts +4 -4
- package/lib/WABinary/types.d.ts +4 -4
- package/lib/index.d.ts +2 -1
- package/lib/index.js +2 -0
- package/package.json +6 -5
package/lib/Utils/generics.js
CHANGED
|
@@ -1,32 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
4
|
};
|
|
28
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.
|
|
6
|
+
exports.bytesToCrockford = exports.trimUndefined = exports.isWABusinessPlatform = exports.getCodeFromWSError = exports.getCallStatusFromNode = exports.getErrorCodeFromStreamError = exports.getStatusFromReceiptType = exports.generateMdTagPrefix = exports.fetchLatestWaWebVersion = exports.fetchLatestBaileysVersion = exports.printQRIfNecessaryListener = exports.bindWaitForConnectionUpdate = exports.bindWaitForEvent = exports.generateMessageID = exports.promiseTimeout = 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.Browsers = void 0;
|
|
30
7
|
const boom_1 = require("@hapi/boom");
|
|
31
8
|
const axios_1 = __importDefault(require("axios"));
|
|
32
9
|
const crypto_1 = require("crypto");
|
|
@@ -203,7 +180,9 @@ exports.bindWaitForConnectionUpdate = bindWaitForConnectionUpdate;
|
|
|
203
180
|
const printQRIfNecessaryListener = (ev, logger) => {
|
|
204
181
|
ev.on('connection.update', async ({ qr }) => {
|
|
205
182
|
if (qr) {
|
|
206
|
-
const QR = await
|
|
183
|
+
const QR = await import('qrcode-terminal')
|
|
184
|
+
.then(m => m.default || m)
|
|
185
|
+
.catch(() => {
|
|
207
186
|
logger.error('QR code terminal not added as dependency');
|
|
208
187
|
});
|
|
209
188
|
QR === null || QR === void 0 ? void 0 : QR.generate(qr, { small: true });
|
|
@@ -357,7 +336,7 @@ const isWABusinessPlatform = (platform) => {
|
|
|
357
336
|
return platform === 'smbi' || platform === 'smba';
|
|
358
337
|
};
|
|
359
338
|
exports.isWABusinessPlatform = isWABusinessPlatform;
|
|
360
|
-
function
|
|
339
|
+
function trimUndefined(obj) {
|
|
361
340
|
for (const key in obj) {
|
|
362
341
|
if (typeof obj[key] === 'undefined') {
|
|
363
342
|
delete obj[key];
|
|
@@ -365,4 +344,23 @@ function trimUndefineds(obj) {
|
|
|
365
344
|
}
|
|
366
345
|
return obj;
|
|
367
346
|
}
|
|
368
|
-
exports.
|
|
347
|
+
exports.trimUndefined = trimUndefined;
|
|
348
|
+
const CROCKFORD_CHARACTERS = '123456789ABCDEFGHJKLMNPQRSTVWXYZ';
|
|
349
|
+
function bytesToCrockford(buffer) {
|
|
350
|
+
let value = 0;
|
|
351
|
+
let bitCount = 0;
|
|
352
|
+
const crockford = [];
|
|
353
|
+
for (let i = 0; i < buffer.length; i++) {
|
|
354
|
+
value = (value << 8) | (buffer[i] & 0xff);
|
|
355
|
+
bitCount += 8;
|
|
356
|
+
while (bitCount >= 5) {
|
|
357
|
+
crockford.push(CROCKFORD_CHARACTERS.charAt((value >>> (bitCount - 5)) & 31));
|
|
358
|
+
bitCount -= 5;
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
if (bitCount > 0) {
|
|
362
|
+
crockford.push(CROCKFORD_CHARACTERS.charAt((value << (5 - bitCount)) & 31));
|
|
363
|
+
}
|
|
364
|
+
return crockford.join('');
|
|
365
|
+
}
|
|
366
|
+
exports.bytesToCrockford = bytesToCrockford;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AxiosRequestConfig } from 'axios';
|
|
2
2
|
import { Logger } from 'pino';
|
|
3
3
|
import { WAMediaUploadFunction, WAUrlInfo } from '../Types';
|
|
4
|
-
export
|
|
4
|
+
export type URLGenerationOptions = {
|
|
5
5
|
thumbnailWidth: number;
|
|
6
6
|
fetchOpts: {
|
|
7
7
|
/** Timeout in ms */
|
|
@@ -1,27 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
3
|
exports.getUrlInfo = void 0;
|
|
27
4
|
const messages_1 = require("./messages");
|
|
@@ -48,7 +25,7 @@ const getUrlInfo = async (text, opts = {
|
|
|
48
25
|
// retries
|
|
49
26
|
const retries = 0;
|
|
50
27
|
const maxRetry = 5;
|
|
51
|
-
const { getLinkPreview } = await
|
|
28
|
+
const { getLinkPreview } = await import('link-preview-js');
|
|
52
29
|
let previewLink = text;
|
|
53
30
|
if (!text.startsWith('https://') && !text.startsWith('http://')) {
|
|
54
31
|
previewLink = 'https://' + previewLink;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export declare const makeMutex: () => {
|
|
2
2
|
mutex<T>(code: () => T | Promise<T>): Promise<T>;
|
|
3
3
|
};
|
|
4
|
-
export
|
|
4
|
+
export type Mutex = ReturnType<typeof makeMutex>;
|
|
5
5
|
export declare const makeKeyedMutex: () => {
|
|
6
6
|
mutex<T>(key: string, task: () => T | Promise<T>): Promise<T>;
|
|
7
7
|
};
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
/// <reference types="node" />
|
|
2
4
|
import { Boom } from '@hapi/boom';
|
|
3
5
|
import { AxiosRequestConfig } from 'axios';
|
|
4
6
|
import type { Logger } from 'pino';
|
|
@@ -24,9 +26,13 @@ export declare const generateProfilePicture: (mediaUpload: WAMediaUpload) => Pro
|
|
|
24
26
|
/** gets the SHA256 of the given media message */
|
|
25
27
|
export declare const mediaMessageSHA256B64: (message: WAMessageContent) => string | null | undefined;
|
|
26
28
|
export declare function getAudioDuration(buffer: Buffer | string | Readable): Promise<number | undefined>;
|
|
29
|
+
/**
|
|
30
|
+
referenced from and modifying https://github.com/wppconnect-team/wa-js/blob/main/src/chat/functions/prepareAudioWaveform.ts
|
|
31
|
+
*/
|
|
32
|
+
export declare function getAudioWaveform(buffer: Buffer | string | Readable, logger?: Logger): Promise<Uint8Array | undefined>;
|
|
27
33
|
export declare const toReadable: (buffer: Buffer) => Readable;
|
|
28
34
|
export declare const toBuffer: (stream: Readable) => Promise<Buffer>;
|
|
29
|
-
export declare const getStream: (item: WAMediaUpload, opts?: AxiosRequestConfig
|
|
35
|
+
export declare const getStream: (item: WAMediaUpload, opts?: AxiosRequestConfig) => Promise<{
|
|
30
36
|
readonly stream: Readable;
|
|
31
37
|
readonly type: "buffer";
|
|
32
38
|
} | {
|
|
@@ -52,7 +58,7 @@ export declare function generateThumbnail(file: string, mediaType: 'video' | 'im
|
|
|
52
58
|
export declare const getHttpStream: (url: string | URL, options?: AxiosRequestConfig & {
|
|
53
59
|
isStream?: true;
|
|
54
60
|
}) => Promise<Readable>;
|
|
55
|
-
|
|
61
|
+
type EncryptedStreamOptions = {
|
|
56
62
|
saveOriginalFileIfRequired?: boolean;
|
|
57
63
|
logger?: Logger;
|
|
58
64
|
opts?: AxiosRequestConfig;
|
|
@@ -67,7 +73,7 @@ export declare const encryptedStream: (media: WAMediaUpload, mediaType: MediaTyp
|
|
|
67
73
|
fileLength: number;
|
|
68
74
|
didSaveToTmpPath: boolean;
|
|
69
75
|
}>;
|
|
70
|
-
export
|
|
76
|
+
export type MediaDownloadOptions = {
|
|
71
77
|
startByte?: number;
|
|
72
78
|
endByte?: number;
|
|
73
79
|
options?: AxiosRequestConfig<any>;
|
|
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.getStatusCodeForMediaRetry = exports.decryptMediaRetryData = exports.decodeMediaRetryNode = exports.encryptMediaRetryRequest = exports.getWAUploadToServer = exports.extensionForMediaMessage = exports.downloadEncryptedContent = exports.downloadContentFromMessage = exports.getUrlFromDirectPath = exports.encryptedStream = exports.getHttpStream = exports.generateThumbnail = exports.getStream = exports.toBuffer = exports.toReadable = exports.getAudioDuration = exports.mediaMessageSHA256B64 = exports.generateProfilePicture = exports.encodeBase64EncodedStringForUpload = exports.extractImageThumb = exports.getMediaKeys = exports.hkdfInfoKey = void 0;
|
|
26
|
+
exports.getStatusCodeForMediaRetry = exports.decryptMediaRetryData = exports.decodeMediaRetryNode = exports.encryptMediaRetryRequest = exports.getWAUploadToServer = exports.extensionForMediaMessage = exports.downloadEncryptedContent = exports.downloadContentFromMessage = exports.getUrlFromDirectPath = exports.encryptedStream = exports.getHttpStream = exports.generateThumbnail = exports.getStream = exports.toBuffer = exports.toReadable = exports.getAudioWaveform = exports.getAudioDuration = exports.mediaMessageSHA256B64 = exports.generateProfilePicture = exports.encodeBase64EncodedStringForUpload = exports.extractImageThumb = exports.getMediaKeys = exports.hkdfInfoKey = void 0;
|
|
27
27
|
const boom_1 = require("@hapi/boom");
|
|
28
28
|
const child_process_1 = require("child_process");
|
|
29
29
|
const Crypto = __importStar(require("crypto"));
|
|
@@ -41,11 +41,13 @@ const getTmpFilesDirectory = () => (0, os_1.tmpdir)();
|
|
|
41
41
|
const getImageProcessingLibrary = async () => {
|
|
42
42
|
const [_jimp, sharp] = await Promise.all([
|
|
43
43
|
(async () => {
|
|
44
|
-
const jimp = await (
|
|
44
|
+
const jimp = await (import('jimp')
|
|
45
|
+
.catch(() => { }));
|
|
45
46
|
return jimp;
|
|
46
47
|
})(),
|
|
47
48
|
(async () => {
|
|
48
|
-
const sharp = await (
|
|
49
|
+
const sharp = await (import('sharp')
|
|
50
|
+
.catch(() => { }));
|
|
49
51
|
return sharp;
|
|
50
52
|
})()
|
|
51
53
|
]);
|
|
@@ -186,7 +188,7 @@ const mediaMessageSHA256B64 = (message) => {
|
|
|
186
188
|
};
|
|
187
189
|
exports.mediaMessageSHA256B64 = mediaMessageSHA256B64;
|
|
188
190
|
async function getAudioDuration(buffer) {
|
|
189
|
-
const musicMetadata = await
|
|
191
|
+
const musicMetadata = await import('music-metadata');
|
|
190
192
|
let metadata;
|
|
191
193
|
if (Buffer.isBuffer(buffer)) {
|
|
192
194
|
metadata = await musicMetadata.parseBuffer(buffer, undefined, { duration: true });
|
|
@@ -206,6 +208,48 @@ async function getAudioDuration(buffer) {
|
|
|
206
208
|
return metadata.format.duration;
|
|
207
209
|
}
|
|
208
210
|
exports.getAudioDuration = getAudioDuration;
|
|
211
|
+
/**
|
|
212
|
+
referenced from and modifying https://github.com/wppconnect-team/wa-js/blob/main/src/chat/functions/prepareAudioWaveform.ts
|
|
213
|
+
*/
|
|
214
|
+
async function getAudioWaveform(buffer, logger) {
|
|
215
|
+
try {
|
|
216
|
+
const audioDecode = (...args) => import('audio-decode').then(({ default: audioDecode }) => audioDecode(...args));
|
|
217
|
+
let audioData;
|
|
218
|
+
if (Buffer.isBuffer(buffer)) {
|
|
219
|
+
audioData = buffer;
|
|
220
|
+
}
|
|
221
|
+
else if (typeof buffer === 'string') {
|
|
222
|
+
const rStream = (0, fs_1.createReadStream)(buffer);
|
|
223
|
+
audioData = await (0, exports.toBuffer)(rStream);
|
|
224
|
+
}
|
|
225
|
+
else {
|
|
226
|
+
audioData = await (0, exports.toBuffer)(buffer);
|
|
227
|
+
}
|
|
228
|
+
const audioBuffer = await audioDecode(audioData);
|
|
229
|
+
const rawData = audioBuffer.getChannelData(0); // We only need to work with one channel of data
|
|
230
|
+
const samples = 64; // Number of samples we want to have in our final data set
|
|
231
|
+
const blockSize = Math.floor(rawData.length / samples); // the number of samples in each subdivision
|
|
232
|
+
const filteredData = [];
|
|
233
|
+
for (let i = 0; i < samples; i++) {
|
|
234
|
+
const blockStart = blockSize * i; // the location of the first sample in the block
|
|
235
|
+
let sum = 0;
|
|
236
|
+
for (let j = 0; j < blockSize; j++) {
|
|
237
|
+
sum = sum + Math.abs(rawData[blockStart + j]); // find the sum of all the samples in the block
|
|
238
|
+
}
|
|
239
|
+
filteredData.push(sum / blockSize); // divide the sum by the block size to get the average
|
|
240
|
+
}
|
|
241
|
+
// This guarantees that the largest data point will be set to 1, and the rest of the data will scale proportionally.
|
|
242
|
+
const multiplier = Math.pow(Math.max(...filteredData), -1);
|
|
243
|
+
const normalizedData = filteredData.map((n) => n * multiplier);
|
|
244
|
+
// Generate waveform like WhatsApp
|
|
245
|
+
const waveform = new Uint8Array(normalizedData.map((n) => Math.floor(100 * n)));
|
|
246
|
+
return waveform;
|
|
247
|
+
}
|
|
248
|
+
catch (e) {
|
|
249
|
+
logger === null || logger === void 0 ? void 0 : logger.debug('Failed to generate waveform: ' + e);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
exports.getAudioWaveform = getAudioWaveform;
|
|
209
253
|
const toReadable = (buffer) => {
|
|
210
254
|
const readable = new stream_1.Readable({ read: () => { } });
|
|
211
255
|
readable.push(buffer);
|
|
@@ -269,7 +313,7 @@ async function generateThumbnail(file, mediaType, options) {
|
|
|
269
313
|
}
|
|
270
314
|
exports.generateThumbnail = generateThumbnail;
|
|
271
315
|
const getHttpStream = async (url, options = {}) => {
|
|
272
|
-
const { default: axios } = await
|
|
316
|
+
const { default: axios } = await import('axios');
|
|
273
317
|
const fetched = await axios.get(url.toString(), { ...options, responseType: 'stream' });
|
|
274
318
|
return fetched.data;
|
|
275
319
|
};
|
|
@@ -481,7 +525,7 @@ exports.extensionForMediaMessage = extensionForMediaMessage;
|
|
|
481
525
|
const getWAUploadToServer = ({ customUploadHosts, fetchAgent, logger, options }, refreshMediaConn) => {
|
|
482
526
|
return async (stream, { mediaType, fileEncSha256B64, timeoutMs }) => {
|
|
483
527
|
var _a, _b;
|
|
484
|
-
const { default: axios } = await
|
|
528
|
+
const { default: axios } = await import('axios');
|
|
485
529
|
// send a query JSON to obtain the url & auth token to upload our media
|
|
486
530
|
let uploadInfo = await refreshMediaConn(false);
|
|
487
531
|
let urls;
|
|
@@ -630,3 +674,7 @@ const MEDIA_RETRY_STATUS_MAP = {
|
|
|
630
674
|
[WAProto_1.proto.MediaRetryNotification.ResultType.NOT_FOUND]: 404,
|
|
631
675
|
[WAProto_1.proto.MediaRetryNotification.ResultType.GENERAL_ERROR]: 418,
|
|
632
676
|
};
|
|
677
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
678
|
+
function __importStar(arg0) {
|
|
679
|
+
throw new Error('Function not implemented.');
|
|
680
|
+
}
|
package/lib/Utils/messages.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
2
3
|
import { Logger } from 'pino';
|
|
3
4
|
import { proto } from '../../WAProto';
|
|
4
5
|
import { AnyMediaMessageContent, AnyMessageContent, MediaGenerationOptions, MessageContentGenerationOptions, MessageGenerationOptions, MessageGenerationOptionsFromContent, MessageUserReceipt, WAMessage, WAMessageContent, WAProto } from '../Types';
|
|
@@ -11,13 +12,13 @@ import { MediaDownloadOptions } from './messages-media';
|
|
|
11
12
|
export declare const extractUrlFromText: (text: string) => string | undefined;
|
|
12
13
|
export declare const generateLinkPreviewIfRequired: (text: string, getUrlInfo: MessageGenerationOptions['getUrlInfo'], logger: MessageGenerationOptions['logger']) => Promise<import("../Types").WAUrlInfo | undefined>;
|
|
13
14
|
export declare const prepareWAMessageMedia: (message: AnyMediaMessageContent, options: MediaGenerationOptions) => Promise<proto.Message>;
|
|
14
|
-
export declare const prepareDisappearingMessageSettingContent: (ephemeralExpiration?: number
|
|
15
|
+
export declare const prepareDisappearingMessageSettingContent: (ephemeralExpiration?: number) => proto.Message;
|
|
15
16
|
/**
|
|
16
17
|
* Generate forwarded message content like WA does
|
|
17
18
|
* @param message the message to forward
|
|
18
19
|
* @param options.forceForward will show the message as forwarded even if it is from you
|
|
19
20
|
*/
|
|
20
|
-
export declare const generateForwardMessageContent: (message: WAMessage, forceForward?: boolean
|
|
21
|
+
export declare const generateForwardMessageContent: (message: WAMessage, forceForward?: boolean) => proto.IMessage;
|
|
21
22
|
export declare const generateWAMessageContent: (message: AnyMessageContent, options: MessageContentGenerationOptions) => Promise<proto.Message>;
|
|
22
23
|
export declare const generateWAMessageFromContent: (jid: string, message: WAMessageContent, options: MessageGenerationOptionsFromContent) => proto.WebMessageInfo;
|
|
23
24
|
export declare const generateWAMessage: (jid: string, content: AnyMessageContent, options: MessageGenerationOptions) => Promise<proto.WebMessageInfo>;
|
|
@@ -45,7 +46,7 @@ export declare const updateMessageWithReceipt: (msg: Pick<WAMessage, 'userReceip
|
|
|
45
46
|
export declare const updateMessageWithReaction: (msg: Pick<WAMessage, 'reactions'>, reaction: proto.IReaction) => void;
|
|
46
47
|
/** Update the message with a new poll update */
|
|
47
48
|
export declare const updateMessageWithPollUpdate: (msg: Pick<WAMessage, 'pollUpdates'>, update: proto.IPollUpdate) => void;
|
|
48
|
-
|
|
49
|
+
type VoteAggregation = {
|
|
49
50
|
name: string;
|
|
50
51
|
voters: string[];
|
|
51
52
|
};
|
|
@@ -62,14 +63,14 @@ export declare const aggregateMessageKeysNotFromMe: (keys: proto.IMessageKey[])
|
|
|
62
63
|
participant: string | undefined;
|
|
63
64
|
messageIds: string[];
|
|
64
65
|
}[];
|
|
65
|
-
|
|
66
|
+
type DownloadMediaMessageContext = {
|
|
66
67
|
reuploadRequest: (msg: WAMessage) => Promise<WAMessage>;
|
|
67
68
|
logger: Logger;
|
|
68
69
|
};
|
|
69
70
|
/**
|
|
70
71
|
* Downloads the given message. Throws an error if it's not a media message
|
|
71
72
|
*/
|
|
72
|
-
export declare const downloadMediaMessage: (message: WAMessage, type: 'buffer' | 'stream', options: MediaDownloadOptions, ctx?: DownloadMediaMessageContext
|
|
73
|
+
export declare const downloadMediaMessage: (message: WAMessage, type: 'buffer' | 'stream', options: MediaDownloadOptions, ctx?: DownloadMediaMessageContext) => Promise<Buffer | import("stream").Transform>;
|
|
73
74
|
/** Checks whether the given message is a media message; if it is returns the inner content */
|
|
74
75
|
export declare const assertMediaContent: (content: proto.IMessage | null | undefined) => proto.Message.IVideoMessage | proto.Message.IImageMessage | proto.Message.IAudioMessage | proto.Message.IDocumentMessage | proto.Message.IStickerMessage;
|
|
75
76
|
export {};
|
package/lib/Utils/messages.js
CHANGED
|
@@ -54,6 +54,20 @@ const generateLinkPreviewIfRequired = async (text, getUrlInfo, logger) => {
|
|
|
54
54
|
}
|
|
55
55
|
};
|
|
56
56
|
exports.generateLinkPreviewIfRequired = generateLinkPreviewIfRequired;
|
|
57
|
+
const assertColor = async (color) => {
|
|
58
|
+
let assertedColor;
|
|
59
|
+
if (typeof color === 'number') {
|
|
60
|
+
assertedColor = color > 0 ? color : 0xffffffff + Number(color) + 1;
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
let hex = color.trim().replace('#', '');
|
|
64
|
+
if (hex.length <= 6) {
|
|
65
|
+
hex = 'FF' + hex.padStart(6, '0');
|
|
66
|
+
}
|
|
67
|
+
assertedColor = parseInt(hex, 16);
|
|
68
|
+
return assertedColor;
|
|
69
|
+
}
|
|
70
|
+
};
|
|
57
71
|
const prepareWAMessageMedia = async (message, options) => {
|
|
58
72
|
const logger = options.logger;
|
|
59
73
|
let mediaType;
|
|
@@ -97,6 +111,8 @@ const prepareWAMessageMedia = async (message, options) => {
|
|
|
97
111
|
const requiresDurationComputation = mediaType === 'audio' && typeof uploadData.seconds === 'undefined';
|
|
98
112
|
const requiresThumbnailComputation = (mediaType === 'image' || mediaType === 'video') &&
|
|
99
113
|
(typeof uploadData['jpegThumbnail'] === 'undefined');
|
|
114
|
+
const requiresWaveformProcessing = mediaType === 'audio' && uploadData.ptt === 'true' || true;
|
|
115
|
+
const requiresAudioBackground = options.backgroundColor && mediaType === 'audio' && uploadData.ptt === 'true' || true;
|
|
100
116
|
const requiresOriginalForSomeProcessing = requiresDurationComputation || requiresThumbnailComputation;
|
|
101
117
|
const { mediaKey, encWriteStream, bodyPath, fileEncSha256, fileSha256, fileLength, didSaveToTmpPath } = await (0, messages_media_1.encryptedStream)(uploadData.media, options.mediaTypeOverride || mediaType, {
|
|
102
118
|
logger,
|
|
@@ -127,6 +143,18 @@ const prepareWAMessageMedia = async (message, options) => {
|
|
|
127
143
|
uploadData.seconds = await (0, messages_media_1.getAudioDuration)(bodyPath);
|
|
128
144
|
logger === null || logger === void 0 ? void 0 : logger.debug('computed audio duration');
|
|
129
145
|
}
|
|
146
|
+
if (requiresWaveformProcessing) {
|
|
147
|
+
uploadData.waveform = await (0, messages_media_1.getAudioWaveform)(bodyPath, logger);
|
|
148
|
+
logger === null || logger === void 0 ? void 0 : logger.debug('processed waveform');
|
|
149
|
+
}
|
|
150
|
+
if (requiresWaveformProcessing) {
|
|
151
|
+
uploadData.waveform = await (0, messages_media_1.getAudioWaveform)(bodyPath, logger);
|
|
152
|
+
logger === null || logger === void 0 ? void 0 : logger.debug('processed waveform');
|
|
153
|
+
}
|
|
154
|
+
if (requiresAudioBackground) {
|
|
155
|
+
uploadData.backgroundArgb = await assertColor(options.backgroundColor);
|
|
156
|
+
logger === null || logger === void 0 ? void 0 : logger.debug('computed backgroundColor audio status');
|
|
157
|
+
}
|
|
130
158
|
}
|
|
131
159
|
catch (error) {
|
|
132
160
|
logger === null || logger === void 0 ? void 0 : logger.warn({ trace: error.stack }, 'failed to obtain extra info');
|
|
@@ -235,6 +263,12 @@ const generateWAMessageContent = async (message, options) => {
|
|
|
235
263
|
extContent.thumbnailEncSha256 = img.fileEncSha256;
|
|
236
264
|
}
|
|
237
265
|
}
|
|
266
|
+
if (options.backgroundColor) {
|
|
267
|
+
extContent.backgroundArgb = await assertColor(options.backgroundColor);
|
|
268
|
+
}
|
|
269
|
+
if (options.font) {
|
|
270
|
+
extContent.font = options.font;
|
|
271
|
+
}
|
|
238
272
|
m.extendedTextMessage = extContent;
|
|
239
273
|
}
|
|
240
274
|
else if ('contacts' in message) {
|
|
@@ -394,6 +428,7 @@ const generateWAMessageContent = async (message, options) => {
|
|
|
394
428
|
protocolMessage: {
|
|
395
429
|
key: message.edit,
|
|
396
430
|
editedMessage: m,
|
|
431
|
+
timestampMs: Date.now(),
|
|
397
432
|
type: Types_1.WAProto.Message.ProtocolMessage.Type.MESSAGE_EDIT
|
|
398
433
|
}
|
|
399
434
|
};
|
|
@@ -431,7 +466,7 @@ const generateWAMessageFromContent = (jid, message, options) => {
|
|
|
431
466
|
contextInfo.quotedMessage = quotedMsg;
|
|
432
467
|
// if a participant is quoted, then it must be a group
|
|
433
468
|
// hence, remoteJid of group must also be entered
|
|
434
|
-
if (quoted.key.
|
|
469
|
+
if (jid !== quoted.key.remoteJid) {
|
|
435
470
|
contextInfo.remoteJid = quoted.key.remoteJid;
|
|
436
471
|
}
|
|
437
472
|
message[key].contextInfo = contextInfo;
|
|
@@ -454,11 +489,6 @@ const generateWAMessageFromContent = (jid, message, options) => {
|
|
|
454
489
|
expiration: options.ephemeralExpiration || Defaults_1.WA_DEFAULT_EPHEMERAL,
|
|
455
490
|
//ephemeralSettingTimestamp: options.ephemeralOptions.eph_setting_ts?.toString()
|
|
456
491
|
};
|
|
457
|
-
message = {
|
|
458
|
-
ephemeralMessage: {
|
|
459
|
-
message
|
|
460
|
-
}
|
|
461
|
-
};
|
|
462
492
|
}
|
|
463
493
|
message = Types_1.WAProto.Message.fromObject(message);
|
|
464
494
|
const messageJSON = {
|
|
@@ -470,7 +500,7 @@ const generateWAMessageFromContent = (jid, message, options) => {
|
|
|
470
500
|
message: message,
|
|
471
501
|
messageTimestamp: timestamp,
|
|
472
502
|
messageStubParameters: [],
|
|
473
|
-
participant: (0, WABinary_1.isJidGroup)(jid) ? userJid : undefined,
|
|
503
|
+
participant: (0, WABinary_1.isJidGroup)(jid) || (0, WABinary_1.isJidStatusBroadcast)(jid) ? userJid : undefined,
|
|
474
504
|
status: Types_1.WAMessageStatus.PENDING
|
|
475
505
|
};
|
|
476
506
|
return Types_1.WAProto.WebMessageInfo.fromObject(messageJSON);
|
|
@@ -2,7 +2,7 @@ import { AxiosRequestConfig } from 'axios';
|
|
|
2
2
|
import type { Logger } from 'pino';
|
|
3
3
|
import { proto } from '../../WAProto';
|
|
4
4
|
import { AuthenticationCreds, BaileysEventEmitter, SignalKeyStoreWithTransaction, SocketConfig } from '../Types';
|
|
5
|
-
|
|
5
|
+
type ProcessMessageContext = {
|
|
6
6
|
shouldProcessHistoryMsg: boolean;
|
|
7
7
|
creds: AuthenticationCreds;
|
|
8
8
|
keyStore: SignalKeyStoreWithTransaction;
|
|
@@ -20,7 +20,7 @@ export declare const shouldIncrementChatUnread: (message: proto.IWebMessageInfo)
|
|
|
20
20
|
* Typically -- that'll be the remoteJid, but for broadcasts, it'll be the participant
|
|
21
21
|
*/
|
|
22
22
|
export declare const getChatId: ({ remoteJid, participant, fromMe }: proto.IMessageKey) => string;
|
|
23
|
-
|
|
23
|
+
type PollContext = {
|
|
24
24
|
/** normalised jid of the person that created the poll */
|
|
25
25
|
pollCreatorJid: string;
|
|
26
26
|
/** ID of the poll creation message */
|
|
@@ -180,9 +180,8 @@ const encodeSignedDeviceIdentity = (account, includeSignatureKey) => {
|
|
|
180
180
|
if (!includeSignatureKey || !((_a = account.accountSignatureKey) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
181
181
|
account.accountSignatureKey = null;
|
|
182
182
|
}
|
|
183
|
-
|
|
183
|
+
return WAProto_1.proto.ADVSignedDeviceIdentity
|
|
184
184
|
.encode(account)
|
|
185
185
|
.finish();
|
|
186
|
-
return accountEnc;
|
|
187
186
|
};
|
|
188
187
|
exports.encodeSignedDeviceIdentity = encodeSignedDeviceIdentity;
|
|
@@ -3,16 +3,16 @@ export declare const OFFICIAL_BIZ_JID = "16505361212@c.us";
|
|
|
3
3
|
export declare const SERVER_JID = "server@c.us";
|
|
4
4
|
export declare const PSA_WID = "0@c.us";
|
|
5
5
|
export declare const STORIES_JID = "status@broadcast";
|
|
6
|
-
export
|
|
7
|
-
export
|
|
6
|
+
export type JidServer = 'c.us' | 'g.us' | 'broadcast' | 's.whatsapp.net' | 'call';
|
|
7
|
+
export type JidWithDevice = {
|
|
8
8
|
user: string;
|
|
9
9
|
device?: number;
|
|
10
10
|
};
|
|
11
|
-
export
|
|
11
|
+
export type FullJid = JidWithDevice & {
|
|
12
12
|
server: JidServer | string;
|
|
13
13
|
agent?: number;
|
|
14
14
|
};
|
|
15
|
-
export declare const jidEncode: (user: string | number | null, server: JidServer, device?: number
|
|
15
|
+
export declare const jidEncode: (user: string | number | null, server: JidServer, device?: number, agent?: number) => string;
|
|
16
16
|
export declare const jidDecode: (jid: string | undefined) => FullJid | undefined;
|
|
17
17
|
/** is the jid a user */
|
|
18
18
|
export declare const areJidsSameUser: (jid1: string | undefined, jid2: string | undefined) => boolean;
|
package/lib/WABinary/types.d.ts
CHANGED
|
@@ -6,13 +6,13 @@ import * as constants from './constants';
|
|
|
6
6
|
* This is done for easy serialization, to prevent running into issues with prototypes &
|
|
7
7
|
* to maintain functional code structure
|
|
8
8
|
* */
|
|
9
|
-
export
|
|
9
|
+
export type BinaryNode = {
|
|
10
10
|
tag: string;
|
|
11
11
|
attrs: {
|
|
12
12
|
[key: string]: string;
|
|
13
13
|
};
|
|
14
14
|
content?: BinaryNode[] | string | Uint8Array;
|
|
15
15
|
};
|
|
16
|
-
export
|
|
17
|
-
export
|
|
18
|
-
export
|
|
16
|
+
export type BinaryNodeAttributes = BinaryNode['attrs'];
|
|
17
|
+
export type BinaryNodeData = BinaryNode['content'];
|
|
18
|
+
export type BinaryNodeCodingOptions = typeof constants;
|
package/lib/index.d.ts
CHANGED
|
@@ -5,5 +5,6 @@ export * from './Types';
|
|
|
5
5
|
export * from './Store';
|
|
6
6
|
export * from './Defaults';
|
|
7
7
|
export * from './WABinary';
|
|
8
|
-
export
|
|
8
|
+
export type WASocket = ReturnType<typeof makeWASocket>;
|
|
9
|
+
export { makeWASocket };
|
|
9
10
|
export default makeWASocket;
|
package/lib/index.js
CHANGED
|
@@ -17,7 +17,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
17
17
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
18
|
};
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.makeWASocket = void 0;
|
|
20
21
|
const Socket_1 = __importDefault(require("./Socket"));
|
|
22
|
+
exports.makeWASocket = Socket_1.default;
|
|
21
23
|
__exportStar(require("../WAProto"), exports);
|
|
22
24
|
__exportStar(require("./Utils"), exports);
|
|
23
25
|
__exportStar(require("./Types"), exports);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@d0v3riz/baileys",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.4.0",
|
|
4
4
|
"description": "WhatsApp API",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"whatsapp",
|
|
@@ -34,8 +34,8 @@
|
|
|
34
34
|
"changelog:update": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0",
|
|
35
35
|
"example": "node --inspect -r ts-node/register Example/example.ts",
|
|
36
36
|
"gen:protobuf": "sh WAProto/GenerateStatics.sh",
|
|
37
|
-
"lint": "eslint
|
|
38
|
-
"lint:fix": "eslint
|
|
37
|
+
"lint": "eslint src --ext .js,.ts,.jsx,.tsx",
|
|
38
|
+
"lint:fix": "eslint src --fix --ext .js,.ts,.jsx,.tsx",
|
|
39
39
|
"prepack": "tsc",
|
|
40
40
|
"prepare": "tsc",
|
|
41
41
|
"release": "release-it",
|
|
@@ -44,6 +44,7 @@
|
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"@adiwajshing/keyed-db": "^0.2.4",
|
|
46
46
|
"@hapi/boom": "^9.1.3",
|
|
47
|
+
"audio-decode": "^2.1.3",
|
|
47
48
|
"axios": "^1.3.3",
|
|
48
49
|
"cache-manager": "^5.2.2",
|
|
49
50
|
"futoin-hkdf": "^1.5.1",
|
|
@@ -57,7 +58,7 @@
|
|
|
57
58
|
"ws": "^8.13.0"
|
|
58
59
|
},
|
|
59
60
|
"devDependencies": {
|
|
60
|
-
"@adiwajshing/eslint-config": "
|
|
61
|
+
"@adiwajshing/eslint-config": "github:adiwajshing/eslint-config",
|
|
61
62
|
"@types/got": "^9.6.11",
|
|
62
63
|
"@types/jest": "^27.5.1",
|
|
63
64
|
"@types/node": "^16.0.0",
|
|
@@ -74,7 +75,7 @@
|
|
|
74
75
|
"ts-jest": "^27.0.3",
|
|
75
76
|
"ts-node": "^10.8.1",
|
|
76
77
|
"typedoc": "^0.24.7",
|
|
77
|
-
"typescript": "^4.
|
|
78
|
+
"typescript": "^4.6.4"
|
|
78
79
|
},
|
|
79
80
|
"peerDependencies": {
|
|
80
81
|
"jimp": "^0.16.1",
|