@pney/whatsapp-web 1.34.6 → 1.34.7-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.
- package/.env.example +0 -1
- package/.gitattributes +4 -0
- package/.husky/commit-msg +4 -0
- package/.husky/pre-commit +1 -0
- package/.lintstagedrc.json +6 -0
- package/.prettierignore +8 -0
- package/.prettierrc.json +10 -0
- package/README.md +83 -80
- package/commitlint.config.js +29 -0
- package/eslint.config.mjs +67 -0
- package/example.js +151 -71
- package/index.d.ts +982 -734
- package/index.js +4 -4
- package/package.json +3 -3
- package/shell.js +4 -4
- package/src/Client.js +1860 -920
- package/src/authStrategies/BaseAuthStrategy.js +4 -2
- package/src/authStrategies/LocalAuth.js +25 -12
- package/src/authStrategies/NoAuth.js +3 -4
- package/src/authStrategies/RemoteAuth.js +92 -43
- package/src/factories/ChatFactory.js +1 -1
- package/src/factories/ContactFactory.js +2 -2
- package/src/structures/Base.js +5 -3
- package/src/structures/Broadcast.js +1 -2
- package/src/structures/BusinessContact.js +1 -2
- package/src/structures/Buttons.js +14 -10
- package/src/structures/Call.js +10 -6
- package/src/structures/Channel.js +171 -91
- package/src/structures/Chat.js +57 -41
- package/src/structures/ClientInfo.js +1 -1
- package/src/structures/Contact.js +37 -16
- package/src/structures/GroupChat.js +425 -228
- package/src/structures/GroupNotification.js +21 -12
- package/src/structures/Label.js +6 -6
- package/src/structures/List.js +22 -14
- package/src/structures/Location.js +5 -4
- package/src/structures/Message.js +412 -168
- package/src/structures/MessageMedia.js +31 -18
- package/src/structures/Order.js +4 -4
- package/src/structures/Payment.js +6 -3
- package/src/structures/Poll.js +2 -2
- package/src/structures/PollVote.js +9 -6
- package/src/structures/PrivateChat.js +2 -4
- package/src/structures/PrivateContact.js +2 -4
- package/src/structures/Product.js +1 -1
- package/src/structures/ProductMetadata.js +1 -2
- package/src/structures/Reaction.js +2 -4
- package/src/structures/ScheduledEvent.js +22 -10
- package/src/util/Constants.js +8 -6
- package/src/util/Injected/AuthStore/AuthStore.js +7 -3
- package/src/util/Injected/Utils.js +753 -345
- package/src/util/InterfaceController.js +72 -25
- package/src/util/Puppeteer.js +1 -1
- package/src/util/Util.js +28 -15
- package/src/webCache/LocalWebCache.js +7 -5
- package/src/webCache/RemoteWebCache.js +10 -4
- package/src/webCache/WebCache.js +8 -5
- package/src/webCache/WebCacheFactory.js +9 -9
- package/CODE_OF_CONDUCT.md +0 -133
|
@@ -32,7 +32,7 @@ class MessageMedia {
|
|
|
32
32
|
* @type {?string}
|
|
33
33
|
*/
|
|
34
34
|
this.filename = filename;
|
|
35
|
-
|
|
35
|
+
|
|
36
36
|
/**
|
|
37
37
|
* Document file size in bytes. Value can be null
|
|
38
38
|
* @type {?number}
|
|
@@ -42,12 +42,12 @@ class MessageMedia {
|
|
|
42
42
|
|
|
43
43
|
/**
|
|
44
44
|
* Creates a MessageMedia instance from a local file path
|
|
45
|
-
* @param {string} filePath
|
|
45
|
+
* @param {string} filePath
|
|
46
46
|
* @returns {MessageMedia}
|
|
47
47
|
*/
|
|
48
48
|
static fromFilePath(filePath) {
|
|
49
|
-
const b64data = fs.readFileSync(filePath, {encoding: 'base64'});
|
|
50
|
-
const mimetype = mime.getType(filePath);
|
|
49
|
+
const b64data = fs.readFileSync(filePath, { encoding: 'base64' });
|
|
50
|
+
const mimetype = mime.getType(filePath);
|
|
51
51
|
const filename = path.basename(filePath);
|
|
52
52
|
|
|
53
53
|
return new MessageMedia(mimetype, b64data, filename);
|
|
@@ -69,16 +69,25 @@ class MessageMedia {
|
|
|
69
69
|
let mimetype = mime.getType(pUrl.pathname);
|
|
70
70
|
|
|
71
71
|
if (!mimetype && !options.unsafeMime)
|
|
72
|
-
throw new Error(
|
|
72
|
+
throw new Error(
|
|
73
|
+
'Unable to determine MIME type using URL. Set unsafeMime to true to download it anyway.',
|
|
74
|
+
);
|
|
73
75
|
|
|
74
|
-
async function fetchData
|
|
75
|
-
const reqOptions = Object.assign(
|
|
76
|
+
async function fetchData(url, options) {
|
|
77
|
+
const reqOptions = Object.assign(
|
|
78
|
+
{ headers: { accept: 'image/* video/* text/* audio/*' } },
|
|
79
|
+
options,
|
|
80
|
+
);
|
|
76
81
|
const response = await fetch(url, reqOptions);
|
|
77
82
|
const mime = response.headers.get('Content-Type');
|
|
78
83
|
const size = response.headers.get('Content-Length');
|
|
79
84
|
|
|
80
|
-
const contentDisposition = response.headers.get(
|
|
81
|
-
|
|
85
|
+
const contentDisposition = response.headers.get(
|
|
86
|
+
'Content-Disposition',
|
|
87
|
+
);
|
|
88
|
+
const name = contentDisposition
|
|
89
|
+
? contentDisposition.match(/((?<=filename=")(.*)(?="))/)
|
|
90
|
+
: null;
|
|
82
91
|
|
|
83
92
|
let data = '';
|
|
84
93
|
if (response.buffer) {
|
|
@@ -90,19 +99,23 @@ class MessageMedia {
|
|
|
90
99
|
});
|
|
91
100
|
data = btoa(data);
|
|
92
101
|
}
|
|
93
|
-
|
|
102
|
+
|
|
94
103
|
return { data, mime, name, size };
|
|
95
104
|
}
|
|
96
105
|
|
|
97
106
|
const res = options.client
|
|
98
|
-
?
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
107
|
+
? await options.client.pupPage.evaluate(
|
|
108
|
+
fetchData,
|
|
109
|
+
url,
|
|
110
|
+
options.reqOptions,
|
|
111
|
+
)
|
|
112
|
+
: await fetchData(url, options.reqOptions);
|
|
113
|
+
|
|
114
|
+
const filename =
|
|
115
|
+
options.filename ||
|
|
116
|
+
(res.name ? res.name[0] : pUrl.pathname.split('/').pop() || 'file');
|
|
117
|
+
|
|
118
|
+
if (!mimetype) mimetype = res.mime;
|
|
106
119
|
|
|
107
120
|
return new MessageMedia(mimetype, res.data, filename, res.size || null);
|
|
108
121
|
}
|
package/src/structures/Order.js
CHANGED
|
@@ -20,7 +20,9 @@ class Order extends Base {
|
|
|
20
20
|
* @type {Array<Product>}
|
|
21
21
|
*/
|
|
22
22
|
if (data.products) {
|
|
23
|
-
this.products = data.products.map(
|
|
23
|
+
this.products = data.products.map(
|
|
24
|
+
(product) => new Product(this.client, product),
|
|
25
|
+
);
|
|
24
26
|
}
|
|
25
27
|
/**
|
|
26
28
|
* Order Subtotal
|
|
@@ -45,8 +47,6 @@ class Order extends Base {
|
|
|
45
47
|
|
|
46
48
|
return super._patch(data);
|
|
47
49
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
module.exports = Order;
|
|
52
|
+
module.exports = Order;
|
|
@@ -54,7 +54,7 @@ class Payment extends Base {
|
|
|
54
54
|
* 9:CANCELLED
|
|
55
55
|
* 10:WAITING_FOR_PAYER
|
|
56
56
|
* 11:WAITING
|
|
57
|
-
*
|
|
57
|
+
*
|
|
58
58
|
* @type {number}
|
|
59
59
|
*/
|
|
60
60
|
this.paymentStatus = data.paymentStatus;
|
|
@@ -69,11 +69,14 @@ class Payment extends Base {
|
|
|
69
69
|
* The note sent with the payment
|
|
70
70
|
* @type {string}
|
|
71
71
|
*/
|
|
72
|
-
this.paymentNote = !data.paymentNoteMsg
|
|
72
|
+
this.paymentNote = !data.paymentNoteMsg
|
|
73
|
+
? undefined
|
|
74
|
+
: data.paymentNoteMsg.body
|
|
75
|
+
? data.paymentNoteMsg.body
|
|
76
|
+
: undefined;
|
|
73
77
|
|
|
74
78
|
return super._patch(data);
|
|
75
79
|
}
|
|
76
|
-
|
|
77
80
|
}
|
|
78
81
|
|
|
79
82
|
module.exports = Payment;
|
package/src/structures/Poll.js
CHANGED
|
@@ -27,7 +27,7 @@ class Poll {
|
|
|
27
27
|
*/
|
|
28
28
|
this.pollOptions = pollOptions.map((option, index) => ({
|
|
29
29
|
name: option.trim(),
|
|
30
|
-
localId: index
|
|
30
|
+
localId: index,
|
|
31
31
|
}));
|
|
32
32
|
|
|
33
33
|
/**
|
|
@@ -36,7 +36,7 @@ class Poll {
|
|
|
36
36
|
*/
|
|
37
37
|
this.options = {
|
|
38
38
|
allowMultipleAnswers: options.allowMultipleAnswers === true,
|
|
39
|
-
messageSecret: options.messageSecret
|
|
39
|
+
messageSecret: options.messageSecret,
|
|
40
40
|
};
|
|
41
41
|
}
|
|
42
42
|
}
|
|
@@ -35,21 +35,24 @@ class PollVote extends Base {
|
|
|
35
35
|
* @type {SelectedPollOption[]}
|
|
36
36
|
*/
|
|
37
37
|
if (data.selectedOptionLocalIds.length > 0) {
|
|
38
|
-
if(data.parentMessage) {
|
|
38
|
+
if (data.parentMessage) {
|
|
39
|
+
// temporary failsafe
|
|
39
40
|
this.selectedOptions = data.selectedOptionLocalIds.map((e) => ({
|
|
40
|
-
name: data.parentMessage.pollOptions.find(
|
|
41
|
-
|
|
41
|
+
name: data.parentMessage.pollOptions.find(
|
|
42
|
+
(x) => x.localId === e,
|
|
43
|
+
).name,
|
|
44
|
+
localId: e,
|
|
42
45
|
}));
|
|
43
46
|
} else {
|
|
44
47
|
this.selectedOptions = data.selectedOptionLocalIds.map((e) => ({
|
|
45
48
|
name: undefined,
|
|
46
|
-
localId: e
|
|
49
|
+
localId: e,
|
|
47
50
|
}));
|
|
48
51
|
}
|
|
49
52
|
} else {
|
|
50
53
|
this.selectedOptions = [];
|
|
51
54
|
}
|
|
52
|
-
|
|
55
|
+
|
|
53
56
|
/**
|
|
54
57
|
* Timestamp the option was selected or deselected at
|
|
55
58
|
* @type {number}
|
|
@@ -66,7 +69,7 @@ class PollVote extends Base {
|
|
|
66
69
|
* The poll creation message id
|
|
67
70
|
* @type {Object}
|
|
68
71
|
*/
|
|
69
|
-
this.parentMsgKey =
|
|
72
|
+
this.parentMsgKey = data.parentMsgKey;
|
|
70
73
|
|
|
71
74
|
return super._patch(data);
|
|
72
75
|
}
|
|
@@ -6,8 +6,6 @@ const Contact = require('./Contact');
|
|
|
6
6
|
* Represents a Private Contact on WhatsApp
|
|
7
7
|
* @extends {Contact}
|
|
8
8
|
*/
|
|
9
|
-
class PrivateContact extends Contact {
|
|
9
|
+
class PrivateContact extends Contact {}
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
module.exports = PrivateContact;
|
|
11
|
+
module.exports = PrivateContact;
|
|
@@ -37,11 +37,13 @@ class ScheduledEvent {
|
|
|
37
37
|
*/
|
|
38
38
|
this.eventSendOptions = {
|
|
39
39
|
description: options.description?.trim(),
|
|
40
|
-
endTimeTs: options.endTime
|
|
40
|
+
endTimeTs: options.endTime
|
|
41
|
+
? Math.floor(options.endTime.getTime() / 1000)
|
|
42
|
+
: null,
|
|
41
43
|
location: options.location?.trim(),
|
|
42
44
|
callType: this._validateInputs('callType', options.callType),
|
|
43
45
|
isEventCanceled: options.isEventCanceled ?? false,
|
|
44
|
-
messageSecret: options.messageSecret
|
|
46
|
+
messageSecret: options.messageSecret,
|
|
45
47
|
};
|
|
46
48
|
}
|
|
47
49
|
|
|
@@ -53,17 +55,27 @@ class ScheduledEvent {
|
|
|
53
55
|
*/
|
|
54
56
|
_validateInputs(propName, propValue) {
|
|
55
57
|
if (propName === 'name' && !propValue) {
|
|
56
|
-
throw new class CreateScheduledEventError extends Error {
|
|
57
|
-
constructor(m) {
|
|
58
|
-
|
|
58
|
+
throw new (class CreateScheduledEventError extends Error {
|
|
59
|
+
constructor(m) {
|
|
60
|
+
super(m);
|
|
61
|
+
}
|
|
62
|
+
})(`Empty '${propName}' parameter value is provided.`);
|
|
59
63
|
}
|
|
60
64
|
|
|
61
|
-
if (
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
+
if (
|
|
66
|
+
propName === 'callType' &&
|
|
67
|
+
propValue &&
|
|
68
|
+
!['video', 'voice', 'none'].includes(propValue)
|
|
69
|
+
) {
|
|
70
|
+
throw new (class CreateScheduledEventError extends Error {
|
|
71
|
+
constructor(m) {
|
|
72
|
+
super(m);
|
|
73
|
+
}
|
|
74
|
+
})(
|
|
75
|
+
`Invalid '${propName}' parameter value is provided. Valid values are: 'voice' | 'video' | 'none'.`,
|
|
76
|
+
);
|
|
65
77
|
}
|
|
66
|
-
|
|
78
|
+
|
|
67
79
|
return propValue;
|
|
68
80
|
}
|
|
69
81
|
}
|
package/src/util/Constants.js
CHANGED
|
@@ -5,7 +5,7 @@ exports.WhatsWebURL = 'https://web.whatsapp.com/';
|
|
|
5
5
|
exports.DefaultOptions = {
|
|
6
6
|
puppeteer: {
|
|
7
7
|
headless: true,
|
|
8
|
-
defaultViewport: null
|
|
8
|
+
defaultViewport: null,
|
|
9
9
|
},
|
|
10
10
|
webVersion: '2.3000.1017054665',
|
|
11
11
|
webVersionCache: {
|
|
@@ -15,7 +15,8 @@ exports.DefaultOptions = {
|
|
|
15
15
|
qrMaxRetries: 0,
|
|
16
16
|
takeoverOnConflict: false,
|
|
17
17
|
takeoverTimeoutMs: 0,
|
|
18
|
-
userAgent:
|
|
18
|
+
userAgent:
|
|
19
|
+
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.67 Safari/537.36',
|
|
19
20
|
ffmpegPath: 'ffmpeg',
|
|
20
21
|
bypassCSP: false,
|
|
21
22
|
proxyAuthentication: undefined,
|
|
@@ -34,7 +35,7 @@ exports.DefaultOptions = {
|
|
|
34
35
|
exports.Status = {
|
|
35
36
|
INITIALIZING: 0,
|
|
36
37
|
AUTHENTICATING: 1,
|
|
37
|
-
READY: 3
|
|
38
|
+
READY: 3,
|
|
38
39
|
};
|
|
39
40
|
|
|
40
41
|
/**
|
|
@@ -50,6 +51,7 @@ exports.Events = {
|
|
|
50
51
|
CHAT_ARCHIVED: 'chat_archived',
|
|
51
52
|
MESSAGE_RECEIVED: 'message',
|
|
52
53
|
MESSAGE_CIPHERTEXT: 'message_ciphertext',
|
|
54
|
+
MESSAGE_CIPHERTEXT_FAILED: 'message_ciphertext_failed',
|
|
53
55
|
MESSAGE_CREATE: 'message_create',
|
|
54
56
|
MESSAGE_REVOKED_EVERYONE: 'message_revoke_everyone',
|
|
55
57
|
MESSAGE_REVOKED_ME: 'message_revoke_me',
|
|
@@ -72,7 +74,7 @@ exports.Events = {
|
|
|
72
74
|
BATTERY_CHANGED: 'change_battery',
|
|
73
75
|
INCOMING_CALL: 'call',
|
|
74
76
|
REMOTE_SESSION_SAVED: 'remote_session_saved',
|
|
75
|
-
VOTE_UPDATE: 'vote_update'
|
|
77
|
+
VOTE_UPDATE: 'vote_update',
|
|
76
78
|
};
|
|
77
79
|
|
|
78
80
|
/**
|
|
@@ -148,7 +150,7 @@ exports.GroupNotificationTypes = {
|
|
|
148
150
|
exports.ChatTypes = {
|
|
149
151
|
SOLO: 'solo',
|
|
150
152
|
GROUP: 'group',
|
|
151
|
-
UNKNOWN: 'unknown'
|
|
153
|
+
UNKNOWN: 'unknown',
|
|
152
154
|
};
|
|
153
155
|
|
|
154
156
|
/**
|
|
@@ -168,7 +170,7 @@ exports.WAState = {
|
|
|
168
170
|
TOS_BLOCK: 'TOS_BLOCK',
|
|
169
171
|
UNLAUNCHED: 'UNLAUNCHED',
|
|
170
172
|
UNPAIRED: 'UNPAIRED',
|
|
171
|
-
UNPAIRED_IDLE: 'UNPAIRED_IDLE'
|
|
173
|
+
UNPAIRED_IDLE: 'UNPAIRED_IDLE',
|
|
172
174
|
};
|
|
173
175
|
|
|
174
176
|
/**
|
|
@@ -5,8 +5,12 @@ exports.ExposeAuthStore = () => {
|
|
|
5
5
|
window.AuthStore.AppState = window.require('WAWebSocketModel').Socket;
|
|
6
6
|
window.AuthStore.Cmd = window.require('WAWebCmd').Cmd;
|
|
7
7
|
window.AuthStore.Conn = window.require('WAWebConnModel').Conn;
|
|
8
|
-
window.AuthStore.OfflineMessageHandler = window.require(
|
|
9
|
-
|
|
8
|
+
window.AuthStore.OfflineMessageHandler = window.require(
|
|
9
|
+
'WAWebOfflineHandler',
|
|
10
|
+
).OfflineMessageHandler;
|
|
11
|
+
window.AuthStore.PairingCodeLinkUtils = window.require(
|
|
12
|
+
'WAWebAltDeviceLinkingApi',
|
|
13
|
+
);
|
|
10
14
|
window.AuthStore.Base64Tools = window.require('WABase64');
|
|
11
15
|
window.AuthStore.RegistrationUtils = {
|
|
12
16
|
...window.require('WAWebCompanionRegClientUtils'),
|
|
@@ -14,4 +18,4 @@ exports.ExposeAuthStore = () => {
|
|
|
14
18
|
...window.require('WAWebUserPrefsInfoStore'),
|
|
15
19
|
...window.require('WAWebSignalStoreApi'),
|
|
16
20
|
};
|
|
17
|
-
};
|
|
21
|
+
};
|