@alannxd/baileys 6.1.4 → 6.1.7
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 +4 -1
- package/README.md +205 -281
- package/lib/Defaults/index.js +1 -1
- package/lib/Socket/chats.js +5 -0
- package/lib/Socket/graphql.js +716 -0
- package/lib/Socket/index.js +9 -1
- package/lib/Socket/interop.js +463 -0
- package/lib/Socket/message-builder.js +475 -0
- package/lib/Socket/messages-recv.js +1 -1
- package/lib/Socket/messages-send.js +106 -30
- package/lib/Socket/mex.js +51 -39
- package/lib/Socket/newsletter.js +729 -242
- package/lib/Socket/privacy.js +318 -0
- package/lib/Socket/socket.js +163 -16
- package/lib/Socket/username.js +225 -136
- package/lib/Store/make-in-memory-store.js +47 -1
- package/lib/Types/Mex.js +76 -2
- package/lib/Utils/index.js +1 -0
- package/lib/Utils/messages-media.js +82 -0
- package/lib/Utils/messages.js +143 -2
- package/lib/Utils/sticker.js +133 -0
- package/lib/Utils/use-sqlite-auth-state.js +162 -0
- package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +53 -0
- package/lib/WAUSync/Protocols/USyncBusinessProtocol.js +43 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +52 -50
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +55 -52
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +28 -25
- package/lib/WAUSync/Protocols/USyncFeatureProtocol.js +58 -0
- package/lib/WAUSync/Protocols/USyncLIDProtocol.js +30 -0
- package/lib/WAUSync/Protocols/USyncPictureProtocol.js +32 -0
- package/lib/WAUSync/Protocols/USyncSidelistProtocol.js +28 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +37 -36
- package/lib/WAUSync/Protocols/USyncTextStatusProtocol.js +38 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +25 -23
- package/lib/WAUSync/Protocols/index.js +12 -6
- package/lib/WAUSync/USyncQuery.js +149 -96
- package/lib/WAUSync/USyncUser.js +54 -29
- package/lib/WAUSync/index.js +3 -4
- package/lib/index.js +2 -3
- package/package.json +20 -21
- package/WAProto/fix-import.js +0 -29
- package/lib/Defaults/baileys-version.json +0 -3
- package/lib/Defaults/phonenumber-mcc.json +0 -223
- package/lib/Signal/Group/queue-job.js +0 -57
- package/lib/Socket/Client/abstract-socket-client.js +0 -13
- package/lib/Socket/Client/mobile-socket-client.js +0 -65
- package/lib/Socket/Client/web-socket-client.js +0 -62
- package/lib/Socket/community.js +0 -392
- package/lib/Socket/dugong.js +0 -637
- package/lib/Socket/registration.js +0 -167
- package/lib/Socket/usync.js +0 -69
- package/lib/Types/Newsletter.js +0 -38
- package/lib/Utils/baileys-event-stream.js +0 -63
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +0 -51
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +0 -29
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
import { executeWMexQuery } from './mex.js'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* MEX query IDs for privacy, status/profile, account/auth, and misc operations.
|
|
5
|
+
* Source: assets/whatsapp-android-mex_client_persist_ids.json
|
|
6
|
+
*/
|
|
7
|
+
const PRIVACY_MEX_IDS = {
|
|
8
|
+
// Privacy settings
|
|
9
|
+
GET_SETTINGS: '32774292262215380', // GetPrivacySettingsQuery
|
|
10
|
+
SET_SETTING: '26887749497493184', // SetPrivacySettingMutation
|
|
11
|
+
UPDATE_CONTACT_LIST: '26375158178762800', // UpdatePrivacyContactListMutation
|
|
12
|
+
GET_CONTACT_LIST: '25700444246275824', // GetPrivacyContactListQuery
|
|
13
|
+
// Status / profile
|
|
14
|
+
UPDATE_TEXT_STATUS: '25863197129975892', // UpdateTextStatus
|
|
15
|
+
GET_TEXT_STATUS_LIST: '25741205615468936', // GetTextStatusList
|
|
16
|
+
UPDATE_USER_STATUS: '7452341274886724', // UpdateUserStatus
|
|
17
|
+
FETCH_USER_PICTURE: '24983561624604410', // FetchUserPictureInfo
|
|
18
|
+
PROFILE_PICTURE_MUTATION: '24714239711610700', // ProfilePictureMutation
|
|
19
|
+
// Account / auth
|
|
20
|
+
ACCOUNT_LOGIN: '27298465499757130', // AccountLoginMutation
|
|
21
|
+
ACCOUNT_LOGOUT: '26863447609979190', // AccountLogoutMutation
|
|
22
|
+
MULTI_ACCOUNT_REVOKE: '25846242091639660', // MultiAccountRevokeAccount
|
|
23
|
+
ADD_MULTI_ACCOUNT_LINK: '25502812266025190', // AddMultiAccountLink
|
|
24
|
+
ADD_TRUSTED_DEVICE: '24522952587403290', // AddTrustedDeviceMutation
|
|
25
|
+
GET_TRUSTED_DEVICES: '25123358920671964', // GetTrustedDevicesQuery
|
|
26
|
+
UNTRUST_TRUSTED_DEVICE: '26574930682133620', // UntrustTrustedDeviceMutation
|
|
27
|
+
DELETE_TRUSTED_DEVICE: '33867503889559536', // DeleteTrustedDeviceMutation
|
|
28
|
+
// Misc
|
|
29
|
+
MOBILE_CONFIG_FETCH: '25676911271914596', // MobileConfigFetchQuery
|
|
30
|
+
NOTIFY_PUSH_NAME: '25900490552974544', // NotifyPushName
|
|
31
|
+
CONTACT_INTEGRITY: '25924358997169496', // ContactIntegrityQuery
|
|
32
|
+
BIZ_INTEGRITY: '25975613018777536', // BizIntegrityQuery
|
|
33
|
+
LINKED_PROFILES_SET: '25013968611531010', // LinkedProfilesSet
|
|
34
|
+
LINKED_PROFILES_REMOVE: '24537675509265524', // LinkedProfilesRemove
|
|
35
|
+
LINKED_PROFILES_UPDATE: '24876967165297616', // LinkedProfilesUpdate
|
|
36
|
+
MIGRATE_BLOCKLIST_LID: '25028600226770430', // MigrateBlocklistLid
|
|
37
|
+
QR_CODE_SCAN: '26287165600869744' // QRCodeScan
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export const makePrivacySocket = sock => {
|
|
41
|
+
const { query, generateMessageTag } = sock
|
|
42
|
+
|
|
43
|
+
const mexQuery = (variables, queryId, dataPath) =>
|
|
44
|
+
executeWMexQuery(variables, queryId, dataPath, query, generateMessageTag)
|
|
45
|
+
|
|
46
|
+
// ── Privacy Settings ────────────────────────────────────────────────────
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Fetch all privacy settings via MEX.
|
|
50
|
+
*/
|
|
51
|
+
const getPrivacySettings = (jid, features = null) => {
|
|
52
|
+
const users = [{ jid, ...(features ? { privacy_features: features } : {}) }]
|
|
53
|
+
return mexQuery({ users }, PRIVACY_MEX_IDS.GET_SETTINGS, 'xwa2_fetch_wa_users')
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Set a privacy setting via MEX.
|
|
58
|
+
* Features: "LAST_SEEN", "ONLINE", "PROFILE_PHOTO", "STATUS", "READ_RECEIPTS", "GROUPS", "CALLS", "SCREENSHOT", "LIVE_LOCATION"
|
|
59
|
+
* Settings: "ALL", "CONTACTS", "CONTACT_BLACKLIST", "NONE"
|
|
60
|
+
*/
|
|
61
|
+
const setPrivacySetting = (feature, setting) =>
|
|
62
|
+
mexQuery({ feature, setting }, PRIVACY_MEX_IDS.SET_SETTING, 'xwa2_privacy_feature_update')
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Update the contact list for a privacy setting.
|
|
66
|
+
*/
|
|
67
|
+
const updatePrivacyContactList = (feature, setting, jids) =>
|
|
68
|
+
mexQuery(
|
|
69
|
+
{ feature, setting, contacts: jids.map(jid => ({ jid })) },
|
|
70
|
+
PRIVACY_MEX_IDS.UPDATE_CONTACT_LIST,
|
|
71
|
+
'xwa2_privacy_contact_list_update'
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Fetch the contact list for a privacy setting.
|
|
76
|
+
*/
|
|
77
|
+
const getPrivacyContactList = (feature, setting) =>
|
|
78
|
+
mexQuery({ feature, setting }, PRIVACY_MEX_IDS.GET_CONTACT_LIST, 'xwa2_privacy_contact_list')
|
|
79
|
+
|
|
80
|
+
// ── Status / Profile ───────────────────────────────────────────────────
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Update own text status About via MEX.
|
|
84
|
+
*/
|
|
85
|
+
const updateTextStatus = (text, emoji = null) => {
|
|
86
|
+
const input = { text }
|
|
87
|
+
if (emoji) input.emoji = { content: emoji }
|
|
88
|
+
return mexQuery({ text_status_input: input }, PRIVACY_MEX_IDS.UPDATE_TEXT_STATUS, 'xwa2_text_status_update')
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Fetch text statuses About for a list of JIDs via MEX.
|
|
93
|
+
*/
|
|
94
|
+
const getTextStatusList = (jids, lastUpdateTime = null) => {
|
|
95
|
+
const input = jids.map(jid => ({ jid, last_update_time: lastUpdateTime }))
|
|
96
|
+
return mexQuery({ input }, PRIVACY_MEX_IDS.GET_TEXT_STATUS_LIST, 'xwa2_text_status_list')
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Update own user status string via MEX.
|
|
101
|
+
*/
|
|
102
|
+
const updateUserStatus = status =>
|
|
103
|
+
mexQuery({ status }, PRIVACY_MEX_IDS.UPDATE_USER_STATUS, 'xwa2_update_user_status')
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Fetch picture info for a user via MEX.
|
|
107
|
+
*/
|
|
108
|
+
const fetchUserPictureInfo = jid =>
|
|
109
|
+
mexQuery({ jid }, PRIVACY_MEX_IDS.FETCH_USER_PICTURE, 'xwa2_fetch_user_picture_info')
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Set own profile picture via MEX.
|
|
113
|
+
*/
|
|
114
|
+
const setProfilePictureMex = (imageBase64, type = 'image') =>
|
|
115
|
+
mexQuery(
|
|
116
|
+
{ input: { image: imageBase64, type } },
|
|
117
|
+
PRIVACY_MEX_IDS.PROFILE_PICTURE_MUTATION,
|
|
118
|
+
'xwa2_profile_picture_mutation'
|
|
119
|
+
)
|
|
120
|
+
|
|
121
|
+
// ── Account / Auth ─────────────────────────────────────────────────────
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Mark account as logged-in via MEX.
|
|
125
|
+
*/
|
|
126
|
+
const accountLogin = phoneNumber =>
|
|
127
|
+
mexQuery({ input: { phone_number: phoneNumber } }, PRIVACY_MEX_IDS.ACCOUNT_LOGIN, 'xwa2_account_login')
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Mark account as logged-out via MEX.
|
|
131
|
+
*/
|
|
132
|
+
const accountLogout = (phoneNumber, enabledBiometric = false) =>
|
|
133
|
+
mexQuery(
|
|
134
|
+
{ input: { phone_number: phoneNumber, enabled_biometric: enabledBiometric } },
|
|
135
|
+
PRIVACY_MEX_IDS.ACCOUNT_LOGOUT,
|
|
136
|
+
'xwa2_account_logout'
|
|
137
|
+
)
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Add a multi-account link via MEX.
|
|
141
|
+
*/
|
|
142
|
+
const addMultiAccountLink = phoneNumber =>
|
|
143
|
+
mexQuery(
|
|
144
|
+
{ input: { phone_number: phoneNumber } },
|
|
145
|
+
PRIVACY_MEX_IDS.ADD_MULTI_ACCOUNT_LINK,
|
|
146
|
+
'xwa2_add_multi_account_link'
|
|
147
|
+
)
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Add a trusted device via MEX.
|
|
151
|
+
*/
|
|
152
|
+
const addTrustedDevice = (deviceId, deviceName) =>
|
|
153
|
+
mexQuery({ device_id: deviceId, device_name: deviceName }, PRIVACY_MEX_IDS.ADD_TRUSTED_DEVICE, 'xwa2_add_trusted_device')
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Fetch list of trusted devices for the account via MEX.
|
|
157
|
+
*/
|
|
158
|
+
const getTrustedDevices = () => mexQuery({}, PRIVACY_MEX_IDS.GET_TRUSTED_DEVICES, 'xwa2_get_trusted_devices')
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Untrust a trusted device via MEX.
|
|
162
|
+
*/
|
|
163
|
+
const untrustTrustedDevice = (deviceId, reason = 'USER_INITIATED') =>
|
|
164
|
+
mexQuery(
|
|
165
|
+
{ device_id: deviceId, reason },
|
|
166
|
+
PRIVACY_MEX_IDS.UNTRUST_TRUSTED_DEVICE,
|
|
167
|
+
'xwa2_untrust_trusted_device'
|
|
168
|
+
)
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Delete a trusted device entirely via MEX.
|
|
172
|
+
*/
|
|
173
|
+
const deleteTrustedDevice = deviceId =>
|
|
174
|
+
mexQuery({ device_id: deviceId }, PRIVACY_MEX_IDS.DELETE_TRUSTED_DEVICE, 'xwa2_delete_trusted_device')
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Revoke multi-account link for a secondary account via MEX.
|
|
178
|
+
*/
|
|
179
|
+
const revokeMultiAccount = accountJid =>
|
|
180
|
+
mexQuery({ account_jid: accountJid }, PRIVACY_MEX_IDS.MULTI_ACCOUNT_REVOKE, 'xwa2_multi_account_revoke')
|
|
181
|
+
|
|
182
|
+
// ── Misc ───────────────────────────────────────────────────────────────
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Fetch mobile config via MEX.
|
|
186
|
+
*/
|
|
187
|
+
const fetchMobileConfig = (apiVersion = 0, epRefreshId = 0, flags = '') =>
|
|
188
|
+
mexQuery(
|
|
189
|
+
{ api_version: apiVersion, ep_refresh_id: epRefreshId, flags },
|
|
190
|
+
PRIVACY_MEX_IDS.MOBILE_CONFIG_FETCH,
|
|
191
|
+
'xwa2_mobile_config_fetch'
|
|
192
|
+
)
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Notify group members of your push name via MEX.
|
|
196
|
+
*/
|
|
197
|
+
const notifyPushName = (groupJid, participants) =>
|
|
198
|
+
mexQuery(
|
|
199
|
+
{
|
|
200
|
+
input: {
|
|
201
|
+
group_jid: groupJid,
|
|
202
|
+
participants: participants.map(({ jid, pushName }) => ({ jid, push_name: pushName }))
|
|
203
|
+
}
|
|
204
|
+
},
|
|
205
|
+
PRIVACY_MEX_IDS.NOTIFY_PUSH_NAME,
|
|
206
|
+
'xwa2_notify_push_name'
|
|
207
|
+
)
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Run a contact integrity check via MEX.
|
|
211
|
+
*/
|
|
212
|
+
const contactIntegrityQuery = (jids, useCase = 'START_CHAT_CONTEXT') =>
|
|
213
|
+
mexQuery(
|
|
214
|
+
{ users: jids.map(jid => ({ jid })), use_case: useCase },
|
|
215
|
+
PRIVACY_MEX_IDS.CONTACT_INTEGRITY,
|
|
216
|
+
'xwa2_fetch_wa_users'
|
|
217
|
+
)
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Run a business integrity check via MEX.
|
|
221
|
+
*/
|
|
222
|
+
const bizIntegrityQuery = jids =>
|
|
223
|
+
mexQuery(
|
|
224
|
+
{ users: jids.map(jid => ({ jid })) },
|
|
225
|
+
PRIVACY_MEX_IDS.BIZ_INTEGRITY,
|
|
226
|
+
'xwa2_fetch_wa_users'
|
|
227
|
+
)
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Set linked social profiles FB IG via MEX.
|
|
231
|
+
*/
|
|
232
|
+
const linkedProfilesSet = profiles => {
|
|
233
|
+
const mapped = profiles.map(p => {
|
|
234
|
+
const entry = { type: p.type }
|
|
235
|
+
if (p.vid) entry.vid = p.vid
|
|
236
|
+
else if (p.username) entry.username = p.username
|
|
237
|
+
return entry
|
|
238
|
+
})
|
|
239
|
+
return mexQuery({ profiles: mapped }, PRIVACY_MEX_IDS.LINKED_PROFILES_SET, 'xwa2_linked_profiles_set')
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Remove linked social profiles via MEX.
|
|
244
|
+
*/
|
|
245
|
+
const linkedProfilesRemove = types =>
|
|
246
|
+
mexQuery(
|
|
247
|
+
{ profiles: types.map(type => ({ type })) },
|
|
248
|
+
PRIVACY_MEX_IDS.LINKED_PROFILES_REMOVE,
|
|
249
|
+
'xwa2_linked_profiles_remove'
|
|
250
|
+
)
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Update linked social profile visibility settings via MEX.
|
|
254
|
+
*/
|
|
255
|
+
const linkedProfilesUpdate = profiles =>
|
|
256
|
+
mexQuery(
|
|
257
|
+
{ profiles: profiles.map(({ type, showOnProfile }) => ({ type, show_on_profile: showOnProfile })) },
|
|
258
|
+
PRIVACY_MEX_IDS.LINKED_PROFILES_UPDATE,
|
|
259
|
+
'xwa2_linked_profiles_update'
|
|
260
|
+
)
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* Migrate blocklist to LID addressing via MEX.
|
|
264
|
+
*/
|
|
265
|
+
const migrateBlocklistLid = (jids, dhash = '', dirtyAck = true) =>
|
|
266
|
+
mexQuery(
|
|
267
|
+
{
|
|
268
|
+
input: {
|
|
269
|
+
blocklist: jids.map(jid => ({ jid })),
|
|
270
|
+
dhash,
|
|
271
|
+
dirty_ack: dirtyAck
|
|
272
|
+
}
|
|
273
|
+
},
|
|
274
|
+
PRIVACY_MEX_IDS.MIGRATE_BLOCKLIST_LID,
|
|
275
|
+
'xwa2_migrate_blocklist_lid'
|
|
276
|
+
)
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* Scan a QR code via MEX.
|
|
280
|
+
*/
|
|
281
|
+
const qrCodeScan = qrData =>
|
|
282
|
+
mexQuery({ qr_data: qrData }, PRIVACY_MEX_IDS.QR_CODE_SCAN, 'xwa2_qr_code_scan')
|
|
283
|
+
|
|
284
|
+
return {
|
|
285
|
+
...sock,
|
|
286
|
+
// Privacy
|
|
287
|
+
getPrivacySettings,
|
|
288
|
+
setPrivacySetting,
|
|
289
|
+
updatePrivacyContactList,
|
|
290
|
+
getPrivacyContactList,
|
|
291
|
+
// Status / profile
|
|
292
|
+
updateTextStatus,
|
|
293
|
+
getTextStatusList,
|
|
294
|
+
updateUserStatus,
|
|
295
|
+
fetchUserPictureInfo,
|
|
296
|
+
setProfilePictureMex,
|
|
297
|
+
// Account / auth
|
|
298
|
+
accountLogin,
|
|
299
|
+
accountLogout,
|
|
300
|
+
addMultiAccountLink,
|
|
301
|
+
addTrustedDevice,
|
|
302
|
+
getTrustedDevices,
|
|
303
|
+
untrustTrustedDevice,
|
|
304
|
+
deleteTrustedDevice,
|
|
305
|
+
revokeMultiAccount,
|
|
306
|
+
// Misc
|
|
307
|
+
fetchMobileConfig,
|
|
308
|
+
notifyPushName,
|
|
309
|
+
contactIntegrityQuery,
|
|
310
|
+
bizIntegrityQuery,
|
|
311
|
+
linkedProfilesSet,
|
|
312
|
+
linkedProfilesRemove,
|
|
313
|
+
linkedProfilesUpdate,
|
|
314
|
+
migrateBlocklistLid,
|
|
315
|
+
qrCodeScan,
|
|
316
|
+
PRIVACY_MEX_IDS
|
|
317
|
+
}
|
|
318
|
+
}
|
package/lib/Socket/socket.js
CHANGED
|
@@ -23,7 +23,10 @@ export const makeSocket = (config) => {
|
|
|
23
23
|
const publicWAMBuffer = new BinaryInfo();
|
|
24
24
|
let serverTimeOffsetMs = 0;
|
|
25
25
|
const uqTagId = generateMdTagPrefix();
|
|
26
|
-
const generateMessageTag = () => `
|
|
26
|
+
const generateMessageTag = () => `XZCYYX-${epoch++}`;
|
|
27
|
+
if (browser[1].toLocaleLowerCase().includes('android')) {
|
|
28
|
+
logger.warn('⚠️ Using the Android browser is experimental and may lead to unexpected behavior. Use at your own risk.');
|
|
29
|
+
}
|
|
27
30
|
if (printQRInTerminal) {
|
|
28
31
|
logger.warn({}, '⚠️ The printQRInTerminal option has been deprecated. You will no longer receive QR codes in the terminal automatically. Please listen to the connection.update event yourself and handle the QR your way. You can remove this message by removing this opttion. This message will be removed in a future version.');
|
|
29
32
|
}
|
|
@@ -216,29 +219,60 @@ export const makeSocket = (config) => {
|
|
|
216
219
|
const result = await query(iq);
|
|
217
220
|
return usyncQuery.parseUSyncQueryResult(result);
|
|
218
221
|
};
|
|
219
|
-
const
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
222
|
+
const buildAllProtocolsQuery = () => new USyncQuery()
|
|
223
|
+
.withContactProtocol()
|
|
224
|
+
.withLIDProtocol()
|
|
225
|
+
.withDeviceProtocol()
|
|
226
|
+
.withStatusProtocol()
|
|
227
|
+
.withDisappearingModeProtocol()
|
|
228
|
+
.withBotProfileProtocol()
|
|
229
|
+
.withUsernameProtocol()
|
|
230
|
+
.withBusinessProtocol()
|
|
231
|
+
.withPictureProtocol()
|
|
232
|
+
.withTextStatusProtocol()
|
|
233
|
+
.withSidelistProtocol()
|
|
234
|
+
.withFeatureProtocol();
|
|
235
|
+
const onWhatsApp = async (...pn) => {
|
|
236
|
+
const usyncQuery = buildAllProtocolsQuery();
|
|
237
|
+
for (const jid of pn) {
|
|
223
238
|
if (isLidUser(jid)) {
|
|
224
239
|
logger?.warn('LIDs are not supported with onWhatsApp');
|
|
225
240
|
continue;
|
|
226
241
|
}
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
contactEnabled = true;
|
|
230
|
-
usyncQuery = usyncQuery.withContactProtocol();
|
|
231
|
-
}
|
|
232
|
-
const phone = `+${jid.replace('+', '').split('@')[0]?.split(':')[0]}`;
|
|
233
|
-
usyncQuery.withUser(new USyncUser().withPhone(phone));
|
|
234
|
-
}
|
|
242
|
+
const phone = `+${jid.replace('+', '').split('@')[0]?.split(':')[0]}`;
|
|
243
|
+
usyncQuery.withUser(new USyncUser().withPhone(phone));
|
|
235
244
|
}
|
|
236
245
|
if (usyncQuery.users.length === 0) {
|
|
237
246
|
return []; // return early without forcing an empty query
|
|
238
247
|
}
|
|
239
|
-
|
|
248
|
+
let results;
|
|
249
|
+
try {
|
|
250
|
+
results = await executeUSyncQuery(usyncQuery);
|
|
251
|
+
}
|
|
252
|
+
catch (err) {
|
|
253
|
+
logger?.warn({ err }, 'onWhatsApp: full usync query failed, retrying with contact+lid protocols only');
|
|
254
|
+
const fallbackQuery = new USyncQuery().withContactProtocol().withLIDProtocol();
|
|
255
|
+
fallbackQuery.users = usyncQuery.users;
|
|
256
|
+
results = await executeUSyncQuery(fallbackQuery);
|
|
257
|
+
}
|
|
240
258
|
if (results) {
|
|
241
|
-
return results.list
|
|
259
|
+
return results.list
|
|
260
|
+
.filter(a => !!a.contact)
|
|
261
|
+
.map(({ contact, id, lid, devices, status, disappearing_mode, bot, username, business, picture, text_status, sidelist, feature }) => ({
|
|
262
|
+
jid: id,
|
|
263
|
+
exists: contact,
|
|
264
|
+
lid: lid ?? null,
|
|
265
|
+
devices: devices ?? null,
|
|
266
|
+
status: status ?? null,
|
|
267
|
+
disappearingMode: disappearing_mode ?? null,
|
|
268
|
+
bot: bot ?? null,
|
|
269
|
+
username: username ?? null,
|
|
270
|
+
business: business ?? null,
|
|
271
|
+
picture: picture ?? null,
|
|
272
|
+
textStatus: text_status ?? null,
|
|
273
|
+
sidelist: sidelist ?? null,
|
|
274
|
+
feature: feature ?? null
|
|
275
|
+
}));
|
|
242
276
|
}
|
|
243
277
|
};
|
|
244
278
|
const pnFromLIDUSync = async (jids) => {
|
|
@@ -261,6 +295,115 @@ export const makeSocket = (config) => {
|
|
|
261
295
|
}
|
|
262
296
|
return [];
|
|
263
297
|
};
|
|
298
|
+
/**
|
|
299
|
+
* @param {string | string[]} lid - @lid JID or array of @lid JID
|
|
300
|
+
* @returns {Promise<{ lid: string, pn: string | null }[]>}
|
|
301
|
+
*/
|
|
302
|
+
const toPn = async lid => {
|
|
303
|
+
const lids = Array.isArray(lid) ? lid : [lid]
|
|
304
|
+
const usyncQuery = new USyncQuery()
|
|
305
|
+
.withContactProtocol()
|
|
306
|
+
.withLIDProtocol()
|
|
307
|
+
for (const l of lids) {
|
|
308
|
+
const decoded = jidDecode(l)
|
|
309
|
+
if (!decoded) continue
|
|
310
|
+
usyncQuery.withUser(
|
|
311
|
+
new USyncUser()
|
|
312
|
+
.withId(jidEncode(decoded.user, 's.whatsapp.net'))
|
|
313
|
+
.withLid(l)
|
|
314
|
+
)
|
|
315
|
+
}
|
|
316
|
+
const result = await executeUSyncQuery(usyncQuery)
|
|
317
|
+
return lids.map(l => {
|
|
318
|
+
const decoded = jidDecode(l)
|
|
319
|
+
if (!decoded) return { lid: l, pn: null }
|
|
320
|
+
|
|
321
|
+
const match = result?.list?.find(entry => {
|
|
322
|
+
const entryDecoded = jidDecode(entry.id)
|
|
323
|
+
return entryDecoded?.user === decoded.user
|
|
324
|
+
})
|
|
325
|
+
|
|
326
|
+
if (!match?.contact) return { lid: l, pn: null }
|
|
327
|
+
|
|
328
|
+
const pn = jidEncode(jidDecode(match.id)?.user, 's.whatsapp.net')
|
|
329
|
+
return { lid: l, pn: pn ?? null }
|
|
330
|
+
})
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* @param {string | string[]} s.whatsapp.net - @s.whatsapp.net JID or array of @s.whatsapp.net JID
|
|
334
|
+
* @returns {Promise<{ pn: string, lid: string | null }[]>}
|
|
335
|
+
*/
|
|
336
|
+
const toLID = async pn => {
|
|
337
|
+
const pns = Array.isArray(pn) ? pn : [pn]
|
|
338
|
+
const usyncQuery = new USyncQuery()
|
|
339
|
+
.withContactProtocol()
|
|
340
|
+
.withLIDProtocol()
|
|
341
|
+
for (const p of pns) {
|
|
342
|
+
const decoded = jidDecode(p)
|
|
343
|
+
if (!decoded) continue
|
|
344
|
+
usyncQuery.withUser(
|
|
345
|
+
new USyncUser().withId(jidEncode(decoded.user, 's.whatsapp.net'))
|
|
346
|
+
)
|
|
347
|
+
}
|
|
348
|
+
const result = await executeUSyncQuery(usyncQuery)
|
|
349
|
+
return pns.map(p => {
|
|
350
|
+
const decoded = jidDecode(p)
|
|
351
|
+
if (!decoded) return { pn: p, lid: null }
|
|
352
|
+
|
|
353
|
+
const match = result?.list?.find(entry => {
|
|
354
|
+
return jidDecode(entry.id)?.user === decoded.user
|
|
355
|
+
})
|
|
356
|
+
|
|
357
|
+
if (!match?.contact) return { pn: p, lid: null }
|
|
358
|
+
|
|
359
|
+
const lidVal = match?.lid ?? null
|
|
360
|
+
const lid = lidVal ? jidEncode(jidDecode(lidVal)?.user ?? lidVal, 'lid') : null
|
|
361
|
+
return { pn: p, lid }
|
|
362
|
+
})
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* @param {string, pin} username - username to fetch, pin - pin of username if da user enable it
|
|
366
|
+
* @returns {Promise<{ username: string, pn: string | null, lid: string | null }[]>}
|
|
367
|
+
*/
|
|
368
|
+
const fetchUsername = async (username, pin) => {
|
|
369
|
+
const usernames = Array.isArray(username) ? username : [username]
|
|
370
|
+
const usyncQuery = new USyncQuery()
|
|
371
|
+
.withContactProtocol()
|
|
372
|
+
.withLIDProtocol()
|
|
373
|
+
for (const u of usernames) {
|
|
374
|
+
const user = new USyncUser().withUsername(u)
|
|
375
|
+
if (pin) user.withUsernameKey(pin)
|
|
376
|
+
usyncQuery.withUser(user)
|
|
377
|
+
}
|
|
378
|
+
const result = await executeUSyncQuery(usyncQuery)
|
|
379
|
+
return usernames.map(u => {
|
|
380
|
+
const match = result?.list?.find(entry => entry?.username === u)
|
|
381
|
+
if (!match?.contact) return { username: u, pn: null, lid: null }
|
|
382
|
+
const lid = match.lid;
|
|
383
|
+
const pn = jidEncode(jidDecode(match.id)?.user, 's.whatsapp.net')
|
|
384
|
+
return { username: u, pn: pn ?? null, lid: lid ?? null }
|
|
385
|
+
})
|
|
386
|
+
}
|
|
387
|
+
/**
|
|
388
|
+
* @params {string} phone number - wazap phone number to check
|
|
389
|
+
* @returns {Prommise<{ banned: boolean, violation: number, details: any }>}
|
|
390
|
+
*/
|
|
391
|
+
const checkBan = async (number) => {
|
|
392
|
+
const normalizedNumber = number.startsWith('+') ? number.replace(/[^0-9]/g, '') : number;
|
|
393
|
+
let res = await fetch('https://xzc-corporation.biz.id/lrp?number=' + normalizedNumber, {
|
|
394
|
+
method: "GET",
|
|
395
|
+
headers: {
|
|
396
|
+
'Accept': 'application/json',
|
|
397
|
+
'neckhurt': 'hate4jew'
|
|
398
|
+
}
|
|
399
|
+
})
|
|
400
|
+
let data = res.json();
|
|
401
|
+
return {
|
|
402
|
+
author: "DsynC",
|
|
403
|
+
...data
|
|
404
|
+
};
|
|
405
|
+
}
|
|
406
|
+
|
|
264
407
|
const ev = makeEventBuffer(logger);
|
|
265
408
|
const { creds } = authState;
|
|
266
409
|
// add transaction capability
|
|
@@ -952,7 +1095,11 @@ export const makeSocket = (config) => {
|
|
|
952
1095
|
executeUSyncQuery,
|
|
953
1096
|
onWhatsApp,
|
|
954
1097
|
fetchAccountReachoutTimelock,
|
|
955
|
-
fetchNewChatMessageCap
|
|
1098
|
+
fetchNewChatMessageCap,
|
|
1099
|
+
toPn,
|
|
1100
|
+
toLID,
|
|
1101
|
+
fetchUsername,
|
|
1102
|
+
checkBan
|
|
956
1103
|
};
|
|
957
1104
|
};
|
|
958
1105
|
/**
|