@wppconnect-team/wppconnect 2.0.0 → 2.0.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.
Files changed (43) 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/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 +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.CommunityLayer = void 0;
71
- var helpers_1 = require("../helpers");
72
- var newsletter_layer_1 = require("./newsletter.layer");
73
- var CommunityLayer = /** @class */ (function (_super) {
74
- __extends(CommunityLayer, _super);
75
- function CommunityLayer(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 newsletter_layer_1 = require("./newsletter.layer");
22
+ class CommunityLayer extends newsletter_layer_1.NewsletterLayer {
23
+ page;
24
+ constructor(page, session, options) {
25
+ super(page, session, options);
26
+ this.page = page;
79
27
  }
80
28
  /**
81
29
  * Create a community
@@ -83,100 +31,61 @@ var CommunityLayer = /** @class */ (function (_super) {
83
31
  * @category Community
84
32
  * @param groupIds Array with groups id
85
33
  */
86
- CommunityLayer.prototype.createCommunity = function (name, description, groupIds) {
87
- return __awaiter(this, void 0, void 0, function () {
88
- return __generator(this, function (_a) {
89
- return [2 /*return*/, (0, helpers_1.evaluateAndReturn)(this.page, function (name, description, groupIds) {
90
- return WPP.community.create(name, description, groupIds);
91
- }, name, description, groupIds)];
92
- });
93
- });
94
- };
34
+ async createCommunity(name, description, groupIds) {
35
+ return (0, helpers_1.evaluateAndReturn)(this.page, (name, description, groupIds) => WPP.community.create(name, description, groupIds), name, description, groupIds);
36
+ }
95
37
  /**
96
38
  * Deactivate a community
97
39
  * @category Community
98
40
  * @param communityId id
99
41
  */
100
- CommunityLayer.prototype.deactivateCommunity = function (communityId) {
101
- return __awaiter(this, void 0, void 0, function () {
102
- return __generator(this, function (_a) {
103
- return [2 /*return*/, (0, helpers_1.evaluateAndReturn)(this.page, function (communityId) { return WPP.community.deactivate(communityId); }, communityId)];
104
- });
105
- });
106
- };
42
+ async deactivateCommunity(communityId) {
43
+ return (0, helpers_1.evaluateAndReturn)(this.page, (communityId) => WPP.community.deactivate(communityId), communityId);
44
+ }
107
45
  /**
108
46
  * Add groups to community
109
47
  *
110
48
  * @category Community
111
49
  * @param communityId id
112
50
  */
113
- CommunityLayer.prototype.addSubgroupsCommunity = function (communityId, groupsIds) {
114
- return __awaiter(this, void 0, void 0, function () {
115
- return __generator(this, function (_a) {
116
- return [2 /*return*/, (0, helpers_1.evaluateAndReturn)(this.page, function (communityId, groupsIds) {
117
- return WPP.community.addSubgroups(communityId, groupsIds);
118
- }, communityId, groupsIds)];
119
- });
120
- });
121
- };
51
+ async addSubgroupsCommunity(communityId, groupsIds) {
52
+ return (0, helpers_1.evaluateAndReturn)(this.page, (communityId, groupsIds) => WPP.community.addSubgroups(communityId, groupsIds), communityId, groupsIds);
53
+ }
122
54
  /**
123
55
  * Remove groups of community
124
56
  *
125
57
  * @category Community
126
58
  * @param communityId id
127
59
  */
128
- CommunityLayer.prototype.removeSubgroupsCommunity = function (communityId, groupsIds) {
129
- return __awaiter(this, void 0, void 0, function () {
130
- return __generator(this, function (_a) {
131
- return [2 /*return*/, (0, helpers_1.evaluateAndReturn)(this.page, function (communityId, groupsIds) {
132
- return WPP.community.removeSubgroups(communityId, groupsIds);
133
- }, communityId, groupsIds)];
134
- });
135
- });
136
- };
60
+ async removeSubgroupsCommunity(communityId, groupsIds) {
61
+ return (0, helpers_1.evaluateAndReturn)(this.page, (communityId, groupsIds) => WPP.community.removeSubgroups(communityId, groupsIds), communityId, groupsIds);
62
+ }
137
63
  /**
138
64
  * Remove admin of community participant
139
65
  *
140
66
  * @category Community
141
67
  * @param communityId id
142
68
  */
143
- CommunityLayer.prototype.demoteCommunityParticipant = function (communityId, participantId) {
144
- return __awaiter(this, void 0, void 0, function () {
145
- return __generator(this, function (_a) {
146
- return [2 /*return*/, (0, helpers_1.evaluateAndReturn)(this.page, function (communityId, participantId) {
147
- return WPP.community.demoteParticipants(communityId, participantId);
148
- }, communityId, participantId)];
149
- });
150
- });
151
- };
69
+ async demoteCommunityParticipant(communityId, participantId) {
70
+ return (0, helpers_1.evaluateAndReturn)(this.page, (communityId, participantId) => WPP.community.demoteParticipants(communityId, participantId), communityId, participantId);
71
+ }
152
72
  /**
153
73
  * Promote participant of community to admin
154
74
  *
155
75
  * @category Community
156
76
  * @param communityId id
157
77
  */
158
- CommunityLayer.prototype.promoteCommunityParticipant = function (communityId, participantId) {
159
- return __awaiter(this, void 0, void 0, function () {
160
- return __generator(this, function (_a) {
161
- return [2 /*return*/, (0, helpers_1.evaluateAndReturn)(this.page, function (communityId, participantId) {
162
- return WPP.community.promoteParticipants(communityId, participantId);
163
- }, communityId, participantId)];
164
- });
165
- });
166
- };
78
+ async promoteCommunityParticipant(communityId, participantId) {
79
+ return (0, helpers_1.evaluateAndReturn)(this.page, (communityId, participantId) => WPP.community.promoteParticipants(communityId, participantId), communityId, participantId);
80
+ }
167
81
  /**
168
82
  * Get all participants of a community
169
83
  *
170
84
  * @category Community
171
85
  * @param communityId id
172
86
  */
173
- CommunityLayer.prototype.getCommunityParticipants = function (communityId) {
174
- return __awaiter(this, void 0, void 0, function () {
175
- return __generator(this, function (_a) {
176
- return [2 /*return*/, (0, helpers_1.evaluateAndReturn)(this.page, function (communityId) { return WPP.community.getParticipants(communityId); }, communityId)];
177
- });
178
- });
179
- };
180
- return CommunityLayer;
181
- }(newsletter_layer_1.NewsletterLayer));
87
+ async getCommunityParticipants(communityId) {
88
+ return (0, helpers_1.evaluateAndReturn)(this.page, (communityId) => WPP.community.getParticipants(communityId), communityId);
89
+ }
90
+ }
182
91
  exports.CommunityLayer = CommunityLayer;
@@ -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.ControlsLayer = void 0;
71
- var helpers_1 = require("../helpers");
72
- var ui_layer_1 = require("./ui.layer");
73
- var ControlsLayer = /** @class */ (function (_super) {
74
- __extends(ControlsLayer, _super);
75
- function ControlsLayer(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 ui_layer_1 = require("./ui.layer");
22
+ class ControlsLayer extends ui_layer_1.UILayer {
23
+ page;
24
+ constructor(page, session, options) {
25
+ super(page, session, options);
26
+ this.page = page;
79
27
  }
80
28
  /**
81
29
  * Unblock contact
@@ -83,73 +31,40 @@ var ControlsLayer = /** @class */ (function (_super) {
83
31
  * @param contactId {string} id '000000000000@c.us'
84
32
  * @returns boolean
85
33
  */
86
- ControlsLayer.prototype.unblockContact = function (contactId) {
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 (contactId) { return WPP.blocklist.unblockContact(contactId); }, contactId)];
91
- case 1:
92
- _a.sent();
93
- return [2 /*return*/, true];
94
- }
95
- });
96
- });
97
- };
34
+ async unblockContact(contactId) {
35
+ await (0, helpers_1.evaluateAndReturn)(this.page, (contactId) => WPP.blocklist.unblockContact(contactId), contactId);
36
+ return true;
37
+ }
98
38
  /**
99
39
  * Block contact
100
40
  * @category Blocklist
101
41
  * @param contactId {string} id '000000000000@c.us'
102
42
  * @returns boolean
103
43
  */
104
- ControlsLayer.prototype.blockContact = function (contactId) {
105
- return __awaiter(this, void 0, void 0, function () {
106
- return __generator(this, function (_a) {
107
- switch (_a.label) {
108
- case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (contactId) { return WPP.blocklist.blockContact(contactId); }, contactId)];
109
- case 1:
110
- _a.sent();
111
- return [2 /*return*/, true];
112
- }
113
- });
114
- });
115
- };
44
+ async blockContact(contactId) {
45
+ await (0, helpers_1.evaluateAndReturn)(this.page, (contactId) => WPP.blocklist.blockContact(contactId), contactId);
46
+ return true;
47
+ }
116
48
  /**
117
49
  * puts the chat as unread
118
50
  * @category Chat
119
51
  * @param contactId {string} id '000000000000@c.us'
120
52
  * @returns boolean
121
53
  */
