@another-trial/whatsapp-web.js 1.34.0 → 1.34.5-alpha.3

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 +706 -690
  6. package/index.d.ts +2259 -2202
  7. package/index.js +35 -35
  8. package/package.json +59 -59
  9. package/shell.js +36 -36
  10. package/src/Client.js +2533 -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 +215 -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 +787 -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 +263 -231
  49. package/src/util/Injected/Utils.js +1221 -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,16 +1,16 @@
1
- 'use strict';
2
-
3
- const PrivateContact = require('../structures/PrivateContact');
4
- const BusinessContact = require('../structures/BusinessContact');
5
-
6
- class ContactFactory {
7
- static create(client, data) {
8
- if(data.isBusiness) {
9
- return new BusinessContact(client, data);
10
- }
11
-
12
- return new PrivateContact(client, data);
13
- }
14
- }
15
-
1
+ 'use strict';
2
+
3
+ const PrivateContact = require('../structures/PrivateContact');
4
+ const BusinessContact = require('../structures/BusinessContact');
5
+
6
+ class ContactFactory {
7
+ static create(client, data) {
8
+ if(data.isBusiness) {
9
+ return new BusinessContact(client, data);
10
+ }
11
+
12
+ return new PrivateContact(client, data);
13
+ }
14
+ }
15
+
16
16
  module.exports = ContactFactory;
@@ -1,22 +1,22 @@
1
- 'use strict';
2
-
3
- /**
4
- * Represents a WhatsApp data structure
5
- */
6
- class Base {
7
- constructor(client) {
8
- /**
9
- * The client that instantiated this
10
- * @readonly
11
- */
12
- Object.defineProperty(this, 'client', { value: client });
13
- }
14
-
15
- _clone() {
16
- return Object.assign(Object.create(this), this);
17
- }
18
-
19
- _patch(data) { return data; }
20
- }
21
-
1
+ 'use strict';
2
+
3
+ /**
4
+ * Represents a WhatsApp data structure
5
+ */
6
+ class Base {
7
+ constructor(client) {
8
+ /**
9
+ * The client that instantiated this
10
+ * @readonly
11
+ */
12
+ Object.defineProperty(this, 'client', { value: client });
13
+ }
14
+
15
+ _clone() {
16
+ return Object.assign(Object.create(this), this);
17
+ }
18
+
19
+ _patch(data) { return data; }
20
+ }
21
+
22
22
  module.exports = Base;
