@wppconnect-team/wppconnect 2.0.0 → 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 (43) hide show
  1. package/CHANGELOG.md +6 -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/file-to-base64.js +30 -81
  7. package/dist/api/helpers/filename-from-mimetype.js +4 -4
  8. package/dist/api/helpers/scrape-img-qr.js +37 -86
  9. package/dist/api/helpers/scrape-login.js +12 -57
  10. package/dist/api/helpers/select-sticker.js +35 -100
  11. package/dist/api/layers/business.layer.js +29 -134
  12. package/dist/api/layers/catalog.layer.js +59 -210
  13. package/dist/api/layers/community.layer.js +29 -120
  14. package/dist/api/layers/controls.layer.js +62 -262
  15. package/dist/api/layers/group.layer.js +126 -391
  16. package/dist/api/layers/host.layer.js +348 -702
  17. package/dist/api/layers/labels.layer.js +35 -131
  18. package/dist/api/layers/listener.layer.js +386 -504
  19. package/dist/api/layers/newsletter.layer.js +20 -89
  20. package/dist/api/layers/profile.layer.js +73 -184
  21. package/dist/api/layers/retriever.layer.js +161 -468
  22. package/dist/api/layers/sender.layer.js +554 -1094
  23. package/dist/api/layers/status.layer.js +80 -179
  24. package/dist/api/layers/ui.layer.js +32 -129
  25. package/dist/api/model/enum/definitions.js +1 -1
  26. package/dist/api/whatsapp.js +200 -437
  27. package/dist/config/WAuserAgente.js +1 -1
  28. package/dist/config/create-config.js +1 -1
  29. package/dist/config/puppeteer.config.js +1 -1
  30. package/dist/controllers/auth.js +42 -110
  31. package/dist/controllers/browser.js +251 -411
  32. package/dist/controllers/initializer.js +171 -265
  33. package/dist/controllers/websocket.js +29 -28
  34. package/dist/controllers/welcome.js +38 -88
  35. package/dist/token-store/fileTokenStore.js +83 -173
  36. package/dist/token-store/isValidSessionToken.js +2 -2
  37. package/dist/token-store/isValidTokenStore.js +2 -2
  38. package/dist/token-store/memoryTokenStore.js +11 -14
  39. package/dist/utils/ffmpeg.js +75 -131
  40. package/dist/utils/logger.js +5 -5
  41. package/dist/utils/semver.js +6 -6
  42. package/dist/utils/sleep.js +1 -1
  43. package/package.json +6 -6
@@ -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,22 @@ 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
+ }
258
149
  // TODO: implement usernameExists(username: string, key?: string) wrapping
259
150
  // WPP.contact.queryUsernameExists — added in wa-js v4.0.0, address in a future version.
260
151
  /**
@@ -265,17 +156,10 @@ var RetrieverLayer = /** @class */ (function (_super) {
265
156
  * @returns array of [Chat]
266
157
  * @deprecated Deprecated in favor of listChats.
267
158
  */
268
- RetrieverLayer.prototype.getAllChatsWithMessages = function () {
269
- return __awaiter(this, arguments, void 0, function (withNewMessageOnly) {
270
- if (withNewMessageOnly === void 0) { withNewMessageOnly = false; }
271
- return __generator(this, function (_a) {
272
- this.logger.warn('Deprecated: This function [getAllChatsWithMessages] is deprecated in favor of the listChats function. Please update your code accordingly.');
273
- return [2 /*return*/, (0, helpers_1.evaluateAndReturn)(this.page, function (withNewMessageOnly) {
274
- return WAPI.getAllChatsWithMessages(withNewMessageOnly);
275
- }, withNewMessageOnly)];
276
- });
277
- });
278
- };
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
+ }
279
163
  /**
280
164
  * Retrieve all groups
281
165
  * Deprecated in favor of {@link listChats}
@@ -284,96 +168,52 @@ var RetrieverLayer = /** @class */ (function (_super) {
284
168
  * @returns array of groups
285
169
  * @deprecated Deprecated in favor of listChats.
286
170
  */
287
- RetrieverLayer.prototype.getAllGroups = function () {
288
- return __awaiter(this, arguments, void 0, function (withNewMessagesOnly) {
289
- var _this = this;
290
- if (withNewMessagesOnly === void 0) { withNewMessagesOnly = false; }
291
- return __generator(this, function (_a) {
292
- switch (_a.label) {
293
- case 0:
294
- this.logger.warn('Deprecated: This function [getAllGroups] is deprecated in favor of the listChats function. Please update your code accordingly.');
295
- return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) { return __awaiter(_this, [_a], void 0, function (_b) {
296
- var chats, groups;
297
- var withNewMessagesOnly = _b.withNewMessagesOnly;
298
- return __generator(this, function (_c) {
299
- switch (_c.label) {
300
- case 0: return [4 /*yield*/, WPP.chat.list({
301
- onlyGroups: true,
302
- onlyWithUnreadMessage: withNewMessagesOnly,
303
- })];
304
- case 1:
305
- chats = _c.sent();
306
- return [4 /*yield*/, Promise.all(chats.map(function (c) { return WPP.group.ensureGroup(c.id); }))];
307
- case 2:
308
- groups = _c.sent();
309
- return [2 /*return*/, groups.map(function (g) { return WAPI._serializeChatObj(g); })];
310
- }
311
- });
312
- }); }, { withNewMessagesOnly: withNewMessagesOnly })];
313
- case 1: return [2 /*return*/, _a.sent()];
314
- }
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,
315
177
  });
316
- });
317
- };
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
+ }
318
182
  /**
319
183
  * Retrieve all broadcast list
320
184
  * @category Group
321
185
  * @returns array of broadcast list
322
186
  */
