@badzz88/baileys 8.4.7 → 8.5.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.
Files changed (144) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1055 -337
  3. package/WAProto/index.js +5 -5
  4. package/lib/Defaults/index.js +187 -127
  5. package/lib/Defaults/phonenumber-mcc.json +223 -0
  6. package/lib/Signal/Group/ciphertext-message.js +14 -11
  7. package/lib/Signal/Group/group-session-builder.js +91 -29
  8. package/lib/Signal/Group/group_cipher.js +88 -81
  9. package/lib/Signal/Group/index.js +136 -12
  10. package/lib/Signal/Group/keyhelper.js +70 -15
  11. package/lib/Signal/Group/sender-chain-key.js +31 -25
  12. package/lib/Signal/Group/sender-key-distribution-message.js +65 -62
  13. package/lib/Signal/Group/sender-key-message.js +68 -65
  14. package/lib/Signal/Group/sender-key-name.js +43 -41
  15. package/lib/Signal/Group/sender-key-record.js +43 -40
  16. package/lib/Signal/Group/sender-key-state.js +96 -83
  17. package/lib/Signal/Group/sender-message-key.js +29 -25
  18. package/lib/Signal/libsignal.js +483 -424
  19. package/lib/Signal/lid-mapping.js +261 -276
  20. package/lib/Socket/Client/index.js +30 -3
  21. package/lib/Socket/Client/types.js +12 -10
  22. package/lib/Socket/Client/websocket.js +61 -53
  23. package/lib/Socket/aigroups.js +240 -0
  24. package/lib/Socket/business.js +422 -379
  25. package/lib/Socket/chats.js +1816 -1193
  26. package/lib/Socket/communities.js +549 -431
  27. package/lib/Socket/graphql.js +656 -0
  28. package/lib/Socket/groups.js +764 -374
  29. package/lib/Socket/index.js +38 -11
  30. package/lib/Socket/interactive-handler.js +522 -0
  31. package/lib/Socket/interop.js +549 -0
  32. package/lib/Socket/luxu.js +6 -5
  33. package/lib/Socket/managed-account.js +183 -0
  34. package/lib/Socket/messages-recv.js +2439 -1915
  35. package/lib/Socket/messages-send.js +1642 -1242
  36. package/lib/Socket/mex.js +59 -40
  37. package/lib/Socket/newsletter.js +812 -249
  38. package/lib/Socket/privacy.js +449 -0
  39. package/lib/Socket/registration.js +427 -0
  40. package/lib/Socket/socket.js +1077 -965
  41. package/lib/Socket/text-router.js +83 -0
  42. package/lib/Socket/username.js +237 -140
  43. package/lib/Store/index.js +36 -10
  44. package/lib/Store/make-cache-manager-store.js +85 -80
  45. package/lib/Store/make-in-memory-store.js +591 -185
  46. package/lib/Store/make-ordered-dictionary.js +78 -72
  47. package/lib/Store/object-repository.js +25 -28
  48. package/lib/Types/Auth.js +38 -2
  49. package/lib/Types/Bussines.js +2 -2
  50. package/lib/Types/Call.js +2 -2
  51. package/lib/Types/Chat.js +4 -8
  52. package/lib/Types/Contact.js +2 -2
  53. package/lib/Types/Events.js +2 -2
  54. package/lib/Types/GroupMetadata.js +2 -2
  55. package/lib/Types/Label.js +26 -24
  56. package/lib/Types/LabelAssociation.js +8 -6
  57. package/lib/Types/Message.js +95 -11
  58. package/lib/Types/Mex.js +112 -37
  59. package/lib/Types/Newsletter.js +121 -0
  60. package/lib/Types/Product.js +2 -2
  61. package/lib/Types/Signal.js +2 -2
  62. package/lib/Types/Socket.js +2 -3
  63. package/lib/Types/State.js +70 -56
  64. package/lib/Types/USync.js +2 -2
  65. package/lib/Types/index.js +55 -26
  66. package/lib/Utils/auth-utils.js +292 -288
  67. package/lib/Utils/browser-utils.js +113 -48
  68. package/lib/Utils/business.js +240 -224
  69. package/lib/Utils/chat-utils.js +1205 -869
  70. package/lib/Utils/command-loader.d.ts +31 -0
  71. package/lib/Utils/command-loader.js +100 -0
  72. package/lib/Utils/companion-reg-client-utils.js +41 -34
  73. package/lib/Utils/consumer-application.js +107 -0
  74. package/lib/Utils/crypto.js +144 -107
  75. package/lib/Utils/curve25519-js.js +275 -0
  76. package/lib/Utils/decode-wa-message.js +518 -308
  77. package/lib/Utils/event-buffer.js +596 -611
  78. package/lib/Utils/generics.js +514 -354
  79. package/lib/Utils/group-history.js +60 -0
  80. package/lib/Utils/history.js +244 -134
  81. package/lib/Utils/identity-change-handler.js +51 -49
  82. package/lib/Utils/index.js +57 -23
  83. package/lib/Utils/jid-display-normalization.js +218 -0
  84. package/lib/Utils/link-preview.js +135 -77
  85. package/lib/Utils/logger.js +9 -3
  86. package/lib/Utils/lt-hash.js +37 -6
  87. package/lib/Utils/make-mutex.js +36 -33
  88. package/lib/Utils/message-composer.js +439 -233
  89. package/lib/Utils/message-retry-manager.js +265 -260
  90. package/lib/Utils/messages-media.js +855 -747
  91. package/lib/Utils/messages.js +2528 -884
  92. package/lib/Utils/meta-ai-msmsg.js +262 -0
  93. package/lib/Utils/native-bridge.js +82 -0
  94. package/lib/Utils/noise-handler.js +195 -200
  95. package/lib/Utils/offline-node-processor.js +35 -33
  96. package/lib/Utils/pre-key-manager.js +103 -102
  97. package/lib/Utils/process-message.js +978 -560
  98. package/lib/Utils/reporting-utils.js +257 -253
  99. package/lib/Utils/session-pool.d.ts +16 -0
  100. package/lib/Utils/session-pool.js +94 -0
  101. package/lib/Utils/signal.js +218 -195
  102. package/lib/Utils/stanza-ack.js +31 -29
  103. package/lib/Utils/sticker.d.ts +17 -0
  104. package/lib/Utils/sticker.js +145 -0
  105. package/lib/Utils/sync-action-utils.js +50 -45
  106. package/lib/Utils/tc-token-utils.js +137 -139
  107. package/lib/Utils/use-multi-file-auth-state.js +109 -109
  108. package/lib/Utils/validate-connection.js +218 -202
  109. package/lib/Utils/view-once-cache.d.ts +9 -0
  110. package/lib/Utils/view-once-cache.js +79 -0
  111. package/lib/Utils/voip-rekey.js +22 -0
  112. package/lib/WABinary/constants.js +1302 -1299
  113. package/lib/WABinary/decode.js +343 -262
  114. package/lib/WABinary/encode.js +12 -4
  115. package/lib/WABinary/generic-utils.js +223 -187
  116. package/lib/WABinary/index.js +33 -6
  117. package/lib/WABinary/jid-utils.js +351 -88
  118. package/lib/WABinary/types.js +2 -2
  119. package/lib/WAM/BinaryInfo.js +12 -9
  120. package/lib/WAM/constants.js +39486 -22853
  121. package/lib/WAM/encode.js +132 -140
  122. package/lib/WAM/index.js +31 -4
  123. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +55 -0
  124. package/lib/WAUSync/Protocols/USyncBusinessProtocol.js +43 -0
  125. package/lib/WAUSync/Protocols/USyncContactProtocol.js +53 -51
  126. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +56 -53
  127. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +29 -26
  128. package/lib/WAUSync/Protocols/USyncFeatureProtocol.js +59 -0
  129. package/lib/WAUSync/Protocols/USyncLIDProtocol.js +31 -0
  130. package/lib/WAUSync/Protocols/USyncPictureProtocol.js +32 -0
  131. package/lib/WAUSync/Protocols/USyncSidelistProtocol.js +29 -0
  132. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +38 -37
  133. package/lib/WAUSync/Protocols/USyncTextStatusProtocol.js +38 -0
  134. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +26 -24
  135. package/lib/WAUSync/Protocols/index.js +39 -6
  136. package/lib/WAUSync/USyncQuery.js +132 -97
  137. package/lib/WAUSync/USyncUser.js +49 -30
  138. package/lib/WAUSync/index.js +31 -4
  139. package/lib/antiban.js +4637 -0
  140. package/lib/index.js +48 -15
  141. package/package.json +55 -92
  142. package/lib/WAUSync/Protocols/USyncNewsletterProtocol.js +0 -263
  143. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +0 -51
  144. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +0 -29
