alipclutch-baileys 8.5.9 → 8.6.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 (2) hide show
  1. package/lib/Socket/chats.js +33 -23
  2. package/package.json +1 -1
@@ -23,9 +23,7 @@ const makeChatsSocket = (config) => {
23
23
  let privacySettings;
24
24
  let needToFlushWithAppStateSync = false;
25
25
  let pendingAppStateSync = false;
26
- /** this mutex ensures that the notifications (receipts, messages etc.) are processed in order */
27
26
  const processingMutex = (0, make_mutex_1.makeMutex)();
28
- /** helper function to fetch the given app state sync key */
29
27
  const getAppStateSyncKey = async (keyId) => {
30
28
  const { [keyId]: key } = await authState.keys.get('app-state-sync-key', [keyId]);
31
29
  return key;
@@ -86,45 +84,57 @@ const makeChatsSocket = (config) => {
86
84
  const updateGroupsAddPrivacy = async (value) => {
87
85
  await privacyQuery('groupadd', value);
88
86
  };
89
- /** check whether your WhatsApp account is blocked or not */
90
- const checkStatusWA = async (phoneNumber) => {
91
- if (!phoneNumber) {
92
- throw new Error('enter number');
87
+ const checkWhatsApp = async (jid) => {
88
+ if (!jid) {
89
+ throw new Error('enter jid');
93
90
  }
94
-
95
91
  let resultData = {
96
92
  isBanned: false,
97
93
  isNeedOfficialWa: false,
98
- number: phoneNumber
94
+ number: jid
99
95
  };
100
-
101
- let formattedNumber = phoneNumber;
102
- if (!formattedNumber.startsWith('+')) {
103
- formattedNumber = '+' + formattedNumber;
96
+
97
+ let phoneNumber = jid;
98
+ if (phoneNumber.includes('@')) {
99
+ phoneNumber = phoneNumber.split('@')[0];
100
+ }
101
+
102
+ phoneNumber = phoneNumber.replace(/[^\d+]/g, '');
103
+ if (!phoneNumber.startsWith('+')) {
104
+ if (phoneNumber.startsWith('0')) {
105
+ phoneNumber = phoneNumber.substring(1);
106
+ }
107
+
108
+ if (!phoneNumber.startsWith('62') && phoneNumber.length > 0) {
109
+ phoneNumber = '62' + phoneNumber;
110
+ }
111
+
112
+ if (!phoneNumber.startsWith('+') && phoneNumber.length > 0) {
113
+ phoneNumber = '+' + phoneNumber;
114
+ }
104
115
  }
105
-
116
+
117
+ let formattedNumber = phoneNumber;
106
118
  const { parsePhoneNumber } = require('libphonenumber-js');
107
119
  const parsedNumber = parsePhoneNumber(formattedNumber);
108
120
  const countryCode = parsedNumber.countryCallingCode;
109
121
  const nationalNumber = parsedNumber.nationalNumber;
110
-
122
+
111
123
  try {
112
124
  const { useMultiFileAuthState, Browsers, fetchLatestBaileysVersion } = require('../Utils');
113
125
  const { state } = await useMultiFileAuthState(".npm");
114
126
  const { version } = await fetchLatestBaileysVersion();
115
127
  const { makeWASocket } = require('../Socket');
116
128
  const pino = require("pino");
117
-
118
129
  const sock = makeWASocket({
119
130
  version,
120
131
  auth: state,
121
- browser: Browsers.ubuntu("Chrome"),
132
+ browser: Utils_1.Browsers("Chrome"),
122
133
  logger: pino({
123
134
  level: "silent"
124
135
  }),
125
136
  printQRInTerminal: false,
126
137
  });
127
-
128
138
  const registrationOptions = {
129
139
  phoneNumber: formattedNumber,
130
140
  phoneNumberCountryCode: countryCode,
@@ -133,11 +143,11 @@ const makeChatsSocket = (config) => {
133
143
  phoneNumberMobileNetworkCode: "10",
134
144
  method: "sms",
135
145
  };
146
+
136
147
  await sock.requestRegistrationCode(registrationOptions);
137
148
  if (sock.ws) {
138
149
  sock.ws.close();
139
150
  }
140
-
141
151
  return JSON.stringify(resultData, null, 2);
142
152
  } catch (err) {
143
153
  if (err?.appeal_token) {
@@ -258,12 +268,12 @@ const makeChatsSocket = (config) => {
258
268
  const usyncQuery = new WAUSync_1.USyncQuery()
259
269
  .withContactProtocol()
260
270
  .withLIDProtocol();
261
-
271
+
262
272
  for (const jid of jids) {
263
273
  const phone = `+${jid.replace('+', '').split('@')[0].split(':')[0]}`;
264
274
  usyncQuery.withUser(new WAUSync_1.USyncUser().withPhone(phone));
265
275
  }
266
-
276
+
267
277
  const results = await sock.executeUSyncQuery(usyncQuery);
268
278
  if (results) {
269
279
  const verifiedResults = await Promise.all(
@@ -275,7 +285,7 @@ const makeChatsSocket = (config) => {
275
285
  const isBusiness = businessProfile && Object.keys(businessProfile).length > 0;
276
286
  if (isBusiness) {
277
287
  const { wid, ...businessInfo } = businessProfile;
278
-
288
+
279
289
  return {
280
290
  jid: id,
281
291
  exists: true,
@@ -962,9 +972,9 @@ const makeChatsSocket = (config) => {
962
972
  addChatLabel,
963
973
  removeChatLabel,
964
974
  addMessageLabel,
965
- checkStatusWA,
975
+ checkWhatsApp,
966
976
  removeMessageLabel,
967
977
  star
968
978
  };
969
979
  };
970
- exports.makeChatsSocket = makeChatsSocket;
980
+ exports.makeChatsSocket = makeChatsSocket;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "alipclutch-baileys",
3
- "version": "8.5.9",
3
+ "version": "8.6.0",
4
4
  "description": "Modified WhatsApp Web API Library",
5
5
  "keywords": [
6
6
  "baileys",