@neelegirl/baileys 2.0.4 → 2.0.6
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 +93 -880
- package/lib/Socket/socket.js +3 -3
- package/lib/Types/Message.d.ts +5 -1
- 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/package.json +44 -10
- package/WAProto/GenerateStatics.sh +0 -3
- package/WAProto/fix-imports.js +0 -81
package/lib/Socket/socket.js
CHANGED
|
@@ -793,7 +793,7 @@ const makeSocket = (config) => {
|
|
|
793
793
|
try {
|
|
794
794
|
const myPN = authState.creds.me.id
|
|
795
795
|
// Store our own LID-PN mapping
|
|
796
|
-
await signalRepository
|
|
796
|
+
await signalRepository?.lidMapping?.storeLIDPNMappings?.([{ lid: myLID, pn: myPN }])
|
|
797
797
|
// Create device list for our own user (needed for bulk migration)
|
|
798
798
|
const { user, device } = WABinary_1.jidDecode(myPN)
|
|
799
799
|
await authState.keys.set({
|
|
@@ -802,7 +802,7 @@ const makeSocket = (config) => {
|
|
|
802
802
|
}
|
|
803
803
|
})
|
|
804
804
|
// migrate our own session
|
|
805
|
-
await signalRepository
|
|
805
|
+
await signalRepository?.migrateSession?.(myPN, myLID)
|
|
806
806
|
logger.info({ myPN, myLID }, 'Own LID session created successfully')
|
|
807
807
|
}
|
|
808
808
|
catch (error) {
|
|
@@ -944,4 +944,4 @@ function mapWebSocketError(handler) {
|
|
|
944
944
|
|
|
945
945
|
module.exports = {
|
|
946
946
|
makeSocket
|
|
947
|
-
}
|
|
947
|
+
}
|
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'>
|
|
@@ -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/package.json
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@neelegirl/baileys",
|
|
3
|
-
"version": "2.0.
|
|
4
|
-
"description": "WhatsApp
|
|
3
|
+
"version": "2.0.6",
|
|
4
|
+
"description": "Conservative Neelegirl-maintained CommonJS WhatsApp Web client based on WhiskeySockets/Baileys with preserved QR, NEELE message IDs and device/LID handling.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"whatsapp",
|
|
7
|
+
"baileys",
|
|
8
|
+
"neelegirl",
|
|
7
9
|
"js-whatsapp",
|
|
8
10
|
"whatsapp-api",
|
|
9
11
|
"whatsapp-web",
|
|
@@ -12,23 +14,52 @@
|
|
|
12
14
|
"automation",
|
|
13
15
|
"multi-device"
|
|
14
16
|
],
|
|
15
|
-
"homepage": "https://
|
|
17
|
+
"homepage": "https://www.npmjs.com/package/@neelegirl/baileys",
|
|
16
18
|
"repository": {
|
|
17
|
-
"
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "git+https://github.com/WhiskeySockets/Baileys.git"
|
|
18
21
|
},
|
|
19
22
|
"license": "MIT",
|
|
20
23
|
"author": "Neele",
|
|
21
24
|
"main": "lib/index.js",
|
|
22
25
|
"types": "lib/index.d.ts",
|
|
26
|
+
"exports": {
|
|
27
|
+
".": {
|
|
28
|
+
"types": "./lib/index.d.ts",
|
|
29
|
+
"require": "./lib/index.js",
|
|
30
|
+
"default": "./lib/index.js"
|
|
31
|
+
},
|
|
32
|
+
"./lib": {
|
|
33
|
+
"types": "./lib/index.d.ts",
|
|
34
|
+
"require": "./lib/index.js",
|
|
35
|
+
"default": "./lib/index.js"
|
|
36
|
+
},
|
|
37
|
+
"./lib/*": {
|
|
38
|
+
"types": "./lib/*.d.ts",
|
|
39
|
+
"require": "./lib/*.js",
|
|
40
|
+
"default": "./lib/*.js"
|
|
41
|
+
},
|
|
42
|
+
"./WAProto": {
|
|
43
|
+
"types": "./WAProto/index.d.ts",
|
|
44
|
+
"require": "./WAProto/index.js",
|
|
45
|
+
"default": "./WAProto/index.js"
|
|
46
|
+
},
|
|
47
|
+
"./WAProto/*": {
|
|
48
|
+
"types": "./WAProto/*.d.ts",
|
|
49
|
+
"require": "./WAProto/*.js",
|
|
50
|
+
"default": "./WAProto/*.js"
|
|
51
|
+
},
|
|
52
|
+
"./package.json": "./package.json"
|
|
53
|
+
},
|
|
23
54
|
"files": [
|
|
24
|
-
"lib
|
|
25
|
-
"WAProto
|
|
26
|
-
"
|
|
55
|
+
"lib/**/*",
|
|
56
|
+
"WAProto/**/*",
|
|
57
|
+
"LICENSE",
|
|
58
|
+
"README.md"
|
|
27
59
|
],
|
|
28
60
|
"scripts": {
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"build:tsc": "tsc"
|
|
61
|
+
"smoke": "node -e \"require('./lib/index.js')\"",
|
|
62
|
+
"test": "node -e \"require('./lib/index.js')\""
|
|
32
63
|
},
|
|
33
64
|
"dependencies": {
|
|
34
65
|
"@adiwajshing/keyed-db": "^0.2.4",
|
|
@@ -90,5 +121,8 @@
|
|
|
90
121
|
"optional": true
|
|
91
122
|
}
|
|
92
123
|
},
|
|
124
|
+
"engines": {
|
|
125
|
+
"node": ">=16.0.0"
|
|
126
|
+
},
|
|
93
127
|
"packageManager": "yarn@1.22.19"
|
|
94
128
|
}
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
yarn pbjs -t static-module --no-beautify -w es6 --no-bundle --no-delimited --no-verify --no-comments -o ./index.js ./WAProto.proto;
|
|
2
|
-
yarn pbjs -t static-module --no-beautify -w es6 --no-bundle --no-delimited --no-verify ./WAProto.proto | yarn pbts --no-comments -o ./index.d.ts -;
|
|
3
|
-
node ./fix-imports.js
|
package/WAProto/fix-imports.js
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import { readFileSync, writeFileSync } from 'fs';
|
|
2
|
-
import { exit } from 'process';
|
|
3
|
-
|
|
4
|
-
const filePath = './index.js'
|
|
5
|
-
|
|
6
|
-
try {
|
|
7
|
-
let content = readFileSync(filePath, 'utf8')
|
|
8
|
-
|
|
9
|
-
content = content.replace(/import \* as (\$protobuf) from/g, 'import $1 from')
|
|
10
|
-
content = content.replace(/(['"])protobufjs\/minimal(['"])/g, '$1protobufjs/minimal.js$2')
|
|
11
|
-
|
|
12
|
-
const marker = 'const $root = $protobuf.roots["default"] || ($protobuf.roots["default"] = {});\n\n'
|
|
13
|
-
const longToStringHelper =
|
|
14
|
-
'function longToString(value, unsigned) {\n' +
|
|
15
|
-
'\tif (typeof value === "string") {\n' +
|
|
16
|
-
'\t\treturn value;\n' +
|
|
17
|
-
'\t}\n' +
|
|
18
|
-
'\tif (typeof value === "number") {\n' +
|
|
19
|
-
'\t\treturn String(value);\n' +
|
|
20
|
-
'\t}\n' +
|
|
21
|
-
'\tif (!$util.Long) {\n' +
|
|
22
|
-
'\t\treturn String(value);\n' +
|
|
23
|
-
'\t}\n' +
|
|
24
|
-
'\tconst normalized = $util.Long.fromValue(value);\n' +
|
|
25
|
-
'\tconst prepared = unsigned && normalized && typeof normalized.toUnsigned === "function"\n' +
|
|
26
|
-
'\t\t? normalized.toUnsigned()\n' +
|
|
27
|
-
'\t\t: normalized;\n' +
|
|
28
|
-
'\treturn prepared.toString();\n' +
|
|
29
|
-
'}\n\n'
|
|
30
|
-
const longToNumberHelper =
|
|
31
|
-
'function longToNumber(value, unsigned) {\n' +
|
|
32
|
-
'\tif (typeof value === "number") {\n' +
|
|
33
|
-
'\t\treturn value;\n' +
|
|
34
|
-
'\t}\n' +
|
|
35
|
-
'\tif (typeof value === "string") {\n' +
|
|
36
|
-
'\t\tconst numeric = Number(value);\n' +
|
|
37
|
-
'\t\treturn numeric;\n' +
|
|
38
|
-
'\t}\n' +
|
|
39
|
-
'\tif (!$util.Long) {\n' +
|
|
40
|
-
'\t\treturn Number(value);\n' +
|
|
41
|
-
'\t}\n' +
|
|
42
|
-
'\tconst normalized = $util.Long.fromValue(value);\n' +
|
|
43
|
-
'\tconst prepared = unsigned && normalized && typeof normalized.toUnsigned === "function"\n' +
|
|
44
|
-
'\t\t? normalized.toUnsigned()\n' +
|
|
45
|
-
'\t\t: typeof normalized.toSigned === "function"\n' +
|
|
46
|
-
'\t\t\t? normalized.toSigned()\n' +
|
|
47
|
-
'\t\t\t: normalized;\n' +
|
|
48
|
-
'\treturn prepared.toNumber();\n' +
|
|
49
|
-
'}\n\n'
|
|
50
|
-
|
|
51
|
-
if (!content.includes('function longToString(')) {
|
|
52
|
-
const markerIndex = content.indexOf(marker)
|
|
53
|
-
if (markerIndex === -1) {
|
|
54
|
-
throw new Error('Unable to inject Long helpers: marker not found in WAProto index output')
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
content = content.replace(marker, `${marker}${longToStringHelper}${longToNumberHelper}`)
|
|
58
|
-
} else {
|
|
59
|
-
const longToStringRegex = /function longToString\(value, unsigned\) {\n[\s\S]*?\n}\n\n/
|
|
60
|
-
const longToNumberRegex = /function longToNumber\(value, unsigned\) {\n[\s\S]*?\n}\n\n/
|
|
61
|
-
|
|
62
|
-
if (!longToStringRegex.test(content) || !longToNumberRegex.test(content)) {
|
|
63
|
-
throw new Error('Unable to update Long helpers: existing definitions not found')
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
content = content.replace(longToStringRegex, longToStringHelper)
|
|
67
|
-
content = content.replace(longToNumberRegex, longToNumberHelper)
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const longPattern = /([ \t]+d\.(\w+) = )o\.longs === String \? \$util\.Long\.prototype\.toString\.call\(m\.\2\) : o\.longs === Number \? new \$util\.LongBits\(m\.\2\.low >>> 0, m\.\2\.high >>> 0\)\.toNumber\((true)?\) : m\.\2;/g
|
|
71
|
-
content = content.replace(longPattern, (_match, prefix, field, unsignedFlag) => {
|
|
72
|
-
const unsignedArg = unsignedFlag ? ', true' : ''
|
|
73
|
-
return `${prefix}o.longs === String ? longToString(m.${field}${unsignedArg}) : o.longs === Number ? longToNumber(m.${field}${unsignedArg}) : m.${field};`
|
|
74
|
-
})
|
|
75
|
-
|
|
76
|
-
writeFileSync(filePath, content, 'utf8')
|
|
77
|
-
console.log(`✅ Fixed imports in ${filePath}`)
|
|
78
|
-
} catch (error) {
|
|
79
|
-
console.error(`❌ Error fixing imports: ${error.message}`)
|
|
80
|
-
exit(1)
|
|
81
|
-
}
|