@another-trial/whatsapp-web.js 1.34.1 → 1.35.0-alpha.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.
Files changed (56) hide show
  1. package/.env.example +2 -2
  2. package/CODE_OF_CONDUCT.md +133 -133
  3. package/LICENSE +201 -201
  4. package/README.md +155 -185
  5. package/example.js +699 -690
  6. package/index.d.ts +2248 -2202
  7. package/index.js +35 -35
  8. package/package.json +59 -59
  9. package/shell.js +36 -36
  10. package/src/Client.js +2447 -2361
  11. package/src/authStrategies/BaseAuthStrategy.js +26 -26
  12. package/src/authStrategies/LocalAuth.js +58 -58
  13. package/src/authStrategies/NoAuth.js +11 -11
  14. package/src/authStrategies/RemoteAuth.js +210 -210
  15. package/src/factories/ChatFactory.js +21 -21
  16. package/src/factories/ContactFactory.js +15 -15
  17. package/src/structures/Base.js +21 -21
  18. package/src/structures/Broadcast.js +69 -69
  19. package/src/structures/BusinessContact.js +20 -20
  20. package/src/structures/Buttons.js +81 -81
  21. package/src/structures/Call.js +75 -75
  22. package/src/structures/Channel.js +382 -382
  23. package/src/structures/Chat.js +329 -299
  24. package/src/structures/ClientInfo.js +70 -70
  25. package/src/structures/Contact.js +208 -208
  26. package/src/structures/GroupChat.js +485 -485
  27. package/src/structures/GroupNotification.js +104 -104
  28. package/src/structures/Label.js +49 -49
  29. package/src/structures/List.js +79 -79
  30. package/src/structures/Location.js +61 -61
  31. package/src/structures/Message.js +780 -747
  32. package/src/structures/MessageMedia.js +111 -111
  33. package/src/structures/Order.js +51 -51
  34. package/src/structures/Payment.js +79 -79
  35. package/src/structures/Poll.js +44 -44
  36. package/src/structures/PollVote.js +75 -75
  37. package/src/structures/PrivateChat.js +12 -12
  38. package/src/structures/PrivateContact.js +12 -12
  39. package/src/structures/Product.js +67 -67
  40. package/src/structures/ProductMetadata.js +24 -24
  41. package/src/structures/Reaction.js +68 -68
  42. package/src/structures/ScheduledEvent.js +71 -71
  43. package/src/structures/index.js +27 -27
  44. package/src/util/Constants.js +186 -183
  45. package/src/util/Injected/AuthStore/AuthStore.js +16 -16
  46. package/src/util/Injected/AuthStore/LegacyAuthStore.js +21 -21
  47. package/src/util/Injected/LegacyStore.js +145 -145
  48. package/src/util/Injected/Store.js +257 -233
  49. package/src/util/Injected/Utils.js +1168 -1169
  50. package/src/util/InterfaceController.js +126 -126
  51. package/src/util/Puppeteer.js +23 -23
  52. package/src/util/Util.js +186 -186
  53. package/src/webCache/LocalWebCache.js +40 -40
  54. package/src/webCache/RemoteWebCache.js +39 -39
  55. package/src/webCache/WebCache.js +13 -13
  56. package/src/webCache/WebCacheFactory.js +19 -19