@@ -1,69 +1,69 @@
1
- 'use strict';
2
-
3
- const Base = require('./Base');
4
- const Message = require('./Message');
5
-
6
- /**
7
- * Represents a Status/Story on WhatsApp
8
- * @extends {Base}
9
- */
10
- class Broadcast extends Base {
11
- constructor(client, data) {
12
- super(client);
13
-
14
- if (data) this._patch(data);
15
- }
16
-
17
- _patch(data) {
18
- /**
19
- * ID that represents the chat
20
- * @type {object}
21
- */
22
- this.id = data.id;
23
-
24
- /**
25
- * Unix timestamp of last status
26
- * @type {number}
27
- */
28
- this.timestamp = data.t;
29
-
30
- /**
31
- * Number of available statuses
32
- * @type {number}
33
- */
34
- this.totalCount = data.totalCount;
35
-
36
- /**
37
- * Number of not viewed
38
- * @type {number}
39
- */
40
- this.unreadCount = data.unreadCount;
41
-
42
- /**
43
- * Messages statuses
44
- * @type {Message[]}
45
- */
46
- this.msgs = data.msgs?.map(msg => new Message(this.client, msg));
47
-
48
- return super._patch(data);
49
- }
50
-
51
- /**
52
- * Returns the Chat this message was sent in
53
- * @returns {Promise<Chat>}
54
- */
55
- getChat() {
56
- return this.client.getChatById(this.id._serialized);
57
- }
58
-
59
- /**
60
- * Returns the Contact this message was sent from
61
- * @returns {Promise<Contact>}
62
- */
63
- getContact() {
64
- return this.client.getContactById(this.id._serialized);
65
- }
66
-
67
- }
68
-
69
- module.exports = Broadcast;
1
+ 'use strict';
2
+
3
+ const Base = require('./Base');
4
+ const Message = require('./Message');
5
+
6
+ /**
7
+ * Represents a Status/Story on WhatsApp
8
+ * @extends {Base}
9
+ */
10
+ class Broadcast extends Base {
11
+ constructor(client, data) {
12
+ super(client);
13
+
14
+ if (data) this._patch(data);
15
+ }
16
+
17
+ _patch(data) {
18
+ /**
19
+ * ID that represents the chat
20
+ * @type {object}
21
+ */
22
+ this.id = data.id;
23
+
24
+ /**
25
+ * Unix timestamp of last status
26
+ * @type {number}
27
+ */
28
+ this.timestamp = data.t;
29
+
30
+ /**
31
+ * Number of available statuses
32
+ * @type {number}
33
+ */
34
+ this.totalCount = data.totalCount;
35
+
36
+ /**
37
+ * Number of not viewed
38
+ * @type {number}
39
+ */
40
+ this.unreadCount = data.unreadCount;
41
+
42
+ /**
43
+ * Messages statuses
44
+ * @type {Message[]}
45
+ */
46
+ this.msgs = data.msgs?.map(msg => new Message(this.client, msg));
47
+
48
+ return super._patch(data);
49
+ }
50
+
51
+ /**
52
+ * Returns the Chat this message was sent in
53
+ * @returns {Promise<Chat>}
54
+ */
55
+ getChat() {
56
+ return this.client.getChatById(this.id._serialized);
57
+ }
58
+
59
+ /**
60
+ * Returns the Contact this message was sent from
61
+ * @returns {Promise<Contact>}
62
+ */
63
+ getContact() {
64
+ return this.client.getContactById(this.id._serialized);
65
+ }
66
+
67
+ }
68
+
69
+ module.exports = Broadcast;
@@ -1,21 +1,21 @@
1
- 'use strict';
2
-
3
- const Contact = require('./Contact');
4
-
5
- /**
6
- * Represents a Business Contact on WhatsApp
7
- * @extends {Contact}
8
- */
9
- class BusinessContact extends Contact {
10
- _patch(data) {
11
- /**
12
- * The contact's business profile
13
- */
14
- this.businessProfile = data.businessProfile;
15
-
16
- return super._patch(data);
17
- }
18
-
19
- }
20
-
1
+ 'use strict';
2
+
3
+ const Contact = require('./Contact');
4
+
5
+ /**
6
+ * Represents a Business Contact on WhatsApp
7
+ * @extends {Contact}
8
+ */
9
+ class BusinessContact extends Contact {
10
+ _patch(data) {
11
+ /**
12
+ * The contact's business profile
13
+ */
14
+ this.businessProfile = data.businessProfile;
15
+
16
+ return super._patch(data);
17
+ }
18
+
19
+ }
20
+
21
21
  module.exports = BusinessContact;
