@wppconnect-team/wppconnect 1.41.3 → 2.0.1

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 (47) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/api/helpers/base64-mimetype.js +2 -2
  3. package/dist/api/helpers/decrypt.js +65 -72
  4. package/dist/api/helpers/download-file.js +31 -81
  5. package/dist/api/helpers/evaluate-and-return.js +98 -93
  6. package/dist/api/helpers/exposed.enum.d.ts +2 -1
  7. package/dist/api/helpers/exposed.enum.js +1 -0
  8. package/dist/api/helpers/file-to-base64.js +30 -81
  9. package/dist/api/helpers/filename-from-mimetype.js +4 -4
  10. package/dist/api/helpers/scrape-img-qr.js +37 -86
  11. package/dist/api/helpers/scrape-login.js +12 -57
  12. package/dist/api/helpers/select-sticker.js +35 -100
  13. package/dist/api/layers/business.layer.js +29 -134
  14. package/dist/api/layers/catalog.layer.js +59 -210
  15. package/dist/api/layers/community.layer.js +29 -120
  16. package/dist/api/layers/controls.layer.js +62 -262
  17. package/dist/api/layers/group.layer.js +126 -391
  18. package/dist/api/layers/host.layer.js +348 -702
  19. package/dist/api/layers/labels.layer.js +35 -131
  20. package/dist/api/layers/listener.layer.d.ts +9 -1
  21. package/dist/api/layers/listener.layer.js +392 -491
  22. package/dist/api/layers/newsletter.layer.js +20 -89
  23. package/dist/api/layers/profile.layer.js +73 -184
  24. package/dist/api/layers/retriever.layer.js +163 -468
  25. package/dist/api/layers/sender.layer.js +554 -1094
  26. package/dist/api/layers/status.layer.js +80 -179
  27. package/dist/api/layers/ui.layer.js +32 -129
  28. package/dist/api/model/enum/definitions.js +1 -1
  29. package/dist/api/whatsapp.js +200 -426
  30. package/dist/config/WAuserAgente.js +1 -1
  31. package/dist/config/create-config.js +1 -1
  32. package/dist/config/puppeteer.config.js +1 -1
  33. package/dist/controllers/auth.js +42 -110
  34. package/dist/controllers/browser.js +251 -411
  35. package/dist/controllers/initializer.js +171 -265
  36. package/dist/controllers/websocket.js +29 -28
  37. package/dist/controllers/welcome.js +38 -88
  38. package/dist/lib/wapi/wapi.js +1 -1
  39. package/dist/token-store/fileTokenStore.js +83 -173
  40. package/dist/token-store/isValidSessionToken.js +2 -2
  41. package/dist/token-store/isValidTokenStore.js +2 -2
  42. package/dist/token-store/memoryTokenStore.js +11 -14
  43. package/dist/utils/ffmpeg.js +75 -131
  44. package/dist/utils/logger.js +5 -5
  45. package/dist/utils/semver.js +6 -6
  46. package/dist/utils/sleep.js +1 -1
  47. package/package.json +8 -8
@@ -15,67 +15,15 @@
15
15
  * You should have received a copy of the GNU Lesser General Public License
16
16
  * along with WPPConnect. If not, see <https://www.gnu.org/licenses/>.
17
17
  */
18
- var __extends = (this && this.__extends) || (function () {
19
- var extendStatics = function (d, b) {
20
- extendStatics = Object.setPrototypeOf ||
21
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
22
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
23
- return extendStatics(d, b);
24
- };
25
- return function (d, b) {
26
- if (typeof b !== "function" && b !== null)
27
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
28
- extendStatics(d, b);
29
- function __() { this.constructor = d; }
30
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
31
- };
32
- })();
33
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
34
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
35
- return new (P || (P = Promise))(function (resolve, reject) {
36
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
37
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
38
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
39
- step((generator = generator.apply(thisArg, _arguments || [])).next());
40
- });
41
- };
42
- var __generator = (this && this.__generator) || function (thisArg, body) {
43
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
44
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
45
- function verb(n) { return function (v) { return step([n, v]); }; }
46
- function step(op) {
47
- if (f) throw new TypeError("Generator is already executing.");
48
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
49
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
50
- if (y = 0, t) op = [op[0] & 2, t.value];
51
- switch (op[0]) {
52
- case 0: case 1: t = op; break;
53
- case 4: _.label++; return { value: op[1], done: false };
54
- case 5: _.label++; y = op[1]; op = [0]; continue;
55
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
56
- default:
57
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
58
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
59
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
60
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
61
- if (t[2]) _.ops.pop();
62
- _.trys.pop(); continue;
63
- }
64
- op = body.call(thisArg, _);
65
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
66
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
67
- }
68
- };
69
18
  Object.defineProperty(exports, "__esModule", { value: true });
70
19
  exports.RetrieverLayer = void 0;
