@d0v3riz/baileys 6.7.7 → 6.7.8
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 +0 -10
- package/lib/Defaults/index.d.ts +1 -231
- package/lib/Defaults/index.js +1 -17
- package/lib/Socket/Client/index.d.ts +2 -3
- package/lib/Socket/Client/index.js +2 -3
- 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 +3 -1
- package/lib/Socket/chats.d.ts +4 -1
- package/lib/Socket/chats.js +39 -11
- package/lib/Socket/groups.d.ts +3 -1
- package/lib/Socket/index.d.ts +12 -12
- package/lib/Socket/index.js +2 -2
- package/lib/Socket/messages-recv.d.ts +4 -2
- package/lib/Socket/messages-recv.js +126 -117
- package/lib/Socket/messages-send.d.ts +3 -1
- package/lib/Socket/messages-send.js +23 -8
- package/lib/Socket/socket.d.ts +3 -1
- package/lib/Socket/socket.js +9 -14
- package/lib/Store/make-cache-manager-store.d.ts +2 -1
- package/lib/Store/make-in-memory-store.js +8 -10
- package/lib/Store/make-ordered-dictionary.js +2 -2
- package/lib/Types/Auth.d.ts +1 -6
- package/lib/Types/Call.d.ts +1 -1
- package/lib/Types/Chat.d.ts +10 -7
- package/lib/Types/Contact.d.ts +1 -1
- package/lib/Types/Events.d.ts +4 -0
- package/lib/Types/Label.d.ts +11 -0
- package/lib/Types/Message.d.ts +5 -2
- package/lib/Types/Socket.d.ts +3 -3
- package/lib/Utils/auth-utils.js +1 -7
- package/lib/Utils/chat-utils.d.ts +5 -4
- package/lib/Utils/chat-utils.js +41 -20
- package/lib/Utils/crypto.d.ts +1 -0
- package/lib/Utils/decode-wa-message.js +1 -0
- package/lib/Utils/event-buffer.js +14 -8
- package/lib/Utils/generics.d.ts +10 -5
- package/lib/Utils/generics.js +35 -7
- package/lib/Utils/history.d.ts +2 -2
- package/lib/Utils/history.js +1 -1
- package/lib/Utils/link-preview.js +24 -1
- package/lib/Utils/make-mutex.js +1 -0
- package/lib/Utils/messages-media.d.ts +2 -1
- package/lib/Utils/messages-media.js +8 -15
- package/lib/Utils/messages.d.ts +1 -0
- package/lib/Utils/messages.js +7 -11
- package/lib/Utils/noise-handler.d.ts +2 -2
- package/lib/Utils/noise-handler.js +5 -10
- package/lib/Utils/process-message.js +3 -1
- package/lib/Utils/signal.js +2 -0
- package/lib/Utils/use-multi-file-auth-state.js +1 -0
- package/lib/Utils/validate-connection.d.ts +0 -1
- package/lib/Utils/validate-connection.js +10 -44
- package/lib/WABinary/constants.js +5 -5
- package/lib/WABinary/decode.d.ts +1 -0
- package/lib/WABinary/encode.d.ts +1 -0
- package/lib/WABinary/encode.js +7 -5
- package/lib/WABinary/generic-utils.d.ts +1 -0
- package/lib/WABinary/jid-utils.d.ts +2 -2
- package/lib/WABinary/jid-utils.js +1 -1
- package/lib/WAM/BinaryInfo.d.ts +3 -2
- package/lib/WAM/constants.d.ts +3 -2
- package/lib/WAM/encode.d.ts +1 -0
- package/lib/WAM/encode.js +2 -2
- package/package.json +5 -6
- package/lib/Defaults/phonenumber-mcc.json +0 -223
- package/lib/Socket/Client/mobile-socket-client.d.ts +0 -13
- package/lib/Socket/Client/mobile-socket-client.js +0 -65
- package/lib/Socket/registration.d.ts +0 -241
- package/lib/Socket/registration.js +0 -166
- /package/lib/Socket/Client/{abstract-socket-client.d.ts → types.d.ts} +0 -0
- /package/lib/Socket/Client/{abstract-socket-client.js → types.js} +0 -0
package/lib/Types/Events.d.ts
CHANGED
|
@@ -22,6 +22,7 @@ export type BaileysEventMap = {
|
|
|
22
22
|
isLatest?: boolean;
|
|
23
23
|
progress?: number | null;
|
|
24
24
|
syncType?: proto.HistorySync.HistorySyncType;
|
|
25
|
+
peerDataRequestSessionId?: string | null;
|
|
25
26
|
};
|
|
26
27
|
/** upsert chats */
|
|
27
28
|
'chats.upsert': Chat[];
|
|
@@ -117,6 +118,9 @@ export type BufferedEventData = {
|
|
|
117
118
|
};
|
|
118
119
|
empty: boolean;
|
|
119
120
|
isLatest: boolean;
|
|
121
|
+
progress?: number | null;
|
|
122
|
+
syncType?: proto.HistorySync.HistorySyncType;
|
|
123
|
+
peerDataRequestSessionId?: string;
|
|
120
124
|
};
|
|
121
125
|
chatUpserts: {
|
|
122
126
|
[jid: string]: Chat;
|
package/lib/Types/Label.d.ts
CHANGED
|
@@ -10,6 +10,17 @@ export interface Label {
|
|
|
10
10
|
/** WhatsApp has 5 predefined labels (New customer, New order & etc) */
|
|
11
11
|
predefinedId?: string;
|
|
12
12
|
}
|
|
13
|
+
export interface LabelActionBody {
|
|
14
|
+
id: string;
|
|
15
|
+
/** Label name */
|
|
16
|
+
name?: string;
|
|
17
|
+
/** Label color ID */
|
|
18
|
+
color?: number;
|
|
19
|
+
/** Is label has been deleted */
|
|
20
|
+
deleted?: boolean;
|
|
21
|
+
/** WhatsApp has 5 predefined labels (New customer, New order & etc) */
|
|
22
|
+
predefinedId?: number;
|
|
23
|
+
}
|
|
13
24
|
/** WhatsApp has 20 predefined colors */
|
|
14
25
|
export declare enum LabelColor {
|
|
15
26
|
Color1 = 0,
|
package/lib/Types/Message.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
/// <reference types="node" />
|
|
3
3
|
/// <reference types="node" />
|
|
4
|
+
/// <reference types="node" />
|
|
4
5
|
import { AxiosRequestConfig } from 'axios';
|
|
5
6
|
import type { Logger } from 'pino';
|
|
6
7
|
import type { Readable } from 'stream';
|
|
@@ -22,11 +23,13 @@ export type WALocationMessage = proto.Message.ILocationMessage;
|
|
|
22
23
|
export type WAGenericMediaMessage = proto.Message.IVideoMessage | proto.Message.IImageMessage | proto.Message.IAudioMessage | proto.Message.IDocumentMessage | proto.Message.IStickerMessage;
|
|
23
24
|
export import WAMessageStubType = proto.WebMessageInfo.StubType;
|
|
24
25
|
export import WAMessageStatus = proto.WebMessageInfo.Status;
|
|
25
|
-
export type
|
|
26
|
+
export type WAMediaPayloadURL = {
|
|
26
27
|
url: URL | string;
|
|
27
|
-
}
|
|
28
|
+
};
|
|
29
|
+
export type WAMediaPayloadStream = {
|
|
28
30
|
stream: Readable;
|
|
29
31
|
};
|
|
32
|
+
export type WAMediaUpload = Buffer | WAMediaPayloadStream | WAMediaPayloadURL;
|
|
30
33
|
/** Set of message types that are supported by the library */
|
|
31
34
|
export type MessageType = keyof proto.Message;
|
|
32
35
|
export type DownloadableMessage = {
|
package/lib/Types/Socket.d.ts
CHANGED
|
@@ -30,7 +30,9 @@ export type SocketConfig = {
|
|
|
30
30
|
defaultQueryTimeoutMs: number | undefined;
|
|
31
31
|
/** ping-pong interval for WS connection */
|
|
32
32
|
keepAliveIntervalMs: number;
|
|
33
|
-
/** should baileys use the mobile api instead of the multi device api
|
|
33
|
+
/** should baileys use the mobile api instead of the multi device api
|
|
34
|
+
* @deprecated This feature has been removed
|
|
35
|
+
*/
|
|
34
36
|
mobile?: boolean;
|
|
35
37
|
/** proxy agent */
|
|
36
38
|
agent?: Agent;
|
|
@@ -111,6 +113,4 @@ export type SocketConfig = {
|
|
|
111
113
|
/** cached group metadata, use to prevent redundant requests to WA & speed up msg sending */
|
|
112
114
|
cachedGroupMetadata: (jid: string) => Promise<GroupMetadata | undefined>;
|
|
113
115
|
makeSignalRepository: (auth: SignalAuthState) => SignalRepository;
|
|
114
|
-
/** Socket passthrough */
|
|
115
|
-
socket?: any;
|
|
116
116
|
};
|
package/lib/Utils/auth-utils.js
CHANGED
|
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.initAuthCreds = exports.addTransactionCapability = exports.makeCacheableSignalKeyStore = void 0;
|
|
7
7
|
const crypto_1 = require("crypto");
|
|
8
8
|
const node_cache_1 = __importDefault(require("node-cache"));
|
|
9
|
-
const uuid_1 = require("uuid");
|
|
10
9
|
const Defaults_1 = require("../Defaults");
|
|
11
10
|
const crypto_2 = require("./crypto");
|
|
12
11
|
const generics_1 = require("./generics");
|
|
@@ -143,6 +142,7 @@ const addTransactionCapability = (state, logger, { maxCommitRetries, delayBetwee
|
|
|
143
142
|
let tries = maxCommitRetries;
|
|
144
143
|
while (tries) {
|
|
145
144
|
tries -= 1;
|
|
145
|
+
//eslint-disable-next-line max-depth
|
|
146
146
|
try {
|
|
147
147
|
await state.set(mutations);
|
|
148
148
|
logger.trace({ dbQueriesInTransaction }, 'committed transaction');
|
|
@@ -191,13 +191,7 @@ const initAuthCreds = () => {
|
|
|
191
191
|
accountSettings: {
|
|
192
192
|
unarchiveChats: false
|
|
193
193
|
},
|
|
194
|
-
// mobile creds
|
|
195
|
-
deviceId: Buffer.from((0, uuid_1.v4)().replace(/-/g, ''), 'hex').toString('base64url'),
|
|
196
|
-
phoneId: (0, uuid_1.v4)(),
|
|
197
|
-
identityId: (0, crypto_1.randomBytes)(20),
|
|
198
194
|
registered: false,
|
|
199
|
-
backupToken: (0, crypto_1.randomBytes)(20),
|
|
200
|
-
registration: {},
|
|
201
195
|
pairingCode: undefined,
|
|
202
196
|
lastPropHash: undefined,
|
|
203
197
|
routingInfo: undefined,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
2
3
|
import { AxiosRequestConfig } from 'axios';
|
|
3
4
|
import type { Logger } from 'pino';
|
|
4
5
|
import { proto } from '../../WAProto';
|
|
@@ -29,7 +30,7 @@ export declare const decodeSyncdPatch: (msg: proto.ISyncdPatch, name: WAPatchNam
|
|
|
29
30
|
};
|
|
30
31
|
};
|
|
31
32
|
}>;
|
|
32
|
-
export declare const extractSyncdPatches: (result: BinaryNode, options: AxiosRequestConfig<
|
|
33
|
+
export declare const extractSyncdPatches: (result: BinaryNode, options: AxiosRequestConfig<{}>) => Promise<{
|
|
33
34
|
critical_block: {
|
|
34
35
|
patches: proto.ISyncdPatch[];
|
|
35
36
|
hasMorePatches: boolean;
|
|
@@ -56,13 +57,13 @@ export declare const extractSyncdPatches: (result: BinaryNode, options: AxiosReq
|
|
|
56
57
|
snapshot?: proto.ISyncdSnapshot | undefined;
|
|
57
58
|
};
|
|
58
59
|
}>;
|
|
59
|
-
export declare const downloadExternalBlob: (blob: proto.IExternalBlobReference, options: AxiosRequestConfig<
|
|
60
|
-
export declare const downloadExternalPatch: (blob: proto.IExternalBlobReference, options: AxiosRequestConfig<
|
|
60
|
+
export declare const downloadExternalBlob: (blob: proto.IExternalBlobReference, options: AxiosRequestConfig<{}>) => Promise<Buffer>;
|
|
61
|
+
export declare const downloadExternalPatch: (blob: proto.IExternalBlobReference, options: AxiosRequestConfig<{}>) => Promise<proto.SyncdMutations>;
|
|
61
62
|
export declare const decodeSyncdSnapshot: (name: WAPatchName, snapshot: proto.ISyncdSnapshot, getAppStateSyncKey: FetchAppStateSyncKey, minimumVersionNumber: number | undefined, validateMacs?: boolean) => Promise<{
|
|
62
63
|
state: LTHashState;
|
|
63
64
|
mutationMap: ChatMutationMap;
|
|
64
65
|
}>;
|
|
65
|
-
export declare const decodePatches: (name: WAPatchName, syncds: proto.ISyncdPatch[], initial: LTHashState, getAppStateSyncKey: FetchAppStateSyncKey, options: AxiosRequestConfig<
|
|
66
|
+
export declare const decodePatches: (name: WAPatchName, syncds: proto.ISyncdPatch[], initial: LTHashState, getAppStateSyncKey: FetchAppStateSyncKey, options: AxiosRequestConfig<{}>, minimumVersionNumber?: number, logger?: Logger, validateMacs?: boolean) => Promise<{
|
|
66
67
|
state: LTHashState;
|
|
67
68
|
mutationMap: ChatMutationMap;
|
|
68
69
|
}>;
|
package/lib/Utils/chat-utils.js
CHANGED
|
@@ -305,8 +305,7 @@ const decodePatches = async (name, syncds, initial, getAppStateSyncKey, options,
|
|
|
305
305
|
indexValueMap: { ...initial.indexValueMap }
|
|
306
306
|
};
|
|
307
307
|
const mutationMap = {};
|
|
308
|
-
for (
|
|
309
|
-
const syncd = syncds[i];
|
|
308
|
+
for (const syncd of syncds) {
|
|
310
309
|
const { version, keyId, snapshotMac } = syncd;
|
|
311
310
|
if (syncd.externalMutations) {
|
|
312
311
|
logger === null || logger === void 0 ? void 0 : logger.trace({ name, version }, 'downloading external patch');
|
|
@@ -418,25 +417,31 @@ const chatModificationToAppPatch = (mod, jid) => {
|
|
|
418
417
|
operation: OP.SET
|
|
419
418
|
};
|
|
420
419
|
}
|
|
420
|
+
else if ('deleteForMe' in mod) {
|
|
421
|
+
const { timestamp, key, deleteMedia } = mod.deleteForMe;
|
|
422
|
+
patch = {
|
|
423
|
+
syncAction: {
|
|
424
|
+
deleteMessageForMeAction: {
|
|
425
|
+
deleteMedia,
|
|
426
|
+
messageTimestamp: timestamp
|
|
427
|
+
}
|
|
428
|
+
},
|
|
429
|
+
index: ['deleteMessageForMe', jid, key.id, key.fromMe ? '1' : '0', '0'],
|
|
430
|
+
type: 'regular_high',
|
|
431
|
+
apiVersion: 3,
|
|
432
|
+
operation: OP.SET
|
|
433
|
+
};
|
|
434
|
+
}
|
|
421
435
|
else if ('clear' in mod) {
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
messageTimestamp: key.timestamp
|
|
432
|
-
}
|
|
433
|
-
},
|
|
434
|
-
index: ['deleteMessageForMe', jid, key.id, key.fromMe ? '1' : '0', '0'],
|
|
435
|
-
type: 'regular_high',
|
|
436
|
-
apiVersion: 3,
|
|
437
|
-
operation: OP.SET
|
|
438
|
-
};
|
|
439
|
-
}
|
|
436
|
+
patch = {
|
|
437
|
+
syncAction: {
|
|
438
|
+
clearChatAction: {} // add message range later
|
|
439
|
+
},
|
|
440
|
+
index: ['clearChat', jid, '1' /*the option here is 0 when keep starred messages is enabled*/, '0'],
|
|
441
|
+
type: 'regular_high',
|
|
442
|
+
apiVersion: 6,
|
|
443
|
+
operation: OP.SET
|
|
444
|
+
};
|
|
440
445
|
}
|
|
441
446
|
else if ('pin' in mod) {
|
|
442
447
|
patch = {
|
|
@@ -491,6 +496,22 @@ const chatModificationToAppPatch = (mod, jid) => {
|
|
|
491
496
|
operation: OP.SET,
|
|
492
497
|
};
|
|
493
498
|
}
|
|
499
|
+
else if ('addLabel' in mod) {
|
|
500
|
+
patch = {
|
|
501
|
+
syncAction: {
|
|
502
|
+
labelEditAction: {
|
|
503
|
+
name: mod.addLabel.name,
|
|
504
|
+
color: mod.addLabel.color,
|
|
505
|
+
predefinedId: mod.addLabel.predefinedId,
|
|
506
|
+
deleted: mod.addLabel.deleted
|
|
507
|
+
}
|
|
508
|
+
},
|
|
509
|
+
index: ['label_edit', mod.addLabel.id],
|
|
510
|
+
type: 'regular',
|
|
511
|
+
apiVersion: 3,
|
|
512
|
+
operation: OP.SET,
|
|
513
|
+
};
|
|
514
|
+
}
|
|
494
515
|
else if ('addChatLabel' in mod) {
|
|
495
516
|
patch = {
|
|
496
517
|
syncAction: {
|
package/lib/Utils/crypto.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
2
3
|
import { KeyPair } from '../Types';
|
|
3
4
|
/** prefix version byte to the pub keys, required for some curve crypto functions */
|
|
4
5
|
export declare const generateSignalPubKey: (pubKey: Uint8Array | Buffer) => Uint8Array | Buffer;
|
|
@@ -153,6 +153,7 @@ const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
|
|
|
153
153
|
let msg = WAProto_1.proto.Message.decode(e2eType !== 'plaintext' ? (0, generics_1.unpadRandomMax16)(msgBuffer) : msgBuffer);
|
|
154
154
|
msg = ((_a = msg.deviceSentMessage) === null || _a === void 0 ? void 0 : _a.message) || msg;
|
|
155
155
|
if (msg.senderKeyDistributionMessage) {
|
|
156
|
+
//eslint-disable-next-line max-depth
|
|
156
157
|
try {
|
|
157
158
|
await repository.processSenderKeyDistributionMessage({
|
|
158
159
|
authorJid: author,
|
|
@@ -138,7 +138,9 @@ const makeBufferData = () => {
|
|
|
138
138
|
groupUpdates: {}
|
|
139
139
|
};
|
|
140
140
|
};
|
|
141
|
-
function append(data, historyCache, event,
|
|
141
|
+
function append(data, historyCache, event,
|
|
142
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
143
|
+
eventData, logger) {
|
|
142
144
|
var _a, _b, _c;
|
|
143
145
|
switch (event) {
|
|
144
146
|
case 'messaging-history.set':
|
|
@@ -176,6 +178,9 @@ function append(data, historyCache, event, eventData, logger) {
|
|
|
176
178
|
}
|
|
177
179
|
}
|
|
178
180
|
data.historySets.empty = false;
|
|
181
|
+
data.historySets.syncType = eventData.syncType;
|
|
182
|
+
data.historySets.progress = eventData.progress;
|
|
183
|
+
data.historySets.peerDataRequestSessionId = eventData.peerDataRequestSessionId;
|
|
179
184
|
data.historySets.isLatest = eventData.isLatest || data.historySets.isLatest;
|
|
180
185
|
break;
|
|
181
186
|
case 'chats.upsert':
|
|
@@ -442,7 +447,10 @@ function consolidateEvents(data) {
|
|
|
442
447
|
chats: Object.values(data.historySets.chats),
|
|
443
448
|
messages: Object.values(data.historySets.messages),
|
|
444
449
|
contacts: Object.values(data.historySets.contacts),
|
|
445
|
-
|
|
450
|
+
syncType: data.historySets.syncType,
|
|
451
|
+
progress: data.historySets.progress,
|
|
452
|
+
isLatest: data.historySets.isLatest,
|
|
453
|
+
peerDataRequestSessionId: data.historySets.peerDataRequestSessionId
|
|
446
454
|
};
|
|
447
455
|
}
|
|
448
456
|
const chatUpsertList = Object.values(data.chatUpserts);
|
|
@@ -496,12 +504,10 @@ function consolidateEvents(data) {
|
|
|
496
504
|
return map;
|
|
497
505
|
}
|
|
498
506
|
function concatChats(a, b) {
|
|
499
|
-
if (b.unreadCount === null
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
b.unreadCount = undefined;
|
|
504
|
-
}
|
|
507
|
+
if (b.unreadCount === null && // neutralize unread counter
|
|
508
|
+
a.unreadCount < 0) {
|
|
509
|
+
a.unreadCount = undefined;
|
|
510
|
+
b.unreadCount = undefined;
|
|
505
511
|
}
|
|
506
512
|
if (typeof a.unreadCount === 'number' && typeof b.unreadCount === 'number') {
|
|
507
513
|
b = { ...b };
|
package/lib/Utils/generics.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
2
3
|
import { AxiosRequestConfig } from 'axios';
|
|
3
4
|
import { Logger } from 'pino';
|
|
4
5
|
import { proto } from '../../WAProto';
|
|
5
|
-
import { BaileysEventEmitter, BaileysEventMap, BrowsersMap, WACallUpdateType, WAVersion } from '../Types';
|
|
6
|
+
import { BaileysEventEmitter, BaileysEventMap, BrowsersMap, ConnectionState, WACallUpdateType, WAVersion } from '../Types';
|
|
6
7
|
import { BinaryNode } from '../WABinary';
|
|
7
8
|
export declare const Browsers: BrowsersMap;
|
|
8
9
|
export declare const getPlatformId: (browser: string) => any;
|
|
@@ -35,13 +36,13 @@ export declare function promiseTimeout<T>(ms: number | undefined, promise: (reso
|
|
|
35
36
|
export declare const generateMessageIDV2: (userId?: string) => string;
|
|
36
37
|
export declare const generateMessageID: () => string;
|
|
37
38
|
export declare function bindWaitForEvent<T extends keyof BaileysEventMap>(ev: BaileysEventEmitter, event: T): (check: (u: BaileysEventMap[T]) => boolean | undefined, timeoutMs?: number) => Promise<void>;
|
|
38
|
-
export declare const bindWaitForConnectionUpdate: (ev: BaileysEventEmitter) => (check: (u: Partial<
|
|
39
|
+
export declare const bindWaitForConnectionUpdate: (ev: BaileysEventEmitter) => (check: (u: Partial<ConnectionState>) => boolean | undefined, timeoutMs?: number) => Promise<void>;
|
|
39
40
|
export declare const printQRIfNecessaryListener: (ev: BaileysEventEmitter, logger: Logger) => void;
|
|
40
41
|
/**
|
|
41
42
|
* utility that fetches latest baileys version from the master branch.
|
|
42
43
|
* Use to ensure your WA connection is always on the latest version
|
|
43
44
|
*/
|
|
44
|
-
export declare const fetchLatestBaileysVersion: (options?: AxiosRequestConfig<
|
|
45
|
+
export declare const fetchLatestBaileysVersion: (options?: AxiosRequestConfig<{}>) => Promise<{
|
|
45
46
|
version: WAVersion;
|
|
46
47
|
isLatest: boolean;
|
|
47
48
|
error?: undefined;
|
|
@@ -54,7 +55,7 @@ export declare const fetchLatestBaileysVersion: (options?: AxiosRequestConfig<an
|
|
|
54
55
|
* A utility that fetches the latest web version of whatsapp.
|
|
55
56
|
* Use to ensure your WA connection is always on the latest version
|
|
56
57
|
*/
|
|
57
|
-
export declare const fetchLatestWaWebVersion: (options: AxiosRequestConfig<
|
|
58
|
+
export declare const fetchLatestWaWebVersion: (options: AxiosRequestConfig<{}>) => Promise<{
|
|
58
59
|
version: WAVersion;
|
|
59
60
|
isLatest: boolean;
|
|
60
61
|
error?: undefined;
|
|
@@ -85,5 +86,9 @@ export declare const getCodeFromWSError: (error: Error) => number;
|
|
|
85
86
|
* @param platform AuthenticationCreds.platform
|
|
86
87
|
*/
|
|
87
88
|
export declare const isWABusinessPlatform: (platform: string) => boolean;
|
|
88
|
-
export declare function trimUndefined(obj:
|
|
89
|
+
export declare function trimUndefined(obj: {
|
|
90
|
+
[_: string]: any;
|
|
91
|
+
}): {
|
|
92
|
+
[_: string]: any;
|
|
93
|
+
};
|
|
89
94
|
export declare function bytesToCrockford(buffer: Buffer): string;
|
package/lib/Utils/generics.js
CHANGED
|
@@ -1,4 +1,27 @@
|
|
|
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
|
+
};
|
|
2
25
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
27
|
};
|
|
@@ -35,12 +58,14 @@ const getPlatformId = (browser) => {
|
|
|
35
58
|
};
|
|
36
59
|
exports.getPlatformId = getPlatformId;
|
|
37
60
|
exports.BufferJSON = {
|
|
61
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
38
62
|
replacer: (k, value) => {
|
|
39
63
|
if (Buffer.isBuffer(value) || value instanceof Uint8Array || (value === null || value === void 0 ? void 0 : value.type) === 'Buffer') {
|
|
40
64
|
return { type: 'Buffer', data: Buffer.from((value === null || value === void 0 ? void 0 : value.data) || value).toString('base64') };
|
|
41
65
|
}
|
|
42
66
|
return value;
|
|
43
67
|
},
|
|
68
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
44
69
|
reviver: (_, value) => {
|
|
45
70
|
if (typeof value === 'object' && !!value && (value.buffer === true || value.type === 'Buffer')) {
|
|
46
71
|
const val = value.data || value.value;
|
|
@@ -88,7 +113,7 @@ const encodeBigEndian = (e, t = 4) => {
|
|
|
88
113
|
return a;
|
|
89
114
|
};
|
|
90
115
|
exports.encodeBigEndian = encodeBigEndian;
|
|
91
|
-
const toNumber = (t) => ((typeof t === 'object' && t) ? ('toNumber' in t ? t.toNumber() : t.low) : t);
|
|
116
|
+
const toNumber = (t) => ((typeof t === 'object' && t) ? ('toNumber' in t ? t.toNumber() : t.low) : t || 0);
|
|
92
117
|
exports.toNumber = toNumber;
|
|
93
118
|
/** unix timestamp of a date in seconds */
|
|
94
119
|
const unixTimestampSeconds = (date = new Date()) => Math.floor(date.getTime() / 1000);
|
|
@@ -207,8 +232,7 @@ exports.bindWaitForConnectionUpdate = bindWaitForConnectionUpdate;
|
|
|
207
232
|
const printQRIfNecessaryListener = (ev, logger) => {
|
|
208
233
|
ev.on('connection.update', async ({ qr }) => {
|
|
209
234
|
if (qr) {
|
|
210
|
-
const QR = await
|
|
211
|
-
.then(m => m.default || m)
|
|
235
|
+
const QR = await Promise.resolve().then(() => __importStar(require('qrcode-terminal'))).then(m => m.default || m)
|
|
212
236
|
.catch(() => {
|
|
213
237
|
logger.error('QR code terminal not added as dependency');
|
|
214
238
|
});
|
|
@@ -322,7 +346,8 @@ const getCallStatusFromNode = ({ tag, attrs }) => {
|
|
|
322
346
|
status = 'timeout';
|
|
323
347
|
}
|
|
324
348
|
else {
|
|
325
|
-
|
|
349
|
+
//fired when accepted/rejected/timeout/caller hangs up
|
|
350
|
+
status = 'terminate';
|
|
326
351
|
}
|
|
327
352
|
break;
|
|
328
353
|
case 'reject':
|
|
@@ -348,7 +373,9 @@ const getCodeFromWSError = (error) => {
|
|
|
348
373
|
statusCode = code;
|
|
349
374
|
}
|
|
350
375
|
}
|
|
351
|
-
else if (
|
|
376
|
+
else if (
|
|
377
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
378
|
+
((_b = error === null || error === void 0 ? void 0 : error.code) === null || _b === void 0 ? void 0 : _b.startsWith('E'))
|
|
352
379
|
|| ((_c = error === null || error === void 0 ? void 0 : error.message) === null || _c === void 0 ? void 0 : _c.includes('timed out'))) { // handle ETIMEOUT, ENOTFOUND etc
|
|
353
380
|
statusCode = 408;
|
|
354
381
|
}
|
|
@@ -363,6 +390,7 @@ const isWABusinessPlatform = (platform) => {
|
|
|
363
390
|
return platform === 'smbi' || platform === 'smba';
|
|
364
391
|
};
|
|
365
392
|
exports.isWABusinessPlatform = isWABusinessPlatform;
|
|
393
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
366
394
|
function trimUndefined(obj) {
|
|
367
395
|
for (const key in obj) {
|
|
368
396
|
if (typeof obj[key] === 'undefined') {
|
|
@@ -377,8 +405,8 @@ function bytesToCrockford(buffer) {
|
|
|
377
405
|
let value = 0;
|
|
378
406
|
let bitCount = 0;
|
|
379
407
|
const crockford = [];
|
|
380
|
-
for (
|
|
381
|
-
value = (value << 8) | (
|
|
408
|
+
for (const element of buffer) {
|
|
409
|
+
value = (value << 8) | (element & 0xff);
|
|
382
410
|
bitCount += 8;
|
|
383
411
|
while (bitCount >= 5) {
|
|
384
412
|
crockford.push(CROCKFORD_CHARACTERS.charAt((value >>> (bitCount - 5)) & 31));
|
package/lib/Utils/history.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
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[];
|
|
@@ -9,7 +9,7 @@ export declare const processHistoryMessage: (item: proto.IHistorySync) => {
|
|
|
9
9
|
syncType: proto.HistorySync.HistorySyncType;
|
|
10
10
|
progress: number | null | undefined;
|
|
11
11
|
};
|
|
12
|
-
export declare const downloadAndProcessHistorySyncNotification: (msg: proto.Message.IHistorySyncNotification, options: AxiosRequestConfig<
|
|
12
|
+
export declare const downloadAndProcessHistorySyncNotification: (msg: proto.Message.IHistorySyncNotification, options: AxiosRequestConfig<{}>) => Promise<{
|
|
13
13
|
chats: Chat[];
|
|
14
14
|
contacts: Contact[];
|
|
15
15
|
messages: proto.IWebMessageInfo[];
|
package/lib/Utils/history.js
CHANGED
|
@@ -1,4 +1,27 @@
|
|
|
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
|
+
};
|
|
2
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
26
|
exports.getUrlInfo = void 0;
|
|
4
27
|
const messages_1 = require("./messages");
|
|
@@ -25,7 +48,7 @@ const getUrlInfo = async (text, opts = {
|
|
|
25
48
|
// retries
|
|
26
49
|
const retries = 0;
|
|
27
50
|
const maxRetry = 5;
|
|
28
|
-
const { getLinkPreview } = await
|
|
51
|
+
const { getLinkPreview } = await Promise.resolve().then(() => __importStar(require('link-preview-js')));
|
|
29
52
|
let previewLink = text;
|
|
30
53
|
if (!text.startsWith('https://') && !text.startsWith('http://')) {
|
|
31
54
|
previewLink = 'https://' + previewLink;
|
package/lib/Utils/make-mutex.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.makeKeyedMutex = exports.makeMutex = void 0;
|
|
4
4
|
const makeMutex = () => {
|
|
5
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
5
6
|
let task = Promise.resolve();
|
|
6
7
|
let taskTimeout;
|
|
7
8
|
return {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
/// <reference types="node" />
|
|
3
3
|
/// <reference types="node" />
|
|
4
|
+
/// <reference types="node" />
|
|
4
5
|
import { Boom } from '@hapi/boom';
|
|
5
6
|
import { AxiosRequestConfig } from 'axios';
|
|
6
7
|
import type { Logger } from 'pino';
|
|
@@ -76,7 +77,7 @@ export declare const encryptedStream: (media: WAMediaUpload, mediaType: MediaTyp
|
|
|
76
77
|
export type MediaDownloadOptions = {
|
|
77
78
|
startByte?: number;
|
|
78
79
|
endByte?: number;
|
|
79
|
-
options?: AxiosRequestConfig<
|
|
80
|
+
options?: AxiosRequestConfig<{}>;
|
|
80
81
|
};
|
|
81
82
|
export declare const getUrlFromDirectPath: (directPath: string) => string;
|
|
82
83
|
export declare const downloadContentFromMessage: ({ mediaKey, directPath, url }: DownloadableMessage, type: MediaType, opts?: MediaDownloadOptions) => Promise<Transform>;
|
|
@@ -45,13 +45,11 @@ const getTmpFilesDirectory = () => (0, os_1.tmpdir)();
|
|
|
45
45
|
const getImageProcessingLibrary = async () => {
|
|
46
46
|
const [_jimp, sharp] = await Promise.all([
|
|
47
47
|
(async () => {
|
|
48
|
-
const jimp = await (
|
|
49
|
-
.catch(() => { }));
|
|
48
|
+
const jimp = await (Promise.resolve().then(() => __importStar(require('jimp'))).catch(() => { }));
|
|
50
49
|
return jimp;
|
|
51
50
|
})(),
|
|
52
51
|
(async () => {
|
|
53
|
-
const sharp = await (
|
|
54
|
-
.catch(() => { }));
|
|
52
|
+
const sharp = await (Promise.resolve().then(() => __importStar(require('sharp'))).catch(() => { }));
|
|
55
53
|
return sharp;
|
|
56
54
|
})()
|
|
57
55
|
]);
|
|
@@ -192,7 +190,7 @@ const mediaMessageSHA256B64 = (message) => {
|
|
|
192
190
|
};
|
|
193
191
|
exports.mediaMessageSHA256B64 = mediaMessageSHA256B64;
|
|
194
192
|
async function getAudioDuration(buffer) {
|
|
195
|
-
const musicMetadata = await
|
|
193
|
+
const musicMetadata = await Promise.resolve().then(() => __importStar(require('music-metadata')));
|
|
196
194
|
let metadata;
|
|
197
195
|
if (Buffer.isBuffer(buffer)) {
|
|
198
196
|
metadata = await musicMetadata.parseBuffer(buffer, undefined, { duration: true });
|
|
@@ -217,7 +215,7 @@ exports.getAudioDuration = getAudioDuration;
|
|
|
217
215
|
*/
|
|
218
216
|
async function getAudioWaveform(buffer, logger) {
|
|
219
217
|
try {
|
|
220
|
-
const audioDecode = (buffer) =>
|
|
218
|
+
const audioDecode = (buffer) => Promise.resolve().then(() => __importStar(require('audio-decode'))).then(({ default: audioDecode }) => audioDecode(buffer));
|
|
221
219
|
let audioData;
|
|
222
220
|
if (Buffer.isBuffer(buffer)) {
|
|
223
221
|
audioData = buffer;
|
|
@@ -331,7 +329,7 @@ const encryptedStream = async (media, mediaType, { logger, saveOriginalFileIfReq
|
|
|
331
329
|
let writeStream;
|
|
332
330
|
let didSaveToTmpPath = false;
|
|
333
331
|
if (type === 'file') {
|
|
334
|
-
bodyPath = media.url;
|
|
332
|
+
bodyPath = media.url.toString();
|
|
335
333
|
}
|
|
336
334
|
else if (saveOriginalFileIfRequired) {
|
|
337
335
|
bodyPath = (0, path_1.join)(getTmpFilesDirectory(), mediaType + (0, generics_1.generateMessageID)());
|
|
@@ -354,10 +352,8 @@ const encryptedStream = async (media, mediaType, { logger, saveOriginalFileIfReq
|
|
|
354
352
|
});
|
|
355
353
|
}
|
|
356
354
|
sha256Plain = sha256Plain.update(data);
|
|
357
|
-
if (writeStream) {
|
|
358
|
-
|
|
359
|
-
await (0, events_1.once)(writeStream, 'drain');
|
|
360
|
-
}
|
|
355
|
+
if (writeStream && !writeStream.write(data)) {
|
|
356
|
+
await (0, events_1.once)(writeStream, 'drain');
|
|
361
357
|
}
|
|
362
358
|
onChunk(aes.update(data));
|
|
363
359
|
}
|
|
@@ -537,6 +533,7 @@ const getWAUploadToServer = ({ customUploadHosts, fetchAgent, logger, options },
|
|
|
537
533
|
logger.debug(`uploading to "${hostname}"`);
|
|
538
534
|
const auth = encodeURIComponent(uploadInfo.auth); // the auth token
|
|
539
535
|
const url = `https://${hostname}${Defaults_1.MEDIA_PATH_MAP[mediaType]}/${fileEncSha256B64}?auth=${auth}&token=${fileEncSha256B64}`;
|
|
536
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
540
537
|
let result;
|
|
541
538
|
try {
|
|
542
539
|
const body = await axios_1.default.post(url, stream, {
|
|
@@ -668,7 +665,3 @@ const MEDIA_RETRY_STATUS_MAP = {
|
|
|
668
665
|
[WAProto_1.proto.MediaRetryNotification.ResultType.NOT_FOUND]: 404,
|
|
669
666
|
[WAProto_1.proto.MediaRetryNotification.ResultType.GENERAL_ERROR]: 418,
|
|
670
667
|
};
|
|
671
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
672
|
-
function __importStar(arg0) {
|
|
673
|
-
throw new Error('Function not implemented.');
|
|
674
|
-
}
|
package/lib/Utils/messages.d.ts
CHANGED
package/lib/Utils/messages.js
CHANGED
|
@@ -699,17 +699,13 @@ const downloadMediaMessage = async (message, type, options, ctx) => {
|
|
|
699
699
|
const result = await downloadMsg()
|
|
700
700
|
.catch(async (error) => {
|
|
701
701
|
var _a;
|
|
702
|
-
if (ctx)
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
const result = await downloadMsg();
|
|
710
|
-
return result;
|
|
711
|
-
}
|
|
712
|
-
}
|
|
702
|
+
if (ctx && axios_1.default.isAxiosError(error) && // check if the message requires a reupload
|
|
703
|
+
REUPLOAD_REQUIRED_STATUS.includes((_a = error.response) === null || _a === void 0 ? void 0 : _a.status)) {
|
|
704
|
+
ctx.logger.info({ key: message.key }, 'sending reupload media request...');
|
|
705
|
+
// request reupload
|
|
706
|
+
message = await ctx.reuploadRequest(message);
|
|
707
|
+
const result = await downloadMsg();
|
|
708
|
+
return result;
|
|
713
709
|
}
|
|
714
710
|
throw error;
|
|
715
711
|
});
|