@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,104 +1,104 @@
1
- 'use strict';
2
-
3
- const Base = require('./Base');
4
-
5
- /**
6
- * Represents a GroupNotification on WhatsApp
7
- * @extends {Base}
8
- */
9
- class GroupNotification extends Base {
10
- constructor(client, data) {
11
- super(client);
12
-
13
- if(data) this._patch(data);
14
- }
15
-
16
- _patch(data) {
17
- /**
18
- * ID that represents the groupNotification
19
- * @type {object}
20
- */
21
- this.id = data.id;
22
-
23
- /**
24
- * Extra content
25
- * @type {string}
26
- */
27
- this.body = data.body || '';
28
-
29
- /**
30
- * GroupNotification type
31
- * @type {GroupNotificationTypes}
32
- */
33
- this.type = data.subtype;
34
-
35
- /**
36
- * Unix timestamp for when the groupNotification was created
37
- * @type {number}
38
- */
39
- this.timestamp = data.t;
40
-
41
- /**
42
- * ID for the Chat that this groupNotification was sent for.
43
- *
44
- * @type {string}
45
- */
46
- this.chatId = typeof (data.id.remote) === 'object' ? data.id.remote._serialized : data.id.remote;
47
-
48
- /**
49
- * ContactId for the user that produced the GroupNotification.
50
- * @type {string}
51
- */
52
- this.author = typeof (data.author) === 'object' ? data.author._serialized : data.author;
53
-
54
- /**
55
- * Contact IDs for the users that were affected by this GroupNotification.
56
- * @type {Array<string>}
57
- */
58
- this.recipientIds = [];
59
-
60
- if (data.recipients) {
61
- this.recipientIds = data.recipients;
62
- }
63
-
64
- return super._patch(data);
65
- }
66
-
67
- /**
68
- * Returns the Chat this groupNotification was sent in
69
- * @returns {Promise<Chat>}
70
- */
71
- getChat() {
72
- return this.client.getChatById(this.chatId);
73
- }
74
-
75
- /**
76
- * Returns the Contact this GroupNotification was produced by
77
- * @returns {Promise<Contact>}
78
- */
79
- getContact() {
80
- return this.client.getContactById(this.author);
81
- }
82
-
83
- /**
84
- * Returns the Contacts affected by this GroupNotification.
85
- * @returns {Promise<Array<Contact>>}
86
- */
87
- async getRecipients() {
88
- return await Promise.all(this.recipientIds.map(async m => await this.client.getContactById(m)));
89
- }
90
-
91
- /**
92
- * Sends a message to the same chat this GroupNotification was produced in.
93
- *
94
- * @param {string|MessageMedia|Location} content
95
- * @param {object} options
96
- * @returns {Promise<Message>}
97
- */
98
- async reply(content, options={}) {
99
- return this.client.sendMessage(this.chatId, content, options);
100
- }
101
-
102
- }
103
-
104
- module.exports = GroupNotification;
1
+ 'use strict';
2
+
3
+ const Base = require('./Base');
4
+
5
+ /**
6
+ * Represents a GroupNotification on WhatsApp
7
+ * @extends {Base}
8
+ */
9
+ class GroupNotification extends Base {
10
+ constructor(client, data) {
11
+ super(client);
12
+
13
+ if(data) this._patch(data);
14
+ }
15
+
16
+ _patch(data) {
17
+ /**
18
+ * ID that represents the groupNotification
19
+ * @type {object}
20
+ */
21
+ this.id = data.id;
22
+
23
+ /**
24
+ * Extra content
25
+ * @type {string}
26
+ */
27
+ this.body = data.body || '';
28
+
29
+ /**
30
+ * GroupNotification type
31
+ * @type {GroupNotificationTypes}
32
+ */
33
+ this.type = data.subtype;
34
+
35
+ /**
36
+ * Unix timestamp for when the groupNotification was created
37
+ * @type {number}
38
+ */
39
+ this.timestamp = data.t;
40
+
41
+ /**
42
+ * ID for the Chat that this groupNotification was sent for.
43
+ *
44
+ * @type {string}
45
+ */
46
+ this.chatId = typeof (data.id.remote) === 'object' ? data.id.remote._serialized : data.id.remote;
47
+
48
+ /**
49
+ * ContactId for the user that produced the GroupNotification.
50
+ * @type {string}
51
+ */
52
+ this.author = typeof (data.author) === 'object' ? data.author._serialized : data.author;
53
+
54
+ /**
55
+ * Contact IDs for the users that were affected by this GroupNotification.
56
+ * @type {Array<string>}
57
+ */
58
+ this.recipientIds = [];
59
+
60
+ if (data.recipients) {
61
+ this.recipientIds = data.recipients;
62
+ }
63
+
64
+ return super._patch(data);
65
+ }
66
+
67
+ /**
68
+ * Returns the Chat this groupNotification was sent in
69
+ * @returns {Promise<Chat>}
70
+ */
71
+ getChat() {
72
+ return this.client.getChatById(this.chatId);
73
+ }
74
+
75
+ /**
76
+ * Returns the Contact this GroupNotification was produced by
77
+ * @returns {Promise<Contact>}
78
+ */
79
+ getContact() {
80
+ return this.client.getContactById(this.author);
81
+ }
82
+
83
+ /**
84
+ * Returns the Contacts affected by this GroupNotification.
85
+ * @returns {Promise<Array<Contact>>}
86
+ */
87
+ async getRecipients() {
88
+ return await Promise.all(this.recipientIds.map(async m => await this.client.getContactById(m)));
89
+ }
90
+
91
+ /**
92
+ * Sends a message to the same chat this GroupNotification was produced in.
93
+ *
94
+ * @param {string|MessageMedia|Location} content
95
+ * @param {object} options
96
+ * @returns {Promise<Message>}
97
+ */
98
+ async reply(content, options={}) {
99
+ return this.client.sendMessage(this.chatId, content, options);
100
+ }
101
+
102
+ }
103
+
104
+ module.exports = GroupNotification;
@@ -1,50 +1,50 @@
1
- 'use strict';
2
-
3
- const Base = require('./Base');
4
- // eslint-disable-next-line no-unused-vars
5
- const Chat = require('./Chat');
6
-
7
- /**
8
- * WhatsApp Business Label information
9
- */
10
- class Label extends Base {
11
- /**
12
- * @param {Base} client
13
- * @param {object} labelData
14
- */
15
- constructor(client, labelData){
16
- super(client);
17
-
18
- if(labelData) this._patch(labelData);
19
- }
20
-
21
- _patch(labelData){
22
- /**
23
- * Label ID
24
- * @type {string}
25
- */
26
- this.id = labelData.id;
27
-
28
- /**
29
- * Label name
30
- * @type {string}
31
- */
32
- this.name = labelData.name;
33
-
34
- /**
35
- * Label hex color
36
- * @type {string}
37
- */
38
- this.hexColor = labelData.hexColor;
39
- }
40
- /**
41
- * Get all chats that have been assigned this Label
42
- * @returns {Promise<Array<Chat>>}
43
- */
44
- async getChats(){
45
- return this.client.getChatsByLabelId(this.id);
46
- }
47
-
48
- }
49
-
1
+ 'use strict';
2
+
3
+ const Base = require('./Base');
4
+ // eslint-disable-next-line no-unused-vars
5
+ const Chat = require('./Chat');
6
+
7
+ /**
8
+ * WhatsApp Business Label information
9
+ */
10
+ class Label extends Base {
11
+ /**
12
+ * @param {Base} client
13
+ * @param {object} labelData
14
+ */
15
+ constructor(client, labelData){
16
+ super(client);
17
+
18
+ if(labelData) this._patch(labelData);
19
+ }
20
+
21
+ _patch(labelData){
22
+ /**
23
+ * Label ID
24
+ * @type {string}
25
+ */
26
+ this.id = labelData.id;
27
+
28
+ /**
29
+ * Label name
30
+ * @type {string}
31
+ */
32
+ this.name = labelData.name;
33
+
34
+ /**
35
+ * Label hex color
36
+ * @type {string}
37
+ */
38
+ this.hexColor = labelData.hexColor;
39
+ }
40
+ /**
41
+ * Get all chats that have been assigned this Label
42
+ * @returns {Promise<Array<Chat>>}
43
+ */
44
+ async getChats(){
45
+ return this.client.getChatsByLabelId(this.id);
46
+ }
47
+
48
+ }
49
+
50
50
  module.exports = Label;