@@ -1,98 +1,361 @@
1
- export const S_WHATSAPP_NET = '@s.whatsapp.net';
2
- export const OFFICIAL_BIZ_JID = '16505361212@c.us';
3
- export const SERVER_JID = 'server@c.us';
4
- export const PSA_WID = '0@c.us';
5
- export const STORIES_JID = 'status@broadcast';
6
- export const META_AI_JID = '13135550002@c.us';
7
- export var WAJIDDomains;
8
- (function (WAJIDDomains) {
9
- WAJIDDomains[WAJIDDomains["WHATSAPP"] = 0] = "WHATSAPP";
10
- WAJIDDomains[WAJIDDomains["LID"] = 1] = "LID";
11
- WAJIDDomains[WAJIDDomains["HOSTED"] = 128] = "HOSTED";
12
- WAJIDDomains[WAJIDDomains["HOSTED_LID"] = 129] = "HOSTED_LID";
13
- })(WAJIDDomains || (WAJIDDomains = {}));
14
- export const getServerFromDomainType = (initialServer, domainType) => {
15
- switch (domainType) {
16
- case WAJIDDomains.LID:
17
- return 'lid';
18
- case WAJIDDomains.HOSTED:
19
- return 'hosted';
20
- case WAJIDDomains.HOSTED_LID:
21
- return 'hosted.lid';
22
- case WAJIDDomains.WHATSAPP:
23
- default:
24
- return initialServer;
25
- }
26
- };
27
- export const jidEncode = (user, server, device, agent) => {
28
- return `${user || ''}${!!agent ? `_${agent}` : ''}${!!device ? `:${device}` : ''}@${server}`;
29
- };
30
- export const jidDecode = (jid) => {
31
- // todo: investigate how to implement hosted ids in this case
32
- const sepIdx = typeof jid === 'string' ? jid.indexOf('@') : -1;
33
- if (sepIdx < 0) {
34
- return undefined;
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
- domainType = WAJIDDomains.LID;
43
- }
44
- else if (server === 'hosted') {
45
- domainType = WAJIDDomains.HOSTED;
46
- }
47
- else if (server === 'hosted.lid') {
48
- domainType = WAJIDDomains.HOSTED_LID;
49
- }
50
- else if (agent) {
51
- domainType = parseInt(agent);
52
- }
53
- return {
54
- server: server,
55
- user: user,
56
- domainType,
57
- device: device ? +device : undefined
58
- };
59
- };
1
+ 'use strict'
2
+ Object.defineProperty(exports, '__esModule', { value: true })
3
+ exports.transferDevice =
4
+ exports.jidNormalizedUser =
5
+ exports.isJidBot =
6
+ exports.isHostedLidUser =
7
+ exports.isHostedPnUser =
8
+ exports.isJidNewsletter =
9
+ exports.isJidStatusBroadcast =
10
+ exports.isJidGroup =
11
+ exports.isJidBroadcast =
12
+ exports.isLidUser =
13
+ exports.isPnUser =
14
+ exports.isInteropUser =
15
+ exports.isJidMetaAI =
16
+ exports.areJidsSameUser =
17
+ exports.jidDecode =
18
+ exports.jidEncode =
19
+ exports.getServerFromDomainType =
20
+ exports.WAJIDDomains =
21
+ exports.META_AI_JID =
22
+ exports.STORIES_JID =
23
+ exports.PSA_WID =
24
+ exports.SERVER_JID =
25
+ exports.OFFICIAL_BIZ_JID =
26
+ exports.S_WHATSAPP_NET =
27
+ void 0
28
+ exports.S_WHATSAPP_NET = '@s.whatsapp.net'
29
+ exports.OFFICIAL_BIZ_JID = '16505361212@c.us'
30
+ exports.SERVER_JID = 'server@c.us'
31
+ exports.PSA_WID = '0@c.us'
32
+ exports.STORIES_JID = 'status@broadcast'
33
+ exports.META_AI_JID = '13135550002@c.us'
34
+ var WAJIDDomains
35
+ ;(function (WAJIDDomains) {
36
+ WAJIDDomains[(WAJIDDomains['WHATSAPP'] = 0)] = 'WHATSAPP'
37
+ WAJIDDomains[(WAJIDDomains['LID'] = 1)] = 'LID'
38
+ WAJIDDomains[(WAJIDDomains['HOSTED'] = 128)] = 'HOSTED'
39
+ WAJIDDomains[(WAJIDDomains['HOSTED_LID'] = 129)] = 'HOSTED_LID'
40
+ })(WAJIDDomains || (exports.WAJIDDomains = WAJIDDomains = {}))
41
+ const getServerFromDomainType = (initialServer, domainType) => {
42
+ switch (domainType) {
43
+ case WAJIDDomains.LID:
44
+ return 'lid'
45
+ case WAJIDDomains.HOSTED:
46
+ return 'hosted'
47
+ case WAJIDDomains.HOSTED_LID:
48
+ return 'hosted.lid'
49
+ case WAJIDDomains.WHATSAPP:
50
+ default:
51
+ return initialServer
52
+ }
53
+ }
54
+ exports.getServerFromDomainType = getServerFromDomainType
55
+
56
+ const getBotJid = jid => {
57
+ const BOT_MAP = new Map([
58
+ ['867051314767696', '13135550002'],
59
+ ['1061492271844689', '13135550005'],
60
+ ['245886058483988', '13135550009'],
61
+ ['3509905702656130', '13135550012'],
62
+ ['1059680132034576', '13135550013'],
63
+ ['715681030623646', '13135550014'],
64
+ ['1644971366323052', '13135550015'],
65
+ ['582497970646566', '13135550019'],
66
+ ['645459357769306', '13135550022'],
67
+ ['294997126699143', '13135550023'],
68
+ ['1522631578502677', '13135550027'],
69
+ ['719421926276396', '13135550030'],
70
+ ['1788488635002167', '13135550031'],
71
+ ['24232338603080193', '13135550033'],
72
+ ['689289903143209', '13135550035'],
73
+ ['871626054177096', '13135550039'],
74
+ ['362351902849370', '13135550042'],
75
+ ['1744617646041527', '13135550043'],
76
+ ['893887762270570', '13135550046'],
77
+ ['1155032702135830', '13135550047'],
78
+ ['333931965993883', '13135550048'],
79
+ ['853748013058752', '13135550049'],
80
+ ['1559068611564819', '13135550053'],
81
+ ['890487432705716', '13135550054'],
82
+ ['240254602395494', '13135550055'],
83
+ ['1578420349663261', '13135550062'],
84
+ ['322908887140421', '13135550065'],
85
+ ['3713961535514771', '13135550067'],
86
+ ['997884654811738', '13135550070'],
87
+ ['403157239387035', '13135550081'],
88
+ ['535242369074963', '13135550082'],
89
+ ['946293427247659', '13135550083'],
90
+ ['3664707673802291', '13135550084'],
91
+ ['1821827464894892', '13135550085'],
92
+ ['1760312477828757', '13135550086'],
93
+ ['439480398712216', '13135550087'],
94
+ ['1876735582800984', '13135550088'],
95
+ ['984025089825661', '13135550089'],
96
+ ['1001336351558186', '13135550090'],
97
+ ['3739346336347061', '13135550091'],
98
+ ['3632749426974980', '13135550092'],
99
+ ['427864203481615', '13135550093'],
100
+ ['1434734570493055', '13135550094'],
101
+ ['992873449225921', '13135550095'],
102
+ ['813087747426445', '13135550096'],
103
+ ['806369104931434', '13135550098'],
104
+ ['1220982902403148', '13135550099'],
105
+ ['1365893374104393', '13135550100'],
106
+ ['686482033622048', '13135550200'],
107
+ ['1454999838411253', '13135550201'],
108
+ ['718584497008509', '13135550202'],
109
+ ['743520384213443', '13135550301'],
110
+ ['1147715789823789', '13135550302'],
111
+ ['1173034540372201', '13135550303'],
112
+ ['974785541030953', '13135550304'],
113
+ ['1122200255531507', '13135550305'],
114
+ ['899669714813162', '13135550306'],
115
+ ['631880108970650', '13135550307'],
116
+ ['435816149330026', '13135550308'],
117
+ ['1368717161184556', '13135550309'],
118
+ ['7849963461784891', '13135550310'],
119
+ ['3609617065968984', '13135550312'],
120
+ ['356273980574602', '13135550313'],
121
+ ['1043447920539760', '13135550314'],
122
+ ['1052764336525346', '13135550315'],
123
+ ['2631118843732685', '13135550316'],
124
+ ['510505411332176', '13135550317'],
125
+ ['1945664239227513', '13135550318'],
126
+ ['1518594378764656', '13135550319'],
127
+ ['1378821579456138', '13135550320'],
128
+ ['490214716896013', '13135550321'],
129
+ ['1028577858870699', '13135550322'],
130
+ ['308915665545959', '13135550323'],
131
+ ['845884253678900', '13135550324'],
132
+ ['995031308616442', '13135550325'],
133
+ ['2787365464763437', '13135550326'],
134
+ ['1532790990671645', '13135550327'],
135
+ ['302617036180485', '13135550328'],
136
+ ['723376723197227', '13135550329'],
137
+ ['8393570407377966', '13135550330'],
138
+ ['1931159970680725', '13135550331'],
139
+ ['401073885688605', '13135550332'],
140
+ ['2234478453565422', '13135550334'],
141
+ ['814748673882312', '13135550335'],
142
+ ['26133635056281592', '13135550336'],
143
+ ['1439804456676119', '13135550337'],
144
+ ['889851503172161', '13135550338'],
145
+ ['1018283232836879', '13135550339'],
146
+ ['1012781386779537', '13135559000'],
147
+ ['823280953239532', '13135559001'],
148
+ ['1597090934573334', '13135559002'],
149
+ ['485965054020343', '13135559003'],
150
+ ['1033381648363446', '13135559004'],
151
+ ['491802010206446', '13135559005'],
152
+ ['1017139033184870', '13135559006'],
153
+ ['499638325922174', '13135559008'],
154
+ ['468946335863664', '13135559009'],
155
+ ['1570389776875816', '13135559010'],
156
+ ['1004342694328995', '13135559011'],
157
+ ['1012240323971229', '13135559012'],
158
+ ['392171787222419', '13135559013'],
159
+ ['952081212945019', '13135559016'],
160
+ ['444507875070178', '13135559017'],
161
+ ['1274819440594668', '13135559018'],
162
+ ['1397041101147050', '13135559019'],
163
+ ['425657699872640', '13135559020'],
164
+ ['532292852562549', '13135559021'],
165
+ ['705863241720292', '13135559022'],
166
+ ['476449815183959', '13135559023'],
167
+ ['488071553854222', '13135559024'],
168
+ ['468693832665397', '13135559025'],
169
+ ['517422564037340', '13135559026'],
170
+ ['819805466613825', '13135559027'],
171
+ ['1847708235641382', '13135559028'],
172
+ ['716282970644228', '13135559029'],
173
+ ['521655380527741', '13135559030'],
174
+ ['476193631941905', '13135559031'],
175
+ ['485600497445562', '13135559032'],
176
+ ['440217235683910', '13135559033'],
177
+ ['523342446758478', '13135559034'],
178
+ ['514784864360240', '13135559035'],
179
+ ['505790121814530', '13135559036'],
180
+ ['420008964419580', '13135559037'],
181
+ ['492141680204555', '13135559038'],
182
+ ['388462787271952', '13135559039'],
183
+ ['423473920752072', '13135559040'],
184
+ ['489574180468229', '13135559041'],
185
+ ['432360635854105', '13135559042'],
186
+ ['477878201669248', '13135559043'],
187
+ ['351656951234045', '13135559044'],
188
+ ['430178036732582', '13135559045'],
189
+ ['434537312944552', '13135559046'],
190
+ ['1240614300631808', '13135559047'],
191
+ ['473135945605128', '13135559048'],
192
+ ['423669800729310', '13135559049'],
193
+ ['3685666705015792', '13135559050'],
194
+ ['504196509016638', '13135559051'],
195
+ ['346844785189449', '13135559052'],
196
+ ['504823088911074', '13135559053'],
197
+ ['402669415797083', '13135559054'],
198
+ ['490939640234431', '13135559055'],
199
+ ['875124128063715', '13135559056'],
200
+ ['468788962654605', '13135559057'],
201
+ ['562386196354570', '13135559058'],
202
+ ['372159285928791', '13135559059'],
203
+ ['531017479591050', '13135559060'],
204
+ ['1328873881401826', '13135559061'],
205
+ ['1608363646390484', '13135559062'],
206
+ ['1229628561554232', '13135559063'],
207
+ ['348802211530364', '13135559064'],
208
+ ['3708535859420184', '13135559065'],
209
+ ['415517767742187', '13135559066'],
210
+ ['479330341612638', '13135559067'],
211
+ ['480785414723083', '13135559068'],
212
+ ['387299107507991', '13135559069'],
213
+ ['333389813188944', '13135559070'],
214
+ ['391794130316996', '13135559071'],
215
+ ['457893470576314', '13135559072'],
216
+ ['435550496166469', '13135559073'],
217
+ ['1620162702100689', '13135559074'],
218
+ ['867491058616043', '13135559075'],
219
+ ['816224117357759', '13135559076'],
220
+ ['334065176362830', '13135559077'],
221
+ ['489973170554709', '13135559078'],
222
+ ['473060669049665', '13135559079'],
223
+ ['1221505815643060', '13135559080'],
224
+ ['889000703096359', '13135559081'],
225
+ ['475235961979883', '13135559082'],
226
+ ['3434445653519934', '13135559084'],
227
+ ['524503026827421', '13135559085'],
228
+ ['1179639046403856', '13135559086'],
229
+ ['471563305859144', '13135559087'],
230
+ ['533896609192881', '13135559088'],
231
+ ['365443583168041', '13135559089'],
232
+ ['836082305329393', '13135559090'],
233
+ ['1056787705969916', '13135559091'],
234
+ ['503312598958357', '13135559092'],
235
+ ['3718606738453460', '13135559093'],
236
+ ['826066052850902', '13135559094'],
237
+ ['1033611345091888', '13135559095'],
238
+ ['3868390816783240', '13135559096'],
239
+ ['7462677740498860', '13135559097'],
240
+ ['436288576108573', '13135559098'],
241
+ ['1047559746718900', '13135559099'],
242
+ ['1099299455255491', '13135559100'],
243
+ ['1202037301040633', '13135559101'],
244
+ ['1720619402074074', '13135559102'],
245
+ ['1030422235101467', '13135559103'],
246
+ ['827238979523502', '13135559104'],
247
+ ['1516443722284921', '13135559105'],
248
+ ['1174442747196709', '13135559106'],
249
+ ['1653165225503842', '13135559107'],
250
+ ['1037648777635013', '13135559108'],
251
+ ['551617757299900', '13135559109'],
252
+ ['1158813558718726', '13135559110'],
253
+ ['2463236450542262', '13135559111'],
254
+ ['1550393252501466', '13135559112'],
255
+ ['2057065188042796', '13135559113'],
256
+ ['506163028760735', '13135559114'],
257
+ ['2065249100538481', '13135559115'],
258
+ ['1041382867195858', '13135559116'],
259
+ ['886500209499603', '13135559117'],
260
+ ['1491615624892655', '13135559118'],
261
+ ['486563697299617', '13135559119'],
262
+ ['1175736513679463', '13135559120'],
263
+ ['491811473512352', '13165550064']
264
+ ])
265
+ const sepIdx = typeof jid === 'string' ? jid.indexOf('@') : -1
266
+ if (sepIdx < 0) {
267
+ return jid
268
+ }
269
+ const server = jid.slice(sepIdx + 1)
270
+ if (server !== 'bot') return jid
271
+ const user = jid.slice(0, sepIdx)
272
+ const mappedNumber = BOT_MAP.get(user)
273
+ return mappedNumber ? `${mappedNumber}@s.whatsapp.net` : jid
274
+ }
275
+ exports.getBotJid = getBotJid
276
+
277
+ const jidEncode = (user, server, device, agent) => {
278
+ const isInterop = server === 'interop'
279
+ return `${user || ''}${!!agent ? `_${agent}` : ''}${!!device || (device === 0 && !isInterop) ? `:${device}` : ''}@${server}`
280
+ }
281
+ exports.jidEncode = jidEncode
282
+ const jidDecode = jid => {
283
+ // todo: investigate how to implement hosted ids in this case
284
+ const sepIdx = typeof jid === 'string' ? jid.indexOf('@') : -1
285
+ if (sepIdx < 0) {
286
+ return undefined
287
+ }
288
+ const server = jid.slice(sepIdx + 1)
289
+ const userCombined = jid.slice(0, sepIdx)
290
+ const [userAgent, device] = userCombined.split(':')
291
+ const [user, agent] = userAgent.split('_')
292
+ let domainType = WAJIDDomains.WHATSAPP
293
+ if (server === 'lid') {
294
+ domainType = WAJIDDomains.LID
295
+ } else if (server === 'hosted') {
296
+ domainType = WAJIDDomains.HOSTED
297
+ } else if (server === 'hosted.lid') {
298
+ domainType = WAJIDDomains.HOSTED_LID
299
+ } else if (agent) {
300
+ domainType = parseInt(agent)
301
+ }
302
+ return {
303
+ server: server,
304
+ user: user,
305
+ domainType,
306
+ device: device ? +device : undefined
307
+ }
308
+ }
309
+ exports.jidDecode = jidDecode
60
310
  /** is the jid a user */
