@nexustechpro/baileys 2.0.1 → 2.0.5
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 +924 -1299
- package/lib/Defaults/baileys-version.json +6 -2
- package/lib/Defaults/index.js +172 -172
- package/lib/Signal/libsignal.js +380 -292
- package/lib/Signal/lid-mapping.js +264 -171
- package/lib/Socket/Client/index.js +2 -2
- package/lib/Socket/Client/types.js +10 -10
- package/lib/Socket/Client/websocket.js +45 -310
- package/lib/Socket/business.js +375 -375
- package/lib/Socket/chats.js +909 -963
- package/lib/Socket/communities.js +430 -430
- package/lib/Socket/groups.js +342 -342
- package/lib/Socket/index.js +22 -22
- package/lib/Socket/messages-recv.js +777 -743
- package/lib/Socket/messages-send.js +667 -393
- package/lib/Socket/mex.js +50 -50
- package/lib/Socket/newsletter.js +148 -148
- package/lib/Socket/nexus-handler.js +75 -261
- package/lib/Socket/socket.js +709 -1201
- package/lib/Store/index.js +5 -5
- package/lib/Store/make-cache-manager-store.js +81 -81
- package/lib/Store/make-in-memory-store.js +416 -416
- package/lib/Store/make-ordered-dictionary.js +81 -81
- package/lib/Store/object-repository.js +30 -30
- package/lib/Types/Auth.js +1 -1
- package/lib/Types/Bussines.js +1 -1
- package/lib/Types/Call.js +1 -1
- package/lib/Types/Chat.js +7 -7
- package/lib/Types/Contact.js +1 -1
- package/lib/Types/Events.js +1 -1
- package/lib/Types/GroupMetadata.js +1 -1
- package/lib/Types/Label.js +24 -24
- package/lib/Types/LabelAssociation.js +6 -6
- package/lib/Types/Message.js +10 -10
- package/lib/Types/Newsletter.js +28 -28
- package/lib/Types/Product.js +1 -1
- package/lib/Types/Signal.js +1 -1
- package/lib/Types/Socket.js +2 -2
- package/lib/Types/State.js +12 -12
- package/lib/Types/USync.js +1 -1
- package/lib/Types/index.js +25 -25
- package/lib/Utils/auth-utils.js +264 -256
- package/lib/Utils/baileys-event-stream.js +55 -55
- package/lib/Utils/browser-utils.js +27 -27
- package/lib/Utils/business.js +228 -230
- package/lib/Utils/chat-utils.js +694 -764
- package/lib/Utils/crypto.js +109 -135
- package/lib/Utils/decode-wa-message.js +310 -314
- package/lib/Utils/event-buffer.js +547 -547
- package/lib/Utils/generics.js +297 -297
- package/lib/Utils/history.js +91 -83
- package/lib/Utils/index.js +21 -20
- package/lib/Utils/key-store.js +17 -0
- package/lib/Utils/link-preview.js +97 -88
- package/lib/Utils/logger.js +2 -2
- package/lib/Utils/lt-hash.js +47 -47
- package/lib/Utils/make-mutex.js +39 -39
- package/lib/Utils/message-retry-manager.js +148 -148
- package/lib/Utils/messages-media.js +534 -532
- package/lib/Utils/messages.js +705 -705
- package/lib/Utils/noise-handler.js +255 -255
- package/lib/Utils/pre-key-manager.js +105 -105
- package/lib/Utils/process-message.js +412 -412
- package/lib/Utils/signal.js +160 -158
- package/lib/Utils/use-multi-file-auth-state.js +120 -120
- package/lib/Utils/validate-connection.js +194 -194
- package/lib/WABinary/constants.js +1300 -1300
- package/lib/WABinary/decode.js +237 -237
- package/lib/WABinary/encode.js +232 -232
- package/lib/WABinary/generic-utils.js +252 -211
- package/lib/WABinary/index.js +5 -5
- package/lib/WABinary/jid-utils.js +279 -95
- package/lib/WABinary/types.js +1 -1
- package/lib/WAM/BinaryInfo.js +9 -9
- package/lib/WAM/constants.js +22852 -22852
- package/lib/WAM/encode.js +149 -149
- package/lib/WAM/index.js +3 -3
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +28 -28
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +53 -53
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +26 -26
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +37 -37
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +50 -50
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +28 -28
- package/lib/WAUSync/Protocols/index.js +4 -4
- package/lib/WAUSync/USyncQuery.js +93 -93
- package/lib/WAUSync/USyncUser.js +22 -22
- package/lib/WAUSync/index.js +3 -3
- package/lib/index.js +66 -66
- package/package.json +171 -144
- package/lib/Signal/Group/ciphertext-message.js +0 -12
- package/lib/Signal/Group/group-session-builder.js +0 -30
- package/lib/Signal/Group/group_cipher.js +0 -100
- package/lib/Signal/Group/index.js +0 -12
- package/lib/Signal/Group/keyhelper.js +0 -18
- package/lib/Signal/Group/sender-chain-key.js +0 -26
- package/lib/Signal/Group/sender-key-distribution-message.js +0 -63
- package/lib/Signal/Group/sender-key-message.js +0 -66
- package/lib/Signal/Group/sender-key-name.js +0 -48
- package/lib/Signal/Group/sender-key-record.js +0 -41
- package/lib/Signal/Group/sender-key-state.js +0 -84
- package/lib/Signal/Group/sender-message-key.js +0 -26
|
@@ -1,96 +1,280 @@
|
|
|
1
|
-
|
|
2
|
-
export const
|
|
3
|
-
export const
|
|
4
|
-
export const
|
|
5
|
-
export const
|
|
6
|
-
export const
|
|
7
|
-
export
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
WAJIDDomains[WAJIDDomains["
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
case WAJIDDomains.
|
|
21
|
-
|
|
22
|
-
case WAJIDDomains.
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
const server = jid.slice(sepIdx + 1);
|
|
37
|
-
const userCombined = jid.slice(0, sepIdx);
|
|
38
|
-
const [userAgent, device] = userCombined.split(':');
|
|
39
|
-
const [user, agent] = userAgent.split('_');
|
|
40
|
-
let domainType = WAJIDDomains.WHATSAPP;
|
|
41
|
-
if (server === 'lid')
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
else if (
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
domainType
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
/** is the jid a user */
|
|
61
|
-
export const
|
|
62
|
-
/** is the jid
|
|
63
|
-
export const
|
|
64
|
-
/** is the jid a
|
|
65
|
-
export const
|
|
66
|
-
/** is the jid a
|
|
67
|
-
export const
|
|
68
|
-
/** is the jid
|
|
69
|
-
export const
|
|
70
|
-
/** is the jid a
|
|
71
|
-
export const
|
|
72
|
-
/** is the jid
|
|
73
|
-
export const
|
|
74
|
-
/** is the jid a
|
|
75
|
-
export const
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
const
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
1
|
+
// ===== CONSTANTS =====
|
|
2
|
+
export const S_WHATSAPP_NET = '@s.whatsapp.net';
|
|
3
|
+
export const OFFICIAL_BIZ_JID = '16505361212@c.us';
|
|
4
|
+
export const SERVER_JID = 'server@c.us';
|
|
5
|
+
export const PSA_WID = '0@c.us';
|
|
6
|
+
export const STORIES_JID = 'status@broadcast';
|
|
7
|
+
export const META_AI_JID = '13135550002@c.us';
|
|
8
|
+
|
|
9
|
+
// ===== DOMAIN TYPES =====
|
|
10
|
+
export var WAJIDDomains;
|
|
11
|
+
(function (WAJIDDomains) {
|
|
12
|
+
WAJIDDomains[WAJIDDomains["WHATSAPP"] = 0] = "WHATSAPP";
|
|
13
|
+
WAJIDDomains[WAJIDDomains["LID"] = 1] = "LID";
|
|
14
|
+
WAJIDDomains[WAJIDDomains["HOSTED"] = 128] = "HOSTED";
|
|
15
|
+
WAJIDDomains[WAJIDDomains["HOSTED_LID"] = 129] = "HOSTED_LID";
|
|
16
|
+
})(WAJIDDomains || (WAJIDDomains = {}));
|
|
17
|
+
|
|
18
|
+
export const getServerFromDomainType = (initialServer, domainType) => {
|
|
19
|
+
switch (domainType) {
|
|
20
|
+
case WAJIDDomains.LID: return 'lid';
|
|
21
|
+
case WAJIDDomains.HOSTED: return 'hosted';
|
|
22
|
+
case WAJIDDomains.HOSTED_LID: return 'hosted.lid';
|
|
23
|
+
case WAJIDDomains.WHATSAPP:
|
|
24
|
+
default: return initialServer;
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
// ===== CORE ENCODE / DECODE =====
|
|
29
|
+
export const jidEncode = (user, server, device, agent) => {
|
|
30
|
+
return `${user || ''}${!!agent ? `_${agent}` : ''}${!!device ? `:${device}` : ''}@${server}`;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export const jidDecode = (jid) => {
|
|
34
|
+
const sepIdx = typeof jid === 'string' ? jid.indexOf('@') : -1;
|
|
35
|
+
if (sepIdx < 0) return undefined;
|
|
36
|
+
const server = jid.slice(sepIdx + 1);
|
|
37
|
+
const userCombined = jid.slice(0, sepIdx);
|
|
38
|
+
const [userAgent, device] = userCombined.split(':');
|
|
39
|
+
const [user, agent] = userAgent.split('_');
|
|
40
|
+
let domainType = WAJIDDomains.WHATSAPP;
|
|
41
|
+
if (server === 'lid') domainType = WAJIDDomains.LID;
|
|
42
|
+
else if (server === 'hosted') domainType = WAJIDDomains.HOSTED;
|
|
43
|
+
else if (server === 'hosted.lid') domainType = WAJIDDomains.HOSTED_LID;
|
|
44
|
+
else if (agent) domainType = parseInt(agent);
|
|
45
|
+
return {
|
|
46
|
+
server: server,
|
|
47
|
+
user: user,
|
|
48
|
+
domainType,
|
|
49
|
+
device: device ? +device : undefined
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
// ===== JID PREDICATES =====
|
|
54
|
+
/** is the jid a user */
|
|
55
|
+
export const areJidsSameUser = (jid1, jid2) => jidDecode(jid1)?.user === jidDecode(jid2)?.user;
|
|
56
|
+
/** is the jid Meta AI (@bot server) */
|
|
57
|
+
export const isJidMetaAI = (jid) => jid?.endsWith('@bot');
|
|
58
|
+
/** is the jid a PN user (@s.whatsapp.net) */
|
|
59
|
+
export const isPnUser = (jid) => jid?.endsWith('@s.whatsapp.net');
|
|
60
|
+
/** is the jid a user — alias for isPnUser for back-compat */
|
|
61
|
+
export const isJidUser = isPnUser;
|
|
62
|
+
/** is the jid a LID */
|
|
63
|
+
export const isLidUser = (jid) => jid?.endsWith('@lid');
|
|
64
|
+
/** is the jid a broadcast */
|
|
65
|
+
export const isJidBroadcast = (jid) => jid?.endsWith('@broadcast');
|
|
66
|
+
/** is the jid a group */
|
|
67
|
+
export const isJidGroup = (jid) => jid?.endsWith('@g.us');
|
|
68
|
+
/** is the jid the status broadcast */
|
|
69
|
+
export const isJidStatusBroadcast = (jid) => jid === 'status@broadcast';
|
|
70
|
+
/** is the jid a newsletter */
|
|
71
|
+
export const isJidNewsletter = (jid) => jid?.endsWith('@newsletter');
|
|
72
|
+
/** is the jid a hosted PN */
|
|
73
|
+
export const isHostedPnUser = (jid) => jid?.endsWith('@hosted');
|
|
74
|
+
/** is the jid a hosted LID */
|
|
75
|
+
export const isHostedLidUser = (jid) => jid?.endsWith('@hosted.lid');
|
|
76
|
+
|
|
77
|
+
const botRegexp = /^1313555\d{4}$|^131655500\d{2}$/;
|
|
78
|
+
export const isJidBot = (jid) => jid && botRegexp.test(jid.split('@')[0]) && jid.endsWith('@c.us');
|
|
79
|
+
|
|
80
|
+
export const jidNormalizedUser = (jid) => {
|
|
81
|
+
const result = jidDecode(jid);
|
|
82
|
+
if (!result) return '';
|
|
83
|
+
const { user, server } = result;
|
|
84
|
+
return jidEncode(user, server === 'c.us' ? 's.whatsapp.net' : server);
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
export const transferDevice = (fromJid, toJid) => {
|
|
88
|
+
const fromDecoded = jidDecode(fromJid);
|
|
89
|
+
const deviceId = fromDecoded?.device || 0;
|
|
90
|
+
const { server, user } = jidDecode(toJid);
|
|
91
|
+
return jidEncode(user, server, deviceId);
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
// ===== LRU CACHE =====
|
|
95
|
+
class SimpleLRU {
|
|
96
|
+
constructor(maxSize = 2000, ttl = 5 * 60 * 1000) {
|
|
97
|
+
this.maxSize = maxSize;
|
|
98
|
+
this.ttl = ttl;
|
|
99
|
+
this.map = new Map();
|
|
100
|
+
}
|
|
101
|
+
get(key) {
|
|
102
|
+
const entry = this.map.get(key);
|
|
103
|
+
if (!entry) return undefined;
|
|
104
|
+
if (Date.now() - entry.ts > this.ttl) { this.map.delete(key); return undefined; }
|
|
105
|
+
this.map.delete(key);
|
|
106
|
+
this.map.set(key, entry);
|
|
107
|
+
return entry.value;
|
|
108
|
+
}
|
|
109
|
+
set(key, value) {
|
|
110
|
+
if (this.map.has(key)) this.map.delete(key);
|
|
111
|
+
this.map.set(key, { value, ts: Date.now() });
|
|
112
|
+
if (this.map.size > this.maxSize) {
|
|
113
|
+
const lru = this.map.keys().next().value;
|
|
114
|
+
if (lru) this.map.delete(lru);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const lidToJidCache = new SimpleLRU(2000, 5 * 60 * 1000);
|
|
120
|
+
|
|
121
|
+
// ===== SHARED LID ↔ PHONE CACHE =====
|
|
122
|
+
// Bidirectional runtime map populated from sender_pn / participant_pn / phone_number attributes.
|
|
123
|
+
// Used by lidToJid() and messages-recv for resolving LIDs to phone JIDs.
|
|
124
|
+
const _sharedLidPhoneMap = new Map();
|
|
125
|
+
const SHARED_MAP_MAX_SIZE = 3000;
|
|
126
|
+
|
|
127
|
+
export const sharedLidPhoneCache = {
|
|
128
|
+
set(lid, phoneJid) {
|
|
129
|
+
if (!lid || !phoneJid || typeof lid !== 'string' || typeof phoneJid !== 'string') return;
|
|
130
|
+
if (!phoneJid.includes('@')) phoneJid = phoneJid + '@s.whatsapp.net';
|
|
131
|
+
if (_sharedLidPhoneMap.size > SHARED_MAP_MAX_SIZE * 2) {
|
|
132
|
+
const it = _sharedLidPhoneMap.keys();
|
|
133
|
+
const toRemove = Math.floor(_sharedLidPhoneMap.size * 0.25);
|
|
134
|
+
for (let i = 0; i < toRemove; i++) {
|
|
135
|
+
const k = it.next().value;
|
|
136
|
+
if (k === undefined) break;
|
|
137
|
+
_sharedLidPhoneMap.delete(k);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
_sharedLidPhoneMap.set(lid, phoneJid);
|
|
141
|
+
_sharedLidPhoneMap.set(phoneJid, lid);
|
|
142
|
+
lidToJidCache.set(lid, phoneJid);
|
|
143
|
+
},
|
|
144
|
+
get(key) { return _sharedLidPhoneMap.get(key); },
|
|
145
|
+
getLidForPhone(phoneJid) {
|
|
146
|
+
if (!phoneJid) return undefined;
|
|
147
|
+
const val = _sharedLidPhoneMap.get(phoneJid);
|
|
148
|
+
return val && val.endsWith('@lid') ? val : undefined;
|
|
149
|
+
},
|
|
150
|
+
getPhoneForLid(lid) {
|
|
151
|
+
if (!lid) return undefined;
|
|
152
|
+
const val = _sharedLidPhoneMap.get(lid);
|
|
153
|
+
return val && val.endsWith('@s.whatsapp.net') ? val : undefined;
|
|
154
|
+
},
|
|
155
|
+
get size() { return _sharedLidPhoneMap.size; }
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
// ===== BOT MAP =====
|
|
159
|
+
const BOT_MAP_STATIC = new Map([["867051314767696", "13135550002"], ["1061492271844689", "13135550005"], ["245886058483988", "13135550009"], ["3509905702656130", "13135550012"], ["1059680132034576", "13135550013"], ["715681030623646", "13135550014"], ["1644971366323052", "13135550015"], ["582497970646566", "13135550019"], ["645459357769306", "13135550022"], ["294997126699143", "13135550023"], ["1522631578502677", "13135550027"], ["719421926276396", "13135550030"], ["1788488635002167", "13135550031"], ["24232338603080193", "13135550033"], ["689289903143209", "13135550035"], ["871626054177096", "13135550039"], ["362351902849370", "13135550042"], ["1744617646041527", "13135550043"], ["893887762270570", "13135550046"], ["1155032702135830", "13135550047"], ["333931965993883", "13135550048"], ["853748013058752", "13135550049"], ["1559068611564819", "13135550053"], ["890487432705716", "13135550054"], ["240254602395494", "13135550055"], ["1578420349663261", "13135550062"], ["322908887140421", "13135550065"], ["3713961535514771", "13135550067"], ["997884654811738", "13135550070"], ["403157239387035", "13135550081"], ["535242369074963", "13135550082"], ["946293427247659", "13135550083"], ["3664707673802291", "13135550084"], ["1821827464894892", "13135550085"], ["1760312477828757", "13135550086"], ["439480398712216", "13135550087"], ["1876735582800984", "13135550088"], ["984025089825661", "13135550089"], ["1001336351558186", "13135550090"], ["3739346336347061", "13135550091"], ["3632749426974980", "13135550092"], ["427864203481615", "13135550093"], ["1434734570493055", "13135550094"], ["992873449225921", "13135550095"], ["813087747426445", "13135550096"], ["806369104931434", "13135550098"], ["1220982902403148", "13135550099"], ["1365893374104393", "13135550100"], ["686482033622048", "13135550200"], ["1454999838411253", "13135550201"], ["718584497008509", "13135550202"], ["743520384213443", "13135550301"], ["1147715789823789", "13135550302"], ["1173034540372201", "13135550303"], ["974785541030953", "13135550304"], ["1122200255531507", "13135550305"], ["899669714813162", "13135550306"], ["631880108970650", "13135550307"], ["435816149330026", "13135550308"], ["1368717161184556", "13135550309"], ["7849963461784891", "13135550310"], ["3609617065968984", "13135550312"], ["356273980574602", "13135550313"], ["1043447920539760", "13135550314"], ["1052764336525346", "13135550315"], ["2631118843732685", "13135550316"], ["510505411332176", "13135550317"], ["1945664239227513", "13135550318"], ["1518594378764656", "13135550319"], ["1378821579456138", "13135550320"], ["490214716896013", "13135550321"], ["1028577858870699", "13135550322"], ["308915665545959", "13135550323"], ["845884253678900", "13135550324"], ["995031308616442", "13135550325"], ["2787365464763437", "13135550326"], ["1532790990671645", "13135550327"], ["302617036180485", "13135550328"], ["723376723197227", "13135550329"], ["8393570407377966", "13135550330"], ["1931159970680725", "13135550331"], ["401073885688605", "13135550332"], ["2234478453565422", "13135550334"], ["814748673882312", "13135550335"], ["26133635056281592", "13135550336"], ["1439804456676119", "13135550337"], ["889851503172161", "13135550338"], ["1018283232836879", "13135550339"], ["1012781386779537", "13135559000"], ["823280953239532", "13135559001"], ["1597090934573334", "13135559002"], ["485965054020343", "13135559003"], ["1033381648363446", "13135559004"], ["491802010206446", "13135559005"], ["1017139033184870", "13135559006"], ["499638325922174", "13135559008"], ["468946335863664", "13135559009"], ["1570389776875816", "13135559010"], ["1004342694328995", "13135559011"], ["1012240323971229", "13135559012"], ["392171787222419", "13135559013"], ["952081212945019", "13135559016"], ["444507875070178", "13135559017"], ["1274819440594668", "13135559018"], ["1397041101147050", "13135559019"], ["425657699872640", "13135559020"], ["532292852562549", "13135559021"], ["705863241720292", "13135559022"], ["476449815183959", "13135559023"], ["488071553854222", "13135559024"], ["468693832665397", "13135559025"], ["517422564037340", "13135559026"], ["819805466613825", "13135559027"], ["1847708235641382", "13135559028"], ["716282970644228", "13135559029"], ["521655380527741", "13135559030"], ["476193631941905", "13135559031"], ["485600497445562", "13135559032"], ["440217235683910", "13135559033"], ["523342446758478", "13135559034"], ["514784864360240", "13135559035"], ["505790121814530", "13135559036"], ["420008964419580", "13135559037"], ["492141680204555", "13135559038"], ["388462787271952", "13135559039"], ["423473920752072", "13135559040"], ["489574180468229", "13135559041"], ["432360635854105", "13135559042"], ["477878201669248", "13135559043"], ["351656951234045", "13135559044"], ["430178036732582", "13135559045"], ["434537312944552", "13135559046"], ["1240614300631808", "13135559047"], ["473135945605128", "13135559048"], ["423669800729310", "13135559049"], ["3685666705015792", "13135559050"], ["504196509016638", "13135559051"], ["346844785189449", "13135559052"], ["504823088911074", "13135559053"], ["402669415797083", "13135559054"], ["490939640234431", "13135559055"], ["875124128063715", "13135559056"], ["468788962654605", "13135559057"], ["562386196354570", "13135559058"], ["372159285928791", "13135559059"], ["531017479591050", "13135559060"], ["1328873881401826", "13135559061"], ["1608363646390484", "13135559062"], ["1229628561554232", "13135559063"], ["348802211530364", "13135559064"], ["3708535859420184", "13135559065"], ["415517767742187", "13135559066"], ["479330341612638", "13135559067"], ["480785414723083", "13135559068"], ["387299107507991", "13135559069"], ["333389813188944", "13135559070"], ["391794130316996", "13135559071"], ["457893470576314", "13135559072"], ["435550496166469", "13135559073"], ["1620162702100689", "13135559074"], ["867491058616043", "13135559075"], ["816224117357759", "13135559076"], ["334065176362830", "13135559077"], ["489973170554709", "13135559078"], ["473060669049665", "13135559079"], ["1221505815643060", "13135559080"], ["889000703096359", "13135559081"], ["475235961979883", "13135559082"], ["3434445653519934", "13135559084"], ["524503026827421", "13135559085"], ["1179639046403856", "13135559086"], ["471563305859144", "13135559087"], ["533896609192881", "13135559088"], ["365443583168041", "13135559089"], ["836082305329393", "13135559090"], ["1056787705969916", "13135559091"], ["503312598958357", "13135559092"], ["3718606738453460", "13135559093"], ["826066052850902", "13135559094"], ["1033611345091888", "13135559095"], ["3868390816783240", "13135559096"], ["7462677740498860", "13135559097"], ["436288576108573", "13135559098"], ["1047559746718900", "13135559099"], ["1099299455255491", "13135559100"], ["1202037301040633", "13135559101"], ["1720619402074074", "13135559102"], ["1030422235101467", "13135559103"], ["827238979523502", "13135559104"], ["1516443722284921", "13135559105"], ["1174442747196709", "13135559106"], ["1653165225503842", "13135559107"], ["1037648777635013", "13135559108"], ["551617757299900", "13135559109"], ["1158813558718726", "13135559110"], ["2463236450542262", "13135559111"], ["1550393252501466", "13135559112"], ["2057065188042796", "13135559113"], ["506163028760735", "13135559114"], ["2065249100538481", "13135559115"], ["1041382867195858", "13135559116"], ["886500209499603", "13135559117"], ["1491615624892655", "13135559118"], ["486563697299617", "13135559119"], ["1175736513679463", "13135559120"], ["491811473512352", "13165550064"]]);
|
|
160
|
+
|
|
161
|
+
let BOT_MAP = BOT_MAP_STATIC;
|
|
162
|
+
|
|
163
|
+
// ===== BOT MAP MANAGEMENT =====
|
|
164
|
+
export const setBotMap = (mapLike) => {
|
|
165
|
+
if (!mapLike) return;
|
|
166
|
+
BOT_MAP = mapLike instanceof Map ? mapLike : new Map(Object.entries(mapLike));
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
export const loadBotMapFromFile = async (filePath) => {
|
|
170
|
+
const { promises: fsp } = await import('fs');
|
|
171
|
+
const { join } = await import('path');
|
|
172
|
+
const { fileURLToPath } = await import('url');
|
|
173
|
+
const __dirname = fileURLToPath(new URL('.', import.meta.url));
|
|
174
|
+
|
|
175
|
+
const candidates = [];
|
|
176
|
+
if (filePath) candidates.push(filePath);
|
|
177
|
+
candidates.push(join(process.cwd(), 'bot-map.json'));
|
|
178
|
+
candidates.push(join(__dirname, 'bot-map.json'));
|
|
179
|
+
|
|
180
|
+
for (const p of candidates) {
|
|
181
|
+
try {
|
|
182
|
+
const stat = await fsp.stat(p).catch(() => null);
|
|
183
|
+
if (!stat?.isFile()) continue;
|
|
184
|
+
const data = await fsp.readFile(p, 'utf8');
|
|
185
|
+
const obj = JSON.parse(data);
|
|
186
|
+
if (obj && typeof obj === 'object') { BOT_MAP = new Map(Object.entries(obj)); return BOT_MAP; }
|
|
187
|
+
} catch { }
|
|
188
|
+
}
|
|
189
|
+
return BOT_MAP;
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
// ===== LID → JID RESOLUTION =====
|
|
193
|
+
export const lidToJid = (jid) => {
|
|
194
|
+
try {
|
|
195
|
+
if (!jid || typeof jid !== 'string') return jid;
|
|
196
|
+
const cached = lidToJidCache.get(jid);
|
|
197
|
+
if (cached) return cached;
|
|
198
|
+
|
|
199
|
+
let result = jid;
|
|
200
|
+
if (jid.endsWith('@lid')) {
|
|
201
|
+
const lidPart = jid.replace('@lid', '');
|
|
202
|
+
if (BOT_MAP.has(lidPart)) {
|
|
203
|
+
result = BOT_MAP.get(lidPart) + '@s.whatsapp.net';
|
|
204
|
+
} else {
|
|
205
|
+
const phoneFromCache = sharedLidPhoneCache.getPhoneForLid(jid);
|
|
206
|
+
if (phoneFromCache) result = phoneFromCache;
|
|
207
|
+
// LID parts are opaque — never guess from digits
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
if (result !== jid) lidToJidCache.set(jid, result);
|
|
212
|
+
return result;
|
|
213
|
+
} catch {
|
|
214
|
+
return jid;
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
export const resolveJid = (jid) => {
|
|
219
|
+
if (typeof jid === 'string' && jid.endsWith('@lid')) return lidToJid(jid);
|
|
220
|
+
return jid;
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
export const lidToJidEnhanced = (jid) => lidToJid(jid);
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Validates and cleans a JID. For LIDs, attempts resolution via BOT_MAP + sharedLidPhoneCache.
|
|
227
|
+
* Never converts a resolved JID back to LID — that would corrupt stored message keys.
|
|
228
|
+
*/
|
|
229
|
+
export const validateAndCleanJid = (jid) => {
|
|
230
|
+
if (!jid || typeof jid !== 'string') return jid;
|
|
231
|
+
if (jid.endsWith('@lid')) return lidToJid(jid);
|
|
232
|
+
return jid;
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* Async LID → JID with optional WhatsApp existence validation.
|
|
237
|
+
*/
|
|
238
|
+
export const validateAndConvertLidToJid = async (jid, onWhatsApp) => {
|
|
239
|
+
try {
|
|
240
|
+
if (!jid || typeof jid !== 'string') return jid;
|
|
241
|
+
const convertedJid = lidToJid(jid);
|
|
242
|
+
|
|
243
|
+
// Still a LID after resolution — nothing to validate
|
|
244
|
+
if (isLidUser(convertedJid)) return convertedJid;
|
|
245
|
+
|
|
246
|
+
if (onWhatsApp) {
|
|
247
|
+
try {
|
|
248
|
+
const validation = await onWhatsApp(convertedJid);
|
|
249
|
+
if (validation?.length > 0 && validation[0].exists) return convertedJid;
|
|
250
|
+
// Validation says it doesn't exist — return original
|
|
251
|
+
return jid;
|
|
252
|
+
} catch {
|
|
253
|
+
// Validation failed — return best-effort converted JID
|
|
254
|
+
return convertedJid;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
return convertedJid;
|
|
259
|
+
} catch {
|
|
260
|
+
return jid;
|
|
261
|
+
}
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* Maps a @bot server JID to its phone JID using BOT_MAP.
|
|
266
|
+
*/
|
|
267
|
+
export const getBotJid = (jid) => {
|
|
268
|
+
try {
|
|
269
|
+
const sepIdx = typeof jid === 'string' ? jid.indexOf('@') : -1;
|
|
270
|
+
if (sepIdx < 0) return jid;
|
|
271
|
+
if (jid.slice(sepIdx + 1) !== 'bot') return jid;
|
|
272
|
+
const user = jid.slice(0, sepIdx);
|
|
273
|
+
const mappedNumber = BOT_MAP.get(user);
|
|
274
|
+
return mappedNumber ? `${mappedNumber}@s.whatsapp.net` : jid;
|
|
275
|
+
} catch {
|
|
276
|
+
return jid;
|
|
277
|
+
}
|
|
278
|
+
};
|
|
279
|
+
|
|
96
280
|
//# sourceMappingURL=jid-utils.js.map
|
package/lib/WABinary/types.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import * as constants from './constants.js';
|
|
1
|
+
import * as constants from './constants.js';
|
|
2
2
|
//# sourceMappingURL=types.js.map
|
package/lib/WAM/BinaryInfo.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
export class BinaryInfo {
|
|
2
|
-
constructor(options = {}) {
|
|
3
|
-
this.protocolVersion = 5;
|
|
4
|
-
this.sequence = 0;
|
|
5
|
-
this.events = [];
|
|
6
|
-
this.buffer = [];
|
|
7
|
-
Object.assign(this, options);
|
|
8
|
-
}
|
|
9
|
-
}
|
|
1
|
+
export class BinaryInfo {
|
|
2
|
+
constructor(options = {}) {
|
|
3
|
+
this.protocolVersion = 5;
|
|
4
|
+
this.sequence = 0;
|
|
5
|
+
this.events = [];
|
|
6
|
+
this.buffer = [];
|
|
7
|
+
Object.assign(this, options);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
10
|
//# sourceMappingURL=BinaryInfo.js.map
|