@@ -1,79 +1,79 @@
1
- 'use strict';
2
-
3
- const Util = require('../util/Util');
4
-
5
- /**
6
- * Message type List
7
- */
8
- class List {
9
- /**
10
- * @param {string} body
11
- * @param {string} buttonText
12
- * @param {Array<any>} sections
13
- * @param {string?} title
14
- * @param {string?} footer
15
- */
16
- constructor(body, buttonText, sections, title, footer) {
17
- /**
18
- * Message body
19
- * @type {string}
20
- */
21
- this.description = body;
22
-
23
- /**
24
- * List button text
25
- * @type {string}
26
- */
27
- this.buttonText = buttonText;
28
-
29
- /**
30
- * title of message
31
- * @type {string}
32
- */
33
- this.title = title;
34
-
35
-
36
- /**
37
- * footer of message
38
- * @type {string}
39
- */
40
- this.footer = footer;
41
-
42
- /**
43
- * sections of message
44
- * @type {Array<any>}
45
- */
46
- this.sections = this._format(sections);
47
-
48
- }
49
-
50
- /**
51
- * Creates section array from simple array
52
- * @param {Array<any>} sections
53
- * @returns {Array<any>}
54
- * @example
55
- * Input: [{title:'sectionTitle',rows:[{id:'customId', title:'ListItem2', description: 'desc'},{title:'ListItem2'}]}}]
56
- * Returns: [{'title':'sectionTitle','rows':[{'rowId':'customId','title':'ListItem1','description':'desc'},{'rowId':'oGSRoD','title':'ListItem2','description':''}]}]
57
- */
58
- _format(sections){
59
- if(!sections.length){throw '[LT02] List without sections';}
60
- if(sections.length > 1 && sections.filter(s => typeof s.title == 'undefined').length > 1){throw '[LT05] You can\'t have more than one empty title.';}
61
- return sections.map( (section) =>{
62
- if(!section.rows.length){throw '[LT03] Section without rows';}
63
- return {
64
- title: section.title ? section.title : undefined,
65
- rows: section.rows.map( (row) => {
66
- if(!row.title){throw '[LT04] Row without title';}
67
- return {
68
- rowId: row.id ? row.id : Util.generateHash(6),
69
- title: row.title,
70
- description: row.description ? row.description : ''
71
- };
72
- })
73
- };
74
- });
75
- }
76
-
77
- }
78
-
79
- module.exports = List;
1
+ 'use strict';
2
+
3
+ const Util = require('../util/Util');
4
+
5
+ /**
6
+ * Message type List
7
+ */
8
+ class List {
9
+ /**
10
+ * @param {string} body
11
+ * @param {string} buttonText
12
+ * @param {Array<any>} sections
13
+ * @param {string?} title
14
+ * @param {string?} footer
15
+ */
16
+ constructor(body, buttonText, sections, title, footer) {
17
+ /**
18
+ * Message body
19
+ * @type {string}
20
+ */
21
+ this.description = body;
22
+
23
+ /**
24
+ * List button text
25
+ * @type {string}
26
+ */
27
+ this.buttonText = buttonText;
28
+
29
+ /**
30
+ * title of message
31
+ * @type {string}
32
+ */
33
+ this.title = title;
34
+
35
+
36
+ /**
37
+ * footer of message
38
+ * @type {string}
39
+ */
40
+ this.footer = footer;
41
+
42
+ /**
43
+ * sections of message
44
+ * @type {Array<any>}
45
+ */
46
+ this.sections = this._format(sections);
47
+
48
+ }
49
+
50
+ /**
51
+ * Creates section array from simple array
52
+ * @param {Array<any>} sections
53
+ * @returns {Array<any>}
54
+ * @example
55
+ * Input: [{title:'sectionTitle',rows:[{id:'customId', title:'ListItem2', description: 'desc'},{title:'ListItem2'}]}}]
56
+ * Returns: [{'title':'sectionTitle','rows':[{'rowId':'customId','title':'ListItem1','description':'desc'},{'rowId':'oGSRoD','title':'ListItem2','description':''}]}]
57
+ */
58
+ _format(sections){
59
+ if(!sections.length){throw '[LT02] List without sections';}
60
+ if(sections.length > 1 && sections.filter(s => typeof s.title == 'undefined').length > 1){throw '[LT05] You can\'t have more than one empty title.';}
61
+ return sections.map( (section) =>{
62
+ if(!section.rows.length){throw '[LT03] Section without rows';}
63
+ return {
64
+ title: section.title ? section.title : undefined,
65
+ rows: section.rows.map( (row) => {
66
+ if(!row.title){throw '[LT04] Row without title';}
67
+ return {
68
+ rowId: row.id ? row.id : Util.generateHash(6),
69
+ title: row.title,
70
+ description: row.description ? row.description : ''
71
+ };
72
+ })
73
+ };
74
+ });
75
+ }
76
+
77
+ }
78
+
79
+ module.exports = List;
@@ -1,62 +1,62 @@
1
- 'use strict';
2
-
3
- /**
4
- * Location send options
5
- * @typedef {Object} LocationSendOptions
6
- * @property {string} [name] Location name
7
- * @property {string} [address] Location address
8
- * @property {string} [url] URL address to be shown within a location message
9
- * @property {string} [description] Location full description
10
- */
11
-
12
- /**
13
- * Location information
14
- */
15
- class Location {
16
- /**
17
- * @param {number} latitude
18
- * @param {number} longitude
19
- * @param {LocationSendOptions} [options] Location send options
20
- */
21
- constructor(latitude, longitude, options = {}) {
22
- /**
23
- * Location latitude
24
- * @type {number}
25
- */
26
- this.latitude = latitude;
27
-
28
- /**
29
- * Location longitude
30
- * @type {number}
31
- */
32
- this.longitude = longitude;
33
-
34
- /**
35
- * Name for the location
36
- * @type {string|undefined}
37
- */
38
- this.name = options.name;
39
-
40
- /**
41
- * Location address
42
- * @type {string|undefined}
43
- */
44
- this.address = options.address;
45
-
46
- /**
47
- * URL address to be shown within a location message
48
- * @type {string|undefined}
49
- */
50
- this.url = options.url;
51
-
52
- /**
53
- * Location full description
54
- * @type {string|undefined}
55
- */
56
- this.description = this.name && this.address
57
- ? `${this.name}\n${this.address}`
58
- : this.name || this.address || '';
59
- }
60
- }
61
-
1
+ 'use strict';
2
+
3
+ /**
4
+ * Location send options
5
+ * @typedef {Object} LocationSendOptions
6
+ * @property {string} [name] Location name
7
+ * @property {string} [address] Location address
8
+ * @property {string} [url] URL address to be shown within a location message
9
+ * @property {string} [description] Location full description
10
+ */
11
+
12
+ /**
13
+ * Location information
14
+ */
15
+ class Location {
16
+ /**
17
+ * @param {number} latitude
18
+ * @param {number} longitude
19
+ * @param {LocationSendOptions} [options] Location send options
20
+ */
21
+ constructor(latitude, longitude, options = {}) {
22
+ /**
23
+ * Location latitude
24
+ * @type {number}
25
+ */
26
+ this.latitude = latitude;
27
+
28
+ /**
29
+ * Location longitude
30
+ * @type {number}
31
+ */
32
+ this.longitude = longitude;
33
+
34
+ /**
35
+ * Name for the location
36
+ * @type {string|undefined}
37
+ */
38
+ this.name = options.name;
39
+
40
+ /**
41
+ * Location address
42
+ * @type {string|undefined}
43
+ */
44
+ this.address = options.address;
45
+
46
+ /**
47
+ * URL address to be shown within a location message
48
+ * @type {string|undefined}
49
+ */
50
+ this.url = options.url;
51
+
52
+ /**
53
+ * Location full description
54
+ * @type {string|undefined}
55
+ */
56
+ this.description = this.name && this.address
57
+ ? `${this.name}\n${this.address}`
58
+ : this.name || this.address || '';
59
+ }
60
+ }
61
+
62
62
  module.exports = Location;