61
- export const areJidsSameUser = (jid1, jid2) => jidDecode(jid1)?.user === jidDecode(jid2)?.user;
311
+ const areJidsSameUser = (jid1, jid2) => (0, exports.jidDecode)(jid1)?.user === (0, exports.jidDecode)(jid2)?.user
312
+ exports.areJidsSameUser = areJidsSameUser
62
313
  /** is the jid Meta AI */
63
- export const isJidMetaAI = (jid) => jid?.endsWith('@bot');
314
+ const isJidMetaAI = jid => jid?.endsWith('@bot')
315
+ exports.isJidMetaAI = isJidMetaAI
64
316
  /** is the jid a PN user */
65
- export const isPnUser = (jid) => jid?.endsWith('@s.whatsapp.net');
317
+ const isPnUser = jid => jid?.endsWith('@s.whatsapp.net')
318
+ exports.isPnUser = isPnUser
319
+ /** is the jid an interop (BirdyChat/Haiket) user */
320
+ const isInteropUser = jid => jid?.endsWith('@interop')
321
+ exports.isInteropUser = isInteropUser
66
322
  /** is the jid a LID */
67
- export const isLidUser = (jid) => jid?.endsWith('@lid');
323
+ const isLidUser = jid => jid?.endsWith('@lid')
324
+ exports.isLidUser = isLidUser
68
325
  /** is the jid a broadcast */
