sanka-baileyss 2.4.9 → 2.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.
@@ -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 }
227
- }]
222
+ tag: 'business_profile',
223
+ attrs: { v: '244' },
224
+ content: [{
225
+ tag: 'profile',
226
+ attrs: { jid }
228
227
  }]
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 {
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) {
287
295
  return {
288
296
  jid: id,
289
297
  exists: true,
290
298
  lid: lid,
291
- status: 'regular'
299
+ status: error
292
300
  };
293
301
  }
294
- } catch (error) {
295
- return {
296
- jid: id,
297
- exists: true,
298
- lid: lid,
299
- status: error
300
- };
301
- }
302
- })
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,16 +499,20 @@ 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({ 'app-state-sync-version': {
502
+ await authState.keys.set({
503
+ 'app-state-sync-version': {
503
504
  [name]: newState
504
- } });
505
+ }
506
+ });
505
507
  }
506
508
 
507
509
  if (patches.length) {
508
510
  const { state: newState, mutationMap } = await (0, Utils_1.decodePatches)(name, patches, states[name], getAppStateSyncKey, config.options, initialVersionMap[name], logger, appStateMacVerification.patch);
509
- await authState.keys.set({ 'app-state-sync-version': {
511
+ await authState.keys.set({
512
+ 'app-state-sync-version': {
510
513
  [name]: newState
511
- } });
514
+ }
515
+ });
512
516
  logger.info(`synced ${name} to v${newState.version}`);
513
517
  initialVersionMap[name] = newState.version;
514
518
  Object.assign(globalMutationMap, mutationMap);
@@ -516,7 +520,7 @@ const makeChatsSocket = (config) => {
516
520
  if (hasMorePatches) {
517
521
  logger.info(`${name} has more patches...`);
518
522
  }
519
- else {
523
+ else {
520
524
  collectionsToHandle.delete(name);
521
525
  }
522
526
  }
@@ -525,9 +529,11 @@ const makeChatsSocket = (config) => {
525
529
  ((_a = error.output) === null || _a === void 0 ? void 0 : _a.statusCode) === 404 ||
526
530
  error.name === 'TypeError';
527
531
  logger.info({ name, error: error.stack }, `failed to sync state from version${isIrrecoverableError ? '' : ', removing and trying from scratch'}`);
528
- await authState.keys.set({ 'app-state-sync-version': {
532
+ await authState.keys.set({
533
+ 'app-state-sync-version': {
529
534
  [name]: null
530
- } });
535
+ }
536
+ });
531
537
  attemptsMap[name] = (attemptsMap[name] || 0) + 1;
532
538
  if (isIrrecoverableError) {
533
539
  collectionsToHandle.delete(name);
@@ -648,9 +654,11 @@ const makeChatsSocket = (config) => {
648
654
  logger.error({ tag, attrs, content }, 'recv invalid presence node');
649
655
  }
650
656
  if (presence) {
651
- ev.emit('presence.update', { id: jid, presences: {
657
+ ev.emit('presence.update', {
658
+ id: jid, presences: {
652
659
  [participant]: presence
653
- } });
660
+ }
661
+ });
654
662
  }
655
663
  };
656
664
  const appPatch = async (patchCreate) => {
@@ -701,9 +709,11 @@ const makeChatsSocket = (config) => {
701
709
  ]
702
710
  };
703
711
  await query(node);
704
- await authState.keys.set({ 'app-state-sync-version': {
712
+ await authState.keys.set({
713
+ 'app-state-sync-version': {
705
714
  [name]: state
706
- } });
715
+ }
716
+ });
707
717
  });
708
718
  });
709
719
  if (config.emitOwnEvents) {
@@ -853,7 +863,7 @@ const makeChatsSocket = (config) => {
853
863
  creds: authState.creds,
854
864
  keyStore: authState.keys,
855
865
  logger,
856
- options: config.options,
866
+ options: { ...config.options, socket: sock },
857
867
  getMessage: config.getMessage,
858
868
  })
859
869
  ]);
@@ -75,7 +75,15 @@ export type BaileysEventMap = {
75
75
  'group-participants.update': {
76
76
  id: string;
77
77
  author: string;
78
+ pushName?: string;
78
79
  participants: string[];
80
+ participantsData?: Array<{
81
+ jid: string;
82
+ pushName?: string;
83
+ notify?: string;
84
+ name?: string;
85
+ verifiedName?: string;
86
+ }>;
79
87
  action: ParticipantAction;
80
88
  };
81
89
  'blocklist.set': {
@@ -207,15 +207,38 @@ 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 = (action) => (ev.emit('group-participants.update', { id: jid, author: message.participant, participants, action }));
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
+ };
219
242
  const emitGroupUpdate = (update) => {
220
243
  var _a;
221
244
  ev.emit('groups.update', [{ id: jid, ...update, author: (_a = message.participant) !== null && _a !== void 0 ? _a : undefined }]);
@@ -225,7 +248,7 @@ const processMessage = async (message, { shouldProcessHistoryMsg, ev, creds, key
225
248
  case Types_1.WAMessageStubType.GROUP_PARTICIPANT_LEAVE:
226
249
  case Types_1.WAMessageStubType.GROUP_PARTICIPANT_REMOVE:
227
250
  participants = message.messageStubParameters || [];
228
- emitParticipantsUpdate('remove');
251
+ await emitParticipantsUpdate('remove');
229
252
  // mark the chat read only if you left the group
230
253
  if (participantsIncludesMe()) {
231
254
  chat.readOnly = true;
@@ -238,15 +261,15 @@ const processMessage = async (message, { shouldProcessHistoryMsg, ev, creds, key
238
261
  if (participantsIncludesMe()) {
239
262
  chat.readOnly = false;
240
263
  }
241
- emitParticipantsUpdate('add');
264
+ await emitParticipantsUpdate('add');
242
265
  break;
243
266
  case Types_1.WAMessageStubType.GROUP_PARTICIPANT_DEMOTE:
244
267
  participants = message.messageStubParameters || [];
245
- emitParticipantsUpdate('demote');
268
+ await emitParticipantsUpdate('demote');
246
269
  break;
247
270
  case Types_1.WAMessageStubType.GROUP_PARTICIPANT_PROMOTE:
248
271
  participants = message.messageStubParameters || [];
249
- emitParticipantsUpdate('promote');
272
+ await emitParticipantsUpdate('promote');
250
273
  break;
251
274
  case Types_1.WAMessageStubType.GROUP_CHANGE_ANNOUNCE:
252
275
  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.4.9",
3
+ "version": "2.5.0",
4
4
  "description": "WhatsApp API Modification By Sanka_Vollerei",
5
5
  "keywords": [
6
6
  "Baileys",