@@ -1,82 +1,82 @@
1
- 'use strict';
2
-
3
- const MessageMedia = require('./MessageMedia');
4
- const Util = require('../util/Util');
5
-
6
- /**
7
- * Button spec used in Buttons constructor
8
- * @typedef {Object} ButtonSpec
9
- * @property {string=} id - Custom ID to set on the button. A random one will be generated if one is not passed.
10
- * @property {string} body - The text to show on the button.
11
- */
12
-
13
- /**
14
- * @typedef {Object} FormattedButtonSpec
15
- * @property {string} buttonId
16
- * @property {number} type
17
- * @property {Object} buttonText
18
- */
19
-
20
- /**
21
- * Message type buttons
22
- */
23
- class Buttons {
24
- /**
25
- * @param {string|MessageMedia} body
26
- * @param {ButtonSpec[]} buttons - See {@link ButtonSpec}
27
- * @param {string?} title
28
- * @param {string?} footer
29
- */
30
- constructor(body, buttons, title, footer) {
31
- /**
32
- * Message body
33
- * @type {string|MessageMedia}
34
- */
35
- this.body = body;
36
-
37
- /**
38
- * title of message
39
- * @type {string}
40
- */
41
- this.title = title;
42
-
43
- /**
44
- * footer of message
45
- * @type {string}
46
- */
47
- this.footer = footer;
48
-
49
- if (body instanceof MessageMedia) {
50
- this.type = 'media';
51
- this.title = '';
52
- }else{
53
- this.type = 'chat';
54
- }
55
-
56
- /**
57
- * buttons of message
58
- * @type {FormattedButtonSpec[]}
59
- */
60
- this.buttons = this._format(buttons);
61
- if(!this.buttons.length){ throw '[BT01] No buttons';}
62
-
63
- }
64
-
65
- /**
66
- * Creates button array from simple array
67
- * @param {ButtonSpec[]} buttons
68
- * @returns {FormattedButtonSpec[]}
69
- * @example
70
- * Input: [{id:'customId',body:'button1'},{body:'button2'},{body:'button3'},{body:'button4'}]
71
- * Returns: [{ buttonId:'customId',buttonText:{'displayText':'button1'},type: 1 },{buttonId:'n3XKsL',buttonText:{'displayText':'button2'},type:1},{buttonId:'NDJk0a',buttonText:{'displayText':'button3'},type:1}]
72
- */
73
- _format(buttons){
74
- buttons = buttons.slice(0,3); // phone users can only see 3 buttons, so lets limit this
75
- return buttons.map((btn) => {
76
- return {'buttonId':btn.id ? String(btn.id) : Util.generateHash(6),'buttonText':{'displayText':btn.body},'type':1};
77
- });
78
- }
79
-
80
- }
81
-
1
+ 'use strict';
2
+
3
+ const MessageMedia = require('./MessageMedia');
4
+ const Util = require('../util/Util');
5
+
6
+ /**
7
+ * Button spec used in Buttons constructor
8
+ * @typedef {Object} ButtonSpec
9
+ * @property {string=} id - Custom ID to set on the button. A random one will be generated if one is not passed.
10
+ * @property {string} body - The text to show on the button.
11
+ */
12
+
13
+ /**
14
+ * @typedef {Object} FormattedButtonSpec
15
+ * @property {string} buttonId
16
+ * @property {number} type
17
+ * @property {Object} buttonText
18
+ */
19
+
20
+ /**
21
+ * Message type buttons
22
+ */
23
+ class Buttons {
24
+ /**
25
+ * @param {string|MessageMedia} body
26
+ * @param {ButtonSpec[]} buttons - See {@link ButtonSpec}
27
+ * @param {string?} title
28
+ * @param {string?} footer
29
+ */
30
+ constructor(body, buttons, title, footer) {
31
+ /**
32
+ * Message body
33
+ * @type {string|MessageMedia}
34
+ */
35
+ this.body = body;
36
+
37
+ /**
38
+ * title of message
39
+ * @type {string}
40
+ */
41
+ this.title = title;
42
+
43
+ /**
44
+ * footer of message
45
+ * @type {string}
46
+ */
47
+ this.footer = footer;
48
+
49
+ if (body instanceof MessageMedia) {
50
+ this.type = 'media';
51
+ this.title = '';
52
+ }else{
53
+ this.type = 'chat';
54
+ }
55
+
56
+ /**
57
+ * buttons of message
58
+ * @type {FormattedButtonSpec[]}
59
+ */
60
+ this.buttons = this._format(buttons);
61
+ if(!this.buttons.length){ throw '[BT01] No buttons';}
62
+
63
+ }
64
+
65
+ /**
66
+ * Creates button array from simple array
67
+ * @param {ButtonSpec[]} buttons
68
+ * @returns {FormattedButtonSpec[]}
69
+ * @example
70
+ * Input: [{id:'customId',body:'button1'},{body:'button2'},{body:'button3'},{body:'button4'}]
71
+ * Returns: [{ buttonId:'customId',buttonText:{'displayText':'button1'},type: 1 },{buttonId:'n3XKsL',buttonText:{'displayText':'button2'},type:1},{buttonId:'NDJk0a',buttonText:{'displayText':'button3'},type:1}]
72
+ */
73
+ _format(buttons){
74
+ buttons = buttons.slice(0,3); // phone users can only see 3 buttons, so lets limit this
75
+ return buttons.map((btn) => {
76
+ return {'buttonId':btn.id ? String(btn.id) : Util.generateHash(6),'buttonText':{'displayText':btn.body},'type':1};
77
+ });
78
+ }
79
+
80
+ }
81
+
82
82
  module.exports = Buttons;