@@ -1,75 +1,75 @@
1
- 'use strict';
2
-
3
- const Message = require('./Message');
4
- const Base = require('./Base');
5
-
6
- /**
7
- * Selected poll option structure
8
- * @typedef {Object} SelectedPollOption
9
- * @property {number} id The local selected or deselected option ID
10
- * @property {string} name The option name
11
- */
12
-
13
- /**
14
- * Represents a Poll Vote on WhatsApp
15
- * @extends {Base}
16
- */
17
- class PollVote extends Base {
18
- constructor(client, data) {
19
- super(client);
20
-
21
- if (data) this._patch(data);
22
- }
23
-
24
- _patch(data) {
25
- /**
26
- * The person who voted
27
- * @type {string}
28
- */
29
- this.voter = data.sender;
30
-
31
- /**
32
- * The selected poll option(s)
33
- * If it's an empty array, the user hasn't selected any options on the poll,
34
- * may occur when they deselected all poll options
35
- * @type {SelectedPollOption[]}
36
- */
37
- if (data.selectedOptionLocalIds.length > 0) {
38
- if(data.parentMessage) { // temporary failsafe
39
- this.selectedOptions = data.selectedOptionLocalIds.map((e) => ({
40
- name: data.parentMessage.pollOptions.find((x) => x.localId === e).name,
41
- localId: e
42
- }));
43
- } else {
44
- this.selectedOptions = data.selectedOptionLocalIds.map((e) => ({
45
- name: undefined,
46
- localId: e
47
- }));
48
- }
49
- } else {
50
- this.selectedOptions = [];
51
- }
52
-
53
- /**
54
- * Timestamp the option was selected or deselected at
55
- * @type {number}
56
- */
57
- this.interractedAtTs = data.senderTimestampMs;
58
-
59
- /**
60
- * The poll creation message associated with the poll vote
61
- * @type {Message}
62
- */
63
- this.parentMessage = new Message(this.client, data.parentMessage);
64
-
65
- /**
66
- * The poll creation message id
67
- * @type {Object}
68
- */
69
- this.parentMsgKey = data.parentMsgKey;
70
-
71
- return super._patch(data);
72
- }
73
- }
74
-
75
- module.exports = PollVote;
1
+ 'use strict';
2
+
3
+ const Message = require('./Message');
4
+ const Base = require('./Base');
5
+
6
+ /**
7
+ * Selected poll option structure
8
+ * @typedef {Object} SelectedPollOption
9
+ * @property {number} id The local selected or deselected option ID
10
+ * @property {string} name The option name
11
+ */
12
+
13
+ /**
14
+ * Represents a Poll Vote on WhatsApp
15
+ * @extends {Base}
16
+ */
17
+ class PollVote extends Base {
18
+ constructor(client, data) {
19
+ super(client);
20
+
21
+ if (data) this._patch(data);
22
+ }
23
+
24
+ _patch(data) {
25
+ /**
26
+ * The person who voted
27
+ * @type {string}
28
+ */
29
+ this.voter = data.sender;
30
+
31
+ /**
32
+ * The selected poll option(s)
33
+ * If it's an empty array, the user hasn't selected any options on the poll,
34
+ * may occur when they deselected all poll options
35
+ * @type {SelectedPollOption[]}
36
+ */
37
+ if (data.selectedOptionLocalIds.length > 0) {
38
+ if(data.parentMessage) { // temporary failsafe
39
+ this.selectedOptions = data.selectedOptionLocalIds.map((e) => ({
40
+ name: data.parentMessage.pollOptions.find((x) => x.localId === e).name,
41
+ localId: e
42
+ }));
43
+ } else {
44
+ this.selectedOptions = data.selectedOptionLocalIds.map((e) => ({
45
+ name: undefined,
46
+ localId: e
47
+ }));
48
+ }
49
+ } else {
50
+ this.selectedOptions = [];
51
+ }
52
+
53
+ /**
54
+ * Timestamp the option was selected or deselected at
55
+ * @type {number}
56
+ */
57
+ this.interractedAtTs = data.senderTimestampMs;
58
+
59
+ /**
60
+ * The poll creation message associated with the poll vote
61
+ * @type {Message}
62
+ */
63
+ this.parentMessage = new Message(this.client, data.parentMessage);
64
+
65
+ /**
66
+ * The poll creation message id
67
+ * @type {Object}
68
+ */
69
+ this.parentMsgKey = data.parentMsgKey;
70
+
71
+ return super._patch(data);
72
+ }
73
+ }
74
+
75
+ module.exports = PollVote;
@@ -1,13 +1,13 @@
1
- 'use strict';
2
-
3
- const Chat = require('./Chat');
4
-
5
- /**
6
- * Represents a Private Chat on WhatsApp
7
- * @extends {Chat}
8
- */
9
- class PrivateChat extends Chat {
10
-
11
- }
12
-
1
+ 'use strict';
2
+
3
+ const Chat = require('./Chat');
4
+
5
+ /**
6
+ * Represents a Private Chat on WhatsApp
7
+ * @extends {Chat}
8
+ */
9
+ class PrivateChat extends Chat {
10
+
11
+ }
12
+
13
13
  module.exports = PrivateChat;
@@ -1,13 +1,13 @@
1
- 'use strict';
2
-
3
- const Contact = require('./Contact');
4
-
5
- /**
6
- * Represents a Private Contact on WhatsApp
7
- * @extends {Contact}
8
- */
9
- class PrivateContact extends Contact {
10
-
11
- }
12
-
1
+ 'use strict';
2
+
3
+ const Contact = require('./Contact');
4
+
5
+ /**
6
+ * Represents a Private Contact on WhatsApp
7
+ * @extends {Contact}
8
+ */
9
+ class PrivateContact extends Contact {
10
+
11
+ }
12
+
13
13
  module.exports = PrivateContact;
