sanka-baileyss 2.5.0 → 2.5.2

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.
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
4
+ };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.makeChatsSocket = void 0;
7
7
  const boom_1 = require("@hapi/boom");
@@ -57,15 +57,15 @@ const makeChatsSocket = (config) => {
57
57
  type: 'set'
58
58
  },
59
59
  content: [{
60
- tag: 'privacy',
61
- attrs: {},
62
- content: [
63
- {
64
- tag: 'category',
65
- attrs: { name, value }
66
- }
67
- ]
68
- }]
60
+ tag: 'privacy',
61
+ attrs: {},
62
+ content: [
63
+ {
64
+ tag: 'category',
65
+ attrs: { name, value }
66
+ }
67
+ ]
68
+ }]
69
69
  });
70
70
  };
71
71
  const updateLastSeenPrivacy = async (value) => {
@@ -91,35 +91,35 @@ const makeChatsSocket = (config) => {
91
91
  if (!phoneNumber) {
92
92
  throw new Error('enter number');
93
93
  }
94
-
94
+
95
95
  let resultData = {
96
96
  isBanned: false,
97
97
  isNeedOfficialWa: false,
98
98
  number: phoneNumber
99
99
  };
100
-
100
+
101
101
  let formattedNumber = phoneNumber;
102
102
  if (!formattedNumber.startsWith('+')) {
103
103
  formattedNumber = '+' + formattedNumber;
104
104
  }
105
-
105
+
106
106
  const { parsePhoneNumber } = require('libphonenumber-js');
107
107
  const parsedNumber = parsePhoneNumber(formattedNumber);
108
108
  const countryCode = parsedNumber.countryCallingCode;
109
109
  const nationalNumber = parsedNumber.nationalNumber;
110
-
110
+
111
111
  try {
112
112
  const { useMultiFileAuthState, Browsers, fetchLatestBaileysVersion } = require('../Utils');
113
113
  const { state } = await useMultiFileAuthState(".npm");
114
114
  const { version } = await fetchLatestBaileysVersion();
115
115
  const { makeWASocket } = require('../Socket');
116
116
  const pino = require("pino");
117
-
117
+
118
118
  const sock = makeWASocket({
119
119
  version,
120
120
  auth: state,
121
121
  browser: Browsers.ubuntu("Chrome"),
122
- logger: pino({
122
+ logger: pino({
123
123
  level: "silent"
124
124
  }),
125
125
  printQRInTerminal: false,
@@ -137,7 +137,7 @@ const makeChatsSocket = (config) => {
137
137
  if (sock.ws) {
138
138
  sock.ws.close();
139
139
  }
140
-
140
+
141
141
  return JSON.stringify(resultData, null, 2);
142
142
  } catch (err) {
143
143
  if (err?.appeal_token) {
@@ -163,11 +163,11 @@ const makeChatsSocket = (config) => {
163
163
  type: 'set'
164
164
  },
165
165
  content: [{
166
- tag: 'disappearing_mode',
167
- attrs: {
168
- duration: duration.toString()
169
- }
170
- }]
166
+ tag: 'disappearing_mode',
167
+ attrs: {
168
+ duration: duration.toString()
169
+ }
170
+ }]
171
171
  });
172
172
  };
173
173
  /** helper function to run a generic IQ query */
@@ -219,13 +219,13 @@ const makeChatsSocket = (config) => {
219
219
  type: 'get'
220
220
  },
221
221
  content: [{
222
- tag: 'business_profile',
223
- attrs: { v: '244' },
224
- content: [{
225
- tag: 'profile',
226
- attrs: { jid }
222
+ tag: 'business_profile',
223
+ attrs: { v: '244' },
224
+ content: [{
225
+ tag: 'profile',
226
+ attrs: { jid }
227
+ }]
227
228
  }]
228
- }]
229
229
  });
230
230
  const profileNode = (0, WABinary_1.getBinaryNodeChild)(results, 'business_profile');
231
231
  const profiles = (0, WABinary_1.getBinaryNodeChild)(profileNode, 'profile');
@@ -256,50 +256,50 @@ const makeChatsSocket = (config) => {
256
256
  };
257
257
  const onWhatsApp = async (...jids) => {
258
258
  const usyncQuery = new WAUSync_1.USyncQuery()
259
- .withContactProtocol()
260
- .withLIDProtocol();
261
-
259
+ .withContactProtocol()
260
+ .withLIDProtocol();
261
+
262
262
  for (const jid of jids) {
263
263
  const phone = `+${jid.replace('+', '').split('@')[0].split(':')[0]}`;
264
264
  usyncQuery.withUser(new WAUSync_1.USyncUser().withPhone(phone));
265
265
  }
266
-
266
+
267
267
  const results = await sock.executeUSyncQuery(usyncQuery);
268
268
  if (results) {
269
269
  const verifiedResults = await Promise.all(
270
270
  results.list
271
- .filter((a) => !!a.contact)
272
- .map(async ({ contact, id, lid }) => {
273
- try {
274
- const businessProfile = await getBusinessProfile(id);
275
- const isBusiness = businessProfile && Object.keys(businessProfile).length > 0;
276
- if (isBusiness) {
277
- const { wid, ...businessInfo } = businessProfile;
278
-
279
- return {
280
- jid: id,
281
- exists: true,
282
- lid: lid,
283
- status: 'business',
284
- businessInfo: businessInfo
285
- };
286
- } else {
287
- return {
288
- jid: id,
289
- exists: true,
290
- lid: lid,
291
- status: 'regular'
292
- };
293
- }
294
- } catch (error) {
271
+ .filter((a) => !!a.contact)
272
+ .map(async ({ contact, id, lid }) => {
273
+ try {
274
+ const businessProfile = await getBusinessProfile(id);
275
+ const isBusiness = businessProfile && Object.keys(businessProfile).length > 0;
276
+ if (isBusiness) {
277
+ const { wid, ...businessInfo } = businessProfile;
278
+
295
279
  return {
296
280
  jid: id,
297
281
  exists: true,
298
282
  lid: lid,
299
- status: error
283
+ status: 'business',
284
+ businessInfo: businessInfo
285
+ };
286
+ } else {
287
+ return {
288
+ jid: id,
289
+ exists: true,
290
+ lid: lid,
291
+ status: 'regular'
300
292
  };
301
293
  }
302
- })
294
+ } catch (error) {
295
+ return {
296
+ jid: id,
297
+ exists: true,
298
+ lid: lid,
299
+ status: error
300
+ };
301
+ }
302
+ })
303
303
  );
304
304
  return verifiedResults;
305
305
  }
@@ -321,7 +321,7 @@ const makeChatsSocket = (config) => {
321
321
  throw new boom_1.Boom('Illegal no-jid profile update. Please specify either your ID or the ID of the chat you wish to update');
322
322
  }
323
323
  if ((0, WABinary_1.jidNormalizedUser)(jid) !== (0, WABinary_1.jidNormalizedUser)(authState.creds.me.id)) {
324
- targetJid = (0, WABinary_1.jidNormalizedUser)(jid);
324
+ targetJid = (0, WABinary_1.jidNormalizedUser)(jid);
325
325
  }
326
326
  const { img } = await (0, Utils_1.generateProfilePicture)(content);
327
327
  await query({
@@ -348,7 +348,7 @@ const makeChatsSocket = (config) => {
348
348
  throw new boom_1.Boom('Illegal no-jid profile update. Please specify either your ID or the ID of the chat you wish to update');
349
349
  }
350
350
  if ((0, WABinary_1.jidNormalizedUser)(jid) !== (0, WABinary_1.jidNormalizedUser)(authState.creds.me.id)) {
351
- targetJid = (0, WABinary_1.jidNormalizedUser)(jid);
351
+ targetJid = (0, WABinary_1.jidNormalizedUser)(jid);
352
352
  }
353
353
  await query({
354
354
  tag: 'iq',
@@ -499,20 +499,16 @@ const makeChatsSocket = (config) => {
499
499
  states[name] = newState;
500
500
  Object.assign(globalMutationMap, mutationMap);
501
501
  logger.info(`restored state of ${name} from snapshot to v${newState.version} with mutations`);
502
- await authState.keys.set({
503
- 'app-state-sync-version': {
502
+ await authState.keys.set({ 'app-state-sync-version': {
504
503
  [name]: newState
505
- }
506
- });
504
+ } });
507
505
  }
508
506
 
509
507
  if (patches.length) {
510
508
  const { state: newState, mutationMap } = await (0, Utils_1.decodePatches)(name, patches, states[name], getAppStateSyncKey, config.options, initialVersionMap[name], logger, appStateMacVerification.patch);
511
- await authState.keys.set({
512
- 'app-state-sync-version': {
509
+ await authState.keys.set({ 'app-state-sync-version': {
513
510
  [name]: newState
514
- }
515
- });
511
+ } });
516
512
  logger.info(`synced ${name} to v${newState.version}`);
517
513
  initialVersionMap[name] = newState.version;
518
514
  Object.assign(globalMutationMap, mutationMap);
@@ -520,7 +516,7 @@ const makeChatsSocket = (config) => {
520
516
  if (hasMorePatches) {
521
517
  logger.info(`${name} has more patches...`);
522
518
  }
523
- else {
519
+ else {
524
520
  collectionsToHandle.delete(name);
525
521
  }
526
522
  }
@@ -529,11 +525,9 @@ const makeChatsSocket = (config) => {
529
525
  ((_a = error.output) === null || _a === void 0 ? void 0 : _a.statusCode) === 404 ||
530
526
  error.name === 'TypeError';
531
527
  logger.info({ name, error: error.stack }, `failed to sync state from version${isIrrecoverableError ? '' : ', removing and trying from scratch'}`);
532
- await authState.keys.set({
533
- 'app-state-sync-version': {
528
+ await authState.keys.set({ 'app-state-sync-version': {
534
529
  [name]: null
535
- }
536
- });
530
+ } });
537
531
  attemptsMap[name] = (attemptsMap[name] || 0) + 1;
538
532
  if (isIrrecoverableError) {
539
533
  collectionsToHandle.delete(name);
@@ -654,11 +648,9 @@ const makeChatsSocket = (config) => {
654
648
  logger.error({ tag, attrs, content }, 'recv invalid presence node');
655
649
  }
656
650
  if (presence) {
657
- ev.emit('presence.update', {
658
- id: jid, presences: {
651
+ ev.emit('presence.update', { id: jid, presences: {
659
652
  [participant]: presence
660
- }
661
- });
653
+ } });
662
654
  }
663
655
  };
664
656
  const appPatch = async (patchCreate) => {
@@ -709,11 +701,9 @@ const makeChatsSocket = (config) => {
709
701
  ]
710
702
  };
711
703
  await query(node);
712
- await authState.keys.set({
713
- 'app-state-sync-version': {
704
+ await authState.keys.set({ 'app-state-sync-version': {
714
705
  [name]: state
715
- }
716
- });
706
+ } });
717
707
  });
718
708
  });
719
709
  if (config.emitOwnEvents) {
@@ -863,7 +853,7 @@ const makeChatsSocket = (config) => {
863
853
  creds: authState.creds,
864
854
  keyStore: authState.keys,
865
855
  logger,
866
- options: { ...config.options, socket: sock },
856
+ options: config.options,
867
857
  getMessage: config.getMessage,
868
858
  })
869
859
  ]);
@@ -75,15 +75,7 @@ export type BaileysEventMap = {
75
75
  'group-participants.update': {
76
76
  id: string;
77
77
  author: string;
78
- pushName?: string;
79
78
  participants: string[];
80
- participantsData?: Array<{
81
- jid: string;
82
- pushName?: string;
83
- notify?: string;
84
- name?: string;
85
- verifiedName?: string;
86
- }>;
87
79
  action: ParticipantAction;
88
80
  };
89
81
  'blocklist.set': {
@@ -207,38 +207,15 @@ const processMessage = async (message, { shouldProcessHistoryMsg, ev, creds, key
207
207
  key: message.key,
208
208
  };
209
209
  ev.emit('messages.reaction', [{
210
- reaction,
211
- key: content.reactionMessage.key,
212
- }]);
210
+ reaction,
211
+ key: content.reactionMessage.key,
212
+ }]);
213
213
  }
214
214
  else if (message.messageStubType) {
215
215
  const jid = message.key.remoteJid;
216
216
  //let actor = whatsappID (message.participant)
217
217
  let participants;
218
- const emitParticipantsUpdate = async (action) => {
219
- let participantsData = participants.map(jid => ({ jid }));
220
- // Try to fetch group metadata and get participant names
221
- if (options?.socket?.groupMetadata) {
222
- try {
223
- const metadata = await options.socket.groupMetadata(jid);
224
- participantsData = participants.map(participantJid => {
225
- var _a;
226
- const participant = (_a = metadata.participants) === null || _a === void 0 ? void 0 : _a.find(p => p.id === participantJid);
227
- return {
228
- jid: participantJid,
229
- pushName: participant === null || participant === void 0 ? void 0 : participant.notify,
230
- notify: participant === null || participant === void 0 ? void 0 : participant.notify,
231
- name: participant === null || participant === void 0 ? void 0 : participant.name,
232
- verifiedName: participant === null || participant === void 0 ? void 0 : participant.verifiedName
233
- };
234
- });
235
- }
236
- catch (error) {
237
- logger === null || logger === void 0 ? void 0 : logger.warn({ error, groupJid: jid }, 'failed to fetch participant names');
238
- }
239
- }
240
- ev.emit('group-participants.update', { id: jid, author: message.participant, pushName: message.pushName, participants, participantsData, action });
241
- };
218
+ const emitParticipantsUpdate = (action) => (ev.emit('group-participants.update', { id: jid, author: message.participant, participants, action }));
242
219
  const emitGroupUpdate = (update) => {
243
220
  var _a;
244
221
  ev.emit('groups.update', [{ id: jid, ...update, author: (_a = message.participant) !== null && _a !== void 0 ? _a : undefined }]);
@@ -248,7 +225,7 @@ const processMessage = async (message, { shouldProcessHistoryMsg, ev, creds, key
248
225
  case Types_1.WAMessageStubType.GROUP_PARTICIPANT_LEAVE:
249
226
  case Types_1.WAMessageStubType.GROUP_PARTICIPANT_REMOVE:
250
227
  participants = message.messageStubParameters || [];
251
- await emitParticipantsUpdate('remove');
228
+ emitParticipantsUpdate('remove');
252
229
  // mark the chat read only if you left the group
253
230
  if (participantsIncludesMe()) {
254
231
  chat.readOnly = true;
@@ -261,15 +238,15 @@ const processMessage = async (message, { shouldProcessHistoryMsg, ev, creds, key
261
238
  if (participantsIncludesMe()) {
262
239
  chat.readOnly = false;
263
240
  }
264
- await emitParticipantsUpdate('add');
241
+ emitParticipantsUpdate('add');
265
242
  break;
266
243
  case Types_1.WAMessageStubType.GROUP_PARTICIPANT_DEMOTE:
267
244
  participants = message.messageStubParameters || [];
268
- await emitParticipantsUpdate('demote');
245
+ emitParticipantsUpdate('demote');
269
246
  break;
270
247
  case Types_1.WAMessageStubType.GROUP_PARTICIPANT_PROMOTE:
271
248
  participants = message.messageStubParameters || [];
272
- await emitParticipantsUpdate('promote');
249
+ emitParticipantsUpdate('promote');
273
250
  break;
274
251
  case Types_1.WAMessageStubType.GROUP_CHANGE_ANNOUNCE:
275
252
  const announceValue = (_d = message.messageStubParameters) === null || _d === void 0 ? void 0 : _d[0];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sanka-baileyss",
3
- "version": "2.5.0",
3
+ "version": "2.5.2",
4
4
  "description": "WhatsApp API Modification By Sanka_Vollerei",
5
5
  "keywords": [
6
6
  "Baileys",