323
- RetrieverLayer.prototype.getAllBroadcastList = function () {
324
- return __awaiter(this, void 0, void 0, function () {
325
- var chats;
326
- return __generator(this, function (_a) {
327
- switch (_a.label) {
328
- case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function () { return WAPI.getAllChats(); })];
329
- case 1:
330
- chats = _a.sent();
331
- return [2 /*return*/, chats.filter(function (chat) { return chat.isBroadcast && chat.id._serialized !== 'status@broadcast'; })];
332
- }
333
- });
334
- });
335
- };
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
+ }
336
191
  /**
337
192
  * Retrieves contact detail object of given contact id
338
193
  * @category Contact
339
194
  * @param contactId
340
195
  * @returns contact details as promise
341
196
  */
342
- RetrieverLayer.prototype.getContact = function (contactId) {
343
- return __awaiter(this, void 0, void 0, function () {
344
- return __generator(this, function (_a) {
345
- return [2 /*return*/, (0, helpers_1.evaluateAndReturn)(this.page, function (contactId) { return WAPI.getContact(contactId); }, contactId)];
346
- });
347
- });
348
- };
197
+ async getContact(contactId) {
198
+ return (0, helpers_1.evaluateAndReturn)(this.page, (contactId) => WAPI.getContact(contactId), contactId);
199
+ }
349
200
  /**
350
201
  * Retrieves all contacts
351
202
  * @category Contact
352
203
  * @returns array of [Contact]
353
204
  */
354
- RetrieverLayer.prototype.getAllContacts = function () {
355
- return __awaiter(this, void 0, void 0, function () {
356
- return __generator(this, function (_a) {
357
- switch (_a.label) {
358
- case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function () { return WAPI.getAllContacts(); })];
359
- case 1: return [2 /*return*/, _a.sent()];
360
- }
361
- });
362
- });
363
- };
205
+ async getAllContacts() {
206
+ return await (0, helpers_1.evaluateAndReturn)(this.page, () => WAPI.getAllContacts());
207
+ }
364
208
  /**
365
209
  * Retrieves chat object of given contact id
366
210
  * @category Chat
367
211
  * @param contactId
368
212
  * @returns chat details as promise
369
213
  */