71
- var helpers_1 = require("../helpers");
72
- var sender_layer_1 = require("./sender.layer");
73
- var RetrieverLayer = /** @class */ (function (_super) {
74
- __extends(RetrieverLayer, _super);
75
- function RetrieverLayer(page, session, options) {
76
- var _this = _super.call(this, page, session, options) || this;
77
- _this.page = page;
78
- return _this;
20
+ const helpers_1 = require("../helpers");
21
+ const sender_layer_1 = require("./sender.layer");
22
+ class RetrieverLayer extends sender_layer_1.SenderLayer {
23
+ page;
24
+ constructor(page, session, options) {
25
+ super(page, session, options);
26
+ this.page = page;
79
27
  }
80
28
  /**
81
29
  * Returns a list of mute and non-mute users
@@ -83,85 +31,57 @@ var RetrieverLayer = /** @class */ (function (_super) {
83
31
  * @param type return type: all, toMute and noMute.
84
32
  * @returns obj
85
33
  */
86
- RetrieverLayer.prototype.getListMutes = function (type) {
87
- return __awaiter(this, void 0, void 0, function () {
88
- return __generator(this, function (_a) {
89
- switch (_a.label) {
90
- case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (type) { return WAPI.getListMute(type); }, type)];
91
- case 1: return [2 /*return*/, _a.sent()];
92
- }
93
- });
94
- });
95
- };
34
+ async getListMutes(type) {
35
+ return await (0, helpers_1.evaluateAndReturn)(this.page, (type) => WAPI.getListMute(type), type);
36
+ }
96
37
  /**
97
38
  * Returns browser session token
98
39
  * @category Host
99
40
  * @returns obj [token]
100
41
  */
101
- RetrieverLayer.prototype.getSessionTokenBrowser = function (removePath) {
102
- return __awaiter(this, void 0, void 0, function () {
103
- return __generator(this, function (_a) {
104
- switch (_a.label) {
105
- case 0:
106
- if (!(removePath === true)) return [3 /*break*/, 2];
107
- return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function () {
108
- window['pathSession'] = true;
109
- })];
110
- case 1:
111
- _a.sent();
112
- _a.label = 2;
113
- case 2: return [4 /*yield*/, this.isMultiDevice()];
114
- case 3:
115
- if (!_a.sent()) return [3 /*break*/, 5];
116
- return [4 /*yield*/, this.page
117
- .evaluate(function () {
118
- if (window.localStorage) {
119
- return {
120
- WABrowserId: window.localStorage.getItem('WABrowserId') || 'MultiDevice',
121
- WASecretBundle: 'MultiDevice',
122
- WAToken1: 'MultiDevice',
123
- WAToken2: 'MultiDevice',
124
- };
125
- }
126
- return null;
127
- })
128
- .catch(function () { return null; })];
129
- case 4: return [2 /*return*/, _a.sent()];
130
- case 5: return [4 /*yield*/, this.page
131
- .evaluate(function () {
132
- if (window.localStorage) {
133
- return {
134
- WABrowserId: window.localStorage.getItem('WABrowserId'),
135
- WASecretBundle: window.localStorage.getItem('WASecretBundle'),
136
- WAToken1: window.localStorage.getItem('WAToken1'),
137
- WAToken2: window.localStorage.getItem('WAToken2'),
138
- };
139
- }
140
- return null;
141
- })
142
- .catch(function () { return null; })];
143
- case 6: return [2 /*return*/, _a.sent()];
42
+ async getSessionTokenBrowser(removePath) {
43
+ if (removePath === true) {
44
+ await (0, helpers_1.evaluateAndReturn)(this.page, () => {
45
+ window['pathSession'] = true;
46
+ });
47
+ }
48
+ if (await this.isMultiDevice()) {
49
+ return await this.page
50
+ .evaluate(() => {
51
+ if (window.localStorage) {
52
+ return {
53
+ WABrowserId: window.localStorage.getItem('WABrowserId') || 'MultiDevice',
54
+ WASecretBundle: 'MultiDevice',
55
+ WAToken1: 'MultiDevice',
56
+ WAToken2: 'MultiDevice',
57
+ };
144
58
  }
145
- });
146
- });
147
- };
59
+ return null;
60
+ })
61
+ .catch(() => null);
62
+ }
63
+ return await this.page
64
+ .evaluate(() => {
65
+ if (window.localStorage) {
66
+ return {
67
+ WABrowserId: window.localStorage.getItem('WABrowserId'),
68
+ WASecretBundle: window.localStorage.getItem('WASecretBundle'),
69
+ WAToken1: window.localStorage.getItem('WAToken1'),
70
+ WAToken2: window.localStorage.getItem('WAToken2'),
71
+ };
72
+ }
73
+ return null;
74
+ })
75
+ .catch(() => null);
76
+ }
148
77
  /**
149
78
  * Receive all blocked contacts
150
79
  * @category Blocklist
151
80
  * @returns array of [0,1,2,3....]
152
81
  */
153
- RetrieverLayer.prototype.getBlockList = function () {
154
- return __awaiter(this, void 0, void 0, function () {
155
- return __generator(this, function (_a) {
156
- switch (_a.label) {
157
- case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function () {
158
- return WPP.blocklist.all().map(function (b) { return b.toString(); });
159
- })];
160
- case 1: return [2 /*return*/, _a.sent()];
161
- }
162
- });
163
- });
164
- };
82
+ async getBlockList() {
83
+ return await (0, helpers_1.evaluateAndReturn)(this.page, () => WPP.blocklist.all().map((b) => b.toString()));
84
+ }
165
85
  /**
166
86
  * Retrieves all chats
167
87
  * Deprecated in favor of {@link listChats}
@@ -170,21 +90,15 @@ var RetrieverLayer = /** @class */ (function (_super) {
170
90
  * @returns array of [Chat]
171
91
  * @deprecated Deprecated in favor of listChats.
172
92
  */
173
- RetrieverLayer.prototype.getAllChats = function () {
174
- return __awaiter(this, arguments, void 0, function (withNewMessageOnly) {
175
- if (withNewMessageOnly === void 0) { withNewMessageOnly = false; }
176
- return __generator(this, function (_a) {
177
- this.logger.warn('Deprecated: This function [getAllChats] is deprecated in favor of the listChats function. Please update your code accordingly.');
178
- if (withNewMessageOnly) {
179
- return [2 /*return*/, (0, helpers_1.evaluateAndReturn)(this.page, function () { return WAPI.getAllChatsWithNewMsg(); })];
180
- }
181
- else {
182
- return [2 /*return*/, (0, helpers_1.evaluateAndReturn)(this.page, function () { return WAPI.getAllChats(); })];
183
- }
184
- return [2 /*return*/];
185
- });
186
- });
187
- };
93
+ async getAllChats(withNewMessageOnly = false) {
94
+ this.logger.warn('Deprecated: This function [getAllChats] is deprecated in favor of the listChats function. Please update your code accordingly.');
95
+ if (withNewMessageOnly) {
96
+ return (0, helpers_1.evaluateAndReturn)(this.page, () => WAPI.getAllChatsWithNewMsg());
97
+ }
98
+ else {
99
+ return (0, helpers_1.evaluateAndReturn)(this.page, () => WAPI.getAllChats());
100
+ }
101
+ }
188
102
  /**
189
103
  * Return list of chats
190
104
  * * @example
@@ -216,45 +130,24 @@ var RetrieverLayer = /** @class */ (function (_super) {
216
130
  * @category Chat
217
131
  * @returns array of [Chat]
218
132
  */
219
- RetrieverLayer.prototype.listChats = function (options) {
220
- return __awaiter(this, void 0, void 0, function () {
221
- var _this = this;
222
- return __generator(this, function (_a) {
223
- switch (_a.label) {
224
- case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) { return __awaiter(_this, [_a], void 0, function (_b) {
225
- var chats, serialized;
226
- var options = _b.options;
227
- return __generator(this, function (_c) {
228
- switch (_c.label) {
229
- case 0: return [4 /*yield*/, WPP.chat.list(options)];
230
- case 1:
231
- chats = _c.sent();
232
- serialized = chats.map(function (c) { return WAPI._serializeChatObj(c); });
233
- return [2 /*return*/, serialized];
234
- }
235
- });
236
- }); }, { options: options })];
237
- case 1: return [2 /*return*/, _a.sent()];
238
- }
239
- });
240
- });
241
- };
133
+ async listChats(options) {
134
+ return await (0, helpers_1.evaluateAndReturn)(this.page, async ({ options }) => {
135
+ const chats = await WPP.chat.list(options);
136
+ const serialized = chats.map((c) => WAPI._serializeChatObj(c));
137
+ return serialized;
138
+ }, { options });
139
+ }
242
140
  /**
243
141
  * Checks if a number is a valid WA number
244
142
  * @category Contact
245
143
  * @param contactId, you need to include the @c.us at the end.
246
144
  * @returns contact details as promise
247
145
  */
248
- RetrieverLayer.prototype.checkNumberStatus = function (contactId) {
249
- return __awaiter(this, void 0, void 0, function () {
250
- return __generator(this, function (_a) {
251
- switch (_a.label) {
252
- case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (contactId) { return WAPI.checkNumberStatus(contactId); }, contactId)];
253
- case 1: return [2 /*return*/, _a.sent()];
254
- }
255
- });
256
- });
257
- };
146
+ async checkNumberStatus(contactId) {
147
+ return await (0, helpers_1.evaluateAndReturn)(this.page, (contactId) => WAPI.checkNumberStatus(contactId), contactId);
148
+ }
149
+ // TODO: implement usernameExists(username: string, key?: string) wrapping
150
+ // WPP.contact.queryUsernameExists — added in wa-js v4.0.0, address in a future version.
258
151
  /**
259
152
  * Retrieves all chats with messages
260
153
  * Deprecated in favor of {@link listChats}
@@ -263,17 +156,10 @@ var RetrieverLayer = /** @class */ (function (_super) {
263
156
  * @returns array of [Chat]
264
157
  * @deprecated Deprecated in favor of listChats.
265
158
  */
266
- RetrieverLayer.prototype.getAllChatsWithMessages = function () {
267
- return __awaiter(this, arguments, void 0, function (withNewMessageOnly) {
268
- if (withNewMessageOnly === void 0) { withNewMessageOnly = false; }
269
- return __generator(this, function (_a) {
270
- this.logger.warn('Deprecated: This function [getAllChatsWithMessages] is deprecated in favor of the listChats function. Please update your code accordingly.');
271
- return [2 /*return*/, (0, helpers_1.evaluateAndReturn)(this.page, function (withNewMessageOnly) {
272
- return WAPI.getAllChatsWithMessages(withNewMessageOnly);
273
- }, withNewMessageOnly)];
274
- });
275
- });
276
- };
159
+ async getAllChatsWithMessages(withNewMessageOnly = false) {
160
+ this.logger.warn('Deprecated: This function [getAllChatsWithMessages] is deprecated in favor of the listChats function. Please update your code accordingly.');
161
+ return (0, helpers_1.evaluateAndReturn)(this.page, (withNewMessageOnly) => WAPI.getAllChatsWithMessages(withNewMessageOnly), withNewMessageOnly);
162
+ }
277
163
  /**
278
164
  * Retrieve all groups
279
165
  * Deprecated in favor of {@link listChats}
@@ -282,96 +168,52 @@ var RetrieverLayer = /** @class */ (function (_super) {
282
168
  * @returns array of groups
283
169
  * @deprecated Deprecated in favor of listChats.
284
170
  */
285
- RetrieverLayer.prototype.getAllGroups = function () {
286
- return __awaiter(this, arguments, void 0, function (withNewMessagesOnly) {
287
- var _this = this;
288
- if (withNewMessagesOnly === void 0) { withNewMessagesOnly = false; }
289
- return __generator(this, function (_a) {
290
- switch (_a.label) {
291
- case 0:
292
- this.logger.warn('Deprecated: This function [getAllGroups] is deprecated in favor of the listChats function. Please update your code accordingly.');
293
- return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) { return __awaiter(_this, [_a], void 0, function (_b) {
294
- var chats, groups;
295
- var withNewMessagesOnly = _b.withNewMessagesOnly;
296
- return __generator(this, function (_c) {
297
- switch (_c.label) {
298
- case 0: return [4 /*yield*/, WPP.chat.list({
299
- onlyGroups: true,
300
- onlyWithUnreadMessage: withNewMessagesOnly,
301
- })];
302
- case 1:
303
- chats = _c.sent();
304
- return [4 /*yield*/, Promise.all(chats.map(function (c) { return WPP.group.ensureGroup(c.id); }))];
305
- case 2:
306
- groups = _c.sent();
307
- return [2 /*return*/, groups.map(function (g) { return WAPI._serializeChatObj(g); })];
308
- }
309
- });
310
- }); }, { withNewMessagesOnly: withNewMessagesOnly })];
311
- case 1: return [2 /*return*/, _a.sent()];
312
- }
171
+ async getAllGroups(withNewMessagesOnly = false) {
172
+ this.logger.warn('Deprecated: This function [getAllGroups] is deprecated in favor of the listChats function. Please update your code accordingly.');
173
+ return await (0, helpers_1.evaluateAndReturn)(this.page, async ({ withNewMessagesOnly }) => {
174
+ const chats = await WPP.chat.list({
175
+ onlyGroups: true,
176
+ onlyWithUnreadMessage: withNewMessagesOnly,
313
177
  });
314
- });
315
- };
178
+ const groups = await Promise.all(chats.map((c) => WPP.group.ensureGroup(c.id)));
179
+ return groups.map((g) => WAPI._serializeChatObj(g));
180
+ }, { withNewMessagesOnly });
181
+ }
316
182
  /**
317
183
  * Retrieve all broadcast list
318
184
  * @category Group
319
185
  * @returns array of broadcast list
320
186
  */
321
- RetrieverLayer.prototype.getAllBroadcastList = function () {
322
- return __awaiter(this, void 0, void 0, function () {
323
- var chats;
324
- return __generator(this, function (_a) {
325
- switch (_a.label) {
326
- case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function () { return WAPI.getAllChats(); })];
327
- case 1:
328
- chats = _a.sent();
329
- return [2 /*return*/, chats.filter(function (chat) { return chat.isBroadcast && chat.id._serialized !== 'status@broadcast'; })];
330
- }
331
- });
332
- });
333
- };
187
+ async getAllBroadcastList() {
188
+ const chats = await (0, helpers_1.evaluateAndReturn)(this.page, () => WAPI.getAllChats());
189
+ return chats.filter((chat) => chat.isBroadcast && chat.id._serialized !== 'status@broadcast');
190
+ }
334
191
  /**
335
192
  * Retrieves contact detail object of given contact id
336
193
  * @category Contact
337
194
  * @param contactId
338
195
  * @returns contact details as promise
339
196
  */
340
- RetrieverLayer.prototype.getContact = function (contactId) {
341
- return __awaiter(this, void 0, void 0, function () {
342
- return __generator(this, function (_a) {
343
- return [2 /*return*/, (0, helpers_1.evaluateAndReturn)(this.page, function (contactId) { return WAPI.getContact(contactId); }, contactId)];
344
- });
345
- });
346
- };
197
+ async getContact(contactId) {
198
+ return (0, helpers_1.evaluateAndReturn)(this.page, (contactId) => WAPI.getContact(contactId), contactId);
199
+ }
347
200
  /**
348
201
  * Retrieves all contacts
349
202
  * @category Contact
350
203
  * @returns array of [Contact]
351
204
  */
352
- RetrieverLayer.prototype.getAllContacts = function () {
353
- return __awaiter(this, void 0, void 0, function () {
354
- return __generator(this, function (_a) {
355
- switch (_a.label) {
356
- case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function () { return WAPI.getAllContacts(); })];
357
- case 1: return [2 /*return*/, _a.sent()];
358
- }
359
- });
360
- });
361
- };
205
+ async getAllContacts() {
206
+ return await (0, helpers_1.evaluateAndReturn)(this.page, () => WAPI.getAllContacts());
207
+ }
362
208
  /**
363
209
  * Retrieves chat object of given contact id
364
210
  * @category Chat
365
211
  * @param contactId
366
212
  * @returns chat details as promise
367
213
  */