@@ -1,68 +1,68 @@
1
- 'use strict';
2
-
3
- const Base = require('./Base');
4
- const ProductMetadata = require('./ProductMetadata');
5
-
6
- /**
7
- * Represents a Product on WhatsAppBusiness
8
- * @extends {Base}
9
- */
10
- class Product extends Base {
11
- constructor(client, data) {
12
- super(client);
13
-
14
- if (data) this._patch(data);
15
- }
16
-
17
- _patch(data) {
18
- /**
19
- * Product ID
20
- * @type {string}
21
- */
22
- this.id = data.id;
23
- /**
24
- * Price
25
- * @type {string}
26
- */
27
- this.price = data.price ? data.price : '';
28
- /**
29
- * Product Thumbnail
30
- * @type {string}
31
- */
32
- this.thumbnailUrl = data.thumbnailUrl;
33
- /**
34
- * Currency
35
- * @type {string}
36
- */
37
- this.currency = data.currency;
38
- /**
39
- * Product Name
40
- * @type {string}
41
- */
42
- this.name = data.name;
43
- /**
44
- * Product Quantity
45
- * @type {number}
46
- */
47
- this.quantity = data.quantity;
48
- /** Product metadata */
49
- this.data = null;
50
- return super._patch(data);
51
- }
52
-
53
- async getData() {
54
- if (this.data === null) {
55
- let result = await this.client.pupPage.evaluate((productId) => {
56
- return window.WWebJS.getProductMetadata(productId);
57
- }, this.id);
58
- if (!result) {
59
- this.data = undefined;
60
- } else {
61
- this.data = new ProductMetadata(this.client, result);
62
- }
63
- }
64
- return this.data;
65
- }
66
- }
67
-
1
+ 'use strict';
2
+
3
+ const Base = require('./Base');
4
+ const ProductMetadata = require('./ProductMetadata');
5
+
6
+ /**
7
+ * Represents a Product on WhatsAppBusiness
8
+ * @extends {Base}
9
+ */
10
+ class Product extends Base {
11
+ constructor(client, data) {
12
+ super(client);
13
+
14
+ if (data) this._patch(data);
15
+ }
16
+
17
+ _patch(data) {
18
+ /**
19
+ * Product ID
20
+ * @type {string}
21
+ */
22
+ this.id = data.id;
23
+ /**
24
+ * Price
25
+ * @type {string}
26
+ */
27
+ this.price = data.price ? data.price : '';
28
+ /**
29
+ * Product Thumbnail
30
+ * @type {string}
31
+ */
32
+ this.thumbnailUrl = data.thumbnailUrl;
33
+ /**
34
+ * Currency
35
+ * @type {string}
36
+ */
37
+ this.currency = data.currency;
38
+ /**
39
+ * Product Name
40
+ * @type {string}
41
+ */
42
+ this.name = data.name;
43
+ /**
44
+ * Product Quantity
45
+ * @type {number}
46
+ */
47
+ this.quantity = data.quantity;
48
+ /** Product metadata */
49
+ this.data = null;
50
+ return super._patch(data);
51
+ }
52
+
53
+ async getData() {
54
+ if (this.data === null) {
55
+ let result = await this.client.pupPage.evaluate((productId) => {
56
+ return window.WWebJS.getProductMetadata(productId);
57
+ }, this.id);
58
+ if (!result) {
59
+ this.data = undefined;
60
+ } else {
61
+ this.data = new ProductMetadata(this.client, result);
62
+ }
63
+ }
64
+ return this.data;
65
+ }
66
+ }
67
+
68
68
  module.exports = Product;
@@ -1,25 +1,25 @@
1
- const Base = require('./Base');
2
-
3
- class ProductMetadata extends Base {
4
- constructor(client, data) {
5
- super(client);
6
-
7
- if (data) this._patch(data);
8
- }
9
-
10
- _patch(data) {
11
- /** Product ID */
12
- this.id = data.id;
13
- /** Retailer ID */
14
- this.retailer_id = data.retailer_id;
15
- /** Product Name */
16
- this.name = data.name;
17
- /** Product Description */
18
- this.description = data.description;
19
-
20
- return super._patch(data);
21
- }
22
-
23
- }
24
-
1
+ const Base = require('./Base');
2
+
3
+ class ProductMetadata extends Base {
4
+ constructor(client, data) {
5
+ super(client);
6
+
7
+ if (data) this._patch(data);
8
+ }
9
+
10
+ _patch(data) {
11
+ /** Product ID */
12
+ this.id = data.id;
13
+ /** Retailer ID */
14
+ this.retailer_id = data.retailer_id;
15
+ /** Product Name */
16
+ this.name = data.name;
17
+ /** Product Description */
18
+ this.description = data.description;
19
+
20
+ return super._patch(data);
21
+ }
22
+
23
+ }
24
+
25
25
  module.exports = ProductMetadata;