370
- RetrieverLayer.prototype.getChatById = function (contactId) {
371
- return __awaiter(this, void 0, void 0, function () {
372
- return __generator(this, function (_a) {
373
- return [2 /*return*/, (0, helpers_1.evaluateAndReturn)(this.page, function (contactId) { return WAPI.getChatById(contactId); }, contactId)];
374
- });
375
- });
376
- };
214
+ async getChatById(contactId) {
215
+ return (0, helpers_1.evaluateAndReturn)(this.page, (contactId) => WAPI.getChatById(contactId), contactId);
216
+ }
377
217
  /**
378
218
  * Retrieves chat object of given contact id
379
219
  * @category Chat
@@ -381,26 +221,18 @@ var RetrieverLayer = /** @class */ (function (_super) {
381
221
  * @returns chat details as promise
382
222
  * @deprecated
383
223
  */
384
- RetrieverLayer.prototype.getChat = function (contactId) {
385
- return __awaiter(this, void 0, void 0, function () {
386
- return __generator(this, function (_a) {
387
- return [2 /*return*/, this.getChatById(contactId)];
388
- });
389
- });
390
- };
224
+ async getChat(contactId) {
225
+ return this.getChatById(contactId);
226
+ }
391
227
  /**
392
228
  * Retorna dados da imagem do contato
393
229
  * @category Contact
394
230
  * @param chatId Chat id
395
231
  * @returns url of the chat picture or undefined if there is no picture for the chat.
396
232
  */
397
- RetrieverLayer.prototype.getProfilePicFromServer = function (chatId) {
398
- return __awaiter(this, void 0, void 0, function () {
399
- return __generator(this, function (_a) {
400
- return [2 /*return*/, (0, helpers_1.evaluateAndReturn)(this.page, function (chatId) { return WAPI._profilePicfunc(chatId); }, chatId)];
401
- });
402
- });
403
- };
233
+ async getProfilePicFromServer(chatId) {
234
+ return (0, helpers_1.evaluateAndReturn)(this.page, (chatId) => WAPI._profilePicfunc(chatId), chatId);
235
+ }
404
236
  /**
405
237
  * Load more messages in chat object from server. Use this in a while loop
406
238
  * Depreciado em favor de {@link getMessages}
@@ -410,42 +242,23 @@ var RetrieverLayer = /** @class */ (function (_super) {
410
242
  * @param contactId
411
243
  * @returns contact details as promise
412
244
  */
413
- RetrieverLayer.prototype.loadEarlierMessages = function (contactId) {
414
- return __awaiter(this, void 0, void 0, function () {
415
- return __generator(this, function (_a) {
416
- return [2 /*return*/, (0, helpers_1.evaluateAndReturn)(this.page, function (contactId) { return WAPI.loadEarlierMessages(contactId); }, contactId)];
417
- });
418
- });
419
- };
245
+ async loadEarlierMessages(contactId) {
246
+ return (0, helpers_1.evaluateAndReturn)(this.page, (contactId) => WAPI.loadEarlierMessages(contactId), contactId);
247
+ }
420
248
  /**
421
249
  * Retrieves status of given contact
422
250
  * @category Contact
423
251
  * @param contactId
424
252
  */
425
- RetrieverLayer.prototype.getStatus = function (contactId) {
426
- return __awaiter(this, void 0, void 0, function () {
427
- var _this = this;
428
- return __generator(this, function (_a) {
429
- switch (_a.label) {
430
- case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (contactId) { return __awaiter(_this, void 0, void 0, function () {
431
- var status;
432
- return __generator(this, function (_a) {
433
- switch (_a.label) {
434
- case 0: return [4 /*yield*/, WPP.contact.getStatus(contactId)];
435
- case 1:
436
- status = _a.sent();
437
- return [2 /*return*/, {
438
- id: contactId,
439
- status: (status === null || status === void 0 ? void 0 : status.status) || status,
440
- }];
441
- }
442
- });
443
- }); }, contactId)];
444
- case 1: return [2 /*return*/, _a.sent()];
445
- }
446
- });
447
- });
448
- };
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
+ }
449
262
  /**
450
263
  * Checks if a number is a valid whatsapp number
451
264
  *
@@ -455,14 +268,10 @@ var RetrieverLayer = /** @class */ (function (_super) {
455
268
  * @param contactId, you need to include the @c.us at the end.
456
269
  * @returns contact details as promise
457
270
  */
458
- RetrieverLayer.prototype.getNumberProfile = function (contactId) {
459
- return __awaiter(this, void 0, void 0, function () {
460
- return __generator(this, function (_a) {
461
- this.log('warn', 'The getNumberProfile function is deprecated, please use checkNumberStatus');
462
- return [2 /*return*/, (0, helpers_1.evaluateAndReturn)(this.page, function (contactId) { return WAPI.getNumberProfile(contactId); }, contactId)];
463
- });
464
- });
465
- };
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
+ }
466
275
  /**
467
276
  * Retrieves all undread Messages
468
277
  * @category Chat
@@ -472,47 +281,26 @@ var RetrieverLayer = /** @class */ (function (_super) {
472
281
  * @returns any
473
282
  * @deprecated
474
283
  */
475
- RetrieverLayer.prototype.getUnreadMessages = function (includeMe, includeNotifications, useUnreadCount) {
476
- return __awaiter(this, void 0, void 0, function () {
477
- return __generator(this, function (_a) {
478
- switch (_a.label) {
479
- case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
480
- var includeMe = _a.includeMe, includeNotifications = _a.includeNotifications, useUnreadCount = _a.useUnreadCount;
481
- return WAPI.getUnreadMessages(includeMe, includeNotifications, useUnreadCount);
482
- }, { includeMe: includeMe, includeNotifications: includeNotifications, useUnreadCount: useUnreadCount })];
483
- case 1: return [2 /*return*/, _a.sent()];
484
- }
485
- });
486
- });
487
- };
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
+ }
488
287
  /**
489
288
  * Retrieves all unread messages (where ack is -1)
490
289
  * @category Chat
491
290
  * @returns list of messages
492
291
  */
