@alannxd/baileys 6.1.2 → 6.1.4

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/lib/Socket/mex.js CHANGED
@@ -1,41 +1,42 @@
1
- import * as boom_1 from '@hapi/boom'
2
- import * as WABinary_1 from '../WABinary/index.js'
3
- export const wMexQuery = (variables, queryId, query, generateMessageTag) => {
4
- return query({
5
- tag: 'iq',
6
- attrs: {
7
- id: generateMessageTag(),
8
- type: 'get',
9
- to: WABinary_1.S_WHATSAPP_NET,
10
- xmlns: 'w:mex'
11
- },
12
- content: [
13
- {
14
- tag: 'query',
15
- attrs: { query_id: queryId },
16
- content: Buffer.from(JSON.stringify({ variables }), 'utf-8')
17
- }
18
- ]
19
- })
20
- }
1
+ import { Boom } from '@hapi/boom';
2
+ import { getBinaryNodeChild, S_WHATSAPP_NET } from '../WABinary/index.js';
3
+ const wMexQuery = (variables, queryId, query, generateMessageTag) => {
4
+ return query({
5
+ tag: 'iq',
6
+ attrs: {
7
+ id: generateMessageTag(),
8
+ type: 'get',
9
+ to: S_WHATSAPP_NET,
10
+ xmlns: 'w:mex'
11
+ },
12
+ content: [
13
+ {
14
+ tag: 'query',
15
+ attrs: { query_id: queryId },
16
+ content: Buffer.from(JSON.stringify({ variables }), 'utf-8')
17
+ }
18
+ ]
19
+ });
20
+ };
21
21
  export const executeWMexQuery = async (variables, queryId, dataPath, query, generateMessageTag) => {
22
- const result = await wMexQuery(variables, queryId, query, generateMessageTag)
23
- const child = (0, WABinary_1.getBinaryNodeChild)(result, 'result')
24
- if (child?.content) {
25
- const data = JSON.parse(child.content.toString())
26
- if (data.errors && data.errors.length > 0) {
27
- const errorMessages = data.errors.map(err => err.message || 'Unknown error').join(', ')
28
- const firstError = data.errors[0]
29
- const errorCode = firstError.extensions?.error_code || 400
30
- throw new boom_1.Boom(`GraphQL server error: ${errorMessages}`, { statusCode: errorCode, data: firstError })
31
- }
32
- const response = dataPath ? data?.data?.[dataPath] : data?.data
33
- if (typeof response !== 'undefined') {
34
- return response
35
- }
36
- }
37
- const action = (dataPath || '').startsWith('xwa2_')
38
- ? dataPath.substring(5).replace(/_/g, ' ')
39
- : dataPath?.replace(/_/g, ' ')
40
- throw new boom_1.Boom(`Failed to ${action}, unexpected response structure.`, { statusCode: 400, data: result })
41
- }
22
+ const result = await wMexQuery(variables, queryId, query, generateMessageTag);
23
+ const child = getBinaryNodeChild(result, 'result');
24
+ if (child?.content) {
25
+ const data = JSON.parse(child.content.toString());
26
+ if (data.errors && data.errors.length > 0) {
27
+ const errorMessages = data.errors.map((err) => err.message || 'Unknown error').join(', ');
28
+ const firstError = data.errors[0];
29
+ const errorCode = firstError.extensions?.error_code || 400;
30
+ throw new Boom(`GraphQL server error: ${errorMessages}`, { statusCode: errorCode, data: firstError });
31
+ }
32
+ const response = dataPath ? data?.data?.[dataPath] : data?.data;
33
+ if (typeof response !== 'undefined') {
34
+ return response;
35
+ }
36
+ }
37
+ const action = (dataPath || '').startsWith('xwa2_')
38
+ ? dataPath.substring(5).replace(/_/g, ' ')
39
+ : dataPath?.replace(/_/g, ' ');
40
+ throw new Boom(`Failed to ${action}, unexpected response structure.`, { statusCode: 400, data: result });
41
+ };
42
+ //# sourceMappingURL=mex.js.map
@@ -0,0 +1,167 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.mobileRegisterFetch = exports.mobileRegisterEncrypt = exports.mobileRegister = exports.mobileRegisterExists = exports.mobileRegisterCode = exports.registrationParams = exports.makeRegistrationSocket = void 0;
7
+ /* eslint-disable camelcase */
8
+ const axios_1 = __importDefault(require("axios"));
9
+ const Defaults_1 = require("../Defaults");
10
+ const crypto_1 = require("../Utils/crypto");
11
+ const WABinary_1 = require("../WABinary");
12
+ const business_1 = require("./business");
13
+ const community_1 = require("./community");
14
+ function urlencode(str) {
15
+ return str.replace(/-/g, '%2d').replace(/_/g, '%5f').replace(/~/g, '%7e');
16
+ }
17
+ const validRegistrationOptions = (config) => (config === null || config === void 0 ? void 0 : config.phoneNumberCountryCode) &&
18
+ config.phoneNumberNationalNumber &&
19
+ config.phoneNumberMobileCountryCode;
20
+ const makeRegistrationSocket = (config) => {
21
+ const sock = (0, community_1.makeCommunitiesSocket)(config);
22
+ const register = async (code) => {
23
+ if (!validRegistrationOptions(config.auth.creds.registration)) {
24
+ throw new Error('please specify the registration options');
25
+ }
26
+ const result = await mobileRegister({ ...sock.authState.creds, ...sock.authState.creds.registration, code }, config.options);
27
+ sock.authState.creds.me = {
28
+ id: (0, WABinary_1.jidEncode)(result.login, 's.whatsapp.net'),
29
+ name: '~'
30
+ };
31
+ sock.authState.creds.registered = true;
32
+ sock.ev.emit('creds.update', sock.authState.creds);
33
+ return result;
34
+ };
35
+ const requestRegistrationCode = async (registrationOptions) => {
36
+ registrationOptions = registrationOptions || config.auth.creds.registration;
37
+ if (!validRegistrationOptions(registrationOptions)) {
38
+ throw new Error('Invalid registration options');
39
+ }
40
+ sock.authState.creds.registration = registrationOptions;
41
+ sock.ev.emit('creds.update', sock.authState.creds);
42
+ return mobileRegisterCode({ ...config.auth.creds, ...registrationOptions }, config.options);
43
+ };
44
+ return {
45
+ ...sock,
46
+ register,
47
+ requestRegistrationCode,
48
+ };
49
+ };
50
+ exports.makeRegistrationSocket = makeRegistrationSocket;
51
+ function convertBufferToUrlHex(buffer) {
52
+ var id = '';
53
+ buffer.forEach((x) => {
54
+ // encode random identity_id buffer as percentage url encoding
55
+ id += `%${x.toString(16).padStart(2, '0').toLowerCase()}`;
56
+ });
57
+ return id;
58
+ }
59
+ function registrationParams(params) {
60
+ const e_regid = Buffer.alloc(4);
61
+ e_regid.writeInt32BE(params.registrationId);
62
+ const e_skey_id = Buffer.alloc(3);
63
+ e_skey_id.writeInt16BE(params.signedPreKey.keyId);
64
+ params.phoneNumberCountryCode = params.phoneNumberCountryCode.replace('+', '').trim();
65
+ params.phoneNumberNationalNumber = params.phoneNumberNationalNumber.replace(/[/-\s)(]/g, '').trim();
66
+ return {
67
+ cc: params.phoneNumberCountryCode,
68
+ in: params.phoneNumberNationalNumber,
69
+ Rc: '0',
70
+ lg: 'en',
71
+ lc: 'GB',
72
+ mistyped: '6',
73
+ authkey: Buffer.from(params.noiseKey.public).toString('base64url'),
74
+ e_regid: e_regid.toString('base64url'),
75
+ e_keytype: 'BQ',
76
+ e_ident: Buffer.from(params.signedIdentityKey.public).toString('base64url'),
77
+ // e_skey_id: e_skey_id.toString('base64url'),
78
+ e_skey_id: 'AAAA',
79
+ e_skey_val: Buffer.from(params.signedPreKey.keyPair.public).toString('base64url'),
80
+ e_skey_sig: Buffer.from(params.signedPreKey.signature).toString('base64url'),
81
+ fdid: params.phoneId,
82
+ network_ratio_type: '1',
83
+ expid: params.deviceId,
84
+ simnum: '1',
85
+ hasinrc: '1',
86
+ pid: Math.floor(Math.random() * 1000).toString(),
87
+ id: convertBufferToUrlHex(params.identityId),
88
+ backup_token: convertBufferToUrlHex(params.backupToken),
89
+ token: (0, crypto_1.md5)(Buffer.concat([Defaults_1.MOBILE_TOKEN, Buffer.from(params.phoneNumberNationalNumber)])).toString('hex'),
90
+ fraud_checkpoint_code: params.captcha,
91
+ };
92
+ }
93
+ exports.registrationParams = registrationParams;
94
+ /**
95
+ * Requests a registration code for the given phone number.
96
+ */
97
+ function mobileRegisterCode(params, fetchOptions) {
98
+ return mobileRegisterFetch('/code', {
99
+ params: {
100
+ ...registrationParams(params),
101
+ mcc: `${params.phoneNumberMobileCountryCode}`.padStart(3, '0'),
102
+ mnc: `${params.phoneNumberMobileNetworkCode || '001'}`.padStart(3, '0'),
103
+ sim_mcc: '000',
104
+ sim_mnc: '000',
105
+ method: (params === null || params === void 0 ? void 0 : params.method) || 'sms',
106
+ reason: '',
107
+ hasav: '1'
108
+ },
109
+ ...fetchOptions,
110
+ });
111
+ }
112
+ exports.mobileRegisterCode = mobileRegisterCode;
113
+ function mobileRegisterExists(params, fetchOptions) {
114
+ return mobileRegisterFetch('/exist', {
115
+ params: registrationParams(params),
116
+ ...fetchOptions
117
+ });
118
+ }
119
+ exports.mobileRegisterExists = mobileRegisterExists;
120
+ /**
121
+ * Registers the phone number on whatsapp with the received OTP code.
122
+ */
123
+ async function mobileRegister(params, fetchOptions) {
124
+ //const result = await mobileRegisterFetch(`/reg_onboard_abprop?cc=${params.phoneNumberCountryCode}&in=${params.phoneNumberNationalNumber}&rc=0`)
125
+ return mobileRegisterFetch('/register', {
126
+ params: { ...registrationParams(params), code: params.code.replace('-', '') },
127
+ ...fetchOptions,
128
+ });
129
+ }
130
+ exports.mobileRegister = mobileRegister;
131
+ /**
132
+ * Encrypts the given string as AEAD aes-256-gcm with the public whatsapp key and a random keypair.
133
+ */
134
+ function mobileRegisterEncrypt(data) {
135
+ const keypair = crypto_1.Curve.generateKeyPair();
136
+ const key = crypto_1.Curve.sharedKey(keypair.private, Defaults_1.REGISTRATION_PUBLIC_KEY);
137
+ const buffer = (0, crypto_1.aesEncryptGCM)(Buffer.from(data), new Uint8Array(key), Buffer.alloc(12), Buffer.alloc(0));
138
+ return Buffer.concat([Buffer.from(keypair.public), buffer]).toString('base64url');
139
+ }
140
+ exports.mobileRegisterEncrypt = mobileRegisterEncrypt;
141
+ async function mobileRegisterFetch(path, opts = {}) {
142
+ let url = `${Defaults_1.MOBILE_REGISTRATION_ENDPOINT}${path}`;
143
+ if (opts.params) {
144
+ const parameter = [];
145
+ for (const param in opts.params) {
146
+ if (opts.params[param] !== null && opts.params[param] !== undefined) {
147
+ parameter.push(param + '=' + urlencode(opts.params[param]));
148
+ }
149
+ }
150
+ url += `?${parameter.join('&')}`;
151
+ delete opts.params;
152
+ }
153
+ if (!opts.headers) {
154
+ opts.headers = {};
155
+ }
156
+ opts.headers['User-Agent'] = Defaults_1.MOBILE_USERAGENT;
157
+ const response = await (0, axios_1.default)(url, opts);
158
+ var json = response.data;
159
+ if (response.status > 300 || json.reason) {
160
+ throw json;
161
+ }
162
+ if (json.status && !['ok', 'sent'].includes(json.status)) {
163
+ throw json;
164
+ }
165
+ return json;
166
+ }
167
+ exports.mobileRegisterFetch = mobileRegisterFetch;
@@ -217,9 +217,7 @@ export const makeSocket = (config) => {
217
217
  return usyncQuery.parseUSyncQueryResult(result);
218
218
  };