@@ -1,69 +1,69 @@
1
- 'use strict';
2
-
3
- const Base = require('./Base');
4
-
5
- /**
6
- * Represents a Reaction on WhatsApp
7
- * @extends {Base}
8
- */
9
- class Reaction extends Base {
10
- constructor(client, data) {
11
- super(client);
12
-
13
- if (data) this._patch(data);
14
- }
15
-
16
- _patch(data) {
17
- /**
18
- * Reaction ID
19
- * @type {object}
20
- */
21
- this.id = data.msgKey;
22
- /**
23
- * Orphan
24
- * @type {number}
25
- */
26
- this.orphan = data.orphan;
27
- /**
28
- * Orphan reason
29
- * @type {?string}
30
- */
31
- this.orphanReason = data.orphanReason;
32
- /**
33
- * Unix timestamp for when the reaction was created
34
- * @type {number}
35
- */
36
- this.timestamp = data.timestamp;
37
- /**
38
- * Reaction
39
- * @type {string}
40
- */
41
- this.reaction = data.reactionText;
42
- /**
43
- * Read
44
- * @type {boolean}
45
- */
46
- this.read = data.read;
47
- /**
48
- * Message ID
49
- * @type {object}
50
- */
51
- this.msgId = data.parentMsgKey;
52
- /**
53
- * Sender ID
54
- * @type {string}
55
- */
56
- this.senderId = data.senderUserJid;
57
- /**
58
- * ACK
59
- * @type {?number}
60
- */
61
- this.ack = data.ack;
62
-
63
-
64
- return super._patch(data);
65
- }
66
-
67
- }
68
-
1
+ 'use strict';
2
+
3
+ const Base = require('./Base');
4
+
5
+ /**
6
+ * Represents a Reaction on WhatsApp
7
+ * @extends {Base}
8
+ */
9
+ class Reaction extends Base {
10
+ constructor(client, data) {
11
+ super(client);
12
+
13
+ if (data) this._patch(data);
14
+ }
15
+
16
+ _patch(data) {
17
+ /**
18
+ * Reaction ID
19
+ * @type {object}
20
+ */
21
+ this.id = data.msgKey;
22
+ /**
23
+ * Orphan
24
+ * @type {number}
25
+ */
26
+ this.orphan = data.orphan;
27
+ /**
28
+ * Orphan reason
29
+ * @type {?string}
30
+ */
31
+ this.orphanReason = data.orphanReason;
32
+ /**
33
+ * Unix timestamp for when the reaction was created
34
+ * @type {number}
35
+ */
36
+ this.timestamp = data.timestamp;
37
+ /**
38
+ * Reaction
39
+ * @type {string}
40
+ */
41
+ this.reaction = data.reactionText;
42
+ /**
43
+ * Read
44
+ * @type {boolean}
45
+ */
46
+ this.read = data.read;
47
+ /**
48
+ * Message ID
49
+ * @type {object}
50
+ */
51
+ this.msgId = data.parentMsgKey;
52
+ /**
53
+ * Sender ID
54
+ * @type {string}
55
+ */
56
+ this.senderId = data.senderUserJid;
57
+ /**
58
+ * ACK
59
+ * @type {?number}
60
+ */
61
+ this.ack = data.ack;
62
+
63
+
64
+ return super._patch(data);
65
+ }
66
+
67
+ }
68
+
69
69
  module.exports = Reaction;