493
- RetrieverLayer.prototype.getAllUnreadMessages = function () {
494
- return __awaiter(this, void 0, void 0, function () {
495
- return __generator(this, function (_a) {
496
- return [2 /*return*/, (0, helpers_1.evaluateAndReturn)(this.page, function () { return WAPI.getAllUnreadMessages(); })];
497
- });
498
- });
499
- };
292
+ async getAllUnreadMessages() {
293
+ return (0, helpers_1.evaluateAndReturn)(this.page, () => WAPI.getAllUnreadMessages());
294
+ }
500
295
  /**
501
296
  * Retrieves all new messages (where isNewMsg is true)
502
297
  * @category Chat
503
298
  * @returns List of messages
504
299
  * @deprecated Use getAllUnreadMessages
505
300
  */
506
- RetrieverLayer.prototype.getAllNewMessages = function () {
507
- return __awaiter(this, void 0, void 0, function () {
508
- return __generator(this, function (_a) {
509
- switch (_a.label) {
510
- case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function () { return WAPI.getAllNewMessages(); })];
511
- case 1: return [2 /*return*/, _a.sent()];
512
- }
513
- });
514
- });
515
- };
301
+ async getAllNewMessages() {
302
+ return await (0, helpers_1.evaluateAndReturn)(this.page, () => WAPI.getAllNewMessages());
303
+ }
516
304
  /**
517
305
  * Retrieves all messages already loaded in a chat
518
306
  * For loading every message use loadAndGetAllMessagesInChat
@@ -526,19 +314,9 @@ var RetrieverLayer = /** @class */ (function (_super) {
526
314
  * @param includeNotifications
527
315
  * @returns any
528
316
  */
529
- RetrieverLayer.prototype.getAllMessagesInChat = function (chatId, includeMe, includeNotifications) {
530
- return __awaiter(this, void 0, void 0, function () {
531
- return __generator(this, function (_a) {
532
- switch (_a.label) {
533
- case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
534
- var chatId = _a.chatId, includeMe = _a.includeMe, includeNotifications = _a.includeNotifications;
535
- return WAPI.getAllMessagesInChat(chatId, includeMe, includeNotifications);
536
- }, { chatId: chatId, includeMe: includeMe, includeNotifications: includeNotifications })];
537
- case 1: return [2 /*return*/, _a.sent()];
538
- }
539
- });
540
- });
541
- };
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
+ }
542
320
  /**
543
321
  * Loads and Retrieves all Messages in a chat
544
322
  * Depreciado em favor de {@link getMessages}
@@ -550,51 +328,25 @@ var RetrieverLayer = /** @class */ (function (_super) {
550
328
  * @param includeNotifications
551
329
  * @returns any
552
330
  */
553
- RetrieverLayer.prototype.loadAndGetAllMessagesInChat = function (chatId_1) {
554
- return __awaiter(this, arguments, void 0, function (chatId, includeMe, includeNotifications) {
555
- if (includeMe === void 0) { includeMe = false; }
556
- if (includeNotifications === void 0) { includeNotifications = false; }
557
- return __generator(this, function (_a) {
558
- switch (_a.label) {
559
- case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
560
- var chatId = _a.chatId, includeMe = _a.includeMe, includeNotifications = _a.includeNotifications;
561
- return WAPI.loadAndGetAllMessagesInChat(chatId, includeMe, includeNotifications);
562
- }, { chatId: chatId, includeMe: includeMe, includeNotifications: includeNotifications })];
563
- case 1: return [2 /*return*/, _a.sent()];
564
- }
565
- });
566
- });
567
- };
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
+ }
568
334
  /**
569
335
  * Checks if a CHAT contact is online.
570
336
  * @category Chat
571
337
  * @param chatId chat id: xxxxx@c.us
572
338
  */