69
- export const isJidBroadcast = (jid) => jid?.endsWith('@broadcast');
326
+ const isJidBroadcast = jid => jid?.endsWith('@broadcast')
327
+ exports.isJidBroadcast = isJidBroadcast
70
328
  /** is the jid a group */
71
- export const isJidGroup = (jid) => jid?.endsWith('@g.us');
329
+ const isJidGroup = jid => jid?.endsWith('@g.us')
330
+ exports.isJidGroup = isJidGroup
72
331
  /** is the jid the status broadcast */
73
- export const isJidStatusBroadcast = (jid) => jid === 'status@broadcast';
332
+ const isJidStatusBroadcast = jid => jid === 'status@broadcast'
333
+ exports.isJidStatusBroadcast = isJidStatusBroadcast
74
334
  /** is the jid a newsletter */
75
- export const isJidNewsletter = (jid) => jid?.endsWith('@newsletter');
335
+ const isJidNewsletter = jid => jid?.endsWith('@newsletter')
336
+ exports.isJidNewsletter = isJidNewsletter
76
337
  /** is the jid a hosted PN */
77
- export const isHostedPnUser = (jid) => jid?.endsWith('@hosted');
338
+ const isHostedPnUser = jid => jid?.endsWith('@hosted')
339
+ exports.isHostedPnUser = isHostedPnUser
78
340
  /** is the jid a hosted LID */