@@ -1,76 +1,76 @@
1
- 'use strict';
2
-
3
- const Base = require('./Base');
4
-
5
- /**
6
- * Represents a Call on WhatsApp
7
- * @extends {Base}
8
- */
9
- class Call extends Base {
10
- constructor(client, data) {
11
- super(client);
12
-
13
- if (data) this._patch(data);
14
- }
15
-
16
- _patch(data) {
17
- /**
18
- * Call ID
19
- * @type {string}
20
- */
21
- this.id = data.id;
22
- /**
23
- * From
24
- * @type {string}
25
- */
26
- this.from = data.peerJid;
27
- /**
28
- * Unix timestamp for when the call was created
29
- * @type {number}
30
- */
31
- this.timestamp = data.offerTime;
32
- /**
33
- * Is video
34
- * @type {boolean}
35
- */
36
- this.isVideo = data.isVideo;
37
- /**
38
- * Is Group
39
- * @type {boolean}
40
- */
41
- this.isGroup = data.isGroup;
42
- /**
43
- * Indicates if the call was sent by the current user
44
- * @type {boolean}
45
- */
46
- this.fromMe = data.outgoing;
47
- /**
48
- * Indicates if the call can be handled in waweb
49
- * @type {boolean}
50
- */
51
- this.canHandleLocally = data.canHandleLocally;
52
- /**
53
- * Indicates if the call Should be handled in waweb
54
- * @type {boolean}
55
- */
56
- this.webClientShouldHandle = data.webClientShouldHandle;
57
- /**
58
- * Object with participants
59
- * @type {object}
60
- */
61
- this.participants = data.participants;
62
-
63
- return super._patch(data);
64
- }
65
-
66
- /**
67
- * Reject the call
68
- */
69
- async reject() {
70
- return this.client.pupPage.evaluate((peerJid, id) => {
71
- return window.WWebJS.rejectCall(peerJid, id);
72
- }, this.from, this.id);
73
- }
74
- }
75
-
1
+ 'use strict';
2
+
3
+ const Base = require('./Base');
4
+
5
+ /**
6
+ * Represents a Call on WhatsApp
7
+ * @extends {Base}
8
+ */
9
+ class Call extends Base {
10
+ constructor(client, data) {
11
+ super(client);
12
+
13
+ if (data) this._patch(data);
14
+ }
15
+
16
+ _patch(data) {
17
+ /**
18
+ * Call ID
19
+ * @type {string}
20
+ */
21
+ this.id = data.id;
22
+ /**
23
+ * From
24
+ * @type {string}
25
+ */
26
+ this.from = data.peerJid;
27
+ /**
28
+ * Unix timestamp for when the call was created
29
+ * @type {number}
30
+ */
31
+ this.timestamp = data.offerTime;
32
+ /**
33
+ * Is video
34
+ * @type {boolean}
35
+ */
36
+ this.isVideo = data.isVideo;
37
+ /**
38
+ * Is Group
39
+ * @type {boolean}
40
+ */
41
+ this.isGroup = data.isGroup;
42
+ /**
43
+ * Indicates if the call was sent by the current user
44
+ * @type {boolean}
45
+ */
46
+ this.fromMe = data.outgoing;
47
+ /**
48
+ * Indicates if the call can be handled in waweb
49
+ * @type {boolean}
50
+ */
51
+ this.canHandleLocally = data.canHandleLocally;
52
+ /**
53
+ * Indicates if the call Should be handled in waweb
54
+ * @type {boolean}
55
+ */
56
+ this.webClientShouldHandle = data.webClientShouldHandle;
57
+ /**
58
+ * Object with participants
59
+ * @type {object}
60
+ */
61
+ this.participants = data.participants;
62
+
63
+ return super._patch(data);
64
+ }
65
+
66
+ /**
67
+ * Reject the call
68
+ */
69
+ async reject() {
70
+ return this.client.pupPage.evaluate((peerJid, id) => {
71
+ return window.WWebJS.rejectCall(peerJid, id);
72
+ }, this.from, this.id);
73
+ }
74
+ }
75
+
76
76
  module.exports = Call;