368
- RetrieverLayer.prototype.getChatById = function (contactId) {
369
- return __awaiter(this, void 0, void 0, function () {
370
- return __generator(this, function (_a) {
371
- return [2 /*return*/, (0, helpers_1.evaluateAndReturn)(this.page, function (contactId) { return WAPI.getChatById(contactId); }, contactId)];
372
- });
373
- });
374
- };
214
+ async getChatById(contactId) {
215
+ return (0, helpers_1.evaluateAndReturn)(this.page, (contactId) => WAPI.getChatById(contactId), contactId);
216
+ }
375
217
  /**
376
218
  * Retrieves chat object of given contact id
377
219
  * @category Chat
@@ -379,26 +221,18 @@ var RetrieverLayer = /** @class */ (function (_super) {
379
221
  * @returns chat details as promise
380
222
  * @deprecated
381
223
  */
382
- RetrieverLayer.prototype.getChat = function (contactId) {
383
- return __awaiter(this, void 0, void 0, function () {
384
- return __generator(this, function (_a) {
385
- return [2 /*return*/, this.getChatById(contactId)];
386
- });
387
- });
388
- };
224
+ async getChat(contactId) {
225
+ return this.getChatById(contactId);
226
+ }
389
227
  /**
390
228
  * Retorna dados da imagem do contato
391
229
  * @category Contact
392
230
  * @param chatId Chat id
393
231
  * @returns url of the chat picture or undefined if there is no picture for the chat.
394
232
  */
395
- RetrieverLayer.prototype.getProfilePicFromServer = function (chatId) {
396
- return __awaiter(this, void 0, void 0, function () {
397
- return __generator(this, function (_a) {
398
- return [2 /*return*/, (0, helpers_1.evaluateAndReturn)(this.page, function (chatId) { return WAPI._profilePicfunc(chatId); }, chatId)];
399
- });
400
- });
401
- };
233
+ async getProfilePicFromServer(chatId) {
234
+ return (0, helpers_1.evaluateAndReturn)(this.page, (chatId) => WAPI._profilePicfunc(chatId), chatId);
235
+ }
402
236
  /**
403
237
  * Load more messages in chat object from server. Use this in a while loop
404
238
  * Depreciado em favor de {@link getMessages}
@@ -408,42 +242,23 @@ var RetrieverLayer = /** @class */ (function (_super) {
408
242
  * @param contactId
409
243
  * @returns contact details as promise
410
244
  */
411
- RetrieverLayer.prototype.loadEarlierMessages = function (contactId) {
412
- return __awaiter(this, void 0, void 0, function () {
413
- return __generator(this, function (_a) {
414
- return [2 /*return*/, (0, helpers_1.evaluateAndReturn)(this.page, function (contactId) { return WAPI.loadEarlierMessages(contactId); }, contactId)];
415
- });
416
- });
417
- };
245
+ async loadEarlierMessages(contactId) {
246
+ return (0, helpers_1.evaluateAndReturn)(this.page, (contactId) => WAPI.loadEarlierMessages(contactId), contactId);
247
+ }
418
248
  /**
419
249
  * Retrieves status of given contact
420
250
  * @category Contact
421
251
  * @param contactId
422
252
  */
423
- RetrieverLayer.prototype.getStatus = function (contactId) {
424
- return __awaiter(this, void 0, void 0, function () {
425
- var _this = this;
426
- return __generator(this, function (_a) {
427
- switch (_a.label) {
428
- case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (contactId) { return __awaiter(_this, void 0, void 0, function () {
429
- var status;
430
- return __generator(this, function (_a) {
431
- switch (_a.label) {
432
- case 0: return [4 /*yield*/, WPP.contact.getStatus(contactId)];
433
- case 1:
434
- status = _a.sent();
435
- return [2 /*return*/, {
436
- id: contactId,
437
- status: (status === null || status === void 0 ? void 0 : status.status) || status,
438
- }];
439
- }
440
- });
441
- }); }, contactId)];
442
- case 1: return [2 /*return*/, _a.sent()];
443
- }
444
- });
445
- });
446
- };
253
+ async getStatus(contactId) {
254
+ return await (0, helpers_1.evaluateAndReturn)(this.page, async (contactId) => {
255
+ const status = await WPP.contact.getStatus(contactId);
256
+ return {
257
+ id: contactId,
258
+ status: status?.status || status,
259
+ };
260
+ }, contactId);
261
+ }
447
262
  /**
448
263
  * Checks if a number is a valid whatsapp number
449
264
  *
@@ -453,14 +268,10 @@ var RetrieverLayer = /** @class */ (function (_super) {
453
268
  * @param contactId, you need to include the @c.us at the end.
454
269
  * @returns contact details as promise
455
270
  */
456
- RetrieverLayer.prototype.getNumberProfile = function (contactId) {
457
- return __awaiter(this, void 0, void 0, function () {
458
- return __generator(this, function (_a) {
459
- this.log('warn', 'The getNumberProfile function is deprecated, please use checkNumberStatus');
460
- return [2 /*return*/, (0, helpers_1.evaluateAndReturn)(this.page, function (contactId) { return WAPI.getNumberProfile(contactId); }, contactId)];
461
- });
462
- });
463
- };
271
+ async getNumberProfile(contactId) {
272
+ this.log('warn', 'The getNumberProfile function is deprecated, please use checkNumberStatus');
273
+ return (0, helpers_1.evaluateAndReturn)(this.page, (contactId) => WAPI.getNumberProfile(contactId), contactId);
274
+ }
464
275
  /**
465
276
  * Retrieves all undread Messages
466
277
  * @category Chat
@@ -470,47 +281,26 @@ var RetrieverLayer = /** @class */ (function (_super) {
470
281
  * @returns any
471
282
  * @deprecated
472
283
  */
473
- RetrieverLayer.prototype.getUnreadMessages = function (includeMe, includeNotifications, useUnreadCount) {
474
- return __awaiter(this, void 0, void 0, function () {
475
- return __generator(this, function (_a) {
476
- switch (_a.label) {
477
- case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
478
- var includeMe = _a.includeMe, includeNotifications = _a.includeNotifications, useUnreadCount = _a.useUnreadCount;
479
- return WAPI.getUnreadMessages(includeMe, includeNotifications, useUnreadCount);
480
- }, { includeMe: includeMe, includeNotifications: includeNotifications, useUnreadCount: useUnreadCount })];
481
- case 1: return [2 /*return*/, _a.sent()];
482
- }
483
- });
484
- });
485
- };
284
+ async getUnreadMessages(includeMe, includeNotifications, useUnreadCount) {
285
+ return await (0, helpers_1.evaluateAndReturn)(this.page, ({ includeMe, includeNotifications, useUnreadCount }) => WAPI.getUnreadMessages(includeMe, includeNotifications, useUnreadCount), { includeMe, includeNotifications, useUnreadCount });
286
+ }
486
287
  /**
487
288
  * Retrieves all unread messages (where ack is -1)
488
289
  * @category Chat
489
290
  * @returns list of messages
490
291
  */
491
- RetrieverLayer.prototype.getAllUnreadMessages = function () {
492
- return __awaiter(this, void 0, void 0, function () {
493
- return __generator(this, function (_a) {
494
- return [2 /*return*/, (0, helpers_1.evaluateAndReturn)(this.page, function () { return WAPI.getAllUnreadMessages(); })];
495
- });
496
- });
497
- };
292
+ async getAllUnreadMessages() {
293
+ return (0, helpers_1.evaluateAndReturn)(this.page, () => WAPI.getAllUnreadMessages());
294
+ }
498
295
  /**
499
296
  * Retrieves all new messages (where isNewMsg is true)
500
297
  * @category Chat
501
298
  * @returns List of messages
502
299
  * @deprecated Use getAllUnreadMessages
503
300
  */
504
- RetrieverLayer.prototype.getAllNewMessages = function () {
505
- return __awaiter(this, void 0, void 0, function () {
506
- return __generator(this, function (_a) {
507
- switch (_a.label) {
508
- case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function () { return WAPI.getAllNewMessages(); })];
509
- case 1: return [2 /*return*/, _a.sent()];
510
- }
511
- });
512
- });
513
- };
301
+ async getAllNewMessages() {
302
+ return await (0, helpers_1.evaluateAndReturn)(this.page, () => WAPI.getAllNewMessages());
303
+ }
514
304
  /**
515
305
  * Retrieves all messages already loaded in a chat
516
306
  * For loading every message use loadAndGetAllMessagesInChat
@@ -524,19 +314,9 @@ var RetrieverLayer = /** @class */ (function (_super) {
524
314
  * @param includeNotifications
525
315
  * @returns any
526
316
  */
527
- RetrieverLayer.prototype.getAllMessagesInChat = function (chatId, includeMe, includeNotifications) {
528
- return __awaiter(this, void 0, void 0, function () {
529
- return __generator(this, function (_a) {
530
- switch (_a.label) {
531
- case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
532
- var chatId = _a.chatId, includeMe = _a.includeMe, includeNotifications = _a.includeNotifications;
533
- return WAPI.getAllMessagesInChat(chatId, includeMe, includeNotifications);
534
- }, { chatId: chatId, includeMe: includeMe, includeNotifications: includeNotifications })];
535
- case 1: return [2 /*return*/, _a.sent()];
536
- }
537
- });
538
- });
539
- };
317
+ async getAllMessagesInChat(chatId, includeMe, includeNotifications) {
318
+ return await (0, helpers_1.evaluateAndReturn)(this.page, ({ chatId, includeMe, includeNotifications }) => WAPI.getAllMessagesInChat(chatId, includeMe, includeNotifications), { chatId, includeMe, includeNotifications });
319
+ }
540
320
  /**
541
321
  * Loads and Retrieves all Messages in a chat
542
322
  * Depreciado em favor de {@link getMessages}
@@ -548,51 +328,25 @@ var RetrieverLayer = /** @class */ (function (_super) {
548
328
  * @param includeNotifications
549
329
  * @returns any
550
330
  */
551
- RetrieverLayer.prototype.loadAndGetAllMessagesInChat = function (chatId_1) {
552
- return __awaiter(this, arguments, void 0, function (chatId, includeMe, includeNotifications) {
553
- if (includeMe === void 0) { includeMe = false; }
554
- if (includeNotifications === void 0) { includeNotifications = false; }
555
- return __generator(this, function (_a) {
556
- switch (_a.label) {
557
- case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
558
- var chatId = _a.chatId, includeMe = _a.includeMe, includeNotifications = _a.includeNotifications;
559
- return WAPI.loadAndGetAllMessagesInChat(chatId, includeMe, includeNotifications);
560
- }, { chatId: chatId, includeMe: includeMe, includeNotifications: includeNotifications })];
561
- case 1: return [2 /*return*/, _a.sent()];
562
- }
563
- });
564
- });
565
- };
331
+ async loadAndGetAllMessagesInChat(chatId, includeMe = false, includeNotifications = false) {
332
+ return await (0, helpers_1.evaluateAndReturn)(this.page, ({ chatId, includeMe, includeNotifications }) => WAPI.loadAndGetAllMessagesInChat(chatId, includeMe, includeNotifications), { chatId, includeMe, includeNotifications });
333
+ }
566
334
  /**
567
335
  * Checks if a CHAT contact is online.
568
336
  * @category Chat
569
337
  * @param chatId chat id: xxxxx@c.us
570
338
  */
