whatsapp-web-jf.js 1.31.0
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 +3 -0
- package/CODE_OF_CONDUCT.md +133 -0
- package/LICENSE +201 -0
- package/README.md +185 -0
- package/example.js +680 -0
- package/index.d.ts +2069 -0
- package/index.js +34 -0
- package/package.json +55 -0
- package/shell.js +36 -0
- package/src/Client.js +2188 -0
- package/src/authStrategies/BaseAuthStrategy.js +27 -0
- package/src/authStrategies/LocalAuth.js +58 -0
- package/src/authStrategies/NoAuth.js +12 -0
- package/src/authStrategies/RemoteAuth.js +210 -0
- package/src/factories/ChatFactory.js +21 -0
- package/src/factories/ContactFactory.js +16 -0
- package/src/structures/Base.js +22 -0
- package/src/structures/Broadcast.js +69 -0
- package/src/structures/BusinessContact.js +21 -0
- package/src/structures/Buttons.js +82 -0
- package/src/structures/Call.js +76 -0
- package/src/structures/Channel.js +382 -0
- package/src/structures/Chat.js +291 -0
- package/src/structures/ClientInfo.js +71 -0
- package/src/structures/Contact.js +208 -0
- package/src/structures/GroupChat.js +473 -0
- package/src/structures/GroupNotification.js +104 -0
- package/src/structures/Label.js +50 -0
- package/src/structures/List.js +79 -0
- package/src/structures/Location.js +62 -0
- package/src/structures/Message.js +704 -0
- package/src/structures/MessageMedia.js +111 -0
- package/src/structures/Order.js +52 -0
- package/src/structures/Payment.js +79 -0
- package/src/structures/Poll.js +44 -0
- package/src/structures/PollVote.js +61 -0
- package/src/structures/PrivateChat.js +13 -0
- package/src/structures/PrivateContact.js +13 -0
- package/src/structures/Product.js +68 -0
- package/src/structures/ProductMetadata.js +25 -0
- package/src/structures/Reaction.js +69 -0
- package/src/structures/index.js +26 -0
- package/src/util/Constants.js +176 -0
- package/src/util/Injected/AuthStore/AuthStore.js +17 -0
- package/src/util/Injected/AuthStore/LegacyAuthStore.js +22 -0
- package/src/util/Injected/LegacyStore.js +146 -0
- package/src/util/Injected/Store.js +215 -0
- package/src/util/Injected/Utils.js +1139 -0
- package/src/util/InterfaceController.js +126 -0
- package/src/util/Puppeteer.js +23 -0
- package/src/util/Util.js +186 -0
- package/src/webCache/LocalWebCache.js +40 -0
- package/src/webCache/RemoteWebCache.js +40 -0
- package/src/webCache/WebCache.js +14 -0
- package/src/webCache/WebCacheFactory.js +20 -0
@@ -0,0 +1,71 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
const Base = require('./Base');
|
4
|
+
|
5
|
+
/**
|
6
|
+
* Current connection information
|
7
|
+
* @extends {Base}
|
8
|
+
*/
|
9
|
+
class ClientInfo extends Base {
|
10
|
+
constructor(client, data) {
|
11
|
+
super(client);
|
12
|
+
|
13
|
+
if (data) this._patch(data);
|
14
|
+
}
|
15
|
+
|
16
|
+
_patch(data) {
|
17
|
+
/**
|
18
|
+
* Name configured to be shown in push notifications
|
19
|
+
* @type {string}
|
20
|
+
*/
|
21
|
+
this.pushname = data.pushname;
|
22
|
+
|
23
|
+
/**
|
24
|
+
* Current user ID
|
25
|
+
* @type {object}
|
26
|
+
*/
|
27
|
+
this.wid = data.wid;
|
28
|
+
|
29
|
+
/**
|
30
|
+
* @type {object}
|
31
|
+
* @deprecated Use .wid instead
|
32
|
+
*/
|
33
|
+
this.me = data.wid;
|
34
|
+
|
35
|
+
/**
|
36
|
+
* Information about the phone this client is connected to. Not available in multi-device.
|
37
|
+
* @type {object}
|
38
|
+
* @property {string} wa_version WhatsApp Version running on the phone
|
39
|
+
* @property {string} os_version OS Version running on the phone (iOS or Android version)
|
40
|
+
* @property {string} device_manufacturer Device manufacturer
|
41
|
+
* @property {string} device_model Device model
|
42
|
+
* @property {string} os_build_number OS build number
|
43
|
+
* @deprecated
|
44
|
+
*/
|
45
|
+
this.phone = data.phone;
|
46
|
+
|
47
|
+
/**
|
48
|
+
* Platform WhatsApp is running on
|
49
|
+
* @type {string}
|
50
|
+
*/
|
51
|
+
this.platform = data.platform;
|
52
|
+
|
53
|
+
return super._patch(data);
|
54
|
+
}
|
55
|
+
|
56
|
+
/**
|
57
|
+
* Get current battery percentage and charging status for the attached device
|
58
|
+
* @returns {object} batteryStatus
|
59
|
+
* @returns {number} batteryStatus.battery - The current battery percentage
|
60
|
+
* @returns {boolean} batteryStatus.plugged - Indicates if the phone is plugged in (true) or not (false)
|
61
|
+
* @deprecated
|
62
|
+
*/
|
63
|
+
async getBatteryStatus() {
|
64
|
+
return await this.client.pupPage.evaluate(() => {
|
65
|
+
const { battery, plugged } = window.Store.Conn;
|
66
|
+
return { battery, plugged };
|
67
|
+
});
|
68
|
+
}
|
69
|
+
}
|
70
|
+
|
71
|
+
module.exports = ClientInfo;
|
@@ -0,0 +1,208 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
const Base = require('./Base');
|
4
|
+
|
5
|
+
/**
|
6
|
+
* ID that represents a contact
|
7
|
+
* @typedef {Object} ContactId
|
8
|
+
* @property {string} server
|
9
|
+
* @property {string} user
|
10
|
+
* @property {string} _serialized
|
11
|
+
*/
|
12
|
+
|
13
|
+
/**
|
14
|
+
* Represents a Contact on WhatsApp
|
15
|
+
* @extends {Base}
|
16
|
+
*/
|
17
|
+
class Contact extends Base {
|
18
|
+
constructor(client, data) {
|
19
|
+
super(client);
|
20
|
+
|
21
|
+
if(data) this._patch(data);
|
22
|
+
}
|
23
|
+
|
24
|
+
_patch(data) {
|
25
|
+
/**
|
26
|
+
* ID that represents the contact
|
27
|
+
* @type {ContactId}
|
28
|
+
*/
|
29
|
+
this.id = data.id;
|
30
|
+
|
31
|
+
/**
|
32
|
+
* Contact's phone number
|
33
|
+
* @type {string}
|
34
|
+
*/
|
35
|
+
this.number = data.userid;
|
36
|
+
|
37
|
+
/**
|
38
|
+
* Indicates if the contact is a business contact
|
39
|
+
* @type {boolean}
|
40
|
+
*/
|
41
|
+
this.isBusiness = data.isBusiness;
|
42
|
+
|
43
|
+
/**
|
44
|
+
* Indicates if the contact is an enterprise contact
|
45
|
+
* @type {boolean}
|
46
|
+
*/
|
47
|
+
this.isEnterprise = data.isEnterprise;
|
48
|
+
|
49
|
+
this.labels = data.labels;
|
50
|
+
|
51
|
+
/**
|
52
|
+
* The contact's name, as saved by the current user
|
53
|
+
* @type {?string}
|
54
|
+
*/
|
55
|
+
this.name = data.name;
|
56
|
+
|
57
|
+
/**
|
58
|
+
* The name that the contact has configured to be shown publically
|
59
|
+
* @type {string}
|
60
|
+
*/
|
61
|
+
this.pushname = data.pushname;
|
62
|
+
|
63
|
+
this.sectionHeader = data.sectionHeader;
|
64
|
+
|
65
|
+
/**
|
66
|
+
* A shortened version of name
|
67
|
+
* @type {?string}
|
68
|
+
*/
|
69
|
+
this.shortName = data.shortName;
|
70
|
+
|
71
|
+
this.statusMute = data.statusMute;
|
72
|
+
this.type = data.type;
|
73
|
+
this.verifiedLevel = data.verifiedLevel;
|
74
|
+
this.verifiedName = data.verifiedName;
|
75
|
+
|
76
|
+
/**
|
77
|
+
* Indicates if the contact is the current user's contact
|
78
|
+
* @type {boolean}
|
79
|
+
*/
|
80
|
+
this.isMe = data.isMe;
|
81
|
+
|
82
|
+
/**
|
83
|
+
* Indicates if the contact is a user contact
|
84
|
+
* @type {boolean}
|
85
|
+
*/
|
86
|
+
this.isUser = data.isUser;
|
87
|
+
|
88
|
+
/**
|
89
|
+
* Indicates if the contact is a group contact
|
90
|
+
* @type {boolean}
|
91
|
+
*/
|
92
|
+
this.isGroup = data.isGroup;
|
93
|
+
|
94
|
+
/**
|
95
|
+
* Indicates if the number is registered on WhatsApp
|
96
|
+
* @type {boolean}
|
97
|
+
*/
|
98
|
+
this.isWAContact = data.isWAContact;
|
99
|
+
|
100
|
+
/**
|
101
|
+
* Indicates if the number is saved in the current phone's contacts
|
102
|
+
* @type {boolean}
|
103
|
+
*/
|
104
|
+
this.isMyContact = data.isMyContact;
|
105
|
+
|
106
|
+
/**
|
107
|
+
* Indicates if you have blocked this contact
|
108
|
+
* @type {boolean}
|
109
|
+
*/
|
110
|
+
this.isBlocked = data.isBlocked;
|
111
|
+
|
112
|
+
return super._patch(data);
|
113
|
+
}
|
114
|
+
|
115
|
+
/**
|
116
|
+
* Returns the contact's profile picture URL, if privacy settings allow it
|
117
|
+
* @returns {Promise<string>}
|
118
|
+
*/
|
119
|
+
async getProfilePicUrl() {
|
120
|
+
return await this.client.getProfilePicUrl(this.id._serialized);
|
121
|
+
}
|
122
|
+
|
123
|
+
/**
|
124
|
+
* Returns the contact's formatted phone number, (12345678901@c.us) => (+1 (234) 5678-901)
|
125
|
+
* @returns {Promise<string>}
|
126
|
+
*/
|
127
|
+
async getFormattedNumber() {
|
128
|
+
return await this.client.getFormattedNumber(this.id._serialized);
|
129
|
+
}
|
130
|
+
|
131
|
+
/**
|
132
|
+
* Returns the contact's countrycode, (1541859685@c.us) => (1)
|
133
|
+
* @returns {Promise<string>}
|
134
|
+
*/
|
135
|
+
async getCountryCode() {
|
136
|
+
return await this.client.getCountryCode(this.id._serialized);
|
137
|
+
}
|
138
|
+
|
139
|
+
/**
|
140
|
+
* Returns the Chat that corresponds to this Contact.
|
141
|
+
* Will return null when getting chat for currently logged in user.
|
142
|
+
* @returns {Promise<Chat>}
|
143
|
+
*/
|
144
|
+
async getChat() {
|
145
|
+
if(this.isMe) return null;
|
146
|
+
|
147
|
+
return await this.client.getChatById(this.id._serialized);
|
148
|
+
}
|
149
|
+
|
150
|
+
/**
|
151
|
+
* Blocks this contact from WhatsApp
|
152
|
+
* @returns {Promise<boolean>}
|
153
|
+
*/
|
154
|
+
async block() {
|
155
|
+
if(this.isGroup) return false;
|
156
|
+
|
157
|
+
await this.client.pupPage.evaluate(async (contactId) => {
|
158
|
+
const contact = window.Store.Contact.get(contactId);
|
159
|
+
await window.Store.BlockContact.blockContact({contact});
|
160
|
+
}, this.id._serialized);
|
161
|
+
|
162
|
+
this.isBlocked = true;
|
163
|
+
return true;
|
164
|
+
}
|
165
|
+
|
166
|
+
/**
|
167
|
+
* Unblocks this contact from WhatsApp
|
168
|
+
* @returns {Promise<boolean>}
|
169
|
+
*/
|
170
|
+
async unblock() {
|
171
|
+
if(this.isGroup) return false;
|
172
|
+
|
173
|
+
await this.client.pupPage.evaluate(async (contactId) => {
|
174
|
+
const contact = window.Store.Contact.get(contactId);
|
175
|
+
await window.Store.BlockContact.unblockContact(contact);
|
176
|
+
}, this.id._serialized);
|
177
|
+
|
178
|
+
this.isBlocked = false;
|
179
|
+
return true;
|
180
|
+
}
|
181
|
+
|
182
|
+
/**
|
183
|
+
* Gets the Contact's current "about" info. Returns null if you don't have permission to read their status.
|
184
|
+
* @returns {Promise<?string>}
|
185
|
+
*/
|
186
|
+
async getAbout() {
|
187
|
+
const about = await this.client.pupPage.evaluate(async (contactId) => {
|
188
|
+
const wid = window.Store.WidFactory.createWid(contactId);
|
189
|
+
return window.Store.StatusUtils.getStatus(wid);
|
190
|
+
}, this.id._serialized);
|
191
|
+
|
192
|
+
if (typeof about.status !== 'string')
|
193
|
+
return null;
|
194
|
+
|
195
|
+
return about.status;
|
196
|
+
}
|
197
|
+
|
198
|
+
/**
|
199
|
+
* Gets the Contact's common groups with you. Returns empty array if you don't have any common group.
|
200
|
+
* @returns {Promise<WAWebJS.ChatId[]>}
|
201
|
+
*/
|
202
|
+
async getCommonGroups() {
|
203
|
+
return await this.client.getCommonGroups(this.id._serialized);
|
204
|
+
}
|
205
|
+
|
206
|
+
}
|
207
|
+
|
208
|
+
module.exports = Contact;
|