@pontalabs/baileys 1.0.6 → 1.0.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/LICENSE +1 -1
- package/README.md +839 -267
- package/WAProto/GenerateStatics.sh +4 -3
- package/WAProto/WAProto.proto +511 -1215
- package/WAProto/index.d.ts +55 -14017
- package/WAProto/index.js +29 -97689
- package/lib/Defaults/index.d.ts +74 -72
- package/lib/Defaults/index.js +108 -94
- package/lib/Signal/Group/ciphertext-message.d.ts +7 -8
- package/lib/Signal/Group/ciphertext-message.js +16 -9
- package/lib/Signal/Group/group-session-builder.d.ts +13 -11
- package/lib/Signal/Group/group-session-builder.js +61 -19
- package/lib/Signal/Group/group_cipher.d.ts +16 -14
- package/lib/Signal/Group/group_cipher.js +70 -41
- package/lib/Signal/Group/index.d.ts +11 -12
- package/lib/Signal/Group/index.js +61 -12
- package/lib/Signal/Group/keyhelper.d.ts +14 -9
- package/lib/Signal/Group/keyhelper.js +58 -10
- package/lib/Signal/Group/sender-chain-key.d.ts +13 -13
- package/lib/Signal/Group/sender-chain-key.js +34 -13
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +16 -16
- package/lib/Signal/Group/sender-key-distribution-message.js +36 -28
- package/lib/Signal/Group/sender-key-message.d.ts +18 -18
- package/lib/Signal/Group/sender-key-message.js +45 -38
- package/lib/Signal/Group/sender-key-name.d.ts +15 -14
- package/lib/Signal/Group/sender-key-name.js +31 -20
- package/lib/Signal/Group/sender-key-record.d.ts +25 -24
- package/lib/Signal/Group/sender-key-record.js +35 -18
- package/lib/Signal/Group/sender-key-state.d.ts +34 -29
- package/lib/Signal/Group/sender-key-state.js +100 -37
- package/lib/Signal/Group/sender-message-key.d.ts +10 -11
- package/lib/Signal/Group/sender-message-key.js +22 -15
- package/lib/Signal/libsignal.d.ts +8 -5
- package/lib/Signal/libsignal.js +142 -288
- package/lib/Signal/lid-mapping.d.ts +28 -23
- package/lib/Signal/lid-mapping.js +184 -277
- package/lib/Socket/Client/index.d.ts +2 -3
- package/lib/Socket/Client/index.js +22 -3
- package/lib/Socket/Client/types.d.ts +15 -15
- package/lib/Socket/Client/types.js +15 -8
- package/lib/Socket/Client/websocket.d.ts +12 -12
- package/lib/Socket/Client/websocket.js +37 -29
- package/lib/Socket/business.d.ts +178 -208
- package/lib/Socket/business.js +127 -91
- package/lib/Socket/chats.d.ts +93 -120
- package/lib/Socket/chats.js +652 -727
- package/lib/Socket/community.js +10 -2
- package/lib/Socket/groups.d.ts +111 -143
- package/lib/Socket/groups.js +186 -165
- package/lib/Socket/index.d.ts +183 -252
- package/lib/Socket/index.js +18 -38
- package/lib/Socket/messages-recv.d.ts +167 -196
- package/lib/Socket/messages-recv.js +1567 -1443
- package/lib/Socket/messages-send.d.ts +158 -192
- package/lib/Socket/messages-send.js +1208 -1102
- package/lib/Socket/newsletter.d.ts +138 -163
- package/lib/Socket/newsletter.js +249 -153
- package/lib/Socket/socket.d.ts +36 -50
- package/lib/Socket/socket.js +820 -749
- package/lib/Store/index.d.ts +4 -4
- package/lib/Store/index.js +24 -4
- package/lib/Store/make-in-memory-store.d.ts +104 -44
- package/lib/Store/make-in-memory-store.js +213 -199
- package/lib/Store/make-ordered-dictionary.d.ts +12 -13
- package/lib/Store/make-ordered-dictionary.js +45 -38
- package/lib/Store/object-repository.d.ts +10 -11
- package/lib/Store/object-repository.js +16 -9
- package/lib/Types/Auth.d.ts +97 -93
- package/lib/Types/Auth.js +3 -2
- package/lib/Types/Bussines.js +3 -2
- package/lib/Types/Call.d.ts +13 -14
- package/lib/Types/Call.js +3 -2
- package/lib/Types/Chat.d.ts +97 -78
- package/lib/Types/Chat.js +9 -8
- package/lib/Types/Contact.d.ts +9 -12
- package/lib/Types/Contact.js +3 -2
- package/lib/Types/Events.d.ts +176 -206
- package/lib/Types/Events.js +3 -2
- package/lib/Types/GroupMetadata.d.ts +48 -53
- package/lib/Types/GroupMetadata.js +3 -2
- package/lib/Types/Label.d.ts +14 -13
- package/lib/Types/Label.js +30 -24
- package/lib/Types/LabelAssociation.d.ts +20 -15
- package/lib/Types/LabelAssociation.js +12 -6
- package/lib/Types/Message.d.ts +412 -248
- package/lib/Types/Message.js +19 -17
- package/lib/Types/Product.d.ts +71 -58
- package/lib/Types/Product.js +3 -2
- package/lib/Types/Signal.d.ts +82 -71
- package/lib/Types/Signal.js +3 -2
- package/lib/Types/Socket.d.ts +81 -76
- package/lib/Types/Socket.js +3 -3
- package/lib/Types/State.d.ts +19 -75
- package/lib/Types/State.js +14 -56
- package/lib/Types/USync.d.ts +8 -8
- package/lib/Types/USync.js +3 -2
- package/lib/Types/index.d.ts +62 -47
- package/lib/Types/index.js +50 -26
- package/lib/Utils/auth-utils.d.ts +10 -13
- package/lib/Utils/auth-utils.js +472 -213
- package/lib/Utils/business.d.ts +20 -14
- package/lib/Utils/business.js +134 -110
- package/lib/Utils/chat-utils.d.ts +70 -88
- package/lib/Utils/chat-utils.js +403 -466
- package/lib/Utils/crypto.d.ts +46 -27
- package/lib/Utils/crypto.js +188 -117
- package/lib/Utils/decode-wa-message.d.ts +45 -58
- package/lib/Utils/decode-wa-message.js +311 -212
- package/lib/Utils/event-buffer.d.ts +17 -14
- package/lib/Utils/event-buffer.js +296 -321
- package/lib/Utils/generics.d.ts +92 -66
- package/lib/Utils/generics.js +436 -270
- package/lib/Utils/history.d.ts +23 -24
- package/lib/Utils/history.js +76 -106
- package/lib/Utils/index.d.ts +21 -24
- package/lib/Utils/index.js +41 -24
- package/lib/Utils/link-preview.d.ts +14 -12
- package/lib/Utils/link-preview.js +75 -40
- package/lib/Utils/logger.d.ts +11 -10
- package/lib/Utils/logger.js +7 -3
- package/lib/Utils/lt-hash.d.ts +14 -8
- package/lib/Utils/lt-hash.js +53 -3
- package/lib/Utils/make-mutex.d.ts +7 -7
- package/lib/Utils/make-mutex.js +44 -28
- package/lib/Utils/message-retry-manager.d.ts +88 -115
- package/lib/Utils/message-retry-manager.js +160 -265
- package/lib/Utils/messages-media.d.ts +107 -105
- package/lib/Utils/messages-media.js +619 -548
- package/lib/Utils/messages.d.ts +66 -52
- package/lib/Utils/messages.js +1558 -1730
- package/lib/Utils/noise-handler.d.ts +18 -18
- package/lib/Utils/noise-handler.js +130 -176
- package/lib/Utils/process-message.d.ts +32 -43
- package/lib/Utils/process-message.js +282 -484
- package/lib/Utils/rich-message-utils.js +724 -1220
- package/lib/Utils/signal.d.ts +32 -37
- package/lib/Utils/signal.js +105 -140
- package/lib/Utils/use-multi-file-auth-state.d.ts +5 -5
- package/lib/Utils/use-multi-file-auth-state.js +120 -70
- package/lib/Utils/use-single-file-auth-state.d.ts +13 -11
- package/lib/Utils/use-single-file-auth-state.js +66 -92
- package/lib/Utils/validate-connection.d.ts +13 -11
- package/lib/Utils/validate-connection.js +113 -128
- package/lib/WABinary/constants.d.ts +27 -25
- package/lib/WABinary/constants.js +1292 -1451
- package/lib/WABinary/decode.d.ts +9 -7
- package/lib/WABinary/decode.js +189 -163
- package/lib/WABinary/encode.d.ts +3 -3
- package/lib/WABinary/encode.js +155 -110
- package/lib/WABinary/generic-utils.d.ts +27 -14
- package/lib/WABinary/generic-utils.js +105 -177
- package/lib/WABinary/index.d.ts +5 -6
- package/lib/WABinary/index.js +25 -6
- package/lib/WABinary/jid-utils.d.ts +54 -41
- package/lib/WABinary/jid-utils.js +152 -83
- package/lib/WABinary/types.d.ts +13 -10
- package/lib/WABinary/types.js +3 -2
- package/lib/WAM/BinaryInfo.d.ts +15 -8
- package/lib/WAM/BinaryInfo.js +14 -7
- package/lib/WAM/constants.d.ts +37 -30
- package/lib/WAM/constants.js +11983 -19465
- package/lib/WAM/encode.d.ts +3 -3
- package/lib/WAM/encode.js +109 -95
- package/lib/WAM/index.d.ts +3 -4
- package/lib/WAM/index.js +23 -4
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +9 -9
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +21 -37
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +22 -19
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +26 -18
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -11
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +20 -12
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -11
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +24 -16
- package/lib/WAUSync/Protocols/index.d.ts +6 -6
- package/lib/WAUSync/Protocols/index.js +26 -6
- package/lib/WAUSync/USyncQuery.d.ts +28 -27
- package/lib/WAUSync/USyncQuery.js +62 -68
- package/lib/WAUSync/USyncUser.d.ts +10 -15
- package/lib/WAUSync/USyncUser.js +19 -20
- package/lib/WAUSync/index.d.ts +3 -4
- package/lib/WAUSync/index.js +23 -4
- package/lib/index.d.ts +12 -11
- package/lib/index.js +39 -12
- package/package.json +43 -87
- package/engine-requirements.js +0 -10
package/lib/Utils/history.d.ts
CHANGED
|
@@ -1,24 +1,23 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
export declare const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
syncType: proto.HistorySync.HistorySyncType
|
|
12
|
-
progress: number | null | undefined
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
export declare const getHistoryMsg: (message: proto.IMessage) => proto.Message.IHistorySyncNotification
|
|
24
|
-
//# sourceMappingURL=history.d.ts.map
|
|
1
|
+
import { AxiosRequestConfig } from 'axios'
|
|
2
|
+
import { proto } from '../../WAProto'
|
|
3
|
+
import { Chat, Contact } from '../Types'
|
|
4
|
+
|
|
5
|
+
export declare const downloadHistory: (msg: proto.Message.IHistorySyncNotification, options: AxiosRequestConfig<{}>) => Promise<proto.HistorySync>
|
|
6
|
+
|
|
7
|
+
export declare const processHistoryMessage: (item: proto.IHistorySync) => {
|
|
8
|
+
chats: Chat[]
|
|
9
|
+
contacts: Contact[]
|
|
10
|
+
messages: proto.IWebMessageInfo[]
|
|
11
|
+
syncType: proto.HistorySync.HistorySyncType
|
|
12
|
+
progress: number | null | undefined
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export declare const downloadAndProcessHistorySyncNotification: (msg: proto.Message.IHistorySyncNotification, options: AxiosRequestConfig<{}>) => Promise<{
|
|
16
|
+
chats: Chat[]
|
|
17
|
+
contacts: Contact[]
|
|
18
|
+
messages: proto.IWebMessageInfo[]
|
|
19
|
+
syncType: proto.HistorySync.HistorySyncType
|
|
20
|
+
progress: number | null | undefined
|
|
21
|
+
}>
|
|
22
|
+
|
|
23
|
+
export declare const getHistoryMsg: (message: proto.IMessage) => proto.Message.IHistorySyncNotification | null | undefined
|
package/lib/Utils/history.js
CHANGED
|
@@ -1,134 +1,104 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
if (userJid && (isPnUser(userJid) || isHostedPnUser(userJid))) {
|
|
21
|
-
return userJid;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
return undefined;
|
|
25
|
-
};
|
|
26
|
-
export const downloadHistory = async (msg, options) => {
|
|
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;
|
|
37
|
-
};
|
|
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 });
|
|
48
|
-
}
|
|
1
|
+
"use strict"
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true })
|
|
4
|
+
|
|
5
|
+
const util_1 = require("util")
|
|
6
|
+
const zlib_1 = require("zlib")
|
|
7
|
+
const WAProto_1 = require("../../WAProto")
|
|
8
|
+
const Types_1 = require("../Types")
|
|
9
|
+
const WABinary_1 = require("../WABinary")
|
|
10
|
+
const generics_1 = require("./generics")
|
|
11
|
+
const messages_1 = require("./messages")
|
|
12
|
+
const messages_media_1 = require("./messages-media")
|
|
13
|
+
const inflatePromise = util_1.promisify(zlib_1.inflate)
|
|
14
|
+
|
|
15
|
+
const downloadHistory = async (msg, options) => {
|
|
16
|
+
const stream = await messages_media_1.downloadContentFromMessage(msg, 'md-msg-hist', { options })
|
|
17
|
+
const bufferArray = []
|
|
18
|
+
for await (const chunk of stream) {
|
|
19
|
+
bufferArray.push(chunk)
|
|
49
20
|
}
|
|
21
|
+
let buffer = Buffer.concat(bufferArray)
|
|
22
|
+
// decompress buffer
|
|
23
|
+
buffer = await inflatePromise(buffer)
|
|
24
|
+
const syncData = WAProto_1.proto.HistorySync.decode(buffer)
|
|
25
|
+
return syncData
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const processHistoryMessage = (item) => {
|
|
29
|
+
const messages = []
|
|
30
|
+
const contacts = []
|
|
31
|
+
const chats = []
|
|
50
32
|
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:
|
|
33
|
+
case WAProto_1.proto.HistorySync.HistorySyncType.INITIAL_BOOTSTRAP:
|
|
34
|
+
case WAProto_1.proto.HistorySync.HistorySyncType.RECENT:
|
|
35
|
+
case WAProto_1.proto.HistorySync.HistorySyncType.FULL:
|
|
36
|
+
case WAProto_1.proto.HistorySync.HistorySyncType.ON_DEMAND:
|
|
55
37
|
for (const chat of item.conversations) {
|
|
56
38
|
contacts.push({
|
|
57
39
|
id: chat.id,
|
|
58
|
-
name: chat.
|
|
59
|
-
|
|
60
|
-
lid: chat.lidJid || chat.accountLid || undefined,
|
|
40
|
+
name: chat.name || undefined,
|
|
41
|
+
lid: chat.lidJid || undefined,
|
|
61
42
|
phoneNumber: chat.pnJid || undefined
|
|
62
|
-
})
|
|
63
|
-
const
|
|
64
|
-
|
|
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;
|
|
43
|
+
})
|
|
44
|
+
const msgs = chat.messages || []
|
|
45
|
+
delete chat.messages
|
|
81
46
|
for (const item of msgs) {
|
|
82
|
-
const message = item.message
|
|
83
|
-
messages.push(message)
|
|
47
|
+
const message = item.message
|
|
48
|
+
messages.push(message)
|
|
84
49
|
if (!chat.messages?.length) {
|
|
85
50
|
// keep only the most recent message in the chat array
|
|
86
|
-
chat.messages = [{ message }]
|
|
51
|
+
chat.messages = [{ message }]
|
|
87
52
|
}
|
|
88
53
|
if (!message.key.fromMe && !chat.lastMessageRecvTimestamp) {
|
|
89
|
-
chat.lastMessageRecvTimestamp = toNumber(message.messageTimestamp)
|
|
54
|
+
chat.lastMessageRecvTimestamp = generics_1.toNumber(message.messageTimestamp)
|
|
90
55
|
}
|
|
91
|
-
if (
|
|
92
|
-
message.messageStubType === WAMessageStubType.BIZ_PRIVACY_MODE_TO_FB
|
|
93
|
-
message.messageStubParameters?.[0]) {
|
|
56
|
+
if (message.messageStubType === Types_1.WAMessageStubType.BIZ_PRIVACY_MODE_TO_BSP
|
|
57
|
+
|| message.messageStubType === Types_1.WAMessageStubType.BIZ_PRIVACY_MODE_TO_FB
|
|
58
|
+
&& message.messageStubParameters?.[0]) {
|
|
94
59
|
contacts.push({
|
|
95
60
|
id: message.key.participant || message.key.remoteJid,
|
|
96
61
|
verifiedName: message.messageStubParameters?.[0]
|
|
97
|
-
})
|
|
62
|
+
})
|
|
98
63
|
}
|
|
99
64
|
}
|
|
100
|
-
chats.push(chat)
|
|
65
|
+
chats.push({ ...chat })
|
|
101
66
|
}
|
|
102
|
-
break
|
|
103
|
-
case proto.HistorySync.HistorySyncType.PUSH_NAME:
|
|
67
|
+
break
|
|
68
|
+
case WAProto_1.proto.HistorySync.HistorySyncType.PUSH_NAME:
|
|
104
69
|
for (const c of item.pushnames) {
|
|
105
|
-
contacts.push({
|
|
70
|
+
contacts.push({
|
|
71
|
+
id: c.id,
|
|
72
|
+
name: c.name || undefined,
|
|
73
|
+
lid: c.lidJid || undefined,
|
|
74
|
+
jid: WABinary_1.isJidUser(c.id) ? c.id : undefined
|
|
75
|
+
})
|
|
106
76
|
}
|
|
107
|
-
break
|
|
77
|
+
break
|
|
108
78
|
}
|
|
109
79
|
return {
|
|
110
80
|
chats,
|
|
111
81
|
contacts,
|
|
112
82
|
messages,
|
|
113
|
-
lidPnMappings,
|
|
114
|
-
pastParticipants: item.pastParticipants,
|
|
115
83
|
syncType: item.syncType,
|
|
116
84
|
progress: item.progress
|
|
117
|
-
};
|
|
118
|
-
};
|
|
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
85
|
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
const
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const downloadAndProcessHistorySyncNotification = async (msg, options) => {
|
|
89
|
+
const historyMsg = await downloadHistory(msg, options)
|
|
90
|
+
return processHistoryMessage(historyMsg)
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const getHistoryMsg = (message) => {
|
|
94
|
+
const normalizedContent = !!message ? messages_1.normalizeMessageContent(message) : undefined
|
|
95
|
+
const anyHistoryMsg = normalizedContent?.protocolMessage?.historySyncNotification
|
|
96
|
+
return anyHistoryMsg
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
module.exports = {
|
|
100
|
+
downloadHistory,
|
|
101
|
+
processHistoryMessage,
|
|
102
|
+
downloadAndProcessHistorySyncNotification,
|
|
103
|
+
getHistoryMsg
|
|
104
|
+
}
|
package/lib/Utils/index.d.ts
CHANGED
|
@@ -1,24 +1,21 @@
|
|
|
1
|
-
export * from
|
|
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
|
-
export * from
|
|
22
|
-
export * from "./identity-change-handler.js";
|
|
23
|
-
export * from "./stanza-ack.js";
|
|
24
|
-
//# sourceMappingURL=index.d.ts.map
|
|
1
|
+
export * from './generics'
|
|
2
|
+
export * from './decode-wa-message'
|
|
3
|
+
export * from './messages'
|
|
4
|
+
export * from './messages-media'
|
|
5
|
+
export * from './message-retry-manager'
|
|
6
|
+
export * from './validate-connection'
|
|
7
|
+
export * from './crypto'
|
|
8
|
+
export * from './signal'
|
|
9
|
+
export * from './noise-handler'
|
|
10
|
+
export * from './history'
|
|
11
|
+
export * from './chat-utils'
|
|
12
|
+
export * from './lt-hash'
|
|
13
|
+
export * from './auth-utils'
|
|
14
|
+
export * from './baileys-event-stream'
|
|
15
|
+
export * from './use-mongo-file-auth-state'
|
|
16
|
+
export * from './use-single-file-auth-state'
|
|
17
|
+
export * from './use-multi-file-auth-state'
|
|
18
|
+
export * from './link-preview'
|
|
19
|
+
export * from './event-buffer'
|
|
20
|
+
export * from './process-message'
|
|
21
|
+
export * from './signal-housekeeping'
|
package/lib/Utils/index.js
CHANGED
|
@@ -1,24 +1,41 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
1
|
+
"use strict"
|
|
2
|
+
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k)
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k] } }
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc)
|
|
10
|
+
}) : (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k
|
|
12
|
+
o[k2] = m[k]
|
|
13
|
+
}))
|
|
14
|
+
|
|
15
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
16
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true })
|
|
20
|
+
|
|
21
|
+
__exportStar(require("./generics"), exports)
|
|
22
|
+
__exportStar(require("./decode-wa-message"), exports)
|
|
23
|
+
__exportStar(require("./messages"), exports)
|
|
24
|
+
__exportStar(require("./messages-media"), exports)
|
|
25
|
+
__exportStar(require("./message-retry-manager"), exports)
|
|
26
|
+
__exportStar(require("./validate-connection"), exports)
|
|
27
|
+
__exportStar(require("./crypto"), exports)
|
|
28
|
+
__exportStar(require("./signal"), exports)
|
|
29
|
+
__exportStar(require("./noise-handler"), exports)
|
|
30
|
+
__exportStar(require("./history"), exports)
|
|
31
|
+
__exportStar(require("./chat-utils"), exports)
|
|
32
|
+
__exportStar(require("./lt-hash"), exports)
|
|
33
|
+
__exportStar(require("./auth-utils"), exports)
|
|
34
|
+
__exportStar(require("./baileys-event-stream"), exports)
|
|
35
|
+
__exportStar(require("./use-mongo-file-auth-state"), exports)
|
|
36
|
+
__exportStar(require("./use-single-file-auth-state"), exports)
|
|
37
|
+
__exportStar(require("./use-multi-file-auth-state"), exports)
|
|
38
|
+
__exportStar(require("./link-preview"), exports)
|
|
39
|
+
__exportStar(require("./event-buffer"), exports)
|
|
40
|
+
__exportStar(require("./process-message"), exports)
|
|
41
|
+
__exportStar(require("./signal-housekeeping"), exports)
|
|
@@ -1,21 +1,23 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import { AxiosRequestConfig } from 'axios'
|
|
2
|
+
import { WAMediaUploadFunction, WAUrlInfo } from '../Types'
|
|
3
|
+
import { ILogger } from './logger'
|
|
4
|
+
|
|
3
5
|
export type URLGenerationOptions = {
|
|
4
|
-
thumbnailWidth: number
|
|
6
|
+
thumbnailWidth: number
|
|
5
7
|
fetchOpts: {
|
|
6
8
|
/** Timeout in ms */
|
|
7
|
-
timeout: number
|
|
8
|
-
proxyUrl?: string
|
|
9
|
-
headers?:
|
|
10
|
-
}
|
|
11
|
-
uploadImage?: WAMediaUploadFunction
|
|
12
|
-
logger?: ILogger
|
|
13
|
-
}
|
|
9
|
+
timeout: number
|
|
10
|
+
proxyUrl?: string
|
|
11
|
+
headers?: AxiosRequestConfig<{}>['headers']
|
|
12
|
+
}
|
|
13
|
+
uploadImage?: WAMediaUploadFunction
|
|
14
|
+
logger?: ILogger
|
|
15
|
+
}
|
|
16
|
+
|
|
14
17
|
/**
|
|
15
18
|
* Given a piece of text, checks for any URL present, generates link preview for the same and returns it
|
|
16
19
|
* Return undefined if the fetch failed or no URL was found
|
|
17
20
|
* @param text first matched URL in text
|
|
18
21
|
* @returns the URL info required to generate link preview
|
|
19
22
|
*/
|
|
20
|
-
export declare const getUrlInfo: (text: string, opts?: URLGenerationOptions) => Promise<WAUrlInfo | undefined
|
|
21
|
-
//# sourceMappingURL=link-preview.d.ts.map
|
|
23
|
+
export declare const getUrlInfo: (text: string, opts?: URLGenerationOptions) => Promise<WAUrlInfo | undefined>
|
|
@@ -1,85 +1,120 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict"
|
|
2
|
+
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k)
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k] } }
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc)
|
|
10
|
+
}) : (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k
|
|
12
|
+
o[k2] = m[k]
|
|
13
|
+
}))
|
|
14
|
+
|
|
15
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
16
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v })
|
|
17
|
+
}) : function(o, v) {
|
|
18
|
+
o["default"] = v
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
22
|
+
if (mod && mod.__esModule) return mod
|
|
23
|
+
var result = {}
|
|
24
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k)
|
|
25
|
+
__setModuleDefault(result, mod)
|
|
26
|
+
return result
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
Object.defineProperty(exports, "__esModule", { value: true })
|
|
30
|
+
|
|
31
|
+
const messages_1 = require("./messages")
|
|
32
|
+
const messages_media_1 = require("./messages-media")
|
|
33
|
+
const THUMBNAIL_WIDTH_PX = 192
|
|
34
|
+
|
|
4
35
|
/** Fetches an image and generates a thumbnail for it */
|
|
5
36
|
const getCompressedJpegThumbnail = async (url, { thumbnailWidth, fetchOpts }) => {
|
|
6
|
-
const stream = await getHttpStream(url, fetchOpts)
|
|
7
|
-
const result = await extractImageThumb(stream, thumbnailWidth)
|
|
8
|
-
return result
|
|
9
|
-
}
|
|
37
|
+
const stream = await messages_media_1.getHttpStream(url, fetchOpts)
|
|
38
|
+
const result = await messages_media_1.extractImageThumb(stream, thumbnailWidth)
|
|
39
|
+
return result
|
|
40
|
+
}
|
|
41
|
+
|
|
10
42
|
/**
|
|
11
43
|
* Given a piece of text, checks for any URL present, generates link preview for the same and returns it
|
|
12
44
|
* Return undefined if the fetch failed or no URL was found
|
|
13
45
|
* @param text first matched URL in text
|
|
14
46
|
* @returns the URL info required to generate link preview
|
|
15
47
|
*/
|
|
16
|
-
|
|
17
|
-
thumbnailWidth: THUMBNAIL_WIDTH_PX,
|
|
18
|
-
fetchOpts: { timeout: 3000 }
|
|
19
|
-
}) => {
|
|
48
|
+
const getUrlInfo = async (text, opts = { thumbnailWidth: THUMBNAIL_WIDTH_PX, fetchOpts: { timeout: 3000 }}) => {
|
|
20
49
|
try {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
let previewLink = text;
|
|
50
|
+
const retries = 0
|
|
51
|
+
const maxRetry = 5
|
|
52
|
+
const { getLinkPreview } = await Promise.resolve().then(() => __importStar(require('link-preview-js')))
|
|
53
|
+
let previewLink = text
|
|
26
54
|
if (!text.startsWith('https://') && !text.startsWith('http://')) {
|
|
27
|
-
previewLink = 'https://' + previewLink
|
|
55
|
+
previewLink = 'https://' + previewLink
|
|
28
56
|
}
|
|
29
57
|
const info = await getLinkPreview(previewLink, {
|
|
30
58
|
...opts.fetchOpts,
|
|
31
59
|
followRedirects: 'follow',
|
|
32
60
|
handleRedirects: (baseURL, forwardedURL) => {
|
|
33
|
-
const urlObj = new URL(baseURL)
|
|
34
|
-
const forwardedURLObj = new URL(forwardedURL)
|
|
61
|
+
const urlObj = new URL(baseURL)
|
|
62
|
+
const forwardedURLObj = new URL(forwardedURL)
|
|
35
63
|
if (retries >= maxRetry) {
|
|
36
|
-
return false
|
|
64
|
+
return false
|
|
37
65
|
}
|
|
38
|
-
if (forwardedURLObj.hostname === urlObj.hostname
|
|
39
|
-
forwardedURLObj.hostname === 'www.' + urlObj.hostname
|
|
40
|
-
'www.' + forwardedURLObj.hostname === urlObj.hostname) {
|
|
41
|
-
retries
|
|
42
|
-
return true
|
|
66
|
+
if (forwardedURLObj.hostname === urlObj.hostname
|
|
67
|
+
|| forwardedURLObj.hostname === 'www.' + urlObj.hostname
|
|
68
|
+
|| 'www.' + forwardedURLObj.hostname === urlObj.hostname) {
|
|
69
|
+
retries + 1
|
|
70
|
+
return true
|
|
43
71
|
}
|
|
44
72
|
else {
|
|
45
|
-
return false
|
|
73
|
+
return false
|
|
46
74
|
}
|
|
47
75
|
},
|
|
48
|
-
headers: opts.fetchOpts
|
|
49
|
-
})
|
|
76
|
+
headers: opts.fetchOpts
|
|
77
|
+
})
|
|
50
78
|
if (info && 'title' in info && info.title) {
|
|
51
|
-
const [image] = info.images
|
|
79
|
+
const [image] = info.images
|
|
52
80
|
const urlInfo = {
|
|
53
81
|
'canonical-url': info.url,
|
|
54
82
|
'matched-text': text,
|
|
55
83
|
title: info.title,
|
|
56
84
|
description: info.description,
|
|
57
85
|
originalThumbnailUrl: image
|
|
58
|
-
}
|
|
86
|
+
}
|
|
59
87
|
if (opts.uploadImage) {
|
|
60
|
-
const { imageMessage } = await prepareWAMessageMedia({ image: { url: image } }, {
|
|
88
|
+
const { imageMessage } = await messages_1.prepareWAMessageMedia({ image: { url: image } }, {
|
|
61
89
|
upload: opts.uploadImage,
|
|
62
90
|
mediaTypeOverride: 'thumbnail-link',
|
|
63
91
|
options: opts.fetchOpts
|
|
64
|
-
})
|
|
65
|
-
urlInfo.jpegThumbnail = imageMessage?.jpegThumbnail
|
|
66
|
-
|
|
92
|
+
})
|
|
93
|
+
urlInfo.jpegThumbnail = imageMessage?.jpegThumbnail
|
|
94
|
+
? Buffer.from(imageMessage.jpegThumbnail)
|
|
95
|
+
: undefined
|
|
96
|
+
urlInfo.highQualityThumbnail = imageMessage || undefined
|
|
67
97
|
}
|
|
68
98
|
else {
|
|
69
99
|
try {
|
|
70
|
-
urlInfo.jpegThumbnail = image
|
|
100
|
+
urlInfo.jpegThumbnail = image
|
|
101
|
+
? (await getCompressedJpegThumbnail(image, opts)).buffer
|
|
102
|
+
: undefined
|
|
71
103
|
}
|
|
72
104
|
catch (error) {
|
|
73
|
-
opts.logger?.debug({ err: error.stack, url: previewLink }, 'error in generating thumbnail')
|
|
105
|
+
opts.logger?.debug({ err: error.stack, url: previewLink }, 'error in generating thumbnail')
|
|
74
106
|
}
|
|
75
107
|
}
|
|
76
|
-
return urlInfo
|
|
108
|
+
return urlInfo
|
|
77
109
|
}
|
|
78
110
|
}
|
|
79
111
|
catch (error) {
|
|
80
112
|
if (!error.message.includes('receive a valid')) {
|
|
81
|
-
throw error
|
|
113
|
+
throw error
|
|
82
114
|
}
|
|
83
115
|
}
|
|
84
|
-
}
|
|
85
|
-
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
module.exports = {
|
|
119
|
+
getUrlInfo
|
|
120
|
+
}
|
package/lib/Utils/logger.d.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
export interface ILogger {
|
|
2
|
-
level: string
|
|
3
|
-
child(obj: Record<string, unknown>): ILogger
|
|
4
|
-
trace(obj: unknown, msg?: string):
|
|
5
|
-
debug(obj: unknown, msg?: string):
|
|
6
|
-
info(obj: unknown, msg?: string):
|
|
7
|
-
warn(obj: unknown, msg?: string):
|
|
8
|
-
error(obj: unknown, msg?: string):
|
|
2
|
+
level: string
|
|
3
|
+
child(obj: Record<string, unknown>): ILogger
|
|
4
|
+
trace(obj: unknown, msg?: string): any
|
|
5
|
+
debug(obj: unknown, msg?: string): any
|
|
6
|
+
info(obj: unknown, msg?: string): any
|
|
7
|
+
warn(obj: unknown, msg?: string): any
|
|
8
|
+
error(obj: unknown, msg?: string): any
|
|
9
9
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
|
|
11
|
+
declare const _default: import("pino").Logger<never, boolean>
|
|
12
|
+
|
|
13
|
+
export default _default
|
package/lib/Utils/logger.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict"
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod }
|
|
4
|
+
}
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true })
|
|
6
|
+
const pino_1 = __importDefault(require("pino"))
|
|
7
|
+
exports.default = pino_1.default({ timestamp: () => `,"time":"${new Date().toJSON()}"` })
|
package/lib/Utils/lt-hash.d.ts
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
declare class d {
|
|
2
|
+
salt: string
|
|
3
|
+
constructor(e: string)
|
|
4
|
+
add(e: any, t: any): any
|
|
5
|
+
subtract(e: any, t: any): any
|
|
6
|
+
subtractThenAdd(e: any, t: any, r: any): any
|
|
7
|
+
_addSingle(e: any, t: any): Promise<ArrayBuffer>
|
|
8
|
+
_subtractSingle(e: any, t: any): Promise<ArrayBuffer>
|
|
9
|
+
performPointwiseWithOverflow(e: any, t: any, r: any): ArrayBuffer
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export declare const LT_HASH_ANTI_TAMPERING: d
|
|
13
|
+
|
|
14
|
+
export {}
|