573
- RetrieverLayer.prototype.getChatIsOnline = function (chatId) {
574
- return __awaiter(this, void 0, void 0, function () {
575
- return __generator(this, function (_a) {
576
- switch (_a.label) {
577
- case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (chatId) { return WAPI.getChatIsOnline(chatId); }, chatId)];
578
- case 1: return [2 /*return*/, _a.sent()];
579
- }
580
- });
581
- });
582
- };
339
+ async getChatIsOnline(chatId) {
340
+ return await (0, helpers_1.evaluateAndReturn)(this.page, (chatId) => WAPI.getChatIsOnline(chatId), chatId);
341
+ }
583
342
  /**
584
343
  * Retrieves the last seen of a CHAT.
585
344
  * @category Chat
586
345
  * @param chatId chat id: xxxxx@c.us
587
346
  */
588
- RetrieverLayer.prototype.getLastSeen = function (chatId) {
589
- return __awaiter(this, void 0, void 0, function () {
590
- return __generator(this, function (_a) {
591
- switch (_a.label) {
592
- case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (chatId) { return WAPI.getLastSeen(chatId); }, chatId)];
593
- case 1: return [2 /*return*/, _a.sent()];
594
- }
595
- });
596
- });
597
- };
347
+ async getLastSeen(chatId) {
348
+ return await (0, helpers_1.evaluateAndReturn)(this.page, (chatId) => WAPI.getLastSeen(chatId), chatId);
349
+ }
598
350
  /**
599
351
  * Get the platform message from message ID
600
352
  *
@@ -606,63 +358,33 @@ var RetrieverLayer = /** @class */ (function (_super) {
606
358
  * @category Chat
607
359
  * @param chatId chat id: xxxxx@c.us
608
360
  */
609
- RetrieverLayer.prototype.getPlatformFromMessage = function (msgId) {
610
- return __awaiter(this, void 0, void 0, function () {
611
- return __generator(this, function (_a) {
612
- switch (_a.label) {
613
- case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (msgId) { return WPP.chat.getPlatformFromMessage(msgId); }, msgId)];
614
- case 1: return [2 /*return*/, _a.sent()];
615
- }
616
- });
617
- });
618
- };
361
+ async getPlatformFromMessage(msgId) {
362
+ return await (0, helpers_1.evaluateAndReturn)(this.page, (msgId) => WPP.chat.getPlatformFromMessage(msgId), msgId);
363
+ }
619
364
  /**
620
365
  * Get the reactions of a message
621
366
  *
622
367
  * @category Chat
623
368
  */
624
- RetrieverLayer.prototype.getReactions = function (msgId) {
625
- return __awaiter(this, void 0, void 0, function () {
626
- return __generator(this, function (_a) {
627
- switch (_a.label) {
628
- case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (msgId) { return WPP.chat.getReactions(msgId); }, msgId)];
629
- case 1: return [2 /*return*/, _a.sent()];
630
- }
631
- });
632
- });
633
- };
369
+ async getReactions(msgId) {
370
+ return await (0, helpers_1.evaluateAndReturn)(this.page, (msgId) => WPP.chat.getReactions(msgId), msgId);
371
+ }
634
372
  /**
635
373
  * Get the votes of a poll message
636
374
  *
637
375
  * @category Chat
638
376
  */
639
- RetrieverLayer.prototype.getVotes = function (msgId) {
640
- return __awaiter(this, void 0, void 0, function () {
641
- return __generator(this, function (_a) {
642
- switch (_a.label) {
643
- case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (msgId) { return WPP.chat.getVotes(msgId); }, msgId)];
644
- case 1: return [2 /*return*/, _a.sent()];
645
- }
646
- });
647
- });
648
- };
377
+ async getVotes(msgId) {
378
+ return await (0, helpers_1.evaluateAndReturn)(this.page, (msgId) => WPP.chat.getVotes(msgId), msgId);
379
+ }
649
380
  /**
650
381
  * Get the max number of participants for a group
651
382
  *
652
383
  * @category Group
653
384
  */