571
- RetrieverLayer.prototype.getChatIsOnline = function (chatId) {
572
- return __awaiter(this, void 0, void 0, function () {
573
- return __generator(this, function (_a) {
574
- switch (_a.label) {
575
- case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (chatId) { return WAPI.getChatIsOnline(chatId); }, chatId)];
576
- case 1: return [2 /*return*/, _a.sent()];
577
- }
578
- });
579
- });
580
- };
339
+ async getChatIsOnline(chatId) {
340
+ return await (0, helpers_1.evaluateAndReturn)(this.page, (chatId) => WAPI.getChatIsOnline(chatId), chatId);
341
+ }
581
342
  /**
582
343
  * Retrieves the last seen of a CHAT.
583
344
  * @category Chat
584
345
  * @param chatId chat id: xxxxx@c.us
585
346
  */
586
- RetrieverLayer.prototype.getLastSeen = function (chatId) {
587
- return __awaiter(this, void 0, void 0, function () {
588
- return __generator(this, function (_a) {
589
- switch (_a.label) {
590
- case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (chatId) { return WAPI.getLastSeen(chatId); }, chatId)];
591
- case 1: return [2 /*return*/, _a.sent()];
592
- }
593
- });
594
- });
595
- };
347
+ async getLastSeen(chatId) {
348
+ return await (0, helpers_1.evaluateAndReturn)(this.page, (chatId) => WAPI.getLastSeen(chatId), chatId);
349
+ }
596
350
  /**
597
351
  * Get the platform message from message ID
598
352
  *
@@ -604,63 +358,33 @@ var RetrieverLayer = /** @class */ (function (_super) {
604
358
  * @category Chat
605
359
  * @param chatId chat id: xxxxx@c.us
606
360
  */
607
- RetrieverLayer.prototype.getPlatformFromMessage = function (msgId) {
608
- return __awaiter(this, void 0, void 0, function () {
609
- return __generator(this, function (_a) {
610
- switch (_a.label) {
611
- case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (msgId) { return WPP.chat.getPlatformFromMessage(msgId); }, msgId)];
612
- case 1: return [2 /*return*/, _a.sent()];
613
- }
614
- });
615
- });
616
- };
361
+ async getPlatformFromMessage(msgId) {
362
+ return await (0, helpers_1.evaluateAndReturn)(this.page, (msgId) => WPP.chat.getPlatformFromMessage(msgId), msgId);
363
+ }
617
364
  /**
618
365
  * Get the reactions of a message
619
366
  *
620
367
  * @category Chat
621
368
  */