79
- export const isHostedLidUser = (jid) => jid?.endsWith('@hosted.lid');
80
- /** is the jid a interop */
81
- export const isInteropUser = (jid) => jid?.endsWith('@interop');
82
- const botRegexp = /^1313555\d{4}$|^131655500\d{2}$/;
83
- export const isJidBot = (jid) => jid && botRegexp.test(jid.split('@')[0]) && jid.endsWith('@c.us');
84
- export const jidNormalizedUser = (jid) => {
85
- const result = jidDecode(jid);
86
- if (!result) {
87
- return '';
88
- }
89
- const { user, server } = result;
90
- return jidEncode(user, server === 'c.us' ? 's.whatsapp.net' : server);
91
- };
92
- export const transferDevice = (fromJid, toJid) => {
93
- const fromDecoded = jidDecode(fromJid);
94
- const deviceId = fromDecoded?.device || 0;
95
- const { server, user } = jidDecode(toJid);
96
- return jidEncode(user, server, deviceId);
97
- };
98
- //# sourceMappingURL=jid-utils.js.map
341
+ const isHostedLidUser = jid => jid?.endsWith('@hosted.lid')
342
+ exports.isHostedLidUser = isHostedLidUser
343
+ const botRegexp = /^1313555\d{4}$|^131655500\d{2}$/
344
+ const isJidBot = jid => jid && botRegexp.test(jid.split('@')[0]) && jid.endsWith('@c.us')
345
+ exports.isJidBot = isJidBot
346
+ const jidNormalizedUser = jid => {
347
+ const result = (0, exports.jidDecode)(jid)
348
+ if (!result) {
349
+ return ''
350
+ }
351
+ const { user, server } = result
352
+ return (0, exports.jidEncode)(user, server === 'c.us' ? 's.whatsapp.net' : server)
353
+ }
354
+ exports.jidNormalizedUser = jidNormalizedUser
355
+ const transferDevice = (fromJid, toJid) => {
356
+ const fromDecoded = (0, exports.jidDecode)(fromJid)
357
+ const deviceId = fromDecoded?.device || 0
358
+ const { server, user } = (0, exports.jidDecode)(toJid)
359
+ return (0, exports.jidEncode)(user, server, deviceId)
360
+ }
361
+ exports.transferDevice = transferDevice
@@ -1,2 +1,2 @@
1
- import * as constants from './constants.js';
2
- //# sourceMappingURL=types.js.map
1
+ 'use strict'
2
+ Object.defineProperty(exports, '__esModule', { value: true })
@@ -1,10 +1,13 @@
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
- }
1
+ 'use strict'
2
+ Object.defineProperty(exports, '__esModule', { value: true })
3
+ exports.BinaryInfo = void 0
4
+ class BinaryInfo {
5
+ constructor(options = {}) {
6
+ this.protocolVersion = 5
7
+ this.sequence = 0
8
+ this.events = []
9
+ this.buffer = []
10
+ Object.assign(this, options)
11
+ }
9
12
  }
10
- //# sourceMappingURL=BinaryInfo.js.map
13
+ exports.BinaryInfo = BinaryInfo