122
- ControlsLayer.prototype.markUnseenMessage = function (contactId) {
123
- return __awaiter(this, void 0, void 0, function () {
124
- return __generator(this, function (_a) {
125
- switch (_a.label) {
126
- case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (contactId) { return WPP.chat.markIsUnread(contactId); }, contactId)];
127
- case 1:
128
- _a.sent();
129
- return [2 /*return*/, true];
130
- }
131
- });
132
- });
133
- };
54
+ async markUnseenMessage(contactId) {
55
+ await (0, helpers_1.evaluateAndReturn)(this.page, (contactId) => WPP.chat.markIsUnread(contactId), contactId);
56
+ return true;
57
+ }
134
58
  /**
135
59
  * Deletes the given chat
136
60
  * @category Chat
137
61
  * @param chatId {string} id '000000000000@c.us'
138
62
  * @returns boolean
139
63
  */
140
- ControlsLayer.prototype.deleteChat = function (chatId) {
141
- return __awaiter(this, void 0, void 0, function () {
142
- var result;
143
- return __generator(this, function (_a) {
144
- switch (_a.label) {
145
- case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (chatId) { return WPP.chat.delete(chatId); }, chatId)];
146
- case 1:
147
- result = _a.sent();
148
- return [2 /*return*/, result.status === 200];
149
- }
150
- });
151
- });
152
- };
64
+ async deleteChat(chatId) {
65
+ const result = await (0, helpers_1.evaluateAndReturn)(this.page, (chatId) => WPP.chat.delete(chatId), chatId);
66
+ return result.status === 200;
67
+ }
153
68
  /**
154
69
  * Archive and unarchive chat messages with true or false
155
70
  * @category Chat
@@ -157,17 +72,9 @@ var ControlsLayer = /** @class */ (function (_super) {
157
72
  * @param option {boolean} true or false
158
73
  * @returns boolean
159
74
  */
160
- ControlsLayer.prototype.archiveChat = function (chatId_1) {
161
- return __awaiter(this, arguments, void 0, function (chatId, option) {
162
- if (option === void 0) { option = true; }
163
- return __generator(this, function (_a) {
164
- return [2 /*return*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
165
- var chatId = _a.chatId, option = _a.option;
166
- return WPP.chat.archive(chatId, option);
167
- }, { chatId: chatId, option: option })];
168
- });
169
- });
170
- };
75
+ async archiveChat(chatId, option = true) {
76
+ return (0, helpers_1.evaluateAndReturn)(this.page, ({ chatId, option }) => WPP.chat.archive(chatId, option), { chatId, option });
77
+ }
171
78
  /**
172
79
  * Pin and Unpin chat messages with true or false
173
80
  * @category Chat
@@ -176,28 +83,12 @@ var ControlsLayer = /** @class */ (function (_super) {
176
83
  * @param nonExistent {boolean} Pin chat, non-existent (optional)
177
84
  * @returns object
178
85
  */
179
- ControlsLayer.prototype.pinChat = function (chatId, option, nonExistent) {
180
- return __awaiter(this, void 0, void 0, function () {
181
- return __generator(this, function (_a) {
182
- switch (_a.label) {
183
- case 0:
184
- if (!nonExistent) return [3 /*break*/, 2];
185
- return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
186
- var chatId = _a.chatId;
187
- return WPP.chat.find(chatId);
188
- }, { chatId: chatId })];
189
- case 1:
190
- _a.sent();
191
- _a.label = 2;
192
- case 2: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
193
- var chatId = _a.chatId, option = _a.option;
194
- return WPP.chat.pin(chatId, option);
195
- }, { chatId: chatId, option: option })];
196
- case 3: return [2 /*return*/, _a.sent()];
197
- }
198
- });
199
- });
200
- };
86
+ async pinChat(chatId, option, nonExistent) {
87
+ if (nonExistent) {
88
+ await (0, helpers_1.evaluateAndReturn)(this.page, ({ chatId }) => WPP.chat.find(chatId), { chatId });
89
+ }
90
+ return await (0, helpers_1.evaluateAndReturn)(this.page, ({ chatId, option }) => WPP.chat.pin(chatId, option), { chatId, option });
91
+ }
201
92
  /**
202
93
  * Deletes all messages of given chat
203
94
  * @category Chat
@@ -205,23 +96,10 @@ var ControlsLayer = /** @class */ (function (_super) {
205
96
  * @param keepStarred Keep starred messages
206
97
  * @returns boolean
207
98
  */
208
- ControlsLayer.prototype.clearChat = function (chatId_1) {
209
- return __awaiter(this, arguments, void 0, function (chatId, keepStarred) {
210
- var result;
211
- if (keepStarred === void 0) { keepStarred = true; }
212
- return __generator(this, function (_a) {
213
- switch (_a.label) {
214
- case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
215
- var chatId = _a.chatId, keepStarred = _a.keepStarred;
216
- return WPP.chat.clear(chatId, keepStarred);
217
- }, { chatId: chatId, keepStarred: keepStarred })];
218
- case 1:
219
- result = _a.sent();
220
- return [2 /*return*/, result.status === 200];
221
- }
222
- });
223
- });
224
- };
99
+ async clearChat(chatId, keepStarred = true) {
100
+ const result = await (0, helpers_1.evaluateAndReturn)(this.page, ({ chatId, keepStarred }) => WPP.chat.clear(chatId, keepStarred), { chatId, keepStarred });
101
+ return result.status === 200;
102
+ }
225
103
  /**
226
104
  * Deletes message of given message id
227
105
  * @category Chat
@@ -229,23 +107,10 @@ var ControlsLayer = /** @class */ (function (_super) {
229
107
  * @param messageId The specific message id of the message to be deleted
230
108
  * @param onlyLocal If it should only delete locally (message remains on the other recipienct's phone). Defaults to false.
231
109
  */
232
- ControlsLayer.prototype.deleteMessage = function (chatId_1, messageId_1) {
233
- return __awaiter(this, arguments, void 0, function (chatId, messageId, onlyLocal, deleteMediaInDevice) {
234
- if (onlyLocal === void 0) { onlyLocal = false; }
235
- if (deleteMediaInDevice === void 0) { deleteMediaInDevice = true; }
236
- return __generator(this, function (_a) {
237
- switch (_a.label) {
238
- case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
239
- var chatId = _a.chatId, messageId = _a.messageId, onlyLocal = _a.onlyLocal, deleteMediaInDevice = _a.deleteMediaInDevice;
240
- return WPP.chat.deleteMessage(chatId, messageId, deleteMediaInDevice, !onlyLocal);
241
- }, { chatId: chatId, messageId: messageId, onlyLocal: onlyLocal, deleteMediaInDevice: deleteMediaInDevice })];
242
- case 1:
243
- _a.sent();
244
- return [2 /*return*/, true];
245
- }
246
- });
247
- });
248
- };
110
+ async deleteMessage(chatId, messageId, onlyLocal = false, deleteMediaInDevice = true) {
111
+ await (0, helpers_1.evaluateAndReturn)(this.page, ({ chatId, messageId, onlyLocal, deleteMediaInDevice }) => WPP.chat.deleteMessage(chatId, messageId, deleteMediaInDevice, !onlyLocal), { chatId, messageId, onlyLocal, deleteMediaInDevice });
112
+ return true;
113
+ }
249
114
  /**
250
115
  * Edits message of given message id
251
116
  * @category Chat
@@ -259,61 +124,24 @@ var ControlsLayer = /** @class */ (function (_super) {
259
124
  * client.editMessage('true_<number>@c.us_messageId', 'new Text For Simple Message');
260
125
  * ```
261
126
  */
262
- ControlsLayer.prototype.editMessage = function (msgId_1, newText_1) {
263
- return __awaiter(this, arguments, void 0, function (msgId, newText, options) {
264
- var editResult, result;
265
- var _this = this;
266
- if (options === void 0) { options = {}; }
267
- return __generator(this, function (_a) {
268
- switch (_a.label) {
269
- case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
270
- var msgId = _a.msgId, newText = _a.newText, options = _a.options;
271
- return WPP.chat.editMessage(msgId, newText, options);
272
- }, { msgId: msgId, newText: newText, options: options })];
273
- case 1:
274
- editResult = _a.sent();
275
- return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) { return __awaiter(_this, [_a], void 0, function (_b) {
276
- var _c, _d, _e, _f;
277
- var messageId = _b.messageId;
278
- return __generator(this, function (_g) {
279
- switch (_g.label) {
280
- case 0:
281
- _d = (_c = JSON).parse;
282
- _f = (_e = JSON).stringify;
283
- return [4 /*yield*/, WAPI.getMessageById(messageId)];
284
- case 1: return [2 /*return*/, _d.apply(_c, [_f.apply(_e, [_g.sent()])])];
285
- }
286
- });
287
- }); }, { messageId: editResult.id })];
288
- case 2:
289
- result = (_a.sent());
290
- if (result.body !== newText)
291
- throw editResult;
292
- return [2 /*return*/, result];
293
- }
294
- });
295
- });
296
- };
127
+ async editMessage(msgId, newText, options = {}) {
128
+ const editResult = await (0, helpers_1.evaluateAndReturn)(this.page, ({ msgId, newText, options }) => WPP.chat.editMessage(msgId, newText, options), { msgId, newText, options });
129
+ const result = (await (0, helpers_1.evaluateAndReturn)(this.page, async ({ messageId }) => {
130
+ return JSON.parse(JSON.stringify(await WAPI.getMessageById(messageId)));
131
+ }, { messageId: editResult.id }));
132
+ if (result.body !== newText)
133
+ throw editResult;
134
+ return result;
135
+ }
297
136
  /**
298
137
  * Stars message of given message id
299
138
  * @category Chat
300
139
  * @param messagesId The specific message id of the message to be starred
301
140
  * @param star Add or remove star of the message. Defaults to true.
302
141
  */
303
- ControlsLayer.prototype.starMessage = function (messagesId_1) {
304
- return __awaiter(this, arguments, void 0, function (messagesId, star) {
305
- if (star === void 0) { star = true; }
306
- return __generator(this, function (_a) {
307
- switch (_a.label) {
308
- case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
309
- var messagesId = _a.messagesId, star = _a.star;
310
- return WAPI.starMessages(messagesId, star);
311
- }, { messagesId: messagesId, star: star })];
312
- case 1: return [2 /*return*/, _a.sent()];
313
- }
314
- });
315
- });
316
- };
142
+ async starMessage(messagesId, star = true) {
143
+ return await (0, helpers_1.evaluateAndReturn)(this.page, ({ messagesId, star }) => WAPI.starMessages(messagesId, star), { messagesId, star });
144
+ }
317
145
  /**
318
146
  * Allow only admin to send messages with true or false
319
147
  * @category Group
@@ -321,16 +149,9 @@ var ControlsLayer = /** @class */ (function (_super) {
321
149
  * @param option {boolean} true or false
322
150
  * @returns boolean
323
151
  */
324
- ControlsLayer.prototype.setMessagesAdminsOnly = function (chatId, option) {
325
- return __awaiter(this, void 0, void 0, function () {
326
- return __generator(this, function (_a) {
327
- return [2 /*return*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
328
- var chatId = _a.chatId, option = _a.option;
329
- return WAPI.setMessagesAdminsOnly(chatId, option);
330
- }, { chatId: chatId, option: option })];
331
- });
332
- });
333
- };
152
+ async setMessagesAdminsOnly(chatId, option) {
153
+ return (0, helpers_1.evaluateAndReturn)(this.page, ({ chatId, option }) => WAPI.setMessagesAdminsOnly(chatId, option), { chatId, option });
154
+ }
334
155
  /**
335
156
  * Enable or disable temporary messages with true or false
336
157
  * @category Chat
@@ -338,19 +159,9 @@ var ControlsLayer = /** @class */ (function (_super) {
338
159
  * @param value true or false
339
160
  * @returns boolean
340
161
  */
341
- ControlsLayer.prototype.setTemporaryMessages = function (chatOrGroupId, value) {
342
- return __awaiter(this, void 0, void 0, function () {
343
- return __generator(this, function (_a) {
344
- switch (_a.label) {
345
- case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
346
- var chatOrGroupId = _a.chatOrGroupId, value = _a.value;
347
- return WAPI.setTemporaryMessages(chatOrGroupId, value);
348
- }, { chatOrGroupId: chatOrGroupId, value: value })];
349
- case 1: return [2 /*return*/, _a.sent()];
350
- }
351
- });
352
- });
353
- };
162
+ async setTemporaryMessages(chatOrGroupId, value) {
163
+ return await (0, helpers_1.evaluateAndReturn)(this.page, ({ chatOrGroupId, value }) => WAPI.setTemporaryMessages(chatOrGroupId, value), { chatOrGroupId, value });
164
+ }
354
165
  /**
355
166
  * Change limits of whatsapp web
356
167
  * * @example
@@ -372,19 +183,8 @@ var ControlsLayer = /** @class */ (function (_super) {
372
183
  * ```
373
184
  * @category Chat
374
185
  */
375
- ControlsLayer.prototype.setLimit = function (key, value) {
376
- return __awaiter(this, void 0, void 0, function () {
377
- return __generator(this, function (_a) {
378
- switch (_a.label) {
379
- case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
380
- var key = _a.key, value = _a.value;
381
- return WPP.conn.setLimit(key, value);
382
- }, { key: key, value: value })];
383
- case 1: return [2 /*return*/, _a.sent()];
384
- }
385
- });
386
- });
387
- };
388
- return ControlsLayer;
389
- }(ui_layer_1.UILayer));
186
+ async setLimit(key, value) {
187
+ return await (0, helpers_1.evaluateAndReturn)(this.page, ({ key, value }) => WPP.conn.setLimit(key, value), { key, value });
188
+ }
189
+ }
390
190
  exports.ControlsLayer = ControlsLayer;