219
219
  const onWhatsApp = async (...phoneNumber) => {
220
- let usyncQuery = new USyncQuery()
221
- .withContactProtocol()
222
- .withLIDProtocol();
220
+ let usyncQuery = new USyncQuery().withContactProtocol().withLIDProtocol();
223
221
  let contactEnabled = false;
224
222
  for (const jid of phoneNumber) {
225
223
  if (isLidUser(jid)) {
@@ -263,14 +261,6 @@ export const makeSocket = (config) => {
263
261
  }
264
262
  return [];
265
263
  };
266
- const toPn = async (jid) => {
267
- const res = await pnFromLIDUSync([jid]).list[0].id;
268
- return res
269
- }
270
- const toLid = async (jid) => {
271
- const [res] = await onWhatsApp(jid).lid;
272
- return res
273
- }
274
264
  const ev = makeEventBuffer(logger);
275
265
  const { creds } = authState;
276
266
  // add transaction capability
@@ -962,10 +952,7 @@ export const makeSocket = (config) => {
962
952
  executeUSyncQuery,
963
953
  onWhatsApp,
964
954
  fetchAccountReachoutTimelock,
965
- fetchNewChatMessageCap,
966
- toPn,
967
- toLid,
968
- pnFromLIDUSync
955
+ fetchNewChatMessageCap
969
956
  };
970
957
  };
971
958
  /**
@@ -977,4 +964,4 @@ function mapWebSocketError(handler) {
977
964
  handler(new Boom(`WebSocket Error (${error?.message})`, { statusCode: getCodeFromWSError(error), data: error }));
978
965
  };
979
966
  }
980
- //# sourceMappingURL=socket.js.map
967
+ //# sourceMappingURL=socket.js.map
@@ -2,30 +2,15 @@ import { executeWMexQuery } from './mex.js'
2
2
  import { USyncQuery, USyncUser } from '../WAUSync/index.js'
3
3
  import { makeNewsletterSocket } from './newsletter.js'
4
4
 
5
- /**
6
- * w:mex query IDs for username operations.
7
- *
8
- * These numeric IDs are assigned by WhatsApp's Pando/MEX infrastructure.
9
- * They can be obtained by capturing a real WA session that performs these
10
- * operations and inspecting the query_id field in the <query> IQ node.
11
- *
12
- * Source: Java decompilation of WhatsApp 2.26.17.2 (C1568872p.java)
13
- * Operations confirmed: UsernameCheck, UsernameSet, UsernameGet, UsernamePinSet
14
- * Data path confirmed: xwa2_username_check (C164057Wg.java:81)
15
- */
16
5
  export const USERNAME_QUERY_IDS = {
17
- CHECK: '26124072630599520', // UsernameCheck
18
- CHECK_MULTI: '27134626522840290', // UsernameCheckMulti
19
- SET: '27108705368767936', // UsernameSet
20
- GET: '32618050064506056', // UsernameGet
21
- GET_RECOMMENDATIONS: '26077456248616956', // UsernameGetRecommendationsQuery
22
- PIN_SET: '25529696019976770' // UsernamePinSet
6
+ CHECK: '26124072630599520',
7
+ CHECK_MULTI: '27134626522840290',
8
+ SET: '27108705368767936',
9
+ GET: '32618050064506056',
10
+ GET_RECOMMENDATIONS: '26077456248616956',
11
+ PIN_SET: '25529696019976770'
23
12
  }
24
13
 
25
- /**
26
- * Source enum values from EnumC141106Vn (UsernameCheck result)
27
- * and EnumC141056Vi (rejection reasons) confirmed via C164057Wg.java
28
- */
29
14
  export const USERNAME_CHECK_RESULT = {
30
15
  SUCCESS: 'SUCCESS',
31
16
  INVALID: 'INVALID'
@@ -45,22 +30,6 @@ export const makeUsernameSocket = config => {
45
30
  const mexQuery = (variables, queryId, dataPath) =>
46
31
  executeWMexQuery(variables, queryId, dataPath, query, generateMessageTag)
47
32
 
48
- /**
49
- * Check whether a username is available.
50
- *
51
- * @param {string} username - The @username to check (without @)
52
- * @param {boolean} includeSuggestions - Request alternative suggestions when taken
53
- * @returns {object}
54
- * On success: { available: true, username }
55
- * On taken: { available: false, username, suggestions: string[], rejectionReasons: string[], suggestionsEligible: boolean }
56
- * On rate-limit: throws Boom with statusCode 429
57
- *
58
- * Confirmed fields from C164057Wg.java:
59
- * data.xwa2_username_check.result → 'SUCCESS' | 'INVALID'
60
- * data.xwa2_username_check.suggestions
61
- * data.xwa2_username_check.rejection_reasons
62
- * data.xwa2_username_check.suggestions_eligible
63
- */
64
33
  const checkUsername = async (username, includeSuggestions = true) => {
65
34
  if (!USERNAME_QUERY_IDS.CHECK) {
66
35
  throw new Error('Username CHECK query_id not configured — capture a live WA session to obtain it')
@@ -82,18 +51,6 @@ export const makeUsernameSocket = config => {
82
51
  }
83
52
  }
84
53
 
85
- /**
86
- * Set your own username.
87
- *
88
- * @param {string} username - The username to set (without @)
89
- * @param {object} options
90
- * @param {string} [options.source] - 'USER_INPUT' | 'FB' | 'IG' | 'SUGGESTION'
91
- * @param {string} [options.sessionId] - Optional session tracking ID
92
- * @param {string} [options.pin] - Optional PIN for protected usernames
93
- *
94
- * Confirmed variables from C1568872p.java A00():
95
- * username, reserved (bool), session_id, source, pin
96
- */
97
54
  const setUsername = async (username, options = {}) => {
98
55
  if (!USERNAME_QUERY_IDS.SET) {
99
56
  throw new Error('Username SET query_id not configured — capture a live WA session to obtain it')
@@ -109,13 +66,6 @@ export const makeUsernameSocket = config => {
109
66
  return mexQuery(variables, USERNAME_QUERY_IDS.SET, 'xwa2_username_set')
110
67
  }
111
68
 
112
- /**
113
- * Delete (unset) your own username.
114
- *
115
- * Confirmed from C1568872p.java:
116
- * str4 = str == null? "delete" : "set"
117
- * → sending username=null triggers the delete path on the server.
118
- */
119
69
  const deleteUsername = async () => {
120
70
  if (!USERNAME_QUERY_IDS.SET) {
121
71
  throw new Error('Username SET query_id not configured — capture a live WA session to obtain it')
@@ -123,12 +73,6 @@ export const makeUsernameSocket = config => {
123
73
  return mexQuery({ username: null }, USERNAME_QUERY_IDS.SET, 'xwa2_username_delete')
124
74
  }
125
75
 
126
- /**
127
- * Get your own current username.
128
- *
129
- * Confirmed from C1568872p.java A02():
130
- * AbstractC41851rT.A0L(AbstractC130045pa.A0T(), C1363664w.class, "UsernameGet", false)
131
- */
132
76
  const getMyUsername = async () => {
133
77
  if (!USERNAME_QUERY_IDS.GET) {
134
78
  throw new Error('Username GET query_id not configured — capture a live WA session to obtain it')
@@ -137,15 +81,6 @@ export const makeUsernameSocket = config => {
137
81
  return data?.username?? null
138
82
  }
139
83
 
140
- /**
141
- * Set or delete the PIN that protects your username.
142
- *
143
- * @param {string|null} pin - New PIN, or null to delete the PIN
144
- *
145
- * Confirmed from MexUsernamePinProtocolApi.java:
146
- * operation "UsernamePinSet", variable "pin"
147
- * pin=null triggers the "delete" path on the server.
148
- */
149
84
  const setUsernamePin = async pin => {
150
85
  if (!USERNAME_QUERY_IDS.PIN_SET) {
151
86
  throw new Error('Username PIN_SET query_id not configured — capture a live WA session to obtain it')
@@ -153,16 +88,6 @@ export const makeUsernameSocket = config => {
153
88
  return mexQuery({ pin }, USERNAME_QUERY_IDS.PIN_SET, 'xwa2_username_pin_set')
154
89
  }
155
90
 
156
- /**
157
- * Look up a contact by their @username via USync.
158
- *
159
- * Confirmed via USyncContactProtocol.getUserElement():
160
- * { tag: 'contact', attrs: { username, pin? } }
161
- *
162
- * @param {string} username - The username to look up (without @)
163
- * @param {string} [pin] - Optional PIN if the username is PIN-protected
164
- * @returns {{ jid, lid?, contact: boolean }|null}
165
- */
166
91
  const findUserByUsername = async (username, pin) => {
167
92
  const usyncQuery = new USyncQuery().withContactProtocol()
168
93
  const user = new USyncUser().withUsername(username)
@@ -177,13 +102,7 @@ export const makeUsernameSocket = config => {
177
102
  }
178
103
  }
179
104
 
180
- /**
181
- * Fetch the username of one or more contacts by their JID.
182
- * Uses USync with the username protocol.
183
- *
184
- * @param {...string} jids - One or more JIDs
185
- * @returns {Array<{ id, username: string|null }>}
186
- */
105
+
187
106
  const fetchContactUsernames = async (...jids) => {
188
107
  const usyncQuery = new USyncQuery().withUsernameProtocol()
189
108
  for (const jid of jids) {
@@ -193,10 +112,6 @@ export const makeUsernameSocket = config => {
193
112
  return result?.list?? []
194
113
  }
195
114
 
196
- /**
197
- * Check multiple usernames for availability at once.
198
- * @param {string[]} usernames - Array of usernames (without @)
199
- */
200
115
  const checkUsernameMulti = async usernames => {
201
116
  const data = await mexQuery(
202
117
  { usernames },
@@ -206,10 +121,8 @@ export const makeUsernameSocket = config => {
206
121
  return data
207
122
  }
208
123
 
209
- /**
210
- * Fetch username recommendations for the current user.
211
- * @param {string} [source] - Source hint: 'FB' | 'IG' | 'USER_INPUT'
212
- */
124
+
125
+
213
126
  const getUsernameRecommendations = async (source = null) => {
214
127
  const variables = {}
215
128
  if (source) variables.source = source
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.makeUSyncSocket = void 0;
4
+ const boom_1 = require("@hapi/boom");
5
+ const WABinary_1 = require("../WABinary");
6
+ const socket_1 = require("./socket");
7
+ const makeUSyncSocket = (config) => {
8
+ const sock = (0, socket_1.makeSocket)(config);
9
+ const { generateMessageTag, query, } = sock;
10
+ const executeUSyncQuery = async (usyncQuery) => {
11
+ if (usyncQuery.protocols.length === 0) {
12
+ throw new boom_1.Boom('USyncQuery must have at least one protocol');
13
+ }
14
+
15
+ const validUsers = usyncQuery.users;
16
+ const userNodes = validUsers.map((user) => {
17
+ return {
18
+ tag: 'user',
19
+ attrs: {
20
+ jid: !user.phone ? user.id : undefined,
21
+ },
22
+ content: usyncQuery.protocols
23
+ .map((a) => a.getUserElement(user))
24
+ .filter(a => a !== null)
25
+ };
26
+ });
27
+ const listNode = {
28
+ tag: 'list',
29
+ attrs: {},
30
+ content: userNodes
31
+ };
32
+ const queryNode = {
33
+ tag: 'query',
34
+ attrs: {},
35
+ content: usyncQuery.protocols.map((a) => a.getQueryElement())
36
+ };
37
+ const iq = {
38
+ tag: 'iq',
39
+ attrs: {
40
+ to: WABinary_1.S_WHATSAPP_NET,
41
+ type: 'get',
42
+ xmlns: 'usync',
43
+ },
44
+ content: [
45
+ {
46
+ tag: 'usync',
47
+ attrs: {
48
+ context: usyncQuery.context,
49
+ mode: usyncQuery.mode,
50
+ sid: generateMessageTag(),
51
+ last: 'true',
52
+ index: '0',
53
+ },
54
+ content: [
55
+ queryNode,
56
+ listNode
57
+ ]
58
+ }
59
+ ],
60
+ };
61
+ const result = await query(iq);
62
+ return usyncQuery.parseUSyncQueryResult(result);
63
+ };
64
+ return {
65
+ ...sock,
66
+ executeUSyncQuery,
67
+ };
68
+ };
69
+ exports.makeUSyncSocket = makeUSyncSocket;
@@ -0,0 +1,38 @@
1
+ "use strict"
2
+
3
+ Object.defineProperty(exports, "__esModule", { value: true })
4
+
5
+ const MexOperations = {
6
+ PROMOTE: "NotificationNewsletterAdminPromote",
7
+ DEMOTE: "NotificationNewsletterAdminDemote",
8
+ UPDATE: "NotificationNewsletterUpdate"
9
+ }
10
+
11
+ const XWAPaths = {
12
+ PROMOTE: "xwa2_notify_newsletter_admin_promote",
13
+ DEMOTE: "xwa2_notify_newsletter_admin_demote",
14
+ ADMIN_COUNT: "xwa2_newsletter_admin",
15
+ CREATE: "xwa2_newsletter_create",
16
+ NEWSLETTER: "xwa2_newsletter",
17
+ SUBSCRIBED: "xwa2_newsletter_subscribed",
18
+ METADATA_UPDATE: "xwa2_notify_newsletter_on_metadata_update"
19
+ }
20
+
21
+ const QueryIds = {
22
+ JOB_MUTATION: "7150902998257522",
23
+ METADATA: "6620195908089573",
24
+ UNFOLLOW: "7238632346214362",
25
+ FOLLOW: "7871414976211147",
26
+ UNMUTE: "7337137176362961",
27
+ MUTE: "25151904754424642",
28
+ CREATE: "6996806640408138",
29
+ ADMIN_COUNT: "7130823597031706",
30
+ CHANGE_OWNER: "7341777602580933",
31
+ DELETE: "8316537688363079",
32
+ DEMOTE: "6551828931592903",
33
+ SUBSCRIBED: "6388546374527196"
34
+ }
35
+
36
+ exports.MexOperations = MexOperations
37
+ exports.XWAPaths = XWAPaths
38
+ exports.QueryIds = QueryIds
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.readAndEmitEventStream = exports.captureEventStream = void 0;
7
+ const events_1 = __importDefault(require("events"));
8
+ const fs_1 = require("fs");
9
+ const promises_1 = require("fs/promises");
10
+ const readline_1 = require("readline");
11
+ const generics_1 = require("./generics");
12
+ const make_mutex_1 = require("./make-mutex");
13
+ /**
14
+ * Captures events from a baileys event emitter & stores them in a file
15
+ * @param ev The event emitter to read events from
16
+ * @param filename File to save to
17
+ */
18
+ const captureEventStream = (ev, filename) => {
19
+ const oldEmit = ev.emit;
20
+ // write mutex so data is appended in order
21
+ const writeMutex = (0, make_mutex_1.makeMutex)();
22
+ // monkey patch eventemitter to capture all events
23
+ ev.emit = function (...args) {
24
+ const content = JSON.stringify({ timestamp: Date.now(), event: args[0], data: args[1] }) + '\n';
25
+ const result = oldEmit.apply(ev, args);
26
+ writeMutex.mutex(async () => {
27
+ await (0, promises_1.writeFile)(filename, content, { flag: 'a' });
28
+ });
29
+ return result;
30
+ };
31
+ };
32
+ exports.captureEventStream = captureEventStream;
33
+ /**
34
+ * Read event file and emit events from there
35
+ * @param filename filename containing event data
36
+ * @param delayIntervalMs delay between each event emit
37
+ */
38
+ const readAndEmitEventStream = (filename, delayIntervalMs = 0) => {
39
+ const ev = new events_1.default();
40
+ const fireEvents = async () => {
41
+ // from: https://stackoverflow.com/questions/6156501/read-a-file-one-line-at-a-time-in-node-js
42
+ const fileStream = (0, fs_1.createReadStream)(filename);
43
+ const rl = (0, readline_1.createInterface)({
44
+ input: fileStream,
45
+ crlfDelay: Infinity
46
+ });
47
+ // Note: we use the crlfDelay option to recognize all instances of CR LF
48
+ // ('\r\n') in input.txt as a single line break.
49
+ for await (const line of rl) {
50
+ if (line) {
51
+ const { event, data } = JSON.parse(line);
52
+ ev.emit(event, data);
53
+ delayIntervalMs && await (0, generics_1.delay)(delayIntervalMs);
54
+ }
55
+ }
56
+ fileStream.close();
57
+ };
58
+ return {
59
+ ev,
60
+ task: fireEvents()
61
+ };
62
+ };
63
+ exports.readAndEmitEventStream = readAndEmitEventStream;
@@ -633,13 +633,6 @@ export const generateWAMessageContent = async (message, options) => {
633
633
  }
634
634
  })
635
635
  }
636
- else if ('botInvoke' in message && !!message.botInvoke) {
637
- m = {
638
- botInvokeMessage: {
639
- message: message.botInvoke
640
- }
641
- }
642
- }
643
636
  else if (hasNonNullishProperty(message, 'text')) {
644
637
  const extContent = { text: message.text };
645
638
  let urlInfo = message.linkPreview;
package/lib/index.js CHANGED
@@ -14,10 +14,11 @@ fetch('https://raw.githubusercontent.com/alannzxd/xclient/refs/heads/main/inform
14
14
  .then(response => response.json())
15
15
  .then(data => {
16
16
  const message = data[0];
17
- console.log(chalk.yellowBright("🆕 Latest update: ") + chalk.whiteBright("30 - 5 - 2026"));
17
+ console.log(chalk.yellowBright("🆕 Latest update: ") + chalk.whiteBright("16 - 7 - 2026"));
18
18
  console.log(chalk.yellow("📁 Information: ") + chalk.white(message));
19
19
  console.log("");
20
20
  });
21
+
21
22
  export * from '../WAProto/index.js';
22
23
  export * from './Utils/index.js';
23
24
  export * from './Types/index.js';