@rizzxdc/baileys 8.0.10 → 8.1.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/LICENSE +4 -2
- package/README.md +107 -245
- package/WAProto/index.d.ts +15795 -0
- package/WAProto/index.js +25587 -4867
- package/lib/Defaults/index.d.ts +147 -0
- package/lib/Defaults/index.js +134 -104
- package/lib/Signal/Group/ciphertext-message.d.ts +10 -0
- package/lib/Signal/Group/ciphertext-message.js +9 -11
- package/lib/Signal/Group/group-session-builder.d.ts +8 -0
- package/lib/Signal/Group/group-session-builder.js +5 -8
- package/lib/Signal/Group/group_cipher.d.ts +11 -0
- package/lib/Signal/Group/group_cipher.js +72 -75
- package/lib/Signal/Group/index.d.ts +12 -0
- package/lib/Signal/Group/index.js +11 -13
- package/lib/Signal/Group/keyhelper.d.ts +7 -0
- package/lib/Signal/Group/keyhelper.js +11 -14
- package/lib/Signal/Group/sender-chain-key.d.ts +14 -0
- package/lib/Signal/Group/sender-chain-key.js +23 -26
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +17 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +58 -61
- package/lib/Signal/Group/sender-key-message.d.ts +19 -0
- package/lib/Signal/Group/sender-key-message.js +61 -64
- package/lib/Signal/Group/sender-key-name.d.ts +12 -0
- package/lib/Signal/Group/sender-key-name.js +39 -44
- package/lib/Signal/Group/sender-key-record.d.ts +13 -0
- package/lib/Signal/Group/sender-key-record.js +35 -38
- package/lib/Signal/Group/sender-key-state.d.ts +17 -0
- package/lib/Signal/Group/sender-key-state.js +76 -79
- package/lib/Signal/Group/sender-message-key.d.ts +12 -0
- package/lib/Signal/Group/sender-message-key.js +23 -26
- package/lib/Signal/libsignal.d.ts +55 -0
- package/lib/Signal/libsignal.js +414 -308
- package/lib/Signal/lid-mapping.d.ts +21 -0
- package/lib/Signal/lid-mapping.js +270 -149
- package/lib/Socket/Client/index.d.ts +3 -0
- package/lib/Socket/Client/index.js +2 -4
- package/lib/Socket/Client/types.d.ts +6 -0
- package/lib/Socket/Client/types.js +8 -11
- package/lib/Socket/Client/websocket.d.ts +13 -0
- package/lib/Socket/Client/websocket.js +51 -50
- package/lib/Socket/business.d.ts +395 -0
- package/lib/Socket/business.js +357 -355
- package/lib/Socket/chats.d.ts +137 -0
- package/lib/Socket/chats.js +1195 -867
- package/lib/Socket/communities.d.ts +562 -0
- package/lib/Socket/communities.js +416 -398
- package/lib/Socket/dugong.js +8 -1
- package/lib/Socket/groups.d.ts +286 -0
- package/lib/Socket/groups.js +336 -301
- package/lib/Socket/index.d.ts +530 -0
- package/lib/Socket/index.js +8 -13
- package/lib/Socket/messages-recv.d.ts +334 -0
- package/lib/Socket/messages-recv.js +1729 -1121
- package/lib/Socket/messages-send.d.ts +330 -0
- package/lib/Socket/messages-send.js +684 -462
- package/lib/Socket/mex.d.ts +2 -0
- package/lib/Socket/mex.js +36 -40
- package/lib/Socket/newsletter.d.ts +284 -0
- package/lib/Socket/newsletter.js +247 -237
- package/lib/Socket/socket.d.ts +61 -0
- package/lib/Socket/socket.js +968 -790
- package/lib/Store/index.d.ts +4 -0
- package/lib/Store/index.js +4 -6
- package/lib/Store/make-cache-manager-store.js +2 -2
- package/lib/Store/make-in-memory-store.d.ts +63 -0
- package/lib/Store/make-in-memory-store.js +414 -284
- package/lib/Store/make-ordered-dictionary.d.ts +13 -0
- package/lib/Store/make-ordered-dictionary.js +75 -76
- package/lib/Store/object-repository.d.ts +11 -0
- package/lib/Store/object-repository.js +21 -23
- package/lib/Types/Auth.d.ts +2 -0
- package/lib/Types/Auth.js +0 -2
- package/lib/Types/Bussines.d.ts +2 -0
- package/lib/Types/Bussines.js +0 -2
- package/lib/Types/Call.d.ts +2 -0
- package/lib/Types/Call.js +0 -2
- package/lib/Types/Chat.d.ts +2 -0
- package/lib/Types/Chat.js +5 -7
- package/lib/Types/Contact.d.ts +2 -0
- package/lib/Types/Contact.js +0 -2
- package/lib/Types/Events.d.ts +2 -0
- package/lib/Types/Events.js +1 -3
- package/lib/Types/GroupMetadata.d.ts +2 -0
- package/lib/Types/GroupMetadata.js +0 -2
- package/lib/Types/Label.d.ts +3 -0
- package/lib/Types/Label.js +21 -22
- package/lib/Types/LabelAssociation.d.ts +3 -0
- package/lib/Types/LabelAssociation.js +3 -4
- package/lib/Types/Message.d.ts +12 -0
- package/lib/Types/Message.js +11 -6
- package/lib/Types/Mex.d.ts +3 -0
- package/lib/Types/Mex.js +38 -0
- package/lib/Types/Product.d.ts +2 -0
- package/lib/Types/Product.js +0 -2
- package/lib/Types/RichType.d.ts +3 -0
- package/lib/Types/RichType.js +22 -0
- package/lib/Types/Signal.d.ts +2 -0
- package/lib/Types/Signal.js +1 -3
- package/lib/Types/Socket.d.ts +2 -0
- package/lib/Types/Socket.js +1 -4
- package/lib/Types/State.d.ts +6 -0
- package/lib/Types/State.js +52 -8
- package/lib/Types/USync.d.ts +2 -0
- package/lib/Types/USync.js +1 -3
- package/lib/Types/index.d.ts +14 -0
- package/lib/Types/index.js +22 -25
- package/lib/Utils/auth-utils.d.ts +58 -0
- package/lib/Utils/auth-utils.js +285 -203
- package/lib/Utils/browser-utils.d.ts +9 -0
- package/lib/Utils/browser-utils.js +21 -19
- package/lib/Utils/business.d.ts +50 -0
- package/lib/Utils/business.js +206 -209
- package/lib/Utils/chat-utils.d.ts +409 -0
- package/lib/Utils/chat-utils.js +825 -706
- package/lib/Utils/companion-reg-client-utils.d.ts +5 -0
- package/lib/Utils/companion-reg-client-utils.js +39 -0
- package/lib/Utils/crypto.d.ts +40 -0
- package/lib/Utils/crypto.js +88 -101
- package/lib/Utils/decode-wa-message.d.ts +84 -0
- package/lib/Utils/decode-wa-message.js +287 -238
- package/lib/Utils/event-buffer.d.ts +13 -0
- package/lib/Utils/event-buffer.js +602 -509
- package/lib/Utils/generics.d.ts +64 -0
- package/lib/Utils/generics.js +334 -295
- package/lib/Utils/history.d.ts +76 -0
- package/lib/Utils/history.js +125 -79
- package/lib/Utils/identity-change-handler.d.ts +14 -0
- package/lib/Utils/identity-change-handler.js +49 -0
- package/lib/Utils/index.d.ts +25 -0
- package/lib/Utils/index.js +25 -21
- package/lib/Utils/link-preview.d.ts +13 -0
- package/lib/Utils/link-preview.js +73 -70
- package/lib/Utils/logger.d.ts +3 -0
- package/lib/Utils/logger.js +1 -4
- package/lib/Utils/lt-hash.d.ts +7 -0
- package/lib/Utils/lt-hash.js +7 -45
- package/lib/Utils/make-mutex.d.ts +7 -0
- package/lib/Utils/make-mutex.js +27 -31
- package/lib/Utils/message-retry-manager.d.ts +80 -0
- package/lib/Utils/message-retry-manager.js +165 -14
- package/lib/Utils/messages-media.d.ts +137 -0
- package/lib/Utils/messages-media.js +768 -572
- package/lib/Utils/messages.d.ts +46 -0
- package/lib/Utils/messages.js +1082 -130
- package/lib/Utils/noise-handler.d.ts +21 -0
- package/lib/Utils/noise-handler.js +191 -135
- package/lib/Utils/offline-node-processor.d.ts +10 -0
- package/lib/Utils/offline-node-processor.js +39 -0
- package/lib/Utils/pre-key-manager.d.ts +26 -0
- package/lib/Utils/pre-key-manager.js +96 -76
- package/lib/Utils/process-message.d.ts +84 -0
- package/lib/Utils/process-message.js +718 -311
- package/lib/Utils/reporting-utils.d.ts +13 -0
- package/lib/Utils/reporting-utils.js +257 -0
- package/lib/Utils/rich-message-utils.d.ts +49 -0
- package/lib/Utils/rich-message-utils.js +257 -0
- package/lib/Utils/signal.d.ts +83 -0
- package/lib/Utils/signal.js +174 -135
- package/lib/Utils/stanza-ack.d.ts +17 -0
- package/lib/Utils/stanza-ack.js +37 -0
- package/lib/Utils/sync-action-utils.d.ts +3 -0
- package/lib/Utils/sync-action-utils.js +48 -0
- package/lib/Utils/tc-token-utils.d.ts +30 -0
- package/lib/Utils/tc-token-utils.js +162 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts +11 -0
- package/lib/Utils/use-multi-file-auth-state.js +104 -95
- package/lib/Utils/use-single-file-auth-state.d.ts +11 -0
- package/lib/Utils/use-single-file-auth-state.js +108 -0
- package/lib/Utils/use-sqlite-auth-state.d.ts +11 -0
- package/lib/Utils/use-sqlite-auth-state.js +108 -0
- package/lib/Utils/validate-connection.d.ts +44 -0
- package/lib/Utils/validate-connection.js +182 -180
- package/lib/WABinary/constants.d.ts +62 -0
- package/lib/WABinary/constants.js +1455 -1292
- package/lib/WABinary/decode.d.ts +10 -0
- package/lib/WABinary/decode.js +249 -228
- package/lib/WABinary/encode.d.ts +3 -0
- package/lib/WABinary/encode.js +207 -206
- package/lib/WABinary/generic-utils.d.ts +77 -0
- package/lib/WABinary/generic-utils.js +135 -99
- package/lib/WABinary/index.d.ts +6 -0
- package/lib/WABinary/index.js +5 -7
- package/lib/WABinary/jid-utils.d.ts +29 -0
- package/lib/WABinary/jid-utils.js +80 -78
- package/lib/WABinary/types.d.ts +2 -0
- package/lib/WABinary/types.js +1 -3
- package/lib/WAM/BinaryInfo.d.ts +8 -0
- package/lib/WAM/BinaryInfo.js +7 -9
- package/lib/WAM/constants.d.ts +34927 -0
- package/lib/WAM/constants.js +22847 -22848
- package/lib/WAM/encode.d.ts +2 -0
- package/lib/WAM/encode.js +129 -134
- package/lib/WAM/index.d.ts +4 -0
- package/lib/WAM/index.js +3 -5
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +37 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +48 -27
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +23 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +48 -48
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +13 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +23 -26
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +13 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +33 -35
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +10 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +24 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +39 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +46 -49
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +15 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +23 -25
- package/lib/WAUSync/Protocols/index.d.ts +6 -0
- package/lib/WAUSync/Protocols/index.js +5 -6
- package/lib/WAUSync/USyncQuery.d.ts +21 -0
- package/lib/WAUSync/USyncQuery.js +92 -85
- package/lib/WAUSync/USyncUser.d.ts +17 -0
- package/lib/WAUSync/USyncUser.js +28 -22
- package/lib/WAUSync/index.d.ts +4 -0
- package/lib/WAUSync/index.js +3 -5
- package/lib/index.d.ts +12 -0
- package/lib/index.js +31 -19
- package/package.json +12 -6
- package/lib/Types/Newsletter.js +0 -33
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
export function downloadHistory(msg: any, options: any): Promise<proto.HistorySync>;
|
|
2
|
+
export function processHistoryMessage(item: any, logger: any): {
|
|
3
|
+
chats: any[];
|
|
4
|
+
contacts: ({
|
|
5
|
+
id: any;
|
|
6
|
+
name: any;
|
|
7
|
+
username: any;
|
|
8
|
+
lid: any;
|
|
9
|
+
phoneNumber: any;
|
|
10
|
+
verifiedName?: undefined;
|
|
11
|
+
notify?: undefined;
|
|
12
|
+
} | {
|
|
13
|
+
id: any;
|
|
14
|
+
verifiedName: any;
|
|
15
|
+
name?: undefined;
|
|
16
|
+
username?: undefined;
|
|
17
|
+
lid?: undefined;
|
|
18
|
+
phoneNumber?: undefined;
|
|
19
|
+
notify?: undefined;
|
|
20
|
+
} | {
|
|
21
|
+
id: any;
|
|
22
|
+
notify: any;
|
|
23
|
+
name?: undefined;
|
|
24
|
+
username?: undefined;
|
|
25
|
+
lid?: undefined;
|
|
26
|
+
phoneNumber?: undefined;
|
|
27
|
+
verifiedName?: undefined;
|
|
28
|
+
})[];
|
|
29
|
+
messages: any[];
|
|
30
|
+
lidPnMappings: {
|
|
31
|
+
lid: any;
|
|
32
|
+
pn: any;
|
|
33
|
+
}[];
|
|
34
|
+
pastParticipants: any;
|
|
35
|
+
syncType: any;
|
|
36
|
+
progress: any;
|
|
37
|
+
};
|
|
38
|
+
export function downloadAndProcessHistorySyncNotification(msg: any, options: any, logger: any): Promise<{
|
|
39
|
+
chats: any[];
|
|
40
|
+
contacts: ({
|
|
41
|
+
id: any;
|
|
42
|
+
name: any;
|
|
43
|
+
username: any;
|
|
44
|
+
lid: any;
|
|
45
|
+
phoneNumber: any;
|
|
46
|
+
verifiedName?: undefined;
|
|
47
|
+
notify?: undefined;
|
|
48
|
+
} | {
|
|
49
|
+
id: any;
|
|
50
|
+
verifiedName: any;
|
|
51
|
+
name?: undefined;
|
|
52
|
+
username?: undefined;
|
|
53
|
+
lid?: undefined;
|
|
54
|
+
phoneNumber?: undefined;
|
|
55
|
+
notify?: undefined;
|
|
56
|
+
} | {
|
|
57
|
+
id: any;
|
|
58
|
+
notify: any;
|
|
59
|
+
name?: undefined;
|
|
60
|
+
username?: undefined;
|
|
61
|
+
lid?: undefined;
|
|
62
|
+
phoneNumber?: undefined;
|
|
63
|
+
verifiedName?: undefined;
|
|
64
|
+
})[];
|
|
65
|
+
messages: any[];
|
|
66
|
+
lidPnMappings: {
|
|
67
|
+
lid: any;
|
|
68
|
+
pn: any;
|
|
69
|
+
}[];
|
|
70
|
+
pastParticipants: any;
|
|
71
|
+
syncType: any;
|
|
72
|
+
progress: any;
|
|
73
|
+
}>;
|
|
74
|
+
export function getHistoryMsg(message: any): any;
|
|
75
|
+
import { proto } from '../../WAProto/index.js';
|
|
76
|
+
//# sourceMappingURL=history.d.ts.map
|
package/lib/Utils/history.js
CHANGED
|
@@ -1,87 +1,133 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
|
|
1
|
+
import { pipeline } from 'stream/promises';
|
|
2
|
+
import { promisify } from 'util';
|
|
3
|
+
import { createInflate, inflate } from 'zlib';
|
|
4
|
+
import { proto } from '../../WAProto/index.js';
|
|
5
|
+
import { WAMessageStubType } from '../Types/index.js';
|
|
6
|
+
import { isHostedLidUser, isHostedPnUser, isLidUser, isPnUser } from '../WABinary/index.js';
|
|
7
|
+
import { toNumber } from './generics.js';
|
|
8
|
+
import { normalizeMessageContent } from './messages.js';
|
|
9
|
+
import { downloadContentFromMessage } from './messages-media.js';
|
|
10
10
|
const inflatePromise = promisify(inflate);
|
|
11
|
+
const extractPnFromMessages = (messages) => {
|
|
12
|
+
for (const msgItem of messages) {
|
|
13
|
+
const message = msgItem.message;
|
|
14
|
+
// Only extract from outgoing messages (fromMe: true) in 1:1 chats
|
|
15
|
+
// because userReceipt.userJid is the recipient's JID
|
|
16
|
+
if (!message?.key?.fromMe || !message.userReceipt?.length) {
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
const userJid = message.userReceipt[0]?.userJid;
|
|
20
|
+
if (userJid && (isPnUser(userJid) || isHostedPnUser(userJid))) {
|
|
21
|
+
return userJid;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return undefined;
|
|
25
|
+
};
|
|
11
26
|
export const downloadHistory = async (msg, options) => {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
27
|
+
const stream = await downloadContentFromMessage(msg, 'md-msg-hist', { options });
|
|
28
|
+
// Pipe decrypted stream directly through zlib inflate
|
|
29
|
+
// This avoids allocating an intermediate buffer for the compressed data
|
|
30
|
+
const inflater = createInflate();
|
|
31
|
+
const chunks = [];
|
|
32
|
+
inflater.on('data', (chunk) => chunks.push(chunk));
|
|
33
|
+
await pipeline(stream, inflater);
|
|
34
|
+
const buffer = Buffer.concat(chunks);
|
|
35
|
+
const syncData = proto.HistorySync.decode(buffer);
|
|
36
|
+
return syncData;
|
|
21
37
|
};
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
for (const chat of item.conversations) {
|
|
33
|
-
contacts.push({
|
|
34
|
-
id: chat.id,
|
|
35
|
-
name: chat.name || undefined,
|
|
36
|
-
lid: chat.lidJid || undefined,
|
|
37
|
-
phoneNumber: chat.pnJid || undefined
|
|
38
|
-
});
|
|
39
|
-
const msgs = chat.messages || [];
|
|
40
|
-
delete chat.messages;
|
|
41
|
-
for (const item of msgs) {
|
|
42
|
-
const message = item.message;
|
|
43
|
-
messages.push(message);
|
|
44
|
-
if (!chat.messages?.length) {
|
|
45
|
-
chat.messages = [{ message }];
|
|
46
|
-
}
|
|
47
|
-
if (!message.key.fromMe && !chat.lastMessageRecvTimestamp) {
|
|
48
|
-
chat.lastMessageRecvTimestamp = toNumber(message.messageTimestamp);
|
|
49
|
-
}
|
|
50
|
-
if ((message.messageStubType === WAMessageStubType.BIZ_PRIVACY_MODE_TO_BSP ||
|
|
51
|
-
message.messageStubType === WAMessageStubType.BIZ_PRIVACY_MODE_TO_FB) &&
|
|
52
|
-
message.messageStubParameters?.[0]) {
|
|
53
|
-
contacts.push({
|
|
54
|
-
id: message.key.participant || message.key.remoteJid,
|
|
55
|
-
verifiedName: message.messageStubParameters?.[0]
|
|
56
|
-
});
|
|
57
|
-
}
|
|
38
|
+
export const processHistoryMessage = (item, logger) => {
|
|
39
|
+
const messages = [];
|
|
40
|
+
const contacts = [];
|
|
41
|
+
const chats = [];
|
|
42
|
+
const lidPnMappings = [];
|
|
43
|
+
logger?.trace({ progress: item.progress }, 'processing history of type ' + item.syncType?.toString());
|
|
44
|
+
// Extract LID-PN mappings for all sync types
|
|
45
|
+
for (const m of item.phoneNumberToLidMappings || []) {
|
|
46
|
+
if (m.lidJid && m.pnJid) {
|
|
47
|
+
lidPnMappings.push({ lid: m.lidJid, pn: m.pnJid });
|
|
58
48
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
49
|
+
}
|
|
50
|
+
switch (item.syncType) {
|
|
51
|
+
case proto.HistorySync.HistorySyncType.INITIAL_BOOTSTRAP:
|
|
52
|
+
case proto.HistorySync.HistorySyncType.RECENT:
|
|
53
|
+
case proto.HistorySync.HistorySyncType.FULL:
|
|
54
|
+
case proto.HistorySync.HistorySyncType.ON_DEMAND:
|
|
55
|
+
for (const chat of item.conversations) {
|
|
56
|
+
contacts.push({
|
|
57
|
+
id: chat.id,
|
|
58
|
+
name: chat.displayName || chat.name || chat.username || undefined,
|
|
59
|
+
username: chat.username || undefined,
|
|
60
|
+
lid: chat.lidJid || chat.accountLid || undefined,
|
|
61
|
+
phoneNumber: chat.pnJid || undefined
|
|
62
|
+
});
|
|
63
|
+
const chatId = chat.id;
|
|
64
|
+
const isLid = isLidUser(chatId) || isHostedLidUser(chatId);
|
|
65
|
+
const isPn = isPnUser(chatId) || isHostedPnUser(chatId);
|
|
66
|
+
if (isLid && chat.pnJid) {
|
|
67
|
+
lidPnMappings.push({ lid: chatId, pn: chat.pnJid });
|
|
68
|
+
}
|
|
69
|
+
else if (isPn && chat.lidJid) {
|
|
70
|
+
lidPnMappings.push({ lid: chat.lidJid, pn: chatId });
|
|
71
|
+
}
|
|
72
|
+
else if (isLid && !chat.pnJid) {
|
|
73
|
+
// Fallback: extract PN from userReceipt in messages when pnJid is missing
|
|
74
|
+
const pnFromReceipt = extractPnFromMessages(chat.messages || []);
|
|
75
|
+
if (pnFromReceipt) {
|
|
76
|
+
lidPnMappings.push({ lid: chatId, pn: pnFromReceipt });
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
const msgs = chat.messages || [];
|
|
80
|
+
delete chat.messages;
|
|
81
|
+
for (const item of msgs) {
|
|
82
|
+
const message = item.message;
|
|
83
|
+
messages.push(message);
|
|
84
|
+
if (!chat.messages?.length) {
|
|
85
|
+
// keep only the most recent message in the chat array
|
|
86
|
+
chat.messages = [{ message }];
|
|
87
|
+
}
|
|
88
|
+
if (!message.key.fromMe && !chat.lastMessageRecvTimestamp) {
|
|
89
|
+
chat.lastMessageRecvTimestamp = toNumber(message.messageTimestamp);
|
|
90
|
+
}
|
|
91
|
+
if ((message.messageStubType === WAMessageStubType.BIZ_PRIVACY_MODE_TO_BSP ||
|
|
92
|
+
message.messageStubType === WAMessageStubType.BIZ_PRIVACY_MODE_TO_FB) &&
|
|
93
|
+
message.messageStubParameters?.[0]) {
|
|
94
|
+
contacts.push({
|
|
95
|
+
id: message.key.participant || message.key.remoteJid,
|
|
96
|
+
verifiedName: message.messageStubParameters?.[0]
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
chats.push(chat);
|
|
101
|
+
}
|
|
102
|
+
break;
|
|
103
|
+
case proto.HistorySync.HistorySyncType.PUSH_NAME:
|
|
104
|
+
for (const c of item.pushnames) {
|
|
105
|
+
contacts.push({ id: c.id, notify: c.pushname });
|
|
106
|
+
}
|
|
107
|
+
break;
|
|
108
|
+
}
|
|
109
|
+
return {
|
|
110
|
+
chats,
|
|
111
|
+
contacts,
|
|
112
|
+
messages,
|
|
113
|
+
lidPnMappings,
|
|
114
|
+
pastParticipants: item.pastParticipants,
|
|
115
|
+
syncType: item.syncType,
|
|
116
|
+
progress: item.progress
|
|
117
|
+
};
|
|
75
118
|
};
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
119
|
+
export const downloadAndProcessHistorySyncNotification = async (msg, options, logger) => {
|
|
120
|
+
let historyMsg;
|
|
121
|
+
if (msg.initialHistBootstrapInlinePayload) {
|
|
122
|
+
historyMsg = proto.HistorySync.decode(await inflatePromise(msg.initialHistBootstrapInlinePayload));
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
historyMsg = await downloadHistory(msg, options);
|
|
126
|
+
}
|
|
127
|
+
return processHistoryMessage(historyMsg, logger);
|
|
80
128
|
};
|
|
81
|
-
//=======================================================//
|
|
82
129
|
export const getHistoryMsg = (message) => {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
130
|
+
const normalizedContent = !!message ? normalizeMessageContent(message) : undefined;
|
|
131
|
+
const anyHistoryMsg = normalizedContent?.protocolMessage?.historySyncNotification;
|
|
132
|
+
return anyHistoryMsg;
|
|
86
133
|
};
|
|
87
|
-
//=======================================================//
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export function handleIdentityChange(node: any, ctx: any): Promise<{
|
|
2
|
+
action: string;
|
|
3
|
+
device?: undefined;
|
|
4
|
+
error?: undefined;
|
|
5
|
+
} | {
|
|
6
|
+
action: string;
|
|
7
|
+
device: number;
|
|
8
|
+
error?: undefined;
|
|
9
|
+
} | {
|
|
10
|
+
action: string;
|
|
11
|
+
error: unknown;
|
|
12
|
+
device?: undefined;
|
|
13
|
+
}>;
|
|
14
|
+
//# sourceMappingURL=identity-change-handler.d.ts.map
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import NodeCache from '@cacheable/node-cache';
|
|
2
|
+
import { areJidsSameUser, getBinaryNodeChild, jidDecode } from '../WABinary/index.js';
|
|
3
|
+
import { isStringNullOrEmpty } from './generics.js';
|
|
4
|
+
export async function handleIdentityChange(node, ctx) {
|
|
5
|
+
const from = node.attrs.from;
|
|
6
|
+
if (!from) {
|
|
7
|
+
return { action: 'invalid_notification' };
|
|
8
|
+
}
|
|
9
|
+
const identityNode = getBinaryNodeChild(node, 'identity');
|
|
10
|
+
if (!identityNode) {
|
|
11
|
+
return { action: 'no_identity_node' };
|
|
12
|
+
}
|
|
13
|
+
ctx.logger.info({ jid: from }, 'identity changed');
|
|
14
|
+
const decoded = jidDecode(from);
|
|
15
|
+
if (decoded?.device && decoded.device !== 0) {
|
|
16
|
+
ctx.logger.debug({ jid: from, device: decoded.device }, 'ignoring identity change from companion device');
|
|
17
|
+
return { action: 'skipped_companion_device', device: decoded.device };
|
|
18
|
+
}
|
|
19
|
+
const isSelfPrimary = ctx.meId && (areJidsSameUser(from, ctx.meId) || (ctx.meLid && areJidsSameUser(from, ctx.meLid)));
|
|
20
|
+
if (isSelfPrimary) {
|
|
21
|
+
ctx.logger.info({ jid: from }, 'self primary identity changed');
|
|
22
|
+
return { action: 'skipped_self_primary' };
|
|
23
|
+
}
|
|
24
|
+
if (ctx.debounceCache.get(from)) {
|
|
25
|
+
ctx.logger.debug({ jid: from }, 'skipping identity assert (debounced)');
|
|
26
|
+
return { action: 'debounced' };
|
|
27
|
+
}
|
|
28
|
+
ctx.debounceCache.set(from, true);
|
|
29
|
+
const isOfflineNotification = !isStringNullOrEmpty(node.attrs.offline);
|
|
30
|
+
const hasExistingSession = await ctx.validateSession(from);
|
|
31
|
+
if (!hasExistingSession.exists) {
|
|
32
|
+
ctx.logger.debug({ jid: from }, 'no old session, skipping session refresh');
|
|
33
|
+
return { action: 'skipped_no_session' };
|
|
34
|
+
}
|
|
35
|
+
ctx.logger.debug({ jid: from }, 'old session exists, will refresh session');
|
|
36
|
+
if (isOfflineNotification) {
|
|
37
|
+
ctx.logger.debug({ jid: from }, 'skipping session refresh during offline processing');
|
|
38
|
+
return { action: 'skipped_offline' };
|
|
39
|
+
}
|
|
40
|
+
ctx.onBeforeSessionRefresh?.(from);
|
|
41
|
+
try {
|
|
42
|
+
await ctx.assertSessions([from], true);
|
|
43
|
+
return { action: 'session_refreshed' };
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
ctx.logger.warn({ error, jid: from }, 'failed to assert sessions after identity change');
|
|
47
|
+
return { action: 'session_refresh_failed', error };
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export * from "./generics.js";
|
|
2
|
+
export * from "./decode-wa-message.js";
|
|
3
|
+
export * from "./messages.js";
|
|
4
|
+
export * from "./messages-media.js";
|
|
5
|
+
export * from "./validate-connection.js";
|
|
6
|
+
export * from "./crypto.js";
|
|
7
|
+
export * from "./signal.js";
|
|
8
|
+
export * from "./noise-handler.js";
|
|
9
|
+
export * from "./history.js";
|
|
10
|
+
export * from "./chat-utils.js";
|
|
11
|
+
export * from "./lt-hash.js";
|
|
12
|
+
export * from "./auth-utils.js";
|
|
13
|
+
export * from "./use-multi-file-auth-state.js";
|
|
14
|
+
export * from "./use-single-file-auth-state.js";
|
|
15
|
+
export * from "./use-sqlite-auth-state.js";
|
|
16
|
+
export * from "./link-preview.js";
|
|
17
|
+
export * from "./event-buffer.js";
|
|
18
|
+
export * from "./process-message.js";
|
|
19
|
+
export * from "./rich-message-utils.js";
|
|
20
|
+
export * from "./message-retry-manager.js";
|
|
21
|
+
export * from "./browser-utils.js";
|
|
22
|
+
export * from "./companion-reg-client-utils.js";
|
|
23
|
+
export * from "./identity-change-handler.js";
|
|
24
|
+
export * from "./stanza-ack.js";
|
|
25
|
+
//# sourceMappingURL=index.d.ts.map
|
package/lib/Utils/index.js
CHANGED
|
@@ -1,21 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
5
|
-
export * from
|
|
6
|
-
export * from
|
|
7
|
-
export * from
|
|
8
|
-
export * from
|
|
9
|
-
export * from
|
|
10
|
-
export * from
|
|
11
|
-
export * from
|
|
12
|
-
export * from
|
|
13
|
-
export * from
|
|
14
|
-
export * from
|
|
15
|
-
export * from
|
|
16
|
-
export * from
|
|
17
|
-
export * from
|
|
18
|
-
export * from
|
|
19
|
-
export * from
|
|
20
|
-
export * from
|
|
21
|
-
|
|
1
|
+
export * from './generics.js';
|
|
2
|
+
export * from './decode-wa-message.js';
|
|
3
|
+
export * from './messages.js';
|
|
4
|
+
export * from './messages-media.js';
|
|
5
|
+
export * from './validate-connection.js';
|
|
6
|
+
export * from './crypto.js';
|
|
7
|
+
export * from './signal.js';
|
|
8
|
+
export * from './noise-handler.js';
|
|
9
|
+
export * from './history.js';
|
|
10
|
+
export * from './chat-utils.js';
|
|
11
|
+
export * from './lt-hash.js';
|
|
12
|
+
export * from './auth-utils.js';
|
|
13
|
+
export * from './use-multi-file-auth-state.js';
|
|
14
|
+
export * from './use-single-file-auth-state.js';
|
|
15
|
+
export * from './use-sqlite-auth-state.js';
|
|
16
|
+
export * from './link-preview.js';
|
|
17
|
+
export * from './event-buffer.js';
|
|
18
|
+
export * from './process-message.js';
|
|
19
|
+
export * from './rich-message-utils.js';
|
|
20
|
+
export * from './message-retry-manager.js';
|
|
21
|
+
export * from './browser-utils.js';
|
|
22
|
+
export * from './companion-reg-client-utils.js';
|
|
23
|
+
export * from './identity-change-handler.js';
|
|
24
|
+
export * from './stanza-ack.js';
|
|
25
|
+
export * from './baileys-event-stream.js';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export function getUrlInfo(text: any, opts?: {
|
|
2
|
+
thumbnailWidth: number;
|
|
3
|
+
fetchOpts: {
|
|
4
|
+
timeout: number;
|
|
5
|
+
};
|
|
6
|
+
}): Promise<{
|
|
7
|
+
'canonical-url': any;
|
|
8
|
+
'matched-text': any;
|
|
9
|
+
title: any;
|
|
10
|
+
description: any;
|
|
11
|
+
originalThumbnailUrl: any;
|
|
12
|
+
} | undefined>;
|
|
13
|
+
//# sourceMappingURL=link-preview.d.ts.map
|
|
@@ -1,81 +1,84 @@
|
|
|
1
|
-
|
|
2
|
-
import { extractImageThumb, getHttpStream } from
|
|
3
|
-
import { prepareWAMessageMedia } from "./messages.js";
|
|
4
|
-
//=======================================================//
|
|
1
|
+
import { prepareWAMessageMedia } from './messages.js';
|
|
2
|
+
import { extractImageThumb, getHttpStream } from './messages-media.js';
|
|
5
3
|
const THUMBNAIL_WIDTH_PX = 192;
|
|
6
|
-
|
|
4
|
+
/** Fetches an image and generates a thumbnail for it */
|
|
7
5
|
const getCompressedJpegThumbnail = async (url, { thumbnailWidth, fetchOpts }) => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
const stream = await getHttpStream(url, fetchOpts);
|
|
7
|
+
const result = await extractImageThumb(stream, thumbnailWidth);
|
|
8
|
+
return result;
|
|
11
9
|
};
|
|
12
|
-
|
|
10
|
+
/**
|
|
11
|
+
* Given a piece of text, checks for any URL present, generates link preview for the same and returns it
|
|
12
|
+
* Return undefined if the fetch failed or no URL was found
|
|
13
|
+
* @param text first matched URL in text
|
|
14
|
+
* @returns the URL info required to generate link preview
|
|
15
|
+
*/
|
|
13
16
|
export const getUrlInfo = async (text, opts = {
|
|
14
|
-
|
|
15
|
-
|
|
17
|
+
thumbnailWidth: THUMBNAIL_WIDTH_PX,
|
|
18
|
+
fetchOpts: { timeout: 3000 }
|
|
16
19
|
}) => {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const info = await getLinkPreview(previewLink, {
|
|
26
|
-
...opts.fetchOpts,
|
|
27
|
-
followRedirects: "follow",
|
|
28
|
-
handleRedirects: (baseURL, forwardedURL) => {
|
|
29
|
-
const urlObj = new URL(baseURL);
|
|
30
|
-
const forwardedURLObj = new URL(forwardedURL);
|
|
31
|
-
if (retries >= maxRetry) {
|
|
32
|
-
return false;
|
|
33
|
-
}
|
|
34
|
-
if (forwardedURLObj.hostname === urlObj.hostname ||
|
|
35
|
-
forwardedURLObj.hostname === "www." + urlObj.hostname ||
|
|
36
|
-
"www." + forwardedURLObj.hostname === urlObj.hostname) {
|
|
37
|
-
retries + 1;
|
|
38
|
-
return true;
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
return false;
|
|
20
|
+
try {
|
|
21
|
+
// retries
|
|
22
|
+
let retries = 0;
|
|
23
|
+
const maxRetry = 5;
|
|
24
|
+
const { getLinkPreview } = await import('link-preview-js');
|
|
25
|
+
let previewLink = text;
|
|
26
|
+
if (!text.startsWith('https://') && !text.startsWith('http://')) {
|
|
27
|
+
previewLink = 'https://' + previewLink;
|
|
42
28
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
29
|
+
const info = await getLinkPreview(previewLink, {
|
|
30
|
+
...opts.fetchOpts,
|
|
31
|
+
followRedirects: 'follow',
|
|
32
|
+
handleRedirects: (baseURL, forwardedURL) => {
|
|
33
|
+
const urlObj = new URL(baseURL);
|
|
34
|
+
const forwardedURLObj = new URL(forwardedURL);
|
|
35
|
+
if (retries >= maxRetry) {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
if (forwardedURLObj.hostname === urlObj.hostname ||
|
|
39
|
+
forwardedURLObj.hostname === 'www.' + urlObj.hostname ||
|
|
40
|
+
'www.' + forwardedURLObj.hostname === urlObj.hostname) {
|
|
41
|
+
retries += 1;
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
headers: opts.fetchOpts?.headers
|
|
60
49
|
});
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
50
|
+
if (info && 'title' in info && info.title) {
|
|
51
|
+
const [image] = info.images;
|
|
52
|
+
const urlInfo = {
|
|
53
|
+
'canonical-url': info.url,
|
|
54
|
+
'matched-text': text,
|
|
55
|
+
title: info.title,
|
|
56
|
+
description: info.description,
|
|
57
|
+
originalThumbnailUrl: image
|
|
58
|
+
};
|
|
59
|
+
if (opts.uploadImage) {
|
|
60
|
+
const { imageMessage } = await prepareWAMessageMedia({ image: { url: image } }, {
|
|
61
|
+
upload: opts.uploadImage,
|
|
62
|
+
mediaTypeOverride: 'thumbnail-link',
|
|
63
|
+
options: opts.fetchOpts
|
|
64
|
+
});
|
|
65
|
+
urlInfo.jpegThumbnail = imageMessage?.jpegThumbnail ? Buffer.from(imageMessage.jpegThumbnail) : undefined;
|
|
66
|
+
urlInfo.highQualityThumbnail = imageMessage || undefined;
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
try {
|
|
70
|
+
urlInfo.jpegThumbnail = image ? (await getCompressedJpegThumbnail(image, opts)).buffer : undefined;
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
opts.logger?.debug({ err: error.stack, url: previewLink }, 'error in generating thumbnail');
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return urlInfo;
|
|
67
77
|
}
|
|
68
|
-
catch (error) {
|
|
69
|
-
opts.logger?.debug({ err: error.stack, url: previewLink }, "error in generating thumbnail");
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
return urlInfo;
|
|
73
78
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
79
|
+
catch (error) {
|
|
80
|
+
if (!error.message.includes('receive a valid')) {
|
|
81
|
+
throw error;
|
|
82
|
+
}
|
|
78
83
|
}
|
|
79
|
-
}
|
|
80
84
|
};
|
|
81
|
-
//=======================================================//
|
package/lib/Utils/logger.js
CHANGED
|
@@ -1,5 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
import P from "pino";
|
|
3
|
-
//=======================================================//
|
|
1
|
+
import P from 'pino';
|
|
4
2
|
export default P({ timestamp: () => `,"time":"${new Date().toJSON()}"` });
|
|
5
|
-
//=======================================================//
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LT Hash is a summation based hash algorithm that maintains the integrity of a piece of data
|
|
3
|
+
* over a series of mutations. You can add/remove mutations and it'll return a hash equal to
|
|
4
|
+
* if the same series of mutations was made sequentially.
|
|
5
|
+
*/
|
|
6
|
+
export const LT_HASH_ANTI_TAMPERING: any;
|
|
7
|
+
//# sourceMappingURL=lt-hash.d.ts.map
|