@neelegirl/baileys 2.1.8 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +75 -1586
- package/lib/Defaults/baileys-version.json +1 -1
- package/lib/Defaults/index.d.ts +18 -31
- package/lib/Signal/libsignal.d.ts +3 -8
- package/lib/Signal/libsignal.js +79 -288
- package/lib/Socket/chats.js +2 -3
- package/lib/Socket/socket.js +3 -3
- package/lib/Types/Auth.d.ts +2 -15
- package/lib/Types/Contact.d.ts +1 -2
- package/lib/Types/Events.d.ts +1 -4
- package/lib/Types/Message.d.ts +5 -1
- package/lib/Types/Signal.d.ts +1 -16
- package/lib/Types/Socket.d.ts +4 -10
- package/lib/Utils/decode-wa-message.d.ts +4 -4
- package/lib/Utils/decode-wa-message.js +36 -10
- package/lib/Utils/generics.d.ts +4 -3
- package/lib/Utils/generics.js +8 -6
- package/lib/Utils/history.d.ts +4 -11
- package/lib/Utils/history.js +38 -77
- package/lib/Utils/index.d.ts +1 -4
- package/lib/Utils/index.js +1 -2
- package/lib/Utils/message-retry-manager.js +4 -4
- package/lib/Utils/process-message.d.ts +2 -3
- package/lib/Utils/process-message.js +2 -28
- package/lib/WABinary/jid-utils.d.ts +4 -21
- package/lib/WABinary/jid-utils.js +8 -50
- package/package.json +44 -28
- package/WAProto/GenerateStatics.sh +0 -3
- package/WAProto/fix-imports.js +0 -81
- package/engine-requirements.js +0 -10
- package/lib/Signal/lid-mapping.d.ts +0 -23
- package/lib/Signal/lid-mapping.js +0 -278
- package/lib/Utils/browser-utils.d.ts +0 -1
- package/lib/Utils/browser-utils.js +0 -10
package/lib/Types/Events.d.ts
CHANGED
|
@@ -10,7 +10,6 @@ import { LabelAssociation } from './LabelAssociation'
|
|
|
10
10
|
import { MessageUpsertType, MessageUserReceiptUpdate, WAMessage, WAMessageKey, WAMessageUpdate } from './Message'
|
|
11
11
|
import { NewsletterViewRole, SubscriberAction, NewsletterSettingsUpdate } from './Newsletter'
|
|
12
12
|
import { ConnectionState } from './State'
|
|
13
|
-
import { LIDMapping } from './Auth'
|
|
14
13
|
|
|
15
14
|
export type BaileysEventMap = {
|
|
16
15
|
/** connection state has been updated -- WS closed, opened, connecting etc. */
|
|
@@ -22,7 +21,6 @@ export type BaileysEventMap = {
|
|
|
22
21
|
chats: Chat[]
|
|
23
22
|
contacts: Contact[]
|
|
24
23
|
messages: WAMessage[]
|
|
25
|
-
lidPnMappings?: LIDMapping[]
|
|
26
24
|
isLatest?: boolean
|
|
27
25
|
progress?: number | null
|
|
28
26
|
syncType?: proto.HistorySync.HistorySyncType
|
|
@@ -84,7 +82,6 @@ export type BaileysEventMap = {
|
|
|
84
82
|
'message-receipt.update': MessageUserReceiptUpdate[]
|
|
85
83
|
'groups.upsert': GroupMetadata[]
|
|
86
84
|
'groups.update': Partial<GroupMetadata>[]
|
|
87
|
-
'communities.update': Partial<GroupMetadata>[]
|
|
88
85
|
/** apply an action to participants in a group */
|
|
89
86
|
'group-participants.update': {
|
|
90
87
|
id: string
|
|
@@ -237,4 +234,4 @@ export interface BaileysEventEmitter {
|
|
|
237
234
|
off<T extends keyof BaileysEventMap>(event: T, listener: (arg: BaileysEventMap[T]) => void): void
|
|
238
235
|
removeAllListeners<T extends keyof BaileysEventMap>(event: T): void
|
|
239
236
|
emit<T extends keyof BaileysEventMap>(event: T, arg: BaileysEventMap[T]): boolean
|
|
240
|
-
}
|
|
237
|
+
}
|
package/lib/Types/Message.d.ts
CHANGED
|
@@ -19,6 +19,10 @@ export type WAContactMessage = proto.Message.IContactMessage
|
|
|
19
19
|
export type WAContactsArrayMessage = proto.Message.IContactsArrayMessage
|
|
20
20
|
|
|
21
21
|
export type WAMessageKey = proto.IMessageKey & {
|
|
22
|
+
remoteJidAlt?: string
|
|
23
|
+
participantAlt?: string
|
|
24
|
+
addressingMode?: string
|
|
25
|
+
isViewOnce?: boolean
|
|
22
26
|
newsletter_server_id?: string
|
|
23
27
|
}
|
|
24
28
|
|
|
@@ -470,4 +474,4 @@ export type MediaDecryptionKeyInfo = {
|
|
|
470
474
|
macKey?: Buffer
|
|
471
475
|
}
|
|
472
476
|
|
|
473
|
-
export type MinimalMessage = Pick<proto.IWebMessageInfo, 'key' | 'messageTimestamp'>
|
|
477
|
+
export type MinimalMessage = Pick<proto.IWebMessageInfo, 'key' | 'messageTimestamp'>
|
package/lib/Types/Signal.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { proto } from '../../WAProto'
|
|
2
|
-
import type { LIDMappingStore } from '../Signal/lid-mapping'
|
|
3
2
|
|
|
4
3
|
type DecryptGroupSignalOpts = {
|
|
5
4
|
group: string
|
|
@@ -63,21 +62,7 @@ export type SignalRepository = {
|
|
|
63
62
|
ciphertext: Uint8Array
|
|
64
63
|
}>
|
|
65
64
|
injectE2ESession(opts: E2ESessionOpts): Promise<void>
|
|
66
|
-
validateSession(jid: string): Promise<{
|
|
67
|
-
exists: boolean
|
|
68
|
-
reason?: string
|
|
69
|
-
}>
|
|
70
65
|
jidToSignalProtocolAddress(jid: string): string
|
|
71
|
-
migrateSession(fromJid: string, toJid: string): Promise<{
|
|
72
|
-
migrated: number
|
|
73
|
-
skipped: number
|
|
74
|
-
total: number
|
|
75
|
-
}>
|
|
76
|
-
deleteSession(jids: string[]): Promise<void>
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export interface SignalRepositoryWithLIDStore extends SignalRepository {
|
|
80
|
-
lidMapping: LIDMappingStore
|
|
81
66
|
}
|
|
82
67
|
|
|
83
|
-
export {}
|
|
68
|
+
export {}
|
package/lib/Types/Socket.d.ts
CHANGED
|
@@ -3,10 +3,10 @@ import type { Agent } from 'https'
|
|
|
3
3
|
import { ILogger } from '../Utils/logger'
|
|
4
4
|
import type { URL } from 'url'
|
|
5
5
|
import { proto } from '../../WAProto'
|
|
6
|
-
import { AuthenticationState,
|
|
6
|
+
import { AuthenticationState, SignalAuthState, TransactionCapabilityOptions } from './Auth'
|
|
7
7
|
import { GroupMetadata } from './GroupMetadata'
|
|
8
8
|
import { MediaConnInfo } from './Message'
|
|
9
|
-
import {
|
|
9
|
+
import { SignalRepository } from './Signal'
|
|
10
10
|
|
|
11
11
|
export type WAVersion = [number, number, number]
|
|
12
12
|
|
|
@@ -91,8 +91,6 @@ export type SocketConfig = {
|
|
|
91
91
|
* entails uploading the jpegThumbnail to WA
|
|
92
92
|
* */
|
|
93
93
|
generateHighQualityLinkPreview: boolean
|
|
94
|
-
/** Enable automatic session recreation for failed messages */
|
|
95
|
-
enableAutoSessionRecreation: boolean
|
|
96
94
|
/** Enable recent message caching for retry handling */
|
|
97
95
|
enableRecentMessageCache: boolean
|
|
98
96
|
/**
|
|
@@ -120,9 +118,5 @@ export type SocketConfig = {
|
|
|
120
118
|
getMessage: (key: proto.IMessageKey) => Promise<proto.IMessage | undefined>
|
|
121
119
|
/** cached group metadata, use to prevent redundant requests to WA & speed up msg sending */
|
|
122
120
|
cachedGroupMetadata: (jid: string) => Promise<GroupMetadata | undefined>
|
|
123
|
-
makeSignalRepository: (
|
|
124
|
-
|
|
125
|
-
logger: ILogger,
|
|
126
|
-
pnToLIDFunc?: (jids: string[]) => Promise<LIDMapping[] | undefined>
|
|
127
|
-
) => SignalRepositoryWithLIDStore
|
|
128
|
-
}
|
|
121
|
+
makeSignalRepository: (auth: SignalAuthState) => SignalRepository
|
|
122
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { proto } from '../../WAProto'
|
|
2
|
-
import { SignalRepository } from '../Types'
|
|
2
|
+
import { SignalRepository, WAMessage } from '../Types'
|
|
3
3
|
import { BinaryNode } from '../WABinary'
|
|
4
4
|
import { ILogger } from './logger'
|
|
5
5
|
|
|
@@ -28,14 +28,14 @@ export declare const NACK_REASONS: {
|
|
|
28
28
|
* @note this will only parse the message, not decrypt it
|
|
29
29
|
*/
|
|
30
30
|
export declare function decodeMessageNode(stanza: BinaryNode, meId: string, meLid: string): {
|
|
31
|
-
fullMessage:
|
|
31
|
+
fullMessage: WAMessage
|
|
32
32
|
author: string
|
|
33
33
|
sender: string
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
export declare const decryptMessageNode: (stanza: BinaryNode, meId: string, meLid: string, repository: SignalRepository, logger: ILogger) => {
|
|
37
|
-
fullMessage:
|
|
37
|
+
fullMessage: WAMessage
|
|
38
38
|
category: string
|
|
39
39
|
author: string
|
|
40
40
|
decrypt(): Promise<void>
|
|
41
|
-
}
|
|
41
|
+
}
|
|
@@ -28,6 +28,26 @@ const NACK_REASONS = {
|
|
|
28
28
|
DBOperationFailed: 552
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
+
const extractAddressingContext = (stanza) => {
|
|
32
|
+
let senderAlt
|
|
33
|
+
let recipientAlt
|
|
34
|
+
const sender = stanza.attrs.participant || stanza.attrs.from
|
|
35
|
+
const addressingMode = stanza.attrs.addressing_mode || (WABinary_1.isLidUser(sender) ? 'lid' : 'pn')
|
|
36
|
+
if (addressingMode === 'lid') {
|
|
37
|
+
senderAlt = stanza.attrs.participant_pn || stanza.attrs.sender_pn || stanza.attrs.peer_recipient_pn
|
|
38
|
+
recipientAlt = stanza.attrs.recipient_pn
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
senderAlt = stanza.attrs.participant_lid || stanza.attrs.sender_lid || stanza.attrs.peer_recipient_lid
|
|
42
|
+
recipientAlt = stanza.attrs.recipient_lid
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
addressingMode,
|
|
46
|
+
senderAlt,
|
|
47
|
+
recipientAlt
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
31
51
|
/**
|
|
32
52
|
* Decode the received node as a message.
|
|
33
53
|
* @note this will only parse the message, not decrypt it
|
|
@@ -38,8 +58,10 @@ function decodeMessageNode(stanza, meId, meLid) {
|
|
|
38
58
|
let author
|
|
39
59
|
const msgId = stanza.attrs.id
|
|
40
60
|
const from = stanza.attrs.from
|
|
41
|
-
|
|
42
|
-
|
|
61
|
+
const rawParticipant = stanza.attrs.participant
|
|
62
|
+
const addressingContext = extractAddressingContext(stanza)
|
|
63
|
+
let participant = rawParticipant
|
|
64
|
+
if (participant && participant.endsWith('@lid') && stanza.attrs.participant_pn) {
|
|
43
65
|
participant = stanza.attrs.participant_pn;
|
|
44
66
|
}
|
|
45
67
|
const recipient = stanza.attrs.recipient
|
|
@@ -101,20 +123,24 @@ function decodeMessageNode(stanza, meId, meLid) {
|
|
|
101
123
|
else {
|
|
102
124
|
throw new boom_1.Boom('Unknown message type', { data: stanza })
|
|
103
125
|
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
: (0, WABinary_1.areJidsSameUser)(senderJid, meId);
|
|
126
|
+
const senderJid = rawParticipant || stanza.attrs.from
|
|
127
|
+
const fromMe = WABinary_1.isJidNewsletter(stanza.attrs.from)
|
|
128
|
+
? !!stanza.attrs?.is_sender
|
|
129
|
+
: WABinary_1.isLidUser(senderJid)
|
|
130
|
+
? (0, WABinary_1.areJidsSameUser)(senderJid, meLid)
|
|
131
|
+
: (0, WABinary_1.areJidsSameUser)(senderJid, meId)
|
|
111
132
|
|
|
112
133
|
const pushname = stanza?.attrs?.notify
|
|
113
134
|
const key = {
|
|
114
135
|
remoteJid: chatId,
|
|
136
|
+
remoteJidAlt: !WABinary_1.isJidGroup(chatId)
|
|
137
|
+
? (fromMe ? addressingContext.recipientAlt : addressingContext.senderAlt)
|
|
138
|
+
: undefined,
|
|
115
139
|
fromMe,
|
|
116
140
|
id: msgId,
|
|
141
|
+
...(addressingContext.addressingMode !== undefined && { addressingMode: addressingContext.addressingMode }),
|
|
117
142
|
...(participant !== undefined && { participant: fromMe ? meId : participant }),
|
|
143
|
+
...(WABinary_1.isJidGroup(chatId) && addressingContext.senderAlt !== undefined && { participantAlt: addressingContext.senderAlt }),
|
|
118
144
|
...(stanza.attrs.participant_pn !== undefined && { participant_pn: fromMe ? meId : stanza.attrs.participant_pn }),
|
|
119
145
|
...(stanza.attrs.participant_lid !== undefined && { participant_lid: fromMe ? meLid : stanza.attrs.participant_lid }),
|
|
120
146
|
}
|
|
@@ -250,4 +276,4 @@ const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
|
|
|
250
276
|
module.exports = {
|
|
251
277
|
decodeMessageNode,
|
|
252
278
|
decryptMessageNode
|
|
253
|
-
}
|
|
279
|
+
}
|
package/lib/Utils/generics.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { ILogger } from './logger'
|
|
|
3
3
|
import { proto } from '../../WAProto'
|
|
4
4
|
import { BaileysEventEmitter, BaileysEventMap, BrowsersMap, ConnectionState, WACallUpdateType, WAVersion } from '../Types'
|
|
5
5
|
import { BinaryNode } from '../WABinary'
|
|
6
|
+
import { WAMessageKey } from '../Types/Message'
|
|
6
7
|
|
|
7
8
|
export declare const Browsers: BrowsersMap
|
|
8
9
|
|
|
@@ -13,7 +14,7 @@ export declare const BufferJSON: {
|
|
|
13
14
|
reviver: (_: any, value: any) => any
|
|
14
15
|
}
|
|
15
16
|
|
|
16
|
-
export declare const getKeyAuthor: (key: proto.IMessageKey | undefined | null, meId?: string) => string
|
|
17
|
+
export declare const getKeyAuthor: (key: WAMessageKey | proto.IMessageKey | undefined | null, meId?: string) => string
|
|
17
18
|
|
|
18
19
|
export declare const writeRandomPadMax16: (msg: Uint8Array) => Buffer
|
|
19
20
|
|
|
@@ -76,7 +77,7 @@ export declare const fetchLatestBaileysVersion: (options?: AxiosRequestConfig<{}
|
|
|
76
77
|
* A utility that fetches the latest web version of whatsapp.
|
|
77
78
|
* Use to ensure your WA connection is always on the latest version
|
|
78
79
|
*/
|
|
79
|
-
export declare const fetchLatestWaWebVersion: (options
|
|
80
|
+
export declare const fetchLatestWaWebVersion: (options?: AxiosRequestConfig<{}>) => Promise<{
|
|
80
81
|
version: WAVersion
|
|
81
82
|
isLatest: boolean
|
|
82
83
|
error?: undefined
|
|
@@ -126,4 +127,4 @@ export declare function fromUnicodeEscape(escapedText: string): string
|
|
|
126
127
|
|
|
127
128
|
export declare function asciiEncode(text: string): string
|
|
128
129
|
|
|
129
|
-
export declare function asciiDecode(...codes: string[]): string[]
|
|
130
|
+
export declare function asciiDecode(...codes: string[]): string[]
|
package/lib/Utils/generics.js
CHANGED
|
@@ -172,7 +172,9 @@ const getPlatformId = (browser) => {
|
|
|
172
172
|
}
|
|
173
173
|
|
|
174
174
|
const getKeyAuthor = (key, meId = 'me') => {
|
|
175
|
-
return key?.fromMe
|
|
175
|
+
return key?.fromMe
|
|
176
|
+
? meId
|
|
177
|
+
: key?.participantAlt || key?.remoteJidAlt || key?.participant || key?.remoteJid || ''
|
|
176
178
|
}
|
|
177
179
|
|
|
178
180
|
const writeRandomPadMax16 = (msg) => {
|
|
@@ -322,7 +324,7 @@ const generateAndroidMessageID = () => {
|
|
|
322
324
|
|
|
323
325
|
const generateIOSMessageID = () => {
|
|
324
326
|
const prefix = '3A';
|
|
325
|
-
const random = crypto_1.randomBytes(
|
|
327
|
+
const random = crypto_1.randomBytes(10); // trimmed to the expected iOS-style length below
|
|
326
328
|
return (prefix + random.toString('hex')).toUpperCase().substring(0, 21);
|
|
327
329
|
};
|
|
328
330
|
const generateDesktopMessageID = () => {
|
|
@@ -401,15 +403,15 @@ const fetchLatestBaileysVersion = async (options = {}) => {
|
|
|
401
403
|
* A utility that fetches the latest web version of whatsapp.
|
|
402
404
|
* Use to ensure your WA connection is always on the latest version
|
|
403
405
|
*/
|
|
404
|
-
const fetchLatestWaWebVersion = async (options) => {
|
|
406
|
+
const fetchLatestWaWebVersion = async (options = {}) => {
|
|
405
407
|
try {
|
|
406
408
|
const { data } = await axios_1.default.get('https://web.whatsapp.com/sw.js', {
|
|
407
409
|
...options,
|
|
408
|
-
responseType: '
|
|
410
|
+
responseType: 'text'
|
|
409
411
|
})
|
|
410
412
|
const regex = /\\?"client_revision\\?":\s*(\d+)/
|
|
411
413
|
const match = data.match(regex)
|
|
412
|
-
if (!match?.
|
|
414
|
+
if (!match?.[1]) {
|
|
413
415
|
return {
|
|
414
416
|
version: baileys_version_json_1.version,
|
|
415
417
|
isLatest: false,
|
|
@@ -615,4 +617,4 @@ module.exports = {
|
|
|
615
617
|
fromUnicodeEscape,
|
|
616
618
|
asciiEncode,
|
|
617
619
|
asciiDecode
|
|
618
|
-
}
|
|
620
|
+
}
|
package/lib/Utils/history.d.ts
CHANGED
|
@@ -1,30 +1,23 @@
|
|
|
1
1
|
import { AxiosRequestConfig } from 'axios'
|
|
2
2
|
import { proto } from '../../WAProto'
|
|
3
|
-
import { Chat, Contact
|
|
4
|
-
import { ILogger } from './logger'
|
|
3
|
+
import { Chat, Contact } from '../Types'
|
|
5
4
|
|
|
6
5
|
export declare const downloadHistory: (msg: proto.Message.IHistorySyncNotification, options: AxiosRequestConfig<{}>) => Promise<proto.HistorySync>
|
|
7
6
|
|
|
8
|
-
export declare const processHistoryMessage: (item: proto.IHistorySync
|
|
7
|
+
export declare const processHistoryMessage: (item: proto.IHistorySync) => {
|
|
9
8
|
chats: Chat[]
|
|
10
9
|
contacts: Contact[]
|
|
11
10
|
messages: proto.IWebMessageInfo[]
|
|
12
|
-
lidPnMappings: LIDMapping[]
|
|
13
11
|
syncType: proto.HistorySync.HistorySyncType
|
|
14
12
|
progress: number | null | undefined
|
|
15
13
|
}
|
|
16
14
|
|
|
17
|
-
export declare const downloadAndProcessHistorySyncNotification: (
|
|
18
|
-
msg: proto.Message.IHistorySyncNotification,
|
|
19
|
-
options: AxiosRequestConfig<{}>,
|
|
20
|
-
logger?: ILogger
|
|
21
|
-
) => Promise<{
|
|
15
|
+
export declare const downloadAndProcessHistorySyncNotification: (msg: proto.Message.IHistorySyncNotification, options: AxiosRequestConfig<{}>) => Promise<{
|
|
22
16
|
chats: Chat[]
|
|
23
17
|
contacts: Contact[]
|
|
24
18
|
messages: proto.IWebMessageInfo[]
|
|
25
|
-
lidPnMappings: LIDMapping[]
|
|
26
19
|
syncType: proto.HistorySync.HistorySyncType
|
|
27
20
|
progress: number | null | undefined
|
|
28
21
|
}>
|
|
29
22
|
|
|
30
|
-
export declare const getHistoryMsg: (message: proto.IMessage) => proto.Message.IHistorySyncNotification | null | undefined
|
|
23
|
+
export declare const getHistoryMsg: (message: proto.IMessage) => proto.Message.IHistorySyncNotification | null | undefined
|
package/lib/Utils/history.js
CHANGED
|
@@ -10,72 +10,37 @@ const WABinary_1 = require("../WABinary")
|
|
|
10
10
|
const generics_1 = require("./generics")
|
|
11
11
|
const messages_1 = require("./messages")
|
|
12
12
|
const messages_media_1 = require("./messages-media")
|
|
13
|
-
|
|
14
|
-
const inflatePromise = (0, util_1.promisify)(zlib_1.inflate)
|
|
15
|
-
|
|
16
|
-
const extractPnFromMessages = (messages) => {
|
|
17
|
-
for (const msgItem of messages || []) {
|
|
18
|
-
const message = msgItem.message
|
|
19
|
-
if (!message?.key?.fromMe || !message.userReceipt?.length) {
|
|
20
|
-
continue
|
|
21
|
-
}
|
|
22
|
-
const userJid = message.userReceipt[0]?.userJid
|
|
23
|
-
if (userJid && ((0, WABinary_1.isPnUser)(userJid) || (0, WABinary_1.isHostedPnUser)(userJid))) {
|
|
24
|
-
return userJid
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
}
|
|
13
|
+
const inflatePromise = util_1.promisify(zlib_1.inflate)
|
|
28
14
|
|
|
29
15
|
const downloadHistory = async (msg, options) => {
|
|
30
|
-
const stream = await
|
|
16
|
+
const stream = await messages_media_1.downloadContentFromMessage(msg, 'md-msg-hist', { options })
|
|
31
17
|
const bufferArray = []
|
|
32
18
|
for await (const chunk of stream) {
|
|
33
19
|
bufferArray.push(chunk)
|
|
34
20
|
}
|
|
35
21
|
let buffer = Buffer.concat(bufferArray)
|
|
22
|
+
// decompress buffer
|
|
36
23
|
buffer = await inflatePromise(buffer)
|
|
37
|
-
|
|
24
|
+
const syncData = WAProto_1.proto.HistorySync.decode(buffer)
|
|
25
|
+
return syncData
|
|
38
26
|
}
|
|
39
27
|
|
|
40
|
-
const processHistoryMessage = (item
|
|
28
|
+
const processHistoryMessage = (item) => {
|
|
41
29
|
const messages = []
|
|
42
30
|
const contacts = []
|
|
43
31
|
const chats = []
|
|
44
|
-
const lidPnMappings = []
|
|
45
|
-
logger?.trace?.({ progress: item.progress }, `processing history of type ${item.syncType}`)
|
|
46
|
-
for (const mapping of item.phoneNumberToLidMappings || []) {
|
|
47
|
-
if (mapping.lidJid && mapping.pnJid) {
|
|
48
|
-
lidPnMappings.push({ lid: mapping.lidJid, pn: mapping.pnJid })
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
32
|
switch (item.syncType) {
|
|
52
33
|
case WAProto_1.proto.HistorySync.HistorySyncType.INITIAL_BOOTSTRAP:
|
|
53
34
|
case WAProto_1.proto.HistorySync.HistorySyncType.RECENT:
|
|
54
35
|
case WAProto_1.proto.HistorySync.HistorySyncType.FULL:
|
|
55
36
|
case WAProto_1.proto.HistorySync.HistorySyncType.ON_DEMAND:
|
|
56
|
-
for (const chat of item.conversations
|
|
57
|
-
|
|
37
|
+
for (const chat of item.conversations) {
|
|
38
|
+
contacts.push({
|
|
58
39
|
id: chat.id,
|
|
59
|
-
name: chat.
|
|
60
|
-
lid: chat.lidJid ||
|
|
61
|
-
jid: (
|
|
62
|
-
|
|
63
|
-
})
|
|
64
|
-
const chatId = chat.id
|
|
65
|
-
const isLid = (0, WABinary_1.isLidUser)(chatId) || (0, WABinary_1.isHostedLidUser)(chatId)
|
|
66
|
-
const isPn = (0, WABinary_1.isPnUser)(chatId) || (0, WABinary_1.isHostedPnUser)(chatId)
|
|
67
|
-
if (isLid && chat.pnJid) {
|
|
68
|
-
lidPnMappings.push({ lid: chatId, pn: chat.pnJid })
|
|
69
|
-
}
|
|
70
|
-
else if (isPn && chat.lidJid) {
|
|
71
|
-
lidPnMappings.push({ lid: chat.lidJid, pn: chatId })
|
|
72
|
-
}
|
|
73
|
-
else if (isLid && !chat.pnJid) {
|
|
74
|
-
const pnFromReceipt = extractPnFromMessages(chat.messages || [])
|
|
75
|
-
if (pnFromReceipt) {
|
|
76
|
-
lidPnMappings.push({ lid: chatId, pn: pnFromReceipt })
|
|
77
|
-
}
|
|
78
|
-
}
|
|
40
|
+
name: chat.name || undefined,
|
|
41
|
+
lid: chat.lidJid || undefined,
|
|
42
|
+
jid: (0, WABinary_1.isJidUser)(chat.id) ? chat.id : undefined
|
|
43
|
+
});
|
|
79
44
|
const msgs = chat.messages || []
|
|
80
45
|
delete chat.messages
|
|
81
46
|
delete chat.archived
|
|
@@ -85,33 +50,35 @@ const processHistoryMessage = (item, logger) => {
|
|
|
85
50
|
const message = item.message
|
|
86
51
|
messages.push(message)
|
|
87
52
|
if (!chat.messages?.length) {
|
|
53
|
+
// keep only the most recent message in the chat array
|
|
88
54
|
chat.messages = [{ message }]
|
|
89
55
|
}
|
|
90
56
|
if (!message.key.fromMe && !chat.lastMessageRecvTimestamp) {
|
|
91
|
-
chat.lastMessageRecvTimestamp =
|
|
57
|
+
chat.lastMessageRecvTimestamp = generics_1.toNumber(message.messageTimestamp)
|
|
92
58
|
}
|
|
93
|
-
if (
|
|
94
|
-
|| message.messageStubType === Types_1.WAMessageStubType.BIZ_PRIVACY_MODE_TO_FB
|
|
59
|
+
if (message.messageStubType === Types_1.WAMessageStubType.BIZ_PRIVACY_MODE_TO_BSP
|
|
60
|
+
|| message.messageStubType === Types_1.WAMessageStubType.BIZ_PRIVACY_MODE_TO_FB
|
|
95
61
|
&& message.messageStubParameters?.[0]) {
|
|
96
62
|
contacts.push({
|
|
97
63
|
id: message.key.participant || message.key.remoteJid,
|
|
98
|
-
verifiedName: message.messageStubParameters[0]
|
|
64
|
+
verifiedName: message.messageStubParameters?.[0]
|
|
99
65
|
})
|
|
100
66
|
}
|
|
101
67
|
}
|
|
68
|
+
if (WABinary_1.isJidUser(chat.id) && chat.readOnly && chat.archived) {
|
|
69
|
+
delete chat.readOnly
|
|
70
|
+
}
|
|
102
71
|
chats.push({ ...chat })
|
|
103
72
|
}
|
|
104
73
|
break
|
|
105
74
|
case WAProto_1.proto.HistorySync.HistorySyncType.PUSH_NAME:
|
|
106
|
-
for (const c of item.pushnames
|
|
107
|
-
contacts.push({
|
|
108
|
-
|
|
109
|
-
name: c.name || undefined,
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
phoneNumber: ((0, WABinary_1.isPnUser)(c.id) || (0, WABinary_1.isHostedPnUser)(c.id)) ? c.id : undefined
|
|
114
|
-
})
|
|
75
|
+
for (const c of item.pushnames) {
|
|
76
|
+
contacts.push({
|
|
77
|
+
id: c.id,
|
|
78
|
+
name: c.name || undefined,
|
|
79
|
+
lid: c.lidJid || undefined,
|
|
80
|
+
jid: WABinary_1.isJidUser(c.id) ? c.id : undefined
|
|
81
|
+
})
|
|
115
82
|
}
|
|
116
83
|
break
|
|
117
84
|
}
|
|
@@ -119,31 +86,25 @@ const processHistoryMessage = (item, logger) => {
|
|
|
119
86
|
chats,
|
|
120
87
|
contacts,
|
|
121
88
|
messages,
|
|
122
|
-
lidPnMappings,
|
|
123
89
|
syncType: item.syncType,
|
|
124
90
|
progress: item.progress
|
|
125
91
|
}
|
|
126
92
|
}
|
|
127
93
|
|
|
128
|
-
const downloadAndProcessHistorySyncNotification = async (msg, options
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
historyMsg = WAProto_1.proto.HistorySync.decode(await inflatePromise(msg.initialHistBootstrapInlinePayload))
|
|
132
|
-
}
|
|
133
|
-
else {
|
|
134
|
-
historyMsg = await downloadHistory(msg, options)
|
|
135
|
-
}
|
|
136
|
-
return processHistoryMessage(historyMsg, logger)
|
|
94
|
+
const downloadAndProcessHistorySyncNotification = async (msg, options) => {
|
|
95
|
+
const historyMsg = await downloadHistory(msg, options)
|
|
96
|
+
return processHistoryMessage(historyMsg)
|
|
137
97
|
}
|
|
138
98
|
|
|
139
99
|
const getHistoryMsg = (message) => {
|
|
140
|
-
const normalizedContent = !!message ?
|
|
141
|
-
|
|
100
|
+
const normalizedContent = !!message ? messages_1.normalizeMessageContent(message) : undefined
|
|
101
|
+
const anyHistoryMsg = normalizedContent?.protocolMessage?.historySyncNotification
|
|
102
|
+
return anyHistoryMsg
|
|
142
103
|
}
|
|
143
104
|
|
|
144
105
|
module.exports = {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
}
|
|
106
|
+
downloadHistory,
|
|
107
|
+
processHistoryMessage,
|
|
108
|
+
downloadAndProcessHistorySyncNotification,
|
|
109
|
+
getHistoryMsg
|
|
110
|
+
}
|
package/lib/Utils/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
export * from './generics'
|
|
2
|
-
export * from './browser-utils'
|
|
3
2
|
export * from './decode-wa-message'
|
|
4
3
|
export * from './messages'
|
|
5
4
|
export * from './messages-media'
|
|
@@ -17,6 +16,4 @@ export * from './use-single-file-auth-state'
|
|
|
17
16
|
export * from './use-multi-file-auth-state'
|
|
18
17
|
export * from './link-preview'
|
|
19
18
|
export * from './event-buffer'
|
|
20
|
-
export * from './process-message'
|
|
21
|
-
export * from './message-retry-manager'
|
|
22
|
-
export * from './check-npm-version'
|
|
19
|
+
export * from './process-message'
|
package/lib/Utils/index.js
CHANGED
|
@@ -19,7 +19,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true })
|
|
20
20
|
|
|
21
21
|
__exportStar(require("./generics"), exports)
|
|
22
|
-
__exportStar(require("./browser-utils"), exports)
|
|
23
22
|
__exportStar(require("./decode-wa-message"), exports)
|
|
24
23
|
__exportStar(require("./messages"), exports)
|
|
25
24
|
__exportStar(require("./messages-media"), exports)
|
|
@@ -39,4 +38,4 @@ __exportStar(require("./link-preview"), exports)
|
|
|
39
38
|
__exportStar(require("./event-buffer"), exports)
|
|
40
39
|
__exportStar(require("./process-message"), exports)
|
|
41
40
|
__exportStar(require("./message-retry-manager"), exports)
|
|
42
|
-
__exportStar(require("./check-npm-version"), exports)
|
|
41
|
+
__exportStar(require("./check-npm-version"), exports)
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MessageRetryManager = void 0;
|
|
4
4
|
const lru_cache_1 = require("lru-cache");
|
|
5
|
-
const LRUCache = lru_cache_1.LRUCache || lru_cache_1;
|
|
6
5
|
/** Number of sent messages to cache in memory for handling retry receipts */
|
|
7
6
|
const RECENT_MESSAGES_SIZE = 512;
|
|
8
7
|
const MESSAGE_KEY_SEPARATOR = '\u0000';
|
|
@@ -12,7 +11,7 @@ const PHONE_REQUEST_DELAY = 3000;
|
|
|
12
11
|
class MessageRetryManager {
|
|
13
12
|
constructor(logger, maxMsgRetryCount) {
|
|
14
13
|
this.logger = logger;
|
|
15
|
-
this.recentMessagesMap = new LRUCache({
|
|
14
|
+
this.recentMessagesMap = new lru_cache_1.LRUCache({
|
|
16
15
|
max: RECENT_MESSAGES_SIZE,
|
|
17
16
|
ttl: 5 * 60 * 1000,
|
|
18
17
|
ttlAutopurge: true,
|
|
@@ -25,11 +24,11 @@ class MessageRetryManager {
|
|
|
25
24
|
}
|
|
26
25
|
});
|
|
27
26
|
this.messageKeyIndex = new Map();
|
|
28
|
-
this.sessionRecreateHistory = new LRUCache({
|
|
27
|
+
this.sessionRecreateHistory = new lru_cache_1.LRUCache({
|
|
29
28
|
ttl: RECREATE_SESSION_TIMEOUT * 2,
|
|
30
29
|
ttlAutopurge: true
|
|
31
30
|
});
|
|
32
|
-
this.retryCounters = new LRUCache({
|
|
31
|
+
this.retryCounters = new lru_cache_1.LRUCache({
|
|
33
32
|
ttl: 15 * 60 * 1000,
|
|
34
33
|
ttlAutopurge: true,
|
|
35
34
|
updateAgeOnGet: true
|
|
@@ -177,3 +176,4 @@ exports.MessageRetryManager = MessageRetryManager;
|
|
|
177
176
|
//# sourceMappingURL=message-retry-manager.js.map
|
|
178
177
|
|
|
179
178
|
|
|
179
|
+
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AxiosRequestConfig } from 'axios'
|
|
2
2
|
import { proto } from '../../WAProto'
|
|
3
|
-
import { AuthenticationCreds, BaileysEventEmitter, CacheStore, SignalKeyStoreWithTransaction,
|
|
3
|
+
import { AuthenticationCreds, BaileysEventEmitter, CacheStore, SignalKeyStoreWithTransaction, SocketConfig } from '../Types'
|
|
4
4
|
import { ILogger } from './logger'
|
|
5
5
|
|
|
6
6
|
type ProcessMessageContext = {
|
|
@@ -12,7 +12,6 @@ type ProcessMessageContext = {
|
|
|
12
12
|
getMessage: SocketConfig['getMessage']
|
|
13
13
|
logger?: ILogger
|
|
14
14
|
options: AxiosRequestConfig<{}>
|
|
15
|
-
signalRepository: SignalRepositoryWithLIDStore
|
|
16
15
|
}
|
|
17
16
|
|
|
18
17
|
/** Cleans a received message to further processing (Baileys 7.x: hosted Pn/LID + meLid) */
|
|
@@ -47,4 +46,4 @@ type PollContext = {
|
|
|
47
46
|
*/
|
|
48
47
|
export declare function decryptPollVote({ encPayload, encIv }: proto.Message.IPollEncValue, { pollCreatorJid, pollMsgId, pollEncKey, voterJid, }: PollContext): proto.Message.PollVoteMessage
|
|
49
48
|
|
|
50
|
-
export declare const processMessage: (message: proto.IWebMessageInfo, { shouldProcessHistoryMsg, placeholderResendCache, ev, creds, keyStore, logger, options, getMessage
|
|
49
|
+
export declare const processMessage: (message: proto.IWebMessageInfo, { shouldProcessHistoryMsg, placeholderResendCache, ev, creds, keyStore, logger, options, getMessage }: ProcessMessageContext) => Promise<void>
|
|
@@ -112,7 +112,7 @@ function decryptPollVote({ encPayload, encIv }, { pollCreatorJid, pollMsgId, pol
|
|
|
112
112
|
}
|
|
113
113
|
}
|
|
114
114
|
|
|
115
|
-
const processMessage = async (message, { shouldProcessHistoryMsg, placeholderResendCache, ev, creds, keyStore, logger, options, getMessage
|
|
115
|
+
const processMessage = async (message, { shouldProcessHistoryMsg, placeholderResendCache, ev, creds, keyStore, logger, options, getMessage }) => {
|
|
116
116
|
const meId = creds.me.id
|
|
117
117
|
const { accountSettings } = creds
|
|
118
118
|
const chat = { id: WABinary_1.jidNormalizedUser(getChatId(message.key)) }
|
|
@@ -155,12 +155,7 @@ const processMessage = async (message, { shouldProcessHistoryMsg, placeholderRes
|
|
|
155
155
|
]
|
|
156
156
|
})
|
|
157
157
|
}
|
|
158
|
-
const data = await history_1.downloadAndProcessHistorySyncNotification(histNotification, options
|
|
159
|
-
if (data.lidPnMappings?.length) {
|
|
160
|
-
logger?.debug?.({ count: data.lidPnMappings.length }, 'processing LID-PN mappings from history sync')
|
|
161
|
-
await signalRepository?.lidMapping?.storeLIDPNMappings(data.lidPnMappings)
|
|
162
|
-
.catch(err => logger?.warn?.({ err }, 'failed to store LID-PN mappings from history sync'))
|
|
163
|
-
}
|
|
158
|
+
const data = await history_1.downloadAndProcessHistorySyncNotification(histNotification, options)
|
|
164
159
|
ev.emit('messaging-history.set', {
|
|
165
160
|
...data,
|
|
166
161
|
isLatest: histNotification.syncType !== WAProto_1.proto.HistorySync.HistorySyncType.ON_DEMAND
|
|
@@ -269,27 +264,6 @@ const processMessage = async (message, { shouldProcessHistoryMsg, placeholderRes
|
|
|
269
264
|
})
|
|
270
265
|
}
|
|
271
266
|
break
|
|
272
|
-
case WAProto_1.proto.Message.ProtocolMessage.Type.LID_MIGRATION_MAPPING_SYNC:
|
|
273
|
-
const encodedPayload = protocolMsg.lidMigrationMappingSyncMessage?.encodedMappingPayload
|
|
274
|
-
if (encodedPayload?.length && signalRepository?.lidMapping) {
|
|
275
|
-
const { pnToLidMappings, chatDbMigrationTimestamp } = WAProto_1.proto.LIDMigrationMappingSyncPayload.decode(encodedPayload)
|
|
276
|
-
logger?.debug?.({ pnToLidMappings, chatDbMigrationTimestamp }, 'got LID migration mappings')
|
|
277
|
-
const pairs = []
|
|
278
|
-
for (const { pn, latestLid, assignedLid } of pnToLidMappings || []) {
|
|
279
|
-
const lidUser = latestLid || assignedLid
|
|
280
|
-
if (pn && lidUser) {
|
|
281
|
-
pairs.push({
|
|
282
|
-
lid: `${lidUser}@lid`,
|
|
283
|
-
pn: `${pn}@s.whatsapp.net`
|
|
284
|
-
})
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
await signalRepository.lidMapping.storeLIDPNMappings(pairs)
|
|
288
|
-
for (const { pn, lid } of pairs) {
|
|
289
|
-
await signalRepository.migrateSession(pn, lid)
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
break
|
|
293
267
|
}
|
|
294
268
|
}
|
|
295
269
|
else if (content?.reactionMessage) {
|