622
- RetrieverLayer.prototype.getReactions = function (msgId) {
623
- return __awaiter(this, void 0, void 0, function () {
624
- return __generator(this, function (_a) {
625
- switch (_a.label) {
626
- case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (msgId) { return WPP.chat.getReactions(msgId); }, msgId)];
627
- case 1: return [2 /*return*/, _a.sent()];
628
- }
629
- });
630
- });
631
- };
369
+ async getReactions(msgId) {
370
+ return await (0, helpers_1.evaluateAndReturn)(this.page, (msgId) => WPP.chat.getReactions(msgId), msgId);
371
+ }
632
372
  /**
633
373
  * Get the votes of a poll message
634
374
  *
635
375
  * @category Chat
636
376
  */
637
- RetrieverLayer.prototype.getVotes = function (msgId) {
638
- return __awaiter(this, void 0, void 0, function () {
639
- return __generator(this, function (_a) {
640
- switch (_a.label) {
641
- case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (msgId) { return WPP.chat.getVotes(msgId); }, msgId)];
642
- case 1: return [2 /*return*/, _a.sent()];
643
- }
644
- });
645
- });
646
- };
377
+ async getVotes(msgId) {
378
+ return await (0, helpers_1.evaluateAndReturn)(this.page, (msgId) => WPP.chat.getVotes(msgId), msgId);
379
+ }
647
380
  /**
648
381
  * Get the max number of participants for a group
649
382
  *
650
383
  * @category Group
651
384
  */
