@zervonex/baileys 0.0.0-stage → 3.0.1
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 +21 -0
- package/README.md +3203 -2
- package/WAProto/WAProtoCompile.js +291 -0
- package/WAProto/fetcher.js +69 -0
- package/WAProto/index.js +88 -0
- package/WAProto/parser.js +313 -0
- package/engine-requirements.js +10 -0
- package/lib/Builders/AIRich.js +590 -0
- package/lib/Builders/base.js +130 -0
- package/lib/Builders/builders.js +448 -0
- package/lib/Builders/index.js +3 -0
- package/lib/Defaults/index.js +225 -0
- package/lib/Defaults/phonenumber-mcc.json +223 -0
- package/lib/Signal/index.js +2 -0
- package/lib/Signal/libsignal.js +523 -0
- package/lib/Signal/lid-mapping.js +283 -0
- package/lib/Socket/Client/index.js +2 -0
- package/lib/Socket/Client/types.js +10 -0
- package/lib/Socket/Client/websocket.js +84 -0
- package/lib/Socket/business.js +152 -0
- package/lib/Socket/chats.js +855 -0
- package/lib/Socket/communities.js +147 -0
- package/lib/Socket/groups.js +294 -0
- package/lib/Socket/index.js +15 -0
- package/lib/Socket/messages-recv.js +904 -0
- package/lib/Socket/messages-send.js +693 -0
- package/lib/Socket/mex.js +34 -0
- package/lib/Socket/newsletter.js +752 -0
- package/lib/Socket/nexus-handler.js +55 -0
- package/lib/Socket/registration.js +155 -0
- package/lib/Socket/socket.js +798 -0
- package/lib/Socket/spam-report.js +65 -0
- package/lib/Socket/username.js +82 -0
- package/lib/Store/index.js +6 -0
- package/lib/Store/make-cache-manager-store.js +81 -0
- package/lib/Store/make-in-memory-store.js +425 -0
- package/lib/Store/make-ordered-dictionary.js +82 -0
- package/lib/Store/object-repository.js +31 -0
- package/lib/Store/reporting-info-store.js +38 -0
- package/lib/Types/Auth.js +2 -0
- package/lib/Types/Bussines.js +2 -0
- package/lib/Types/Call.js +2 -0
- package/lib/Types/Chat.js +8 -0
- package/lib/Types/Contact.js +2 -0
- package/lib/Types/Events.js +2 -0
- package/lib/Types/GroupMetadata.js +2 -0
- package/lib/Types/Label.js +25 -0
- package/lib/Types/LabelAssociation.js +7 -0
- package/lib/Types/Message.js +15 -0
- package/lib/Types/Newsletter.js +100 -0
- package/lib/Types/Product.js +2 -0
- package/lib/Types/Signal.js +2 -0
- package/lib/Types/Socket.js +14 -0
- package/lib/Types/State.js +26 -0
- package/lib/Types/USync.js +2 -0
- package/lib/Types/index.js +30 -0
- package/lib/Utils/auth-utils.js +142 -0
- package/lib/Utils/baileys-event-stream.js +33 -0
- package/lib/Utils/bot-capabilities.js +40 -0
- package/lib/Utils/bot-planning-replay.js +44 -0
- package/lib/Utils/browser-utils.js +26 -0
- package/lib/Utils/business.js +75 -0
- package/lib/Utils/chat-utils.js +316 -0
- package/lib/Utils/companion-reg-client-utils.js +20 -0
- package/lib/Utils/consumer-application.js +38 -0
- package/lib/Utils/crypto.js +52 -0
- package/lib/Utils/decode-wa-message.js +197 -0
- package/lib/Utils/event-buffer.js +273 -0
- package/lib/Utils/extras.js +186 -0
- package/lib/Utils/generics.js +195 -0
- package/lib/Utils/history.js +51 -0
- package/lib/Utils/identity-change-handler.js +19 -0
- package/lib/Utils/index.js +39 -0
- package/lib/Utils/key-store.js +3 -0
- package/lib/Utils/link-preview.js +51 -0
- package/lib/Utils/logger.js +2 -0
- package/lib/Utils/lt-hash.js +3 -0
- package/lib/Utils/make-mutex.js +16 -0
- package/lib/Utils/message-composer.js +59 -0
- package/lib/Utils/message-retry-manager.js +48 -0
- package/lib/Utils/messages-media.js +520 -0
- package/lib/Utils/messages.js +742 -0
- package/lib/Utils/meta-ai-msmsg.js +122 -0
- package/lib/Utils/meta-compositing.js +75 -0
- package/lib/Utils/modern-messages.js +235 -0
- package/lib/Utils/native-flow.js +55 -0
- package/lib/Utils/noise-handler.js +161 -0
- package/lib/Utils/pre-key-manager.js +76 -0
- package/lib/Utils/process-message.js +399 -0
- package/lib/Utils/reporting-utils.js +171 -0
- package/lib/Utils/signal.js +167 -0
- package/lib/Utils/spam-report-utils.js +142 -0
- package/lib/Utils/sync-action-utils.js +33 -0
- package/lib/Utils/tc-token-utils.js +102 -0
- package/lib/Utils/use-multi-file-auth-state.js +307 -0
- package/lib/Utils/validate-connection.js +181 -0
- package/lib/WABinary/constants.js +1321 -0
- package/lib/WABinary/decode.js +152 -0
- package/lib/WABinary/encode.js +140 -0
- package/lib/WABinary/generic-utils.js +179 -0
- package/lib/WABinary/index.js +6 -0
- package/lib/WABinary/jid-utils.js +235 -0
- package/lib/WABinary/types.js +4 -0
- package/lib/WAM/BinaryInfo.js +10 -0
- package/lib/WAM/constants.js +22853 -0
- package/lib/WAM/encode.js +150 -0
- package/lib/WAM/index.js +3 -0
- package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +30 -0
- package/lib/WAUSync/Protocols/USyncBusinessProtocol.js +48 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +23 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +28 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +15 -0
- package/lib/WAUSync/Protocols/USyncFeatureProtocol.js +24 -0
- package/lib/WAUSync/Protocols/USyncLIDProtocol.js +9 -0
- package/lib/WAUSync/Protocols/USyncPictureProtocol.js +21 -0
- package/lib/WAUSync/Protocols/USyncSidelistProtocol.js +19 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +19 -0
- package/lib/WAUSync/Protocols/USyncTextStatusProtocol.js +22 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +16 -0
- package/lib/WAUSync/Protocols/index.js +12 -0
- package/lib/WAUSync/USyncQuery.js +100 -0
- package/lib/WAUSync/USyncUser.js +20 -0
- package/lib/WAUSync/index.js +3 -0
- package/lib/index.js +68 -0
- package/package.json +216 -5
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
// ─── Constants ────────────────────────────────────────────────────────────────
|
|
2
|
+
|
|
3
|
+
export const S_WHATSAPP_NET = '@s.whatsapp.net'
|
|
4
|
+
export const OFFICIAL_BIZ_JID = '16505361212@c.us'
|
|
5
|
+
export const SERVER_JID = 'server@c.us'
|
|
6
|
+
export const PSA_WID = '0@c.us'
|
|
7
|
+
export const STORIES_JID = 'status@broadcast'
|
|
8
|
+
export const META_AI_JID = '13135550002@c.us'
|
|
9
|
+
|
|
10
|
+
// ─── Domain Types ─────────────────────────────────────────────────────────────
|
|
11
|
+
|
|
12
|
+
export const WAJIDDomains = Object.freeze({
|
|
13
|
+
WHATSAPP: 0,
|
|
14
|
+
LID: 1,
|
|
15
|
+
HOSTED: 128,
|
|
16
|
+
HOSTED_LID: 129
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
export const getServerFromDomainType = (initialServer, domainType) => {
|
|
20
|
+
switch (domainType) {
|
|
21
|
+
case WAJIDDomains.LID: return 'lid'
|
|
22
|
+
case WAJIDDomains.HOSTED: return 'hosted'
|
|
23
|
+
case WAJIDDomains.HOSTED_LID: return 'hosted.lid'
|
|
24
|
+
default: return initialServer
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// ─── Core Encode / Decode ─────────────────────────────────────────────────────
|
|
29
|
+
|
|
30
|
+
export const jidEncode = (user, server, device, agent) =>
|
|
31
|
+
`${user || ''}${agent ? `_${agent}` : ''}${device ? `:${device}` : ''}@${server}`
|
|
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 { server, user, domainType, device: device ? +device : undefined }
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// ─── JID Predicates ───────────────────────────────────────────────────────────
|
|
49
|
+
|
|
50
|
+
export const areJidsSameUser = (jid1, jid2) => jidDecode(jid1)?.user === jidDecode(jid2)?.user
|
|
51
|
+
export const isJidMetaAI = (jid) => jid?.endsWith('@bot')
|
|
52
|
+
export const isPnUser = (jid) => jid?.endsWith('@s.whatsapp.net')
|
|
53
|
+
export const isJidUser = isPnUser
|
|
54
|
+
export const isLidUser = (jid) => jid?.endsWith('@lid')
|
|
55
|
+
export const isJidBroadcast = (jid) => jid?.endsWith('@broadcast')
|
|
56
|
+
export const isJidGroup = (jid) => jid?.endsWith('@g.us')
|
|
57
|
+
export const isJidStatusBroadcast = (jid) => jid === 'status@broadcast'
|
|
58
|
+
export const isJidNewsletter = (jid) => jid?.endsWith('@newsletter')
|
|
59
|
+
export const isHostedPnUser = (jid) => jid?.endsWith('@hosted')
|
|
60
|
+
export const isHostedLidUser = (jid) => jid?.endsWith('@hosted.lid')
|
|
61
|
+
|
|
62
|
+
const botRegexp = /^1313555\d{4}$|^131655500\d{2}$/
|
|
63
|
+
export const isJidBot = (jid) => jid && botRegexp.test(jid.split('@')[0]) && jid.endsWith('@c.us')
|
|
64
|
+
|
|
65
|
+
export const jidNormalizedUser = (jid) => {
|
|
66
|
+
const result = jidDecode(jid)
|
|
67
|
+
if (!result) return ''
|
|
68
|
+
const { user, server } = result
|
|
69
|
+
return jidEncode(user, server === 'c.us' ? 's.whatsapp.net' : server)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export const transferDevice = (fromJid, toJid) => {
|
|
73
|
+
const { device } = jidDecode(fromJid) || {}
|
|
74
|
+
const { server, user } = jidDecode(toJid)
|
|
75
|
+
return jidEncode(user, server, device || 0)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// ─── LRU Cache (module-scoped) ────────────────────────────────────────────────
|
|
79
|
+
|
|
80
|
+
class SimpleLRU {
|
|
81
|
+
constructor(maxSize = 2000, ttl = 5 * 60 * 1000) {
|
|
82
|
+
this.maxSize = maxSize
|
|
83
|
+
this.ttl = ttl
|
|
84
|
+
this.map = new Map()
|
|
85
|
+
}
|
|
86
|
+
get(key) {
|
|
87
|
+
const entry = this.map.get(key)
|
|
88
|
+
if (!entry) return undefined
|
|
89
|
+
if (Date.now() - entry.ts > this.ttl) { this.map.delete(key); return undefined }
|
|
90
|
+
this.map.delete(key)
|
|
91
|
+
this.map.set(key, entry)
|
|
92
|
+
return entry.value
|
|
93
|
+
}
|
|
94
|
+
set(key, value) {
|
|
95
|
+
if (this.map.has(key)) this.map.delete(key)
|
|
96
|
+
this.map.set(key, { value, ts: Date.now() })
|
|
97
|
+
if (this.map.size > this.maxSize) {
|
|
98
|
+
const lru = this.map.keys().next().value
|
|
99
|
+
if (lru !== undefined) this.map.delete(lru)
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const lidToJidCache = new SimpleLRU(2000, 5 * 60 * 1000)
|
|
105
|
+
|
|
106
|
+
// ─── Shared LID ↔ Phone Cache ─────────────────────────────────────────────────
|
|
107
|
+
|
|
108
|
+
const _sharedLidPhoneMap = new Map()
|
|
109
|
+
const SHARED_MAP_MAX = 3000
|
|
110
|
+
|
|
111
|
+
export const sharedLidPhoneCache = {
|
|
112
|
+
set(lid, phoneJid) {
|
|
113
|
+
if (!lid || !phoneJid || typeof lid !== 'string' || typeof phoneJid !== 'string') return
|
|
114
|
+
if (!phoneJid.includes('@')) phoneJid = phoneJid + '@s.whatsapp.net'
|
|
115
|
+
if (_sharedLidPhoneMap.size > SHARED_MAP_MAX * 2) {
|
|
116
|
+
const it = _sharedLidPhoneMap.keys()
|
|
117
|
+
const toRemove = Math.floor(_sharedLidPhoneMap.size * 0.25)
|
|
118
|
+
for (let i = 0; i < toRemove; i++) {
|
|
119
|
+
const k = it.next().value
|
|
120
|
+
if (k === undefined) break
|
|
121
|
+
_sharedLidPhoneMap.delete(k)
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
_sharedLidPhoneMap.set(lid, phoneJid)
|
|
125
|
+
_sharedLidPhoneMap.set(phoneJid, lid)
|
|
126
|
+
lidToJidCache.set(lid, phoneJid)
|
|
127
|
+
},
|
|
128
|
+
get(key) { return _sharedLidPhoneMap.get(key) },
|
|
129
|
+
getLidForPhone(phoneJid) {
|
|
130
|
+
if (!phoneJid) return undefined
|
|
131
|
+
const val = _sharedLidPhoneMap.get(phoneJid)
|
|
132
|
+
return val?.endsWith('@lid') ? val : undefined
|
|
133
|
+
},
|
|
134
|
+
getPhoneForLid(lid) {
|
|
135
|
+
if (!lid) return undefined
|
|
136
|
+
const val = _sharedLidPhoneMap.get(lid)
|
|
137
|
+
return val?.endsWith('@s.whatsapp.net') ? val : undefined
|
|
138
|
+
},
|
|
139
|
+
get size() { return _sharedLidPhoneMap.size }
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// ─── Bot Map ──────────────────────────────────────────────────────────────────
|
|
143
|
+
|
|
144
|
+
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"]])
|
|
145
|
+
|
|
146
|
+
let BOT_MAP = BOT_MAP_STATIC
|
|
147
|
+
|
|
148
|
+
export const setBotMap = (mapLike) => {
|
|
149
|
+
if (!mapLike) return
|
|
150
|
+
BOT_MAP = mapLike instanceof Map ? mapLike : new Map(Object.entries(mapLike))
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export const loadBotMapFromFile = async (filePath) => {
|
|
154
|
+
const { promises: fsp } = await import('fs')
|
|
155
|
+
const { join } = await import('path')
|
|
156
|
+
const { fileURLToPath } = await import('url')
|
|
157
|
+
const __dirname = fileURLToPath(new URL('.', import.meta.url))
|
|
158
|
+
const candidates = []
|
|
159
|
+
if (filePath) candidates.push(filePath)
|
|
160
|
+
candidates.push(join(process.cwd(), 'bot-map.json'))
|
|
161
|
+
candidates.push(join(__dirname, 'bot-map.json'))
|
|
162
|
+
for (const p of candidates) {
|
|
163
|
+
try {
|
|
164
|
+
const stat = await fsp.stat(p).catch(() => null)
|
|
165
|
+
if (!stat?.isFile()) continue
|
|
166
|
+
const data = await fsp.readFile(p, 'utf8')
|
|
167
|
+
const obj = JSON.parse(data)
|
|
168
|
+
if (obj && typeof obj === 'object') { BOT_MAP = new Map(Object.entries(obj)); return BOT_MAP }
|
|
169
|
+
} catch { }
|
|
170
|
+
}
|
|
171
|
+
return BOT_MAP
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// ─── LID → JID Resolution ─────────────────────────────────────────────────────
|
|
175
|
+
|
|
176
|
+
export const lidToJid = (jid) => {
|
|
177
|
+
try {
|
|
178
|
+
if (!jid || typeof jid !== 'string') return jid
|
|
179
|
+
const cached = lidToJidCache.get(jid)
|
|
180
|
+
if (cached) return cached
|
|
181
|
+
let result = jid
|
|
182
|
+
if (jid.endsWith('@lid')) {
|
|
183
|
+
const lidPart = jid.replace('@lid', '')
|
|
184
|
+
if (BOT_MAP.has(lidPart)) {
|
|
185
|
+
result = BOT_MAP.get(lidPart) + '@s.whatsapp.net'
|
|
186
|
+
} else {
|
|
187
|
+
const phoneFromCache = sharedLidPhoneCache.getPhoneForLid(jid)
|
|
188
|
+
if (phoneFromCache) result = phoneFromCache
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
if (result !== jid) lidToJidCache.set(jid, result)
|
|
192
|
+
return result
|
|
193
|
+
} catch {
|
|
194
|
+
return jid
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
export const resolveJid = (jid) => {
|
|
199
|
+
if (typeof jid === 'string' && jid.endsWith('@lid')) return lidToJid(jid)
|
|
200
|
+
return jid
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// lidToJidEnhanced and validateAndCleanJid are canonical aliases — no duplicates
|
|
204
|
+
export const lidToJidEnhanced = (jid) => lidToJid(jid)
|
|
205
|
+
export const validateAndCleanJid = (jid) => {
|
|
206
|
+
if (!jid || typeof jid !== 'string') return jid
|
|
207
|
+
return jid.endsWith('@lid') ? lidToJid(jid) : jid
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
export const validateAndConvertLidToJid = async (jid, onWhatsApp) => {
|
|
211
|
+
try {
|
|
212
|
+
if (!jid || typeof jid !== 'string') return jid
|
|
213
|
+
const converted = lidToJid(jid)
|
|
214
|
+
if (isLidUser(converted)) return converted
|
|
215
|
+
if (onWhatsApp) {
|
|
216
|
+
try {
|
|
217
|
+
const validation = await onWhatsApp(converted)
|
|
218
|
+
if (validation?.length > 0 && validation[0].exists) return converted
|
|
219
|
+
return jid
|
|
220
|
+
} catch { return converted }
|
|
221
|
+
}
|
|
222
|
+
return converted
|
|
223
|
+
} catch { return jid }
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
export const getBotJid = (jid) => {
|
|
227
|
+
try {
|
|
228
|
+
const sepIdx = typeof jid === 'string' ? jid.indexOf('@') : -1
|
|
229
|
+
if (sepIdx < 0) return jid
|
|
230
|
+
if (jid.slice(sepIdx + 1) !== 'bot') return jid
|
|
231
|
+
const user = jid.slice(0, sepIdx)
|
|
232
|
+
const mapped = BOT_MAP.get(user)
|
|
233
|
+
return mapped ? `${mapped}@s.whatsapp.net` : jid
|
|
234
|
+
} catch { return jid }
|
|
235
|
+
}
|