@pney/whatsapp-web 1.34.6 → 1.34.7-1

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 (59) hide show
  1. package/.env.example +0 -1
  2. package/.gitattributes +4 -0
  3. package/.husky/commit-msg +4 -0
  4. package/.husky/pre-commit +1 -0
  5. package/.lintstagedrc.json +6 -0
  6. package/.prettierignore +8 -0
  7. package/.prettierrc.json +10 -0
  8. package/README.md +83 -80
  9. package/commitlint.config.js +29 -0
  10. package/eslint.config.mjs +67 -0
  11. package/example.js +151 -71
  12. package/index.d.ts +982 -734
  13. package/index.js +4 -4
  14. package/package.json +3 -3
  15. package/shell.js +4 -4
  16. package/src/Client.js +1860 -920
  17. package/src/authStrategies/BaseAuthStrategy.js +4 -2
  18. package/src/authStrategies/LocalAuth.js +25 -12
  19. package/src/authStrategies/NoAuth.js +3 -4
  20. package/src/authStrategies/RemoteAuth.js +92 -43
  21. package/src/factories/ChatFactory.js +1 -1
  22. package/src/factories/ContactFactory.js +2 -2
  23. package/src/structures/Base.js +5 -3
  24. package/src/structures/Broadcast.js +1 -2
  25. package/src/structures/BusinessContact.js +1 -2
  26. package/src/structures/Buttons.js +14 -10
  27. package/src/structures/Call.js +10 -6
  28. package/src/structures/Channel.js +171 -91
  29. package/src/structures/Chat.js +57 -41
  30. package/src/structures/ClientInfo.js +1 -1
  31. package/src/structures/Contact.js +37 -16
  32. package/src/structures/GroupChat.js +425 -228
  33. package/src/structures/GroupNotification.js +21 -12
  34. package/src/structures/Label.js +6 -6
  35. package/src/structures/List.js +22 -14
  36. package/src/structures/Location.js +5 -4
  37. package/src/structures/Message.js +412 -168
  38. package/src/structures/MessageMedia.js +31 -18
  39. package/src/structures/Order.js +4 -4
  40. package/src/structures/Payment.js +6 -3
  41. package/src/structures/Poll.js +2 -2
  42. package/src/structures/PollVote.js +9 -6
  43. package/src/structures/PrivateChat.js +2 -4
  44. package/src/structures/PrivateContact.js +2 -4
  45. package/src/structures/Product.js +1 -1
  46. package/src/structures/ProductMetadata.js +1 -2
  47. package/src/structures/Reaction.js +2 -4
  48. package/src/structures/ScheduledEvent.js +22 -10
  49. package/src/util/Constants.js +8 -6
  50. package/src/util/Injected/AuthStore/AuthStore.js +7 -3
  51. package/src/util/Injected/Utils.js +753 -345
  52. package/src/util/InterfaceController.js +72 -25
  53. package/src/util/Puppeteer.js +1 -1
  54. package/src/util/Util.js +28 -15
  55. package/src/webCache/LocalWebCache.js +7 -5
  56. package/src/webCache/RemoteWebCache.js +10 -4
  57. package/src/webCache/WebCache.js +8 -5
  58. package/src/webCache/WebCacheFactory.js +9 -9
  59. package/CODE_OF_CONDUCT.md +0 -133