652
- RetrieverLayer.prototype.getGroupSizeLimit = function () {
653
- return __awaiter(this, void 0, void 0, function () {
654
- return __generator(this, function (_a) {
655
- switch (_a.label) {
656
- case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function () {
657
- return WPP.group.getGroupSizeLimit();
658
- })];
659
- case 1: return [2 /*return*/, _a.sent()];
660
- }
661
- });
662
- });
663
- };
385
+ async getGroupSizeLimit() {
386
+ return await (0, helpers_1.evaluateAndReturn)(this.page, () => WPP.group.getGroupSizeLimit());
387
+ }
664
388
  /**
665
389
  * Get info of your sended order
666
390
  *
@@ -671,13 +395,9 @@ var RetrieverLayer = /** @class */ (function (_super) {
671
395
  * @category Order
672
396
  * @return Your order
673
397
  */
674
- RetrieverLayer.prototype.getOrder = function (msgId) {
675
- return __awaiter(this, void 0, void 0, function () {
676
- return __generator(this, function (_a) {
677
- return [2 /*return*/, (0, helpers_1.evaluateAndReturn)(this.page, function (msgId) { return WPP.order.get(msgId); }, msgId)];
678
- });
679
- });
680
- };
398
+ async getOrder(msgId) {
399
+ return (0, helpers_1.evaluateAndReturn)(this.page, (msgId) => WPP.order.get(msgId), msgId);
400
+ }
681
401
  /**
682
402
  * Get all commons groups for the contact
683
403
  *
@@ -690,19 +410,9 @@ var RetrieverLayer = /** @class */ (function (_super) {
690
410
  * @param groupId Group ID ('000000-000000@g.us')
691
411
  * @returns Promise
692
412
  */
693
- RetrieverLayer.prototype.getCommonGroups = function (wid) {
694
- return __awaiter(this, void 0, void 0, function () {
695
- return __generator(this, function (_a) {
696
- switch (_a.label) {
697
- case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
698
- var wid = _a.wid;
699
- return WPP.contact.getCommonGroups(wid);
700
- }, { wid: wid })];
701
- case 1: return [2 /*return*/, _a.sent()];
702
- }
703
- });
704
- });
705
- };
413
+ async getCommonGroups(wid) {
414
+ return await (0, helpers_1.evaluateAndReturn)(this.page, ({ wid }) => WPP.contact.getCommonGroups(wid), { wid });
415
+ }
706
416
  /**
707
417
  * Get LID/PhoneNumber mapping and Contact information
708
418
  *
@@ -716,16 +426,9 @@ var RetrieverLayer = /** @class */ (function (_super) {
716
426
  * @param phoneOrLid Contact ID (phone number or LID)
717
427
  * @returns Promise with lid, phoneNumber and contact information
718
428
  */
719
- RetrieverLayer.prototype.getPnLidEntry = function (phoneOrLid) {
720
- return __awaiter(this, void 0, void 0, function () {
721
- return __generator(this, function (_a) {
722
- switch (_a.label) {
723
- case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (phoneOrLid) { return WPP.contact.getPnLidEntry(phoneOrLid); }, phoneOrLid)];
724
- case 1: return [2 /*return*/, _a.sent()];
725
- }
726
- });
727
- });
728
- };
429
+ async getPnLidEntry(phoneOrLid) {
430
+ return await (0, helpers_1.evaluateAndReturn)(this.page, (phoneOrLid) => WPP.contact.getPnLidEntry(phoneOrLid), phoneOrLid);
431
+ }
729
432
  /**
730
433
  * Get messages from IndexedDB 'model-storage' database starting from a specific rowId
731
434
  *
@@ -754,16 +457,8 @@ var RetrieverLayer = /** @class */ (function (_super) {
754
457
  * @param options Options for fetching messages
755
458
  * @returns Promise that resolves to an array of message objects from IndexedDB
756
459
  */
757
- RetrieverLayer.prototype.getMessagesFromRowId = function (input) {
758
- return __awaiter(this, void 0, void 0, function () {
759
- return __generator(this, function (_a) {
760
- switch (_a.label) {
761
- case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (options) { return WPP.indexdb.getMessagesFromRowId(options); }, input)];
762
- case 1: return [2 /*return*/, _a.sent()];
763
- }
764
- });
765
- });
766
- };
767
- return RetrieverLayer;
768
- }(sender_layer_1.SenderLayer));
460
+ async getMessagesFromRowId(input) {
461
+ return await (0, helpers_1.evaluateAndReturn)(this.page, (options) => WPP.indexdb.getMessagesFromRowId(options), input);
462
+ }
463
+ }
769
464
  exports.RetrieverLayer = RetrieverLayer;