@@ -1,71 +1,71 @@
1
- 'use strict';
2
-
3
- /**
4
- * ScheduledEvent send options
5
- * @typedef {Object} ScheduledEventSendOptions
6
- * @property {?string} description The scheduled event description
7
- * @property {?Date} endTime The end time of the event
8
- * @property {?string} location The location of the event
9
- * @property {?string} callType The type of a WhatsApp call link to generate, valid values are: `video` | `voice`
10
- * @property {boolean} [isEventCanceled = false] Indicates if a scheduled event should be sent as an already canceled
11
- * @property {?Array<number>} messageSecret The custom message secret, can be used as an event ID. NOTE: it has to be a unique vector with a length of 32
12
- */
13
-
14
- /** Represents a ScheduledEvent on WhatsApp */
15
- class ScheduledEvent {
16
- /**
17
- * @param {string} name
18
- * @param {Date} startTime
19
- * @param {ScheduledEventSendOptions} options
20
- */
21
- constructor(name, startTime, options = {}) {
22
- /**
23
- * The name of the event
24
- * @type {string}
25
- */
26
- this.name = this._validateInputs('name', name).trim();
27
-
28
- /**
29
- * The start time of the event
30
- * @type {number}
31
- */
32
- this.startTimeTs = Math.floor(startTime.getTime() / 1000);
33
-
34
- /**
35
- * The send options for the event
36
- * @type {Object}
37
- */
38
- this.eventSendOptions = {
39
- description: options.description?.trim(),
40
- endTimeTs: options.endTime ? Math.floor(options.endTime.getTime() / 1000) : null,
41
- location: options.location?.trim(),
42
- callType: this._validateInputs('callType', options.callType),
43
- isEventCanceled: options.isEventCanceled ?? false,
44
- messageSecret: options.messageSecret
45
- };
46
- }
47
-
48
- /**
49
- * Inner function to validate input values
50
- * @param {string} propName The property name to validate the value of
51
- * @param {string | number} propValue The property value to validate
52
- * @returns {string | number} The property value if a validation succeeded
53
- */
54
- _validateInputs(propName, propValue) {
55
- if (propName === 'name' && !propValue) {
56
- throw new class CreateScheduledEventError extends Error {
57
- constructor(m) { super(m); }
58
- }(`Empty '${propName}' parameter value is provided.`);
59
- }
60
-
61
- if (propName === 'callType' && propValue && !['video', 'voice'].includes(propValue)) {
62
- throw new class CreateScheduledEventError extends Error {
63
- constructor(m) { super(m); }
64
- }(`Invalid '${propName}' parameter value is provided. Valid values are: 'voice' | 'video'.`);
65
- }
66
-
67
- return propValue;
68
- }
69
- }
70
-
71
- module.exports = ScheduledEvent;
1
+ 'use strict';
2
+
3
+ /**
4
+ * ScheduledEvent send options
5
+ * @typedef {Object} ScheduledEventSendOptions
6
+ * @property {?string} description The scheduled event description
7
+ * @property {?Date} endTime The end time of the event
8
+ * @property {?string} location The location of the event
9
+ * @property {?string} callType The type of a WhatsApp call link to generate, valid values are: `video` | `voice` | `none`
10
+ * @property {boolean} [isEventCanceled = false] Indicates if a scheduled event should be sent as an already canceled
11
+ * @property {?Array<number>} messageSecret The custom message secret, can be used as an event ID. NOTE: it has to be a unique vector with a length of 32
12
+ */
13
+
14
+ /** Represents a ScheduledEvent on WhatsApp */
15
+ class ScheduledEvent {
16
+ /**
17
+ * @param {string} name
18
+ * @param {Date} startTime
19
+ * @param {ScheduledEventSendOptions} options
20
+ */
21
+ constructor(name, startTime, options = {}) {
22
+ /**
23
+ * The name of the event
24
+ * @type {string}
25
+ */
26
+ this.name = this._validateInputs('name', name).trim();
27
+
28
+ /**
29
+ * The start time of the event
30
+ * @type {number}
31
+ */
32
+ this.startTimeTs = Math.floor(startTime.getTime() / 1000);
33
+
34
+ /**
35
+ * The send options for the event
36
+ * @type {Object}
37
+ */
38
+ this.eventSendOptions = {
39
+ description: options.description?.trim(),
40
+ endTimeTs: options.endTime ? Math.floor(options.endTime.getTime() / 1000) : null,
41
+ location: options.location?.trim(),
42
+ callType: this._validateInputs('callType', options.callType),
43
+ isEventCanceled: options.isEventCanceled ?? false,
44
+ messageSecret: options.messageSecret
45
+ };
46
+ }
47
+
48
+ /**
49
+ * Inner function to validate input values
50
+ * @param {string} propName The property name to validate the value of
51
+ * @param {string | number} propValue The property value to validate
52
+ * @returns {string | number} The property value if a validation succeeded
53
+ */
54
+ _validateInputs(propName, propValue) {
55
+ if (propName === 'name' && !propValue) {
56
+ throw new class CreateScheduledEventError extends Error {
57
+ constructor(m) { super(m); }
58
+ }(`Empty '${propName}' parameter value is provided.`);
59
+ }
60
+
61
+ if (propName === 'callType' && propValue && !['video', 'voice', 'none'].includes(propValue)) {
62
+ throw new class CreateScheduledEventError extends Error {
63
+ constructor(m) { super(m); }
64
+ }(`Invalid '${propName}' parameter value is provided. Valid values are: 'voice' | 'video' | 'none'.`);
65
+ }
66
+
67
+ return propValue;
68
+ }
69
+ }
70
+
71
+ module.exports = ScheduledEvent;