654
- RetrieverLayer.prototype.getGroupSizeLimit = function () {
655
- return __awaiter(this, void 0, void 0, function () {
656
- return __generator(this, function (_a) {
657
- switch (_a.label) {
658
- case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function () {
659
- return WPP.group.getGroupSizeLimit();
660
- })];
661
- case 1: return [2 /*return*/, _a.sent()];
662
- }
663
- });
664
- });
665
- };
385
+ async getGroupSizeLimit() {
386
+ return await (0, helpers_1.evaluateAndReturn)(this.page, () => WPP.group.getGroupSizeLimit());
387
+ }
666
388
  /**
667
389
  * Get info of your sended order
668
390
  *
@@ -673,13 +395,9 @@ var RetrieverLayer = /** @class */ (function (_super) {
673
395
  * @category Order
674
396
  * @return Your order
675
397
  */
676
- RetrieverLayer.prototype.getOrder = function (msgId) {
677
- return __awaiter(this, void 0, void 0, function () {
678
- return __generator(this, function (_a) {
679
- return [2 /*return*/, (0, helpers_1.evaluateAndReturn)(this.page, function (msgId) { return WPP.order.get(msgId); }, msgId)];
680
- });
681
- });
682
- };
398
+ async getOrder(msgId) {
399
+ return (0, helpers_1.evaluateAndReturn)(this.page, (msgId) => WPP.order.get(msgId), msgId);
400
+ }
683
401
  /**
684
402
  * Get all commons groups for the contact
685
403
  *
@@ -692,19 +410,9 @@ var RetrieverLayer = /** @class */ (function (_super) {
692
410
  * @param groupId Group ID ('000000-000000@g.us')
693
411
  * @returns Promise
694
412
  */
695
- RetrieverLayer.prototype.getCommonGroups = function (wid) {
696
- return __awaiter(this, void 0, void 0, function () {
697
- return __generator(this, function (_a) {
698
- switch (_a.label) {
699
- case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
700
- var wid = _a.wid;
701
- return WPP.contact.getCommonGroups(wid);
702
- }, { wid: wid })];
703
- case 1: return [2 /*return*/, _a.sent()];
704
- }
705
- });
706
- });
707
- };
413
+ async getCommonGroups(wid) {
414
+ return await (0, helpers_1.evaluateAndReturn)(this.page, ({ wid }) => WPP.contact.getCommonGroups(wid), { wid });
415
+ }
708
416
  /**
709
417
  * Get LID/PhoneNumber mapping and Contact information
710
418
  *
@@ -718,16 +426,9 @@ var RetrieverLayer = /** @class */ (function (_super) {
718
426
  * @param phoneOrLid Contact ID (phone number or LID)
719
427
  * @returns Promise with lid, phoneNumber and contact information
720
428
  */
721
- RetrieverLayer.prototype.getPnLidEntry = function (phoneOrLid) {
722
- return __awaiter(this, void 0, void 0, function () {
723
- return __generator(this, function (_a) {
724
- switch (_a.label) {
725
- case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (phoneOrLid) { return WPP.contact.getPnLidEntry(phoneOrLid); }, phoneOrLid)];
726
- case 1: return [2 /*return*/, _a.sent()];
727
- }
728
- });
729
- });
730
- };
429
+ async getPnLidEntry(phoneOrLid) {
430
+ return await (0, helpers_1.evaluateAndReturn)(this.page, (phoneOrLid) => WPP.contact.getPnLidEntry(phoneOrLid), phoneOrLid);
431
+ }
731
432
  /**
732
433
  * Get messages from IndexedDB 'model-storage' database starting from a specific rowId
733
434
  *
@@ -756,16 +457,8 @@ var RetrieverLayer = /** @class */ (function (_super) {
756
457
  * @param options Options for fetching messages
757
458
  * @returns Promise that resolves to an array of message objects from IndexedDB
758
459
  */
759
- RetrieverLayer.prototype.getMessagesFromRowId = function (input) {
760
- return __awaiter(this, void 0, void 0, function () {
761
- return __generator(this, function (_a) {
762
- switch (_a.label) {
763
- case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (options) { return WPP.indexdb.getMessagesFromRowId(options); }, input)];
764
- case 1: return [2 /*return*/, _a.sent()];
765
- }
766
- });
767
- });
768
- };
769
- return RetrieverLayer;
770
- }(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
+ }
771
464
  exports.RetrieverLayer = RetrieverLayer;