@@ -28,7 +28,7 @@ class GroupChat extends Chat {
28
28
  get owner() {
29
29
  return this.groupMetadata.owner;
30
30
  }
31
-
31
+
32
32
  /**
33
33
  * Gets the date at which the group was created
34
34
  * @type {date}
@@ -37,7 +37,7 @@ class GroupChat extends Chat {
37
37
  return new Date(this.groupMetadata.creation * 1000);
38
38
  }
39
39
 
40
- /**
40
+ /**
41
41
  * Gets the group description
42
42
  * @type {string}
43
43
  */
@@ -71,265 +71,440 @@ class GroupChat extends Chat {
71
71
 
72
72
  /**
73
73
  * Adds a list of participants by ID to the group
74
- * @param {string|Array<string>} participantIds
74
+ * @param {string|Array<string>} participantIds
75
75
  * @param {AddParticipnatsOptions} options An object thay handles options for adding participants
76
76
  * @returns {Promise<Object.<string, AddParticipantsResult>|string>} Returns an object with the resulting data or an error message as a string
77
77
  */
78
78
  async addParticipants(participantIds, options = {}) {
79
- return await this.client.pupPage.evaluate(async (groupId, participantIds, options) => {
80
- const { sleep = [250, 500], autoSendInviteV4 = true, comment = '' } = options;
81
- const participantData = {};
82
-
83
- !Array.isArray(participantIds) && (participantIds = [participantIds]);
84
- const groupWid = window.require('WAWebWidFactory').createWid(groupId);
85
- const group = (window.require('WAWebCollections')).Chat.get(groupWid) || (await (window.require('WAWebCollections')).Chat.find(groupWid));
86
- const participantWids = participantIds.map((p) => window.require('WAWebWidFactory').createWid(p));
87
-
88
- const errorCodes = {
89
- default: 'An unknown error occupied while adding a participant',
90
- isGroupEmpty: 'AddParticipantsError: The participant can\'t be added to an empty group',
91
- iAmNotAdmin: 'AddParticipantsError: You have no admin rights to add a participant to a group',
92
- 200: 'The participant was added successfully',
93
- 403: 'The participant can be added by sending private invitation only',
94
- 404: 'The phone number is not registered on WhatsApp',
95
- 408: 'You cannot add this participant because they recently left the group',
96
- 409: 'The participant is already a group member',
97
- 417: 'The participant can\'t be added to the community. You can invite them privately to join this group through its invite link',
98
- 419: 'The participant can\'t be added because the group is full'
99
- };
100
-
101
- await (window.require('WAWebGroupQueryJob')).queryAndUpdateGroupMetadataById({ id: groupId });
102
-
103
- let groupParticipants = group.groupMetadata?.participants.serialize();
104
-
105
- if (!groupParticipants) {
106
- return errorCodes.isGroupEmpty;
107
- }
79
+ return await this.client.pupPage.evaluate(
80
+ async (groupId, participantIds, options) => {
81
+ const {
82
+ sleep = [250, 500],
83
+ autoSendInviteV4 = true,
84
+ comment = '',
85
+ } = options;
86
+ const participantData = {};
87
+
88
+ !Array.isArray(participantIds) &&
89
+ (participantIds = [participantIds]);
90
+ const groupWid = window
91
+ .require('WAWebWidFactory')
92
+ .createWid(groupId);
93
+ const group =
94
+ window.require('WAWebCollections').Chat.get(groupWid) ||
95
+ (await window
96
+ .require('WAWebCollections')
97
+ .Chat.find(groupWid));
98
+ const participantWids = participantIds.map((p) =>
99
+ window.require('WAWebWidFactory').createWid(p),
100
+ );
101
+
102
+ const errorCodes = {
103
+ default:
104
+ 'An unknown error occupied while adding a participant',
105
+ isGroupEmpty:
106
+ "AddParticipantsError: The participant can't be added to an empty group",
107
+ iAmNotAdmin:
108
+ 'AddParticipantsError: You have no admin rights to add a participant to a group',
109
+ 200: 'The participant was added successfully',
110
+ 403: 'The participant can be added by sending private invitation only',
111
+ 404: 'The phone number is not registered on WhatsApp',
112
+ 408: 'You cannot add this participant because they recently left the group',
113
+ 409: 'The participant is already a group member',
114
+ 417: "The participant can't be added to the community. You can invite them privately to join this group through its invite link",
115
+ 419: "The participant can't be added because the group is full",
116
+ };
108
117
 
109
- if (!group.iAmAdmin()) {
110
- return errorCodes.iAmNotAdmin;
111
- }
118
+ await window
119
+ .require('WAWebGroupQueryJob')
120
+ .queryAndUpdateGroupMetadataById({ id: groupId });
112
121
 
113
- groupParticipants.map(({ id }) => {
114
- return id.server === 'lid' ? window.require('WAWebApiContact').getPhoneNumber(id) : id;
115
- });
122
+ let groupParticipants =
123
+ group.groupMetadata?.participants.serialize();
116
124
 
117
- const _getSleepTime = (sleep) => {
118
- if (!Array.isArray(sleep) || sleep.length === 2 && sleep[0] === sleep[1]) {
119
- return sleep;
125
+ if (!groupParticipants) {
126
+ return errorCodes.isGroupEmpty;
120
127
  }
121
- if (sleep.length === 1) {
122
- return sleep[0];
128
+
129
+ if (!group.iAmAdmin()) {
130
+ return errorCodes.iAmNotAdmin;
123
131
  }
124
- (sleep[1] - sleep[0]) < 100 && (sleep[0] = sleep[1]) && (sleep[1] += 100);
125
- return Math.floor(Math.random() * (sleep[1] - sleep[0] + 1)) + sleep[0];
126
- };
127
-
128
- for (let pWid of participantWids) {
129
- const pId = pWid._serialized;
130
- pWid = pWid.server === 'lid' ? window.require('WAWebApiContact').getPhoneNumber(pWid) : pWid;
131
-
132
- participantData[pId] = {
133
- code: undefined,
134
- message: undefined,
135
- isInviteV4Sent: false
132
+
133
+ groupParticipants.map(({ id }) => {
134
+ return id.server === 'lid'
135
+ ? window.require('WAWebApiContact').getPhoneNumber(id)
136
+ : id;
137
+ });
138
+
139
+ const _getSleepTime = (sleep) => {
140
+ if (
141
+ !Array.isArray(sleep) ||
142
+ (sleep.length === 2 && sleep[0] === sleep[1])
143
+ ) {
144
+ return sleep;
145
+ }
146
+ if (sleep.length === 1) {
147
+ return sleep[0];
148
+ }
149
+ sleep[1] - sleep[0] < 100 &&
150
+ (sleep[0] = sleep[1]) &&
151
+ (sleep[1] += 100);
152
+ return (
153
+ Math.floor(Math.random() * (sleep[1] - sleep[0] + 1)) +
154
+ sleep[0]
155
+ );
136
156
  };
137
157
 
138
- if (groupParticipants.some(p => p._serialized === pId)) {
139
- participantData[pId].code = 409;
140
- participantData[pId].message = errorCodes[409];
141
- continue;
142
- }
158
+ for (let pWid of participantWids) {
159
+ const pId = pWid._serialized;
160
+ pWid =
161
+ pWid.server === 'lid'
162
+ ? window
163
+ .require('WAWebApiContact')
164
+ .getPhoneNumber(pWid)
165
+ : pWid;
166
+
167
+ participantData[pId] = {
168
+ code: undefined,
169
+ message: undefined,
170
+ isInviteV4Sent: false,
171
+ };
172
+
173
+ if (groupParticipants.some((p) => p._serialized === pId)) {
174
+ participantData[pId].code = 409;
175
+ participantData[pId].message = errorCodes[409];
176
+ continue;
177
+ }
143
178
 
144
- if (!(await (window.require('WAWebQueryExistsJob').queryWidExists)(pWid))?.wid) {
145
- participantData[pId].code = 404;
146
- participantData[pId].message = errorCodes[404];
147
- continue;
148
- }
179
+ if (
180
+ !(
181
+ await window
182
+ .require('WAWebQueryExistsJob')
183
+ .queryWidExists(pWid)
184
+ )?.wid
185
+ ) {
186
+ participantData[pId].code = 404;
187
+ participantData[pId].message = errorCodes[404];
188
+ continue;
189
+ }
149
190
 
150
- const rpcResult =
151
- await window.WWebJS.getAddParticipantsRpcResult(groupWid, pWid);
152
- const { code: rpcResultCode } = rpcResult;
153
-
154
- participantData[pId].code = rpcResultCode;
155
- participantData[pId].message =
156
- errorCodes[rpcResultCode] || errorCodes.default;
157
-
158
- if (autoSendInviteV4 && rpcResultCode === 403) {
159
- let userChat, isInviteV4Sent = false;
160
- (window.require('WAWebCollections')).Contact.gadd(pWid, { silent: true });
161
-
162
- if (rpcResult.name === 'ParticipantRequestCodeCanBeSent' &&
163
- (userChat = (window.require('WAWebCollections')).Chat.get(pWid) || (await (window.require('WAWebCollections')).Chat.find(pWid)))) {
164
- const groupName = group.formattedTitle || group.name;
165
- const res = await (window.require('WAWebChatSendMessages')).sendGroupInviteMessage(
166
- userChat,
167
- group.id._serialized,
168
- groupName,
169
- rpcResult.inviteV4Code,
170
- rpcResult.inviteV4CodeExp,
171
- comment,
172
- await window.WWebJS.getProfilePicThumbToBase64(groupWid)
191
+ const rpcResult =
192
+ await window.WWebJS.getAddParticipantsRpcResult(
193
+ groupWid,
194
+ pWid,
173
195
  );
174
- isInviteV4Sent = res.messageSendResult === 'OK';
196
+ const { code: rpcResultCode } = rpcResult;
197
+
198
+ participantData[pId].code = rpcResultCode;
199
+ participantData[pId].message =
200
+ errorCodes[rpcResultCode] || errorCodes.default;
201
+
202
+ if (autoSendInviteV4 && rpcResultCode === 403) {
203
+ let userChat,
204
+ isInviteV4Sent = false;
205
+ window
206
+ .require('WAWebCollections')
207
+ .Contact.gadd(pWid, { silent: true });
208
+
209
+ if (
210
+ rpcResult.name ===
211
+ 'ParticipantRequestCodeCanBeSent' &&
212
+ (userChat =
213
+ window
214
+ .require('WAWebCollections')
215
+ .Chat.get(pWid) ||
216
+ (await window
217
+ .require('WAWebCollections')
218
+ .Chat.find(pWid)))
219
+ ) {
220
+ const groupName =
221
+ group.formattedTitle || group.name;
222
+ const res = await window
223
+ .require('WAWebChatSendMessages')
224
+ .sendGroupInviteMessage(
225
+ userChat,
226
+ group.id._serialized,
227
+ groupName,
228
+ rpcResult.inviteV4Code,
229
+ rpcResult.inviteV4CodeExp,
230
+ comment,
231
+ await window.WWebJS.getProfilePicThumbToBase64(
232
+ groupWid,
233
+ ),
234
+ );
235
+ isInviteV4Sent = res.messageSendResult === 'OK';
236
+ }
237
+
238
+ participantData[pId].isInviteV4Sent = isInviteV4Sent;
175
239
  }
176
240
 
177
- participantData[pId].isInviteV4Sent = isInviteV4Sent;
241
+ sleep &&
242
+ participantWids.length > 1 &&
243
+ participantWids.indexOf(pWid) !==
244
+ participantWids.length - 1 &&
245
+ (await new Promise((resolve) =>
246
+ setTimeout(resolve, _getSleepTime(sleep)),
247
+ ));
178
248
  }
179
249
 
180
- sleep &&
181
- participantWids.length > 1 &&
182
- participantWids.indexOf(pWid) !== participantWids.length - 1 &&
183
- (await new Promise((resolve) => setTimeout(resolve, _getSleepTime(sleep))));
184
- }
185
-
186
- return participantData;
187
- }, this.id._serialized, participantIds, options);
250
+ return participantData;
251
+ },
252
+ this.id._serialized,
253
+ participantIds,
254
+ options,
255
+ );
188
256
  }
189
257
 
190
258
  /**
191
259
  * Removes a list of participants by ID to the group
192
- * @param {Array<string>} participantIds
260
+ * @param {Array<string>} participantIds
193
261
  * @returns {Promise<{ status: number }>}
194
262
  */
195
263
  async removeParticipants(participantIds) {
196
- return await this.client.pupPage.evaluate(async (chatId, participantIds) => {
197
- const chat = await window.WWebJS.getChat(chatId, { getAsModel: false });
198
- const participants = (await Promise.all(participantIds.map(async p => {
199
- const { lid, phone } = await window.WWebJS.enforceLidAndPnRetrieval(p);
200
-
201
- return chat.groupMetadata.participants.get(lid?._serialized) ||
202
- chat.groupMetadata.participants.get(phone?._serialized);
203
- }))).filter(Boolean);
204
- await (window.require('WAWebModifyParticipantsGroupAction')).removeParticipants(chat, participants);
205
- return { status: 200 };
206
- }, this.id._serialized, participantIds);
264
+ return await this.client.pupPage.evaluate(
265
+ async (chatId, participantIds) => {
266
+ const chat = await window.WWebJS.getChat(chatId, {
267
+ getAsModel: false,
268
+ });
269
+ const participants = (
270
+ await Promise.all(
271
+ participantIds.map(async (p) => {
272
+ const { lid, phone } =
273
+ await window.WWebJS.enforceLidAndPnRetrieval(p);
274
+
275
+ return (
276
+ chat.groupMetadata.participants.get(
277
+ lid?._serialized,
278
+ ) ||
279
+ chat.groupMetadata.participants.get(
280
+ phone?._serialized,
281
+ )
282
+ );
283
+ }),
284
+ )
285
+ ).filter(Boolean);
286
+ await window
287
+ .require('WAWebModifyParticipantsGroupAction')
288
+ .removeParticipants(chat, participants);
289
+ return { status: 200 };
290
+ },
291
+ this.id._serialized,
292
+ participantIds,
293
+ );
207
294
  }
208
295
 
209
296
  /**
210
297
  * Promotes participants by IDs to admins
211
- * @param {Array<string>} participantIds
298
+ * @param {Array<string>} participantIds
212
299
  * @returns {Promise<{ status: number }>} Object with status code indicating if the operation was successful
213
300
  */
214
301
  async promoteParticipants(participantIds) {
215
- return await this.client.pupPage.evaluate(async (chatId, participantIds) => {
216
- const chat = await window.WWebJS.getChat(chatId, { getAsModel: false });
217
- const participants = (await Promise.all(participantIds.map(async p => {
218
- const { lid, phone } = await window.WWebJS.enforceLidAndPnRetrieval(p);
219
-
220
- return chat.groupMetadata.participants.get(lid?._serialized) ||
221
- chat.groupMetadata.participants.get(phone?._serialized);
222
- }))).filter(Boolean);
223
- await (window.require('WAWebModifyParticipantsGroupAction')).promoteParticipants(chat, participants);
224
- return { status: 200 };
225
- }, this.id._serialized, participantIds);
302
+ return await this.client.pupPage.evaluate(
303
+ async (chatId, participantIds) => {
304
+ const chat = await window.WWebJS.getChat(chatId, {
305
+ getAsModel: false,
306
+ });
307
+ const participants = (
308
+ await Promise.all(
309
+ participantIds.map(async (p) => {
310
+ const { lid, phone } =
311
+ await window.WWebJS.enforceLidAndPnRetrieval(p);
312
+
313
+ return (
314
+ chat.groupMetadata.participants.get(
315
+ lid?._serialized,
316
+ ) ||
317
+ chat.groupMetadata.participants.get(
318
+ phone?._serialized,
319
+ )
320
+ );
321
+ }),
322
+ )
323
+ ).filter(Boolean);
324
+ await window
325
+ .require('WAWebModifyParticipantsGroupAction')
326
+ .promoteParticipants(chat, participants);
327
+ return { status: 200 };
328
+ },
329
+ this.id._serialized,
330
+ participantIds,
331
+ );
226
332
  }
227
333
 
228
334
  /**
229
335
  * Demotes participants by IDs to regular users
230
- * @param {Array<string>} participantIds
336
+ * @param {Array<string>} participantIds
231
337
  * @returns {Promise<{ status: number }>} Object with status code indicating if the operation was successful
232
338
  */
233
339
  async demoteParticipants(participantIds) {
234
- return await this.client.pupPage.evaluate(async (chatId, participantIds) => {
235
- const chat = await window.WWebJS.getChat(chatId, { getAsModel: false });
236
- const participants = (await Promise.all(participantIds.map(async p => {
237
- const { lid, phone } = await window.WWebJS.enforceLidAndPnRetrieval(p);
238
-
239
- return chat.groupMetadata.participants.get(lid?._serialized) ||
240
- chat.groupMetadata.participants.get(phone?._serialized);
241
- }))).filter(Boolean);
242
- await (window.require('WAWebModifyParticipantsGroupAction')).demoteParticipants(chat, participants);
243
- return { status: 200 };
244
- }, this.id._serialized, participantIds);
340
+ return await this.client.pupPage.evaluate(
341
+ async (chatId, participantIds) => {
342
+ const chat = await window.WWebJS.getChat(chatId, {
343
+ getAsModel: false,
344
+ });
345
+ const participants = (
346
+ await Promise.all(
347
+ participantIds.map(async (p) => {
348
+ const { lid, phone } =
349
+ await window.WWebJS.enforceLidAndPnRetrieval(p);
350
+
351
+ return (
352
+ chat.groupMetadata.participants.get(
353
+ lid?._serialized,
354
+ ) ||
355
+ chat.groupMetadata.participants.get(
356
+ phone?._serialized,
357
+ )
358
+ );
359
+ }),
360
+ )
361
+ ).filter(Boolean);
362
+ await window
363
+ .require('WAWebModifyParticipantsGroupAction')
364
+ .demoteParticipants(chat, participants);
365
+ return { status: 200 };
366
+ },
367
+ this.id._serialized,
368
+ participantIds,
369
+ );
245
370
  }
246
371
 
247
372
  /**
248
373
  * Updates the group subject
249
- * @param {string} subject
374
+ * @param {string} subject
250
375
  * @returns {Promise<boolean>} Returns true if the subject was properly updated. This can return false if the user does not have the necessary permissions.
251
376
  */
252
377
  async setSubject(subject) {
253
- const success = await this.client.pupPage.evaluate(async (chatId, subject) => {
254
- const chatWid = window.require('WAWebWidFactory').createWid(chatId);
255
- try {
256
- await (window.require('WAWebGroupModifyInfoJob')).setGroupSubject(chatWid, subject);
257
- return true;
258
- } catch (err) {
259
- if(err.name === 'ServerStatusCodeError') return false;
260
- throw err;
261
- }
262
- }, this.id._serialized, subject);
378
+ const success = await this.client.pupPage.evaluate(
379
+ async (chatId, subject) => {
380
+ const chatWid = window
381
+ .require('WAWebWidFactory')
382
+ .createWid(chatId);
383
+ try {
384
+ await window
385
+ .require('WAWebGroupModifyInfoJob')
386
+ .setGroupSubject(chatWid, subject);
387
+ return true;
388
+ } catch (err) {
389
+ if (err.name === 'ServerStatusCodeError') return false;
390
+ throw err;
391
+ }
392
+ },
393
+ this.id._serialized,
394
+ subject,
395
+ );
263
396
 
264
- if(!success) return false;
397
+ if (!success) return false;
265
398
  this.name = subject;
266
399
  return true;
267
400
  }
268
401
 
269
402
  /**
270
403
  * Updates the group description
271
- * @param {string} description
404
+ * @param {string} description
272
405
  * @returns {Promise<boolean>} Returns true if the description was properly updated. This can return false if the user does not have the necessary permissions.
273
406
  */
274
407
  async setDescription(description) {
275
- const success = await this.client.pupPage.evaluate(async (chatId, description) => {
276
- const chatWid = window.require('WAWebWidFactory').createWid(chatId);
277
- const chat = await window.WWebJS.getChat(chatId, { getAsModel: false });
278
- let descId = chat.groupMetadata.descId;
279
- let newId = await (window.require('WAWebMsgKey')).newId();
280
- try {
281
- await (window.require('WAWebGroupModifyInfoJob')).setGroupDescription(chatWid, description, newId, descId);
282
- return true;
283
- } catch (err) {
284
- if(err.name === 'ServerStatusCodeError') return false;
285
- throw err;
286
- }
287
- }, this.id._serialized, description);
408
+ const success = await this.client.pupPage.evaluate(
409
+ async (chatId, description) => {
410
+ const chatWid = window
411
+ .require('WAWebWidFactory')
412
+ .createWid(chatId);
413
+ const chat = await window.WWebJS.getChat(chatId, {
414
+ getAsModel: false,
415
+ });
416
+ let descId = chat.groupMetadata.descId;
417
+ let newId = await window.require('WAWebMsgKey').newId();
418
+ try {
419
+ await window
420
+ .require('WAWebGroupModifyInfoJob')
421
+ .setGroupDescription(
422
+ chatWid,
423
+ description,
424
+ newId,
425
+ descId,
426
+ );
427
+ return true;
428
+ } catch (err) {
429
+ if (err.name === 'ServerStatusCodeError') return false;
430
+ throw err;
431
+ }
432
+ },
433
+ this.id._serialized,
434
+ description,
435
+ );
288
436
 
289
- if(!success) return false;
437
+ if (!success) return false;
290
438
  this.groupMetadata.desc = description;
291
439
  return true;
292
440
  }
293
-
441
+
294
442
  /**
295
443
  * Updates the group setting to allow only admins to add members to the group.
296
- * @param {boolean} [adminsOnly=true] Enable or disable this option
444
+ * @param {boolean} [adminsOnly=true] Enable or disable this option
297
445
  * @returns {Promise<boolean>} Returns true if the setting was properly updated. This can return false if the user does not have the necessary permissions.
298
446
  */
299
- async setAddMembersAdminsOnly(adminsOnly=true) {
300
- const success = await this.client.pupPage.evaluate(async (groupId, adminsOnly) => {
301
- const chat = await window.WWebJS.getChat(groupId, { getAsModel: false });
302
- try {
303
- await (window.require('WAWebSetPropertyGroupAction')).setGroupProperty(chat, 'member_add_mode', adminsOnly ? 0 : 1);
304
- return true;
305
- } catch (err) {
306
- if(err.name === 'ServerStatusCodeError') return false;
307
- throw err;
308
- }
309
- }, this.id._serialized, adminsOnly);
310
-
311
- success && (this.groupMetadata.memberAddMode = adminsOnly ? 'admin_add' : 'all_member_add');
447
+ async setAddMembersAdminsOnly(adminsOnly = true) {
448
+ const success = await this.client.pupPage.evaluate(
449
+ async (groupId, adminsOnly) => {
450
+ const chat = await window.WWebJS.getChat(groupId, {
451
+ getAsModel: false,
452
+ });
453
+ try {
454
+ await window
455
+ .require('WAWebSetPropertyGroupAction')
456
+ .setGroupProperty(
457
+ chat,
458
+ 'member_add_mode',
459
+ adminsOnly ? 0 : 1,
460
+ );
461
+ return true;
462
+ } catch (err) {
463
+ if (err.name === 'ServerStatusCodeError') return false;
464
+ throw err;
465
+ }
466
+ },
467
+ this.id._serialized,
468
+ adminsOnly,
469
+ );
470
+
471
+ success &&
472
+ (this.groupMetadata.memberAddMode = adminsOnly
473
+ ? 'admin_add'
474
+ : 'all_member_add');
312
475
  return success;
313
476
  }
314
-
477
+
315
478
  /**
316
479
  * Updates the group settings to only allow admins to send messages.
317
- * @param {boolean} [adminsOnly=true] Enable or disable this option
480
+ * @param {boolean} [adminsOnly=true] Enable or disable this option
318
481
  * @returns {Promise<boolean>} Returns true if the setting was properly updated. This can return false if the user does not have the necessary permissions.
319
482
  */
320
- async setMessagesAdminsOnly(adminsOnly=true) {
321
- const success = await this.client.pupPage.evaluate(async (chatId, adminsOnly) => {
322
- const chat = await window.WWebJS.getChat(chatId, { getAsModel: false });
323
- try {
324
- await (window.require('WAWebSetPropertyGroupAction')).setGroupProperty(chat, 'announcement', adminsOnly ? 1 : 0);
325
- return true;
326
- } catch (err) {
327
- if(err.name === 'ServerStatusCodeError') return false;
328
- throw err;
329
- }
330
- }, this.id._serialized, adminsOnly);
483
+ async setMessagesAdminsOnly(adminsOnly = true) {
484
+ const success = await this.client.pupPage.evaluate(
485
+ async (chatId, adminsOnly) => {
486
+ const chat = await window.WWebJS.getChat(chatId, {
487
+ getAsModel: false,
488
+ });
489
+ try {
490
+ await window
491
+ .require('WAWebSetPropertyGroupAction')
492
+ .setGroupProperty(
493
+ chat,
494
+ 'announcement',
495
+ adminsOnly ? 1 : 0,
496
+ );
497
+ return true;
498
+ } catch (err) {
499
+ if (err.name === 'ServerStatusCodeError') return false;
500
+ throw err;
501
+ }
502
+ },
503
+ this.id._serialized,
504
+ adminsOnly,
505
+ );
331
506
 
332
- if(!success) return false;
507
+ if (!success) return false;
333
508
 
334
509
  this.groupMetadata.announce = adminsOnly;
335
510
  return true;
@@ -337,27 +512,35 @@ class GroupChat extends Chat {
337
512
 
338
513
  /**
339
514
  * Updates the group settings to only allow admins to edit group info (title, description, photo).
340
- * @param {boolean} [adminsOnly=true] Enable or disable this option
515
+ * @param {boolean} [adminsOnly=true] Enable or disable this option
341
516
  * @returns {Promise<boolean>} Returns true if the setting was properly updated. This can return false if the user does not have the necessary permissions.
342
517
  */
343
- async setInfoAdminsOnly(adminsOnly=true) {
344
- const success = await this.client.pupPage.evaluate(async (chatId, adminsOnly) => {
345
- const chat = await window.WWebJS.getChat(chatId, { getAsModel: false });
346
- try {
347
- await (window.require('WAWebSetPropertyGroupAction')).setGroupProperty(chat, 'restrict', adminsOnly ? 1 : 0);
348
- return true;
349
- } catch (err) {
350
- if(err.name === 'ServerStatusCodeError') return false;
351
- throw err;
352
- }
353
- }, this.id._serialized, adminsOnly);
518
+ async setInfoAdminsOnly(adminsOnly = true) {
519
+ const success = await this.client.pupPage.evaluate(
520
+ async (chatId, adminsOnly) => {
521
+ const chat = await window.WWebJS.getChat(chatId, {
522
+ getAsModel: false,
523
+ });
524
+ try {
525
+ await window
526
+ .require('WAWebSetPropertyGroupAction')
527
+ .setGroupProperty(chat, 'restrict', adminsOnly ? 1 : 0);
528
+ return true;
529
+ } catch (err) {
530
+ if (err.name === 'ServerStatusCodeError') return false;
531
+ throw err;
532
+ }
533
+ },
534
+ this.id._serialized,
535
+ adminsOnly,
536
+ );
537
+
538
+ if (!success) return false;
354
539
 
355
- if(!success) return false;
356
-
357
540
  this.groupMetadata.restrict = adminsOnly;
358
541
  return true;
359
542
  }
360
-
543
+
361
544
  /**
362
545
  * Deletes the group's picture.
363
546
  * @returns {Promise<boolean>} Returns true if the picture was properly deleted. This can return false if the user does not have the necessary permissions.
@@ -376,9 +559,13 @@ class GroupChat extends Chat {
376
559
  * @returns {Promise<boolean>} Returns true if the picture was properly updated. This can return false if the user does not have the necessary permissions.
377
560
  */
378
561
  async setPicture(media) {
379
- const success = await this.client.pupPage.evaluate((chatid, media) => {
380
- return window.WWebJS.setPicture(chatid, media);
381
- }, this.id._serialized, media);
562
+ const success = await this.client.pupPage.evaluate(
563
+ (chatid, media) => {
564
+ return window.WWebJS.setPicture(chatid, media);
565
+ },
566
+ this.id._serialized,
567
+ media,
568
+ );
382
569
 
383
570
  return success;
384
571
  }
@@ -388,34 +575,35 @@ class GroupChat extends Chat {
388
575
  * @returns {Promise<string>} Group's invite code
389
576
  */
390
577
  async getInviteCode() {
391
- const codeRes = await this.client.pupPage.evaluate(async chatId => {
578
+ const codeRes = await this.client.pupPage.evaluate(async (chatId) => {
392
579
  try {
393
- return await (window.require('WAWebMexFetchGroupInviteCodeJob')).fetchMexGroupInviteCode(chatId);
394
- }
395
- catch (err) {
396
- if(err.name === 'ServerStatusCodeError') return undefined;
580
+ return await window
581
+ .require('WAWebMexFetchGroupInviteCodeJob')
582
+ .fetchMexGroupInviteCode(chatId);
583
+ } catch (err) {
584
+ if (err.name === 'ServerStatusCodeError') return undefined;
397
585
  throw err;
398
586
  }
399
587
  }, this.id._serialized);
400
588
 
401
- return codeRes?.code
402
- ? codeRes?.code
403
- : codeRes;
589
+ return codeRes?.code ? codeRes?.code : codeRes;
404
590
  }
405
-
591
+
406
592
  /**
407
593
  * Invalidates the current group invite code and generates a new one
408
594
  * @returns {Promise<string>} New invite code
409
595
  */
410
596
  async revokeInvite() {
411
- const codeRes = await this.client.pupPage.evaluate(chatId => {
597
+ const codeRes = await this.client.pupPage.evaluate((chatId) => {
412
598
  const chatWid = window.require('WAWebWidFactory').createWid(chatId);
413
- return (window.require('WAWebGroupQueryJob')).resetGroupInviteCode(chatWid);
599
+ return window
600
+ .require('WAWebGroupQueryJob')
601
+ .resetGroupInviteCode(chatWid);
414
602
  }, this.id._serialized);
415
603
 
416
604
  return codeRes.code;
417
605
  }
418
-
606
+
419
607
  /**
420
608
  * An object that handles the information about the group membership request
421
609
  * @typedef {Object} GroupMembershipRequest
@@ -425,13 +613,15 @@ class GroupChat extends Chat {
425
613
  * @property {string} requestMethod The method used to create the request: NonAdminAdd/InviteLink/LinkedGroupJoin
426
614
  * @property {number} t The timestamp the request was created at
427
615
  */
428
-
616
+
429
617
  /**
430
618
  * Gets an array of membership requests
431
619
  * @returns {Promise<Array<GroupMembershipRequest>>} An array of membership requests
432
620
  */
433
621
  async getGroupMembershipRequests() {
434
- return await this.client.getGroupMembershipRequests(this.id._serialized);
622
+ return await this.client.getGroupMembershipRequests(
623
+ this.id._serialized,
624
+ );
435
625
  }
436
626
 
437
627
  /**
@@ -455,7 +645,10 @@ class GroupChat extends Chat {
455
645
  * @returns {Promise<Array<MembershipRequestActionResult>>} Returns an array of requester IDs whose membership requests were approved and an error for each requester, if any occurred during the operation. If there are no requests, an empty array will be returned
456
646
  */
457
647
  async approveGroupMembershipRequests(options = {}) {
458
- return await this.client.approveGroupMembershipRequests(this.id._serialized, options);
648
+ return await this.client.approveGroupMembershipRequests(
649
+ this.id._serialized,
650
+ options,
651
+ );
459
652
  }
460
653
 
461
654
  /**
@@ -464,7 +657,10 @@ class GroupChat extends Chat {
464
657
  * @returns {Promise<Array<MembershipRequestActionResult>>} Returns an array of requester IDs whose membership requests were rejected and an error for each requester, if any occurred during the operation. If there are no requests, an empty array will be returned
465
658
  */
466
659
  async rejectGroupMembershipRequests(options = {}) {
467
- return await this.client.rejectGroupMembershipRequests(this.id._serialized, options);
660
+ return await this.client.rejectGroupMembershipRequests(
661
+ this.id._serialized,
662
+ options,
663
+ );
468
664
  }
469
665
 
470
666
  /**
@@ -472,12 +668,13 @@ class GroupChat extends Chat {
472
668
  * @returns {Promise}
473
669
  */
474
670
  async leave() {
475
- await this.client.pupPage.evaluate(async chatId => {
476
- const chat = await window.WWebJS.getChat(chatId, { getAsModel: false });
477
- return (window.require('WAWebExitGroupAction')).sendExitGroup(chat);
671
+ await this.client.pupPage.evaluate(async (chatId) => {
672
+ const chat = await window.WWebJS.getChat(chatId, {
673
+ getAsModel: false,
674
+ });
675
+ return window.require('WAWebExitGroupAction').sendExitGroup(chat);
478
676
  }, this.id._serialized);
479
677
  }
480
-
481
678
  }
482
679
 
483
680
  module.exports = GroupChat;