@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,32 +15,6 @@
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 __assign = (this && this.__assign) || function () {
34
- __assign = Object.assign || function(t) {
35
- for (var s, i = 1, n = arguments.length; i < n; i++) {
36
- s = arguments[i];
37
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
38
- t[p] = s[p];
39
- }
40
- return t;
41
- };
42
- return __assign.apply(this, arguments);
43
- };
44
18
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
45
19
  if (k2 === undefined) k2 = k;
46
20
  var desc = Object.getOwnPropertyDescriptor(m, k);
@@ -74,55 +48,18 @@ var __importStar = (this && this.__importStar) || (function () {
74
48
  return result;
75
49
  };
76
50
  })();
77
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
78
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
79
- return new (P || (P = Promise))(function (resolve, reject) {
80
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
81
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
82
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
83
- step((generator = generator.apply(thisArg, _arguments || [])).next());
84
- });
85
- };
86
- var __generator = (this && this.__generator) || function (thisArg, body) {
87
- 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);
88
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
89
- function verb(n) { return function (v) { return step([n, v]); }; }
90
- function step(op) {
91
- if (f) throw new TypeError("Generator is already executing.");
92
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
93
- 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;
94
- if (y = 0, t) op = [op[0] & 2, t.value];
95
- switch (op[0]) {
96
- case 0: case 1: t = op; break;
97
- case 4: _.label++; return { value: op[1], done: false };
98
- case 5: _.label++; y = op[1]; op = [0]; continue;
99
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
100
- default:
101
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
102
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
103
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
104
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
105
- if (t[2]) _.ops.pop();
106
- _.trys.pop(); continue;
107
- }
108
- op = body.call(thisArg, _);
109
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
110
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
111
- }
112
- };
113
51
  Object.defineProperty(exports, "__esModule", { value: true });
114
52
  exports.SenderLayer = void 0;
115
- var path = __importStar(require("path"));
116
- var ffmpeg_1 = require("../../utils/ffmpeg");
117
- var helpers_1 = require("../helpers");
118
- var filename_from_mimetype_1 = require("../helpers/filename-from-mimetype");
119
- var listener_layer_1 = require("./listener.layer");
120
- var SenderLayer = /** @class */ (function (_super) {
121
- __extends(SenderLayer, _super);
122
- function SenderLayer(page, session, options) {
123
- var _this = _super.call(this, page, session, options) || this;
124
- _this.page = page;
125
- return _this;
53
+ const path = __importStar(require("path"));
54
+ const ffmpeg_1 = require("../../utils/ffmpeg");
55
+ const helpers_1 = require("../helpers");
56
+ const filename_from_mimetype_1 = require("../helpers/filename-from-mimetype");
57
+ const listener_layer_1 = require("./listener.layer");
58
+ class SenderLayer extends listener_layer_1.ListenerLayer {
59
+ page;
60
+ constructor(page, session, options) {
61
+ super(page, session, options);
62
+ this.page = page;
126
63
  }
127
64
  /**
128
65
  * Automatically sends a link with the auto generated link preview. You can also add a custom message to be added.
@@ -135,25 +72,13 @@ var SenderLayer = /** @class */ (function (_super) {
135
72
  * @param url string A link, for example for youtube. e.g https://www.youtube.com/watch?v=Zi_XLOBDo_Y&list=RDEMe12_MlgO8mGFdeeftZ2nOQ&start_radio=1
136
73
  * @param text custom text as the message body, this includes the link or will be attached after the link
137
74
  */
138
- SenderLayer.prototype.sendLinkPreview = function (chatId_1, url_1) {
139
- return __awaiter(this, arguments, void 0, function (chatId, url, text) {
140
- var message, result;
141
- if (text === void 0) { text = ''; }
142
- return __generator(this, function (_a) {
143
- switch (_a.label) {
144
- case 0:
145
- message = text.includes(url) ? text : "".concat(url, "\n").concat(text);
146
- return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
147
- var chatId = _a.chatId, message = _a.message;
148
- return WPP.chat.sendTextMessage(chatId, message, { linkPreview: true });
149
- }, { chatId: chatId, message: message })];
150
- case 1:
151
- result = _a.sent();
152
- return [2 /*return*/, result];
153
- }
154
- });
155
- });
156
- };
75
+ async sendLinkPreview(chatId, url, text = '') {
76
+ const message = text.includes(url) ? text : `${url}\n${text}`;
77
+ const result = await (0, helpers_1.evaluateAndReturn)(this.page, ({ chatId, message }) => {
78
+ return WPP.chat.sendTextMessage(chatId, message, { linkPreview: true });
79
+ }, { chatId, message });
80
+ return result;
81
+ }
157
82
  /**
158
83
  * Sends a text message to given chat
159
84
  * @category Chat
@@ -196,41 +121,21 @@ var SenderLayer = /** @class */ (function (_super) {
196
121
  * });
197
122
  * ```
198
123
  */
199
- SenderLayer.prototype.sendText = function (to, content, options) {
200
- return __awaiter(this, void 0, void 0, function () {
201
- var sendResult, result;
202
- var _this = this;
203
- return __generator(this, function (_a) {
204
- switch (_a.label) {
205
- case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
206
- var to = _a.to, content = _a.content, options = _a.options;
207
- return WPP.chat.sendTextMessage(to, content, __assign(__assign({}, options), { waitForAck: true }));
208
- }, { to: to, content: content, options: options })];
209
- case 1:
210
- sendResult = _a.sent();
211
- return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) { return __awaiter(_this, [_a], void 0, function (_b) {
212
- var _c, _d, _e, _f;
213
- var messageId = _b.messageId;
214
- return __generator(this, function (_g) {
215
- switch (_g.label) {
216
- case 0:
217
- _d = (_c = JSON).parse;
218
- _f = (_e = JSON).stringify;
219
- return [4 /*yield*/, WAPI.getMessageById(messageId)];
220
- case 1: return [2 /*return*/, _d.apply(_c, [_f.apply(_e, [_g.sent()])])];
221
- }
222
- });
223
- }); }, { messageId: sendResult.id })];
224
- case 2:
225
- result = (_a.sent());
226
- if (result['erro'] == true) {
227
- throw result;
228
- }
229
- return [2 /*return*/, result];
230
- }
231
- });
232
- });
233
- };
124
+ async sendText(to, content, options) {
125
+ const sendResult = await (0, helpers_1.evaluateAndReturn)(this.page, ({ to, content, options }) => WPP.chat.sendTextMessage(to, content, {
126
+ ...options,
127
+ waitForAck: true,
128
+ }), { to, content, options: options });
129
+ // I don't know why the evaluate is returning undefined for direct call
130
+ // To solve that, I added `JSON.parse(JSON.stringify(<message>))` to solve that
131
+ const result = (await (0, helpers_1.evaluateAndReturn)(this.page, async ({ messageId }) => {
132
+ return JSON.parse(JSON.stringify(await WAPI.getMessageById(messageId)));
133
+ }, { messageId: sendResult.id }));
134
+ if (result['erro'] == true) {
135
+ throw result;
136
+ }
137
+ return result;
138
+ }
234
139
  /**
235
140
  * Sends a pix message to given chat
236
141
  * @category Chat
@@ -248,41 +153,21 @@ var SenderLayer = /** @class */ (function (_super) {
248
153
  });
249
154
  * ```
250
155
  */
251
- SenderLayer.prototype.sendPixKey = function (to, params, options) {
252
- return __awaiter(this, void 0, void 0, function () {
253
- var sendResult, result;
254
- var _this = this;
255
- return __generator(this, function (_a) {
256
- switch (_a.label) {
257
- case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
258
- var to = _a.to, params = _a.params, options = _a.options;
259
- return WPP.chat.sendPixKeyMessage(to, params, __assign(__assign({}, options), { waitForAck: true }));
260
- }, { to: to, params: params, options: options })];
261
- case 1:
262
- sendResult = _a.sent();
263
- return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) { return __awaiter(_this, [_a], void 0, function (_b) {
264
- var _c, _d, _e, _f;
265
- var messageId = _b.messageId;
266
- return __generator(this, function (_g) {
267
- switch (_g.label) {
268
- case 0:
269
- _d = (_c = JSON).parse;
270
- _f = (_e = JSON).stringify;
271
- return [4 /*yield*/, WAPI.getMessageById(messageId)];
272
- case 1: return [2 /*return*/, _d.apply(_c, [_f.apply(_e, [_g.sent()])])];
273
- }
274
- });
275
- }); }, { messageId: sendResult.id })];
276
- case 2:
277
- result = (_a.sent());
278
- if (result['erro'] == true) {
279
- throw result;
280
- }
281
- return [2 /*return*/, result];
282
- }
283
- });
284
- });
285
- };
156
+ async sendPixKey(to, params, options) {
157
+ const sendResult = await (0, helpers_1.evaluateAndReturn)(this.page, ({ to, params, options }) => WPP.chat.sendPixKeyMessage(to, params, {
158
+ ...options,
159
+ waitForAck: true,
160
+ }), { to, params, options: options });
161
+ // I don't know why the evaluate is returning undefined for direct call
162
+ // To solve that, I added `JSON.parse(JSON.stringify(<message>))` to solve that
163
+ const result = (await (0, helpers_1.evaluateAndReturn)(this.page, async ({ messageId }) => {
164
+ return JSON.parse(JSON.stringify(await WAPI.getMessageById(messageId)));
165
+ }, { messageId: sendResult.id }));
166
+ if (result['erro'] == true) {
167
+ throw result;
168
+ }
169
+ return result;
170
+ }
286
171
  /**
287
172
  *
288
173
  * @category Chat
@@ -291,25 +176,13 @@ var SenderLayer = /** @class */ (function (_super) {
291
176
  * @param options
292
177
  * @returns
293
178
  */
294
- SenderLayer.prototype.sendMessageOptions = function (chat, content, options) {
295
- return __awaiter(this, void 0, void 0, function () {
296
- var messageId, result;
297
- return __generator(this, function (_a) {
298
- switch (_a.label) {
299
- case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
300
- var chat = _a.chat, content = _a.content, options = _a.options;
301
- return WAPI.sendMessageOptions(chat, content, options);
302
- }, { chat: chat, content: content, options: options })];
303
- case 1:
304
- messageId = _a.sent();
305
- return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (messageId) { return WAPI.getMessageById(messageId); }, messageId)];
306
- case 2:
307
- result = (_a.sent());
308
- return [2 /*return*/, result];
309
- }
310
- });
311
- });
312
- };
179
+ async sendMessageOptions(chat, content, options) {
180
+ const messageId = await (0, helpers_1.evaluateAndReturn)(this.page, ({ chat, content, options }) => {
181
+ return WAPI.sendMessageOptions(chat, content, options);
182
+ }, { chat, content, options });
183
+ const result = (await (0, helpers_1.evaluateAndReturn)(this.page, (messageId) => WAPI.getMessageById(messageId), messageId));
184
+ return result;
185
+ }
313
186
  /**
314
187
  * Sends image message
315
188
  * @category Chat
@@ -320,43 +193,30 @@ var SenderLayer = /** @class */ (function (_super) {
320
193
  * @param quotedMessageId Quoted message id
321
194
  * @param isViewOnce Enable single view
322
195
  */
323
- SenderLayer.prototype.sendImage = function (to, filePath, filename, caption, quotedMessageId, isViewOnce, options) {
324
- return __awaiter(this, void 0, void 0, function () {
325
- var base64, obj;
326
- return __generator(this, function (_a) {
327
- switch (_a.label) {
328
- case 0: return [4 /*yield*/, (0, helpers_1.downloadFileToBase64)(filePath, [
329
- 'image/gif',
330
- 'image/png',
331
- 'image/jpg',
332
- 'image/jpeg',
333
- 'image/webp',
334
- ])];
335
- case 1:
336
- base64 = _a.sent();
337
- if (!!base64) return [3 /*break*/, 3];
338
- return [4 /*yield*/, (0, helpers_1.fileToBase64)(filePath)];
339
- case 2:
340
- base64 = _a.sent();
341
- _a.label = 3;
342
- case 3:
343
- if (!base64) {
344
- obj = {
345
- erro: true,
346
- to: to,
347
- text: 'No such file or directory, open "' + filePath + '"',
348
- };
349
- throw obj;
350
- }
351
- if (!filename) {
352
- filename = path.basename(filePath);
353
- }
354
- return [4 /*yield*/, this.sendImageFromBase64(to, base64, filename, caption, quotedMessageId, isViewOnce, options === null || options === void 0 ? void 0 : options.mentionedList, options || {})];
355
- case 4: return [2 /*return*/, _a.sent()];
356
- }
357
- });
358
- });
359
- };
196
+ async sendImage(to, filePath, filename, caption, quotedMessageId, isViewOnce, options) {
197
+ let base64 = await (0, helpers_1.downloadFileToBase64)(filePath, [
198
+ 'image/gif',
199
+ 'image/png',
200
+ 'image/jpg',
201
+ 'image/jpeg',
202
+ 'image/webp',
203
+ ]);
204
+ if (!base64) {
205
+ base64 = await (0, helpers_1.fileToBase64)(filePath);
206
+ }
207
+ if (!base64) {
208
+ const obj = {
209
+ erro: true,
210
+ to: to,
211
+ text: 'No such file or directory, open "' + filePath + '"',
212
+ };
213
+ throw obj;
214
+ }
215
+ if (!filename) {
216
+ filename = path.basename(filePath);
217
+ }
218
+ return await this.sendImageFromBase64(to, base64, filename, caption, quotedMessageId, isViewOnce, options?.mentionedList, options || {});
219
+ }
360
220
  /**
361
221
  * Sends image message
362
222
  * @category Chat
@@ -373,76 +233,54 @@ var SenderLayer = /** @class */ (function (_super) {
373
233
  * await client.sendImageFromBase64("120[...]381@g.us'", "data:image/png;base64," + base64picture, "picture.png")
374
234
  * ```
375
235
  */
376
- SenderLayer.prototype.sendImageFromBase64 = function (to, base64, filename, caption, quotedMessageId, isViewOnce, mentionedList, options) {
377
- return __awaiter(this, void 0, void 0, function () {
378
- var mimeType, obj, obj, result;
379
- var _this = this;
380
- return __generator(this, function (_a) {
381
- switch (_a.label) {
382
- case 0:
383
- mimeType = (0, helpers_1.base64MimeType)(base64);
384
- if (!mimeType) {
385
- obj = {
386
- erro: true,
387
- to: to,
388
- text: 'Invalid base64!',
389
- };
390
- throw obj;
391
- }
392
- if (!mimeType.includes('image')) {
393
- obj = {
394
- erro: true,
395
- to: to,
396
- text: 'Not an image, allowed formats png, jpeg and webp',
397
- };
398
- throw obj;
399
- }
400
- filename = (0, filename_from_mimetype_1.filenameFromMimeType)(filename, mimeType);
401
- return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) { return __awaiter(_this, [_a], void 0, function (_b) {
402
- var result;
403
- var _c;
404
- var to = _b.to, base64 = _b.base64, filename = _b.filename, caption = _b.caption, quotedMessageId = _b.quotedMessageId, isViewOnce = _b.isViewOnce, mentionedList = _b.mentionedList, options = _b.options;
405
- return __generator(this, function (_d) {
406
- switch (_d.label) {
407
- case 0: return [4 /*yield*/, WPP.chat.sendFileMessage(to, base64, {
408
- type: 'image',
409
- isViewOnce: isViewOnce,
410
- messageId: options === null || options === void 0 ? void 0 : options.msgId,
411
- filename: filename,
412
- caption: caption,
413
- quotedMsg: quotedMessageId,
414
- waitForAck: true,
415
- detectMentioned: true,
416
- mentionedList: mentionedList,
417
- })];
418
- case 1:
419
- result = _d.sent();
420
- _c = {
421
- ack: result.ack,
422
- id: result.id
423
- };
424
- return [4 /*yield*/, result.sendMsgResult];
425
- case 2: return [2 /*return*/, (_c.sendMsgResult = _d.sent(),
426
- _c)];
427
- }
428
- });
429
- }); }, {
430
- to: to,
431
- base64: base64,
432
- filename: filename,
433
- caption: caption,
434
- quotedMessageId: quotedMessageId,
435
- isViewOnce: isViewOnce,
436
- mentionedList: mentionedList,
437
- options: options,
438
- })];
439
- case 1:
440
- result = _a.sent();
441
- return [2 /*return*/, result];
442
- }
236
+ async sendImageFromBase64(to, base64, filename, caption, quotedMessageId, isViewOnce, mentionedList, options) {
237
+ let mimeType = (0, helpers_1.base64MimeType)(base64);
238
+ if (!mimeType) {
239
+ const obj = {
240
+ erro: true,
241
+ to: to,
242
+ text: 'Invalid base64!',
243
+ };
244
+ throw obj;
245
+ }
246
+ if (!mimeType.includes('image')) {
247
+ const obj = {
248
+ erro: true,
249
+ to: to,
250
+ text: 'Not an image, allowed formats png, jpeg and webp',
251
+ };
252
+ throw obj;
253
+ }
254
+ filename = (0, filename_from_mimetype_1.filenameFromMimeType)(filename, mimeType);
255
+ const result = await (0, helpers_1.evaluateAndReturn)(this.page, async ({ to, base64, filename, caption, quotedMessageId, isViewOnce, mentionedList, options, }) => {
256
+ const result = await WPP.chat.sendFileMessage(to, base64, {
257
+ type: 'image',
258
+ isViewOnce,
259
+ messageId: options?.msgId,
260
+ filename,
261
+ caption,
262
+ quotedMsg: quotedMessageId,
263
+ waitForAck: true,
264
+ detectMentioned: true,
265
+ mentionedList: mentionedList,
443
266
  });
267
+ return {
268
+ ack: result.ack,
269
+ id: result.id,
270
+ sendMsgResult: await result.sendMsgResult,
271
+ };
272
+ }, {
273
+ to,
274
+ base64,
275
+ filename,
276
+ caption,
277
+ quotedMessageId,
278
+ isViewOnce,
279
+ mentionedList,
280
+ options,
444
281
  });
445
- };
282
+ return result;
283
+ }
446
284
  /**
447
285
  * Sends message with thumbnail
448
286
  *
@@ -456,76 +294,60 @@ var SenderLayer = /** @class */ (function (_super) {
456
294
  * @param description
457
295
  * @param chatId
458
296
  */
459
- SenderLayer.prototype.sendMessageWithThumb = function (pathOrBase64, url, title, description, chatId) {
460
- return __awaiter(this, void 0, void 0, function () {
461
- var base64, fileContent, error, mimeInfo, error, thumbnail;
462
- return __generator(this, function (_a) {
463
- switch (_a.label) {
464
- case 0:
465
- base64 = '';
466
- if (!pathOrBase64.startsWith('data:')) return [3 /*break*/, 1];
467
- base64 = pathOrBase64;
468
- return [3 /*break*/, 5];
469
- case 1: return [4 /*yield*/, (0, helpers_1.downloadFileToBase64)(pathOrBase64, [
470
- 'image/gif',
471
- 'image/png',
472
- 'image/jpg',
473
- 'image/jpeg',
474
- 'image/webp',
475
- ])];
476
- case 2:
477
- fileContent = _a.sent();
478
- if (!!fileContent) return [3 /*break*/, 4];
479
- return [4 /*yield*/, (0, helpers_1.fileToBase64)(pathOrBase64)];
480
- case 3:
481
- fileContent = _a.sent();
482
- _a.label = 4;
483
- case 4:
484
- if (fileContent) {
485
- base64 = fileContent;
486
- }
487
- _a.label = 5;
488
- case 5:
489
- if (!base64) {
490
- error = new Error('Empty or invalid file or base64');
491
- Object.assign(error, {
492
- code: 'empty_file',
493
- });
494
- throw error;
495
- }
496
- mimeInfo = (0, helpers_1.base64MimeType)(base64);
497
- if (!mimeInfo || !mimeInfo.includes('image')) {
498
- error = new Error('Not an image, allowed formats png, jpeg, webp and gif');
499
- Object.assign(error, {
500
- code: 'invalid_image',
501
- });
502
- throw error;
503
- }
504
- thumbnail = base64.replace(/^data:image\/(png|jpe?g|webp|gif);base64,/, '');
505
- return [2 /*return*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
506
- var thumbnail = _a.thumbnail, url = _a.url, title = _a.title, description = _a.description, chatId = _a.chatId;
507
- return WPP.chat.sendTextMessage(chatId, url, {
508
- linkPreview: {
509
- thumbnail: thumbnail,
510
- canonicalUrl: url,
511
- description: description,
512
- matchedText: url,
513
- title: title,
514
- richPreviewType: 0,
515
- doNotPlayInline: true,
516
- },
517
- });
518
- }, {
519
- thumbnail: thumbnail,
520
- url: url,
521
- title: title,
522
- description: description,
523
- chatId: chatId,
524
- })];
525
- }
297
+ async sendMessageWithThumb(pathOrBase64, url, title, description, chatId) {
298
+ let base64 = '';
299
+ if (pathOrBase64.startsWith('data:')) {
300
+ base64 = pathOrBase64;
301
+ }
302
+ else {
303
+ let fileContent = await (0, helpers_1.downloadFileToBase64)(pathOrBase64, [
304
+ 'image/gif',
305
+ 'image/png',
306
+ 'image/jpg',
307
+ 'image/jpeg',
308
+ 'image/webp',
309
+ ]);
310
+ if (!fileContent) {
311
+ fileContent = await (0, helpers_1.fileToBase64)(pathOrBase64);
312
+ }
313
+ if (fileContent) {
314
+ base64 = fileContent;
315
+ }
316
+ }
317
+ if (!base64) {
318
+ const error = new Error('Empty or invalid file or base64');
319
+ Object.assign(error, {
320
+ code: 'empty_file',
321
+ });
322
+ throw error;
323
+ }
324
+ const mimeInfo = (0, helpers_1.base64MimeType)(base64);
325
+ if (!mimeInfo || !mimeInfo.includes('image')) {
326
+ const error = new Error('Not an image, allowed formats png, jpeg, webp and gif');
327
+ Object.assign(error, {
328
+ code: 'invalid_image',
526
329
  });
330
+ throw error;
331
+ }
332
+ const thumbnail = base64.replace(/^data:image\/(png|jpe?g|webp|gif);base64,/, '');
333
+ return (0, helpers_1.evaluateAndReturn)(this.page, ({ thumbnail, url, title, description, chatId }) => WPP.chat.sendTextMessage(chatId, url, {
334
+ linkPreview: {
335
+ thumbnail: thumbnail,
336
+ canonicalUrl: url,
337
+ description: description,
338
+ matchedText: url,
339
+ title: title,
340
+ richPreviewType: 0,
341
+ doNotPlayInline: true,
342
+ },
343
+ }), {
344
+ thumbnail,
345
+ url,
346
+ title,
347
+ description,
348
+ chatId,
527
349
  });
528
- };
350
+ }
529
351
  /**
530
352
  * Replies to given mesage id of given chat id
531
353
  *
@@ -538,28 +360,16 @@ var SenderLayer = /** @class */ (function (_super) {
538
360
  * @param content Message body
539
361
  * @param quotedMsg Message id to reply to.
540
362
  */
541
- SenderLayer.prototype.reply = function (to, content, quotedMsg) {
542
- return __awaiter(this, void 0, void 0, function () {
543
- var result, message;
544
- return __generator(this, function (_a) {
545
- switch (_a.label) {
546
- case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
547
- var to = _a.to, content = _a.content, quotedMsg = _a.quotedMsg;
548
- return WPP.chat.sendTextMessage(to, content, { quotedMsg: quotedMsg });
549
- }, { to: to, content: content, quotedMsg: quotedMsg })];
550
- case 1:
551
- result = _a.sent();
552
- return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (messageId) { return WAPI.getMessageById(messageId); }, result.id)];
553
- case 2:
554
- message = (_a.sent());
555
- if (message['erro'] == true) {
556
- throw message;
557
- }
558
- return [2 /*return*/, message];
559
- }
560
- });
561
- });
562
- };
363
+ async reply(to, content, quotedMsg) {
364
+ const result = await (0, helpers_1.evaluateAndReturn)(this.page, ({ to, content, quotedMsg }) => {
365
+ return WPP.chat.sendTextMessage(to, content, { quotedMsg });
366
+ }, { to, content, quotedMsg });
367
+ const message = (await (0, helpers_1.evaluateAndReturn)(this.page, (messageId) => WAPI.getMessageById(messageId), result.id));
368
+ if (message['erro'] == true) {
369
+ throw message;
370
+ }
371
+ return message;
372
+ }
563
373
  /**
564
374
  * Sends ptt audio
565
375
  * base64 parameter should have mime type already defined
@@ -572,47 +382,25 @@ var SenderLayer = /** @class */ (function (_super) {
572
382
  * @param messageId Set the id for this message
573
383
  * @param isPtt Set as ptt audio
574
384
  */
575
- SenderLayer.prototype.sendPttFromBase64 = function (to_1, base64_1, filename_1, caption_1, quotedMessageId_1, messageId_1) {
576
- return __awaiter(this, arguments, void 0, function (to, base64, filename, caption, quotedMessageId, messageId, isPtt) {
577
- var result;
578
- var _this = this;
579
- if (isPtt === void 0) { isPtt = true; }
580
- return __generator(this, function (_a) {
581
- switch (_a.label) {
582
- case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) { return __awaiter(_this, [_a], void 0, function (_b) {
583
- var result;
584
- var _c;
585
- var to = _b.to, base64 = _b.base64, filename = _b.filename, caption = _b.caption, quotedMessageId = _b.quotedMessageId, messageId = _b.messageId, isPtt = _b.isPtt;
586
- return __generator(this, function (_d) {
587
- switch (_d.label) {
588
- case 0: return [4 /*yield*/, WPP.chat.sendFileMessage(to, base64, {
589
- type: 'audio',
590
- isPtt: isPtt,
591
- filename: filename,
592
- caption: caption,
593
- quotedMsg: quotedMessageId,
594
- waitForAck: true,
595
- messageId: messageId,
596
- })];
597
- case 1:
598
- result = _d.sent();
599
- _c = {
600
- ack: result.ack,
601
- id: result.id
602
- };
603
- return [4 /*yield*/, result.sendMsgResult];
604
- case 2: return [2 /*return*/, (_c.sendMsgResult = _d.sent(),
605
- _c)];
606
- }
607
- });
608
- }); }, { to: to, base64: base64, filename: filename, caption: caption, quotedMessageId: quotedMessageId, messageId: messageId, isPtt: isPtt })];
609
- case 1:
610
- result = _a.sent();
611
- return [2 /*return*/, result];
612
- }
385
+ async sendPttFromBase64(to, base64, filename, caption, quotedMessageId, messageId, isPtt = true) {
386
+ const result = await (0, helpers_1.evaluateAndReturn)(this.page, async ({ to, base64, filename, caption, quotedMessageId, messageId, isPtt, }) => {
387
+ const result = await WPP.chat.sendFileMessage(to, base64, {
388
+ type: 'audio',
389
+ isPtt: isPtt,
390
+ filename,
391
+ caption,
392
+ quotedMsg: quotedMessageId,
393
+ waitForAck: true,
394
+ messageId: messageId,
613
395
  });
614
- });
615
- };
396
+ return {
397
+ ack: result.ack,
398
+ id: result.id,
399
+ sendMsgResult: await result.sendMsgResult,
400
+ };
401
+ }, { to, base64, filename, caption, quotedMessageId, messageId, isPtt });
402
+ return result;
403
+ }
616
404
  /**
617
405
  * Sends ptt audio from path
618
406
  * @category Chat
@@ -624,44 +412,28 @@ var SenderLayer = /** @class */ (function (_super) {
624
412
  * @param messageId Set the id for this message
625
413
  * @param isPtt Set as ptt audio
626
414
  */
627
- SenderLayer.prototype.sendPtt = function (to_1, filePath_1, filename_1, caption_1, quotedMessageId_1, messageId_1) {
628
- return __awaiter(this, arguments, void 0, function (to, filePath, filename, caption, quotedMessageId, messageId, isPtt) {
629
- var _this = this;
630
- if (isPtt === void 0) { isPtt = true; }
631
- return __generator(this, function (_a) {
632
- return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
633
- var base64, obj;
634
- return __generator(this, function (_a) {
635
- switch (_a.label) {
636
- case 0: return [4 /*yield*/, (0, helpers_1.downloadFileToBase64)(filePath, [/^audio/])];
637
- case 1:
638
- base64 = _a.sent();
639
- if (!!base64) return [3 /*break*/, 3];
640
- return [4 /*yield*/, (0, helpers_1.fileToBase64)(filePath)];
641
- case 2:
642
- base64 = _a.sent();
643
- _a.label = 3;
644
- case 3:
645
- if (!base64) {
646
- obj = {
647
- erro: true,
648
- to: to,
649
- text: 'No such file or directory, open "' + filePath + '"',
650
- };
651
- return [2 /*return*/, reject(obj)];
652
- }
653
- if (!filename) {
654
- filename = path.basename(filePath);
655
- }
656
- return [2 /*return*/, this.sendPttFromBase64(to, base64, filename, caption, quotedMessageId, messageId, isPtt)
657
- .then(resolve)
658
- .catch(reject)];
659
- }
660
- });
661
- }); })];
662
- });
415
+ async sendPtt(to, filePath, filename, caption, quotedMessageId, messageId, isPtt = true) {
416
+ return new Promise(async (resolve, reject) => {
417
+ let base64 = await (0, helpers_1.downloadFileToBase64)(filePath, [/^audio/]), obj;
418
+ if (!base64) {
419
+ base64 = await (0, helpers_1.fileToBase64)(filePath);
420
+ }
421
+ if (!base64) {
422
+ obj = {
423
+ erro: true,
424
+ to: to,
425
+ text: 'No such file or directory, open "' + filePath + '"',
426
+ };
427
+ return reject(obj);
428
+ }
429
+ if (!filename) {
430
+ filename = path.basename(filePath);
431
+ }
432
+ return this.sendPttFromBase64(to, base64, filename, caption, quotedMessageId, messageId, isPtt)
433
+ .then(resolve)
434
+ .catch(reject);
663
435
  });
664
- };
436
+ }
665
437
  /**
666
438
  * Sends file
667
439
  * base64 parameter should have mime type already defined
@@ -676,79 +448,50 @@ var SenderLayer = /** @class */ (function (_super) {
676
448
  * @param filename
677
449
  * @param caption
678
450
  */
679
- SenderLayer.prototype.sendFileFromBase64 = function (chatId, base64, filename, caption) {
680
- return __awaiter(this, void 0, void 0, function () {
681
- return __generator(this, function (_a) {
682
- return [2 /*return*/, this.sendFile(chatId, base64, filename, caption)];
683
- });
684
- });
685
- };
686
- SenderLayer.prototype.sendFile = function (to, pathOrBase64, nameOrOptions, caption) {
687
- return __awaiter(this, void 0, void 0, function () {
688
- var options, base64, fileContent, error;
689
- var _this = this;
690
- return __generator(this, function (_a) {
691
- switch (_a.label) {
692
- case 0:
693
- options = { type: 'auto-detect' };
694
- if (typeof nameOrOptions === 'string') {
695
- options.filename = nameOrOptions;
696
- options.caption = caption;
697
- }
698
- else if (typeof nameOrOptions === 'object') {
699
- options = nameOrOptions;
700
- }
701
- base64 = '';
702
- if (!pathOrBase64.startsWith('data:')) return [3 /*break*/, 1];
703
- base64 = pathOrBase64;
704
- return [3 /*break*/, 5];
705
- case 1: return [4 /*yield*/, (0, helpers_1.downloadFileToBase64)(pathOrBase64)];
706
- case 2:
707
- fileContent = _a.sent();
708
- if (!!fileContent) return [3 /*break*/, 4];
709
- return [4 /*yield*/, (0, helpers_1.fileToBase64)(pathOrBase64)];
710
- case 3:
711
- fileContent = _a.sent();
712
- _a.label = 4;
713
- case 4:
714
- if (fileContent) {
715
- base64 = fileContent;
716
- }
717
- if (!options.filename) {
718
- options.filename = path.basename(pathOrBase64);
719
- }
720
- _a.label = 5;
721
- case 5:
722
- if (!base64) {
723
- error = new Error('Empty or invalid file or base64');
724
- Object.assign(error, {
725
- code: 'empty_file',
726
- });
727
- throw error;
728
- }
729
- return [2 /*return*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) { return __awaiter(_this, [_a], void 0, function (_b) {
730
- var result;
731
- var _c;
732
- var to = _b.to, base64 = _b.base64, options = _b.options;
733
- return __generator(this, function (_d) {
734
- switch (_d.label) {
735
- case 0: return [4 /*yield*/, WPP.chat.sendFileMessage(to, base64, options)];
736
- case 1:
737
- result = _d.sent();
738
- _c = {
739
- ack: result.ack,
740
- id: result.id
741
- };
742
- return [4 /*yield*/, result.sendMsgResult];
743
- case 2: return [2 /*return*/, (_c.sendMsgResult = _d.sent(),
744
- _c)];
745
- }
746
- });
747
- }); }, { to: to, base64: base64, options: options })];
748
- }
451
+ async sendFileFromBase64(chatId, base64, filename, caption) {
452
+ return this.sendFile(chatId, base64, filename, caption);
453
+ }
454
+ async sendFile(to, pathOrBase64, nameOrOptions, caption) {
455
+ let options = { type: 'auto-detect' };
456
+ if (typeof nameOrOptions === 'string') {
457
+ options.filename = nameOrOptions;
458
+ options.caption = caption;
459
+ }
460
+ else if (typeof nameOrOptions === 'object') {
461
+ options = nameOrOptions;
462
+ }
463
+ let base64 = '';
464
+ if (pathOrBase64.startsWith('data:')) {
465
+ base64 = pathOrBase64;
466
+ }
467
+ else {
468
+ let fileContent = await (0, helpers_1.downloadFileToBase64)(pathOrBase64);
469
+ if (!fileContent) {
470
+ fileContent = await (0, helpers_1.fileToBase64)(pathOrBase64);
471
+ }
472
+ if (fileContent) {
473
+ base64 = fileContent;
474
+ }
475
+ if (!options.filename) {
476
+ options.filename = path.basename(pathOrBase64);
477
+ }
478
+ }
479
+ if (!base64) {
480
+ const error = new Error('Empty or invalid file or base64');
481
+ Object.assign(error, {
482
+ code: 'empty_file',
749
483
  });
750
- });
751
- };
484
+ throw error;
485
+ }
486
+ return (0, helpers_1.evaluateAndReturn)(this.page, async ({ to, base64, options }) => {
487
+ const result = await WPP.chat.sendFileMessage(to, base64, options);
488
+ return {
489
+ ack: result.ack,
490
+ id: result.id,
491
+ sendMsgResult: await result.sendMsgResult,
492
+ };
493
+ }, { to, base64, options: options });
494
+ }
752
495
  /**
753
496
  * Sends a video to given chat as a gif, with caption or not
754
497
  * @category Chat
@@ -757,36 +500,24 @@ var SenderLayer = /** @class */ (function (_super) {
757
500
  * @param filename
758
501
  * @param caption
759
502
  */
760
- SenderLayer.prototype.sendVideoAsGif = function (to, filePath, filename, caption) {
761
- return __awaiter(this, void 0, void 0, function () {
762
- var base64, obj;
763
- return __generator(this, function (_a) {
764
- switch (_a.label) {
765
- case 0: return [4 /*yield*/, (0, helpers_1.downloadFileToBase64)(filePath)];
766
- case 1:
767
- base64 = _a.sent();
768
- if (!!base64) return [3 /*break*/, 3];
769
- return [4 /*yield*/, (0, helpers_1.fileToBase64)(filePath)];
770
- case 2:
771
- base64 = _a.sent();
772
- _a.label = 3;
773
- case 3:
774
- if (!base64) {
775
- obj = {
776
- erro: true,
777
- to: to,
778
- text: 'No such file or directory, open "' + filePath + '"',
779
- };
780
- throw obj;
781
- }
782
- if (!filename) {
783
- filename = path.basename(filePath);
784
- }
785
- return [2 /*return*/, this.sendVideoAsGifFromBase64(to, base64, filename, caption)];
786
- }
787
- });
788
- });
789
- };
503
+ async sendVideoAsGif(to, filePath, filename, caption) {
504
+ let base64 = await (0, helpers_1.downloadFileToBase64)(filePath), obj;
505
+ if (!base64) {
506
+ base64 = await (0, helpers_1.fileToBase64)(filePath);
507
+ }
508
+ if (!base64) {
509
+ obj = {
510
+ erro: true,
511
+ to: to,
512
+ text: 'No such file or directory, open "' + filePath + '"',
513
+ };
514
+ throw obj;
515
+ }
516
+ if (!filename) {
517
+ filename = path.basename(filePath);
518
+ }
519
+ return this.sendVideoAsGifFromBase64(to, base64, filename, caption);
520
+ }
790
521
  /**
791
522
  * Sends a video to given chat as a gif, with caption or not, using base64
792
523
  * @category Chat
@@ -795,45 +526,24 @@ var SenderLayer = /** @class */ (function (_super) {
795
526
  * @param filename string xxxxx
796
527
  * @param caption string xxxxx
797
528
  */
798
- SenderLayer.prototype.sendVideoAsGifFromBase64 = function (to, base64, filename, caption, quotedMessageId) {
799
- return __awaiter(this, void 0, void 0, function () {
800
- var result;
801
- var _this = this;
802
- return __generator(this, function (_a) {
803
- switch (_a.label) {
804
- case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) { return __awaiter(_this, [_a], void 0, function (_b) {
805
- var result;
806
- var _c;
807
- var to = _b.to, base64 = _b.base64, filename = _b.filename, caption = _b.caption, quotedMessageId = _b.quotedMessageId;
808
- return __generator(this, function (_d) {
809
- switch (_d.label) {
810
- case 0: return [4 /*yield*/, WPP.chat.sendFileMessage(to, base64, {
811
- type: 'video',
812
- isGif: true,
813
- filename: filename,
814
- caption: caption,
815
- quotedMsg: quotedMessageId,
816
- waitForAck: true,
817
- })];
818
- case 1:
819
- result = _d.sent();
820
- _c = {
821
- ack: result.ack,
822
- id: result.id
823
- };
824
- return [4 /*yield*/, result.sendMsgResult];
825
- case 2: return [2 /*return*/, (_c.sendMsgResult = _d.sent(),
826
- _c)];
827
- }
828
- });
829
- }); }, { to: to, base64: base64, filename: filename, caption: caption, quotedMessageId: quotedMessageId })];
830
- case 1:
831
- result = _a.sent();
832
- return [2 /*return*/, result];
833
- }
529
+ async sendVideoAsGifFromBase64(to, base64, filename, caption, quotedMessageId) {
530
+ const result = await (0, helpers_1.evaluateAndReturn)(this.page, async ({ to, base64, filename, caption, quotedMessageId }) => {
531
+ const result = await WPP.chat.sendFileMessage(to, base64, {
532
+ type: 'video',
533
+ isGif: true,
534
+ filename,
535
+ caption,
536
+ quotedMsg: quotedMessageId,
537
+ waitForAck: true,
834
538
  });
835
- });
836
- };
539
+ return {
540
+ ack: result.ack,
541
+ id: result.id,
542
+ sendMsgResult: await result.sendMsgResult,
543
+ };
544
+ }, { to, base64, filename, caption, quotedMessageId });
545
+ return result;
546
+ }
837
547
  /**
838
548
  * Sends a video to given chat as a gif, with caption or not, using base64
839
549
  * @category Chat
@@ -842,36 +552,24 @@ var SenderLayer = /** @class */ (function (_super) {
842
552
  * @param filename
843
553
  * @param caption
844
554
  */
845
- SenderLayer.prototype.sendGif = function (to, filePath, filename, caption) {
846
- return __awaiter(this, void 0, void 0, function () {
847
- var base64, obj;
848
- return __generator(this, function (_a) {
849
- switch (_a.label) {
850
- case 0: return [4 /*yield*/, (0, helpers_1.downloadFileToBase64)(filePath)];
851
- case 1:
852
- base64 = _a.sent();
853
- if (!!base64) return [3 /*break*/, 3];
854
- return [4 /*yield*/, (0, helpers_1.fileToBase64)(filePath)];
855
- case 2:
856
- base64 = _a.sent();
857
- _a.label = 3;
858
- case 3:
859
- if (!base64) {
860
- obj = {
861
- erro: true,
862
- to: to,
863
- text: 'No such file or directory, open "' + filePath + '"',
864
- };
865
- throw obj;
866
- }
867
- if (!filename) {
868
- filename = path.basename(filePath);
869
- }
870
- return [2 /*return*/, this.sendGifFromBase64(to, base64, filename, caption)];
871
- }
872
- });
873
- });
874
- };
555
+ async sendGif(to, filePath, filename, caption) {
556
+ let base64 = await (0, helpers_1.downloadFileToBase64)(filePath), obj;
557
+ if (!base64) {
558
+ base64 = await (0, helpers_1.fileToBase64)(filePath);
559
+ }
560
+ if (!base64) {
561
+ obj = {
562
+ erro: true,
563
+ to: to,
564
+ text: 'No such file or directory, open "' + filePath + '"',
565
+ };
566
+ throw obj;
567
+ }
568
+ if (!filename) {
569
+ filename = path.basename(filePath);
570
+ }
571
+ return this.sendGifFromBase64(to, base64, filename, caption);
572
+ }
875
573
  /**
876
574
  * Sends a video to given chat as a gif, with caption or not, using base64
877
575
  * @category Chat
@@ -880,66 +578,37 @@ var SenderLayer = /** @class */ (function (_super) {
880
578
  * @param filename string xxxxx
881
579
  * @param caption string xxxxx
882
580
  */
883
- SenderLayer.prototype.sendGifFromBase64 = function (to, base64, filename, caption) {
884
- return __awaiter(this, void 0, void 0, function () {
885
- return __generator(this, function (_a) {
886
- switch (_a.label) {
887
- case 0: return [4 /*yield*/, (0, ffmpeg_1.convertToMP4GIF)(base64)];
888
- case 1:
889
- base64 = _a.sent();
890
- return [4 /*yield*/, this.sendVideoAsGifFromBase64(to, base64, filename, caption)];
891
- case 2: return [2 /*return*/, _a.sent()];
892
- }
893
- });
894
- });
895
- };
581
+ async sendGifFromBase64(to, base64, filename, caption) {
582
+ base64 = await (0, ffmpeg_1.convertToMP4GIF)(base64);
583
+ return await this.sendVideoAsGifFromBase64(to, base64, filename, caption);
584
+ }
896
585
  /**
897
586
  * Sends contact card to iven chat id
898
587
  * @category Chat
899
588
  * @param to Chat id
900
589
  * @param contactsId Example: 0000@c.us | [000@c.us, 1111@c.us]
901
590
  */
902
- SenderLayer.prototype.sendContactVcard = function (to, contactsId, name) {
903
- return __awaiter(this, void 0, void 0, function () {
904
- var result;
905
- return __generator(this, function (_a) {
906
- switch (_a.label) {
907
- case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
908
- var to = _a.to, contactsId = _a.contactsId, name = _a.name;
909
- return WPP.chat.sendVCardContactMessage(to, {
910
- id: contactsId,
911
- name: name,
912
- });
913
- }, { to: to, contactsId: contactsId, name: name })];
914
- case 1:
915
- result = _a.sent();
916
- return [2 /*return*/, result];
917
- }
591
+ async sendContactVcard(to, contactsId, name) {
592
+ const result = await (0, helpers_1.evaluateAndReturn)(this.page, ({ to, contactsId, name }) => {
593
+ return WPP.chat.sendVCardContactMessage(to, {
594
+ id: contactsId,
595
+ name: name,
918
596
  });
919
- });
920
- };
597
+ }, { to, contactsId, name });
598
+ return result;
599
+ }
921
600
  /**
922
601
  * Send a list of contact cards
923
602
  * @category Chat
924
603
  * @param to Chat id
925
604
  * @param contacts Example: | ['000@c.us', '1111@c.us', {id: '2222@c.us', name: 'Test'}]
926
605
  */
927
- SenderLayer.prototype.sendContactVcardList = function (to, contacts) {
928
- return __awaiter(this, void 0, void 0, function () {
929
- var result;
930
- return __generator(this, function (_a) {
931
- switch (_a.label) {
932
- case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
933
- var to = _a.to, contacts = _a.contacts;
934
- return WPP.chat.sendVCardContactMessage(to, contacts);
935
- }, { to: to, contacts: contacts })];
936
- case 1:
937
- result = _a.sent();
938
- return [2 /*return*/, result];
939
- }
940
- });
941
- });
942
- };
606
+ async sendContactVcardList(to, contacts) {
607
+ const result = await (0, helpers_1.evaluateAndReturn)(this.page, ({ to, contacts }) => {
608
+ return WPP.chat.sendVCardContactMessage(to, contacts);
609
+ }, { to, contacts });
610
+ return result;
611
+ }
943
612
  /**
944
613
  * Forwards array of messages (could be ids or message objects)
945
614
  * @deprecated please use {@link forwardMessagesV2}
@@ -949,16 +618,9 @@ var SenderLayer = /** @class */ (function (_super) {
949
618
  * @param skipMyMessages
950
619
  * @returns array of messages ID
951
620
  */
952
- SenderLayer.prototype.forwardMessage = function (toChatId, msgId, options) {
953
- return __awaiter(this, void 0, void 0, function () {
954
- return __generator(this, function (_a) {
955
- return [2 /*return*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
956
- var toChatId = _a.toChatId, msgId = _a.msgId, options = _a.options;
957
- return WPP.chat.forwardMessage(toChatId, msgId, options);
958
- }, { toChatId: toChatId, msgId: msgId, options: options })];
959
- });
960
- });
961
- };
621
+ async forwardMessage(toChatId, msgId, options) {
622
+ return (0, helpers_1.evaluateAndReturn)(this.page, ({ toChatId, msgId, options }) => WPP.chat.forwardMessage(toChatId, msgId, options), { toChatId, msgId, options });
623
+ }
962
624
  /**
963
625
  * Forwards array of messages (could be ids or message objects)
964
626
  * What is the difference between forwardMessage and forwardMessagesV2?
@@ -972,16 +634,9 @@ var SenderLayer = /** @class */ (function (_super) {
972
634
  * @param options
973
635
  * @returns array of messages ID
974
636
  */
975
- SenderLayer.prototype.forwardMessagesV2 = function (toChatId, messages, options) {
976
- return __awaiter(this, void 0, void 0, function () {
977
- return __generator(this, function (_a) {
978
- return [2 /*return*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
979
- var toChatId = _a.toChatId, messages = _a.messages, options = _a.options;
980
- return WPP.chat.forwardMessages(toChatId, messages, options);
981
- }, { toChatId: toChatId, messages: messages, options: options })];
982
- });
983
- });
984
- };
637
+ async forwardMessagesV2(toChatId, messages, options) {
638
+ return (0, helpers_1.evaluateAndReturn)(this.page, ({ toChatId, messages, options }) => WPP.chat.forwardMessages(toChatId, messages, options), { toChatId, messages, options });
639
+ }
985
640
  /**
986
641
  * Generates sticker from the provided animated gif image and sends it (Send image as animated sticker)
987
642
  *
@@ -1001,69 +656,55 @@ var SenderLayer = /** @class */ (function (_super) {
1001
656
  * @param pathOrBase64 image path imageBase64 A valid gif image is required. You can also send via http/https (http://www.website.com/img.gif)
1002
657
  * @param to chatId '000000000000@c.us'
1003
658
  */
1004
- SenderLayer.prototype.sendImageAsStickerGif = function (to, pathOrBase64, options) {
1005
- return __awaiter(this, void 0, void 0, function () {
1006
- var base64, fileContent, error, mimeInfo, error, buff, obj, error, webpBase64;
1007
- return __generator(this, function (_a) {
1008
- switch (_a.label) {
1009
- case 0:
1010
- base64 = '';
1011
- if (!pathOrBase64.startsWith('data:')) return [3 /*break*/, 1];
1012
- base64 = pathOrBase64;
1013
- return [3 /*break*/, 5];
1014
- case 1: return [4 /*yield*/, (0, helpers_1.downloadFileToBase64)(pathOrBase64, [
1015
- 'image/gif',
1016
- 'image/webp',
1017
- ])];
1018
- case 2:
1019
- fileContent = _a.sent();
1020
- if (!!fileContent) return [3 /*break*/, 4];
1021
- return [4 /*yield*/, (0, helpers_1.fileToBase64)(pathOrBase64)];
1022
- case 3:
1023
- fileContent = _a.sent();
1024
- _a.label = 4;
1025
- case 4:
1026
- if (fileContent) {
1027
- base64 = fileContent;
1028
- }
1029
- _a.label = 5;
1030
- case 5:
1031
- if (!base64) {
1032
- error = new Error('Empty or invalid file or base64');
1033
- Object.assign(error, {
1034
- code: 'empty_file',
1035
- });
1036
- throw error;
1037
- }
1038
- mimeInfo = (0, helpers_1.base64MimeType)(base64);
1039
- if (!mimeInfo || !mimeInfo.includes('image')) {
1040
- error = new Error('Not an image, allowed formats gig and webp');
1041
- Object.assign(error, {
1042
- code: 'invalid_image',
1043
- });
1044
- throw error;
1045
- }
1046
- buff = Buffer.from(base64.replace(/^data:image\/(gif|webp);base64,/, ''), 'base64');
1047
- return [4 /*yield*/, (0, helpers_1.stickerSelect)(buff, 1)];
1048
- case 6:
1049
- obj = _a.sent();
1050
- if (!obj) {
1051
- error = new Error('Error with sharp library, check the console log');
1052
- Object.assign(error, {
1053
- code: 'sharp_error',
1054
- });
1055
- throw error;
1056
- }
1057
- webpBase64 = obj.webpBase64;
1058
- return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
1059
- var to = _a.to, webpBase64 = _a.webpBase64, options = _a.options;
1060
- return WPP.chat.sendFileMessage(to, webpBase64, __assign({ type: 'sticker' }, options));
1061
- }, { to: to, webpBase64: webpBase64, options: options })];
1062
- case 7: return [2 /*return*/, _a.sent()];
1063
- }
659
+ async sendImageAsStickerGif(to, pathOrBase64, options) {
660
+ let base64 = '';
661
+ if (pathOrBase64.startsWith('data:')) {
662
+ base64 = pathOrBase64;
663
+ }
664
+ else {
665
+ let fileContent = await (0, helpers_1.downloadFileToBase64)(pathOrBase64, [
666
+ 'image/gif',
667
+ 'image/webp',
668
+ ]);
669
+ if (!fileContent) {
670
+ fileContent = await (0, helpers_1.fileToBase64)(pathOrBase64);
671
+ }
672
+ if (fileContent) {
673
+ base64 = fileContent;
674
+ }
675
+ }
676
+ if (!base64) {
677
+ const error = new Error('Empty or invalid file or base64');
678
+ Object.assign(error, {
679
+ code: 'empty_file',
1064
680
  });
1065
- });
1066
- };
681
+ throw error;
682
+ }
683
+ const mimeInfo = (0, helpers_1.base64MimeType)(base64);
684
+ if (!mimeInfo || !mimeInfo.includes('image')) {
685
+ const error = new Error('Not an image, allowed formats gig and webp');
686
+ Object.assign(error, {
687
+ code: 'invalid_image',
688
+ });
689
+ throw error;
690
+ }
691
+ const buff = Buffer.from(base64.replace(/^data:image\/(gif|webp);base64,/, ''), 'base64');
692
+ let obj = await (0, helpers_1.stickerSelect)(buff, 1);
693
+ if (!obj) {
694
+ const error = new Error('Error with sharp library, check the console log');
695
+ Object.assign(error, {
696
+ code: 'sharp_error',
697
+ });
698
+ throw error;
699
+ }
700
+ const { webpBase64 } = obj;
701
+ return await (0, helpers_1.evaluateAndReturn)(this.page, ({ to, webpBase64, options }) => {
702
+ return WPP.chat.sendFileMessage(to, webpBase64, {
703
+ type: 'sticker',
704
+ ...options,
705
+ });
706
+ }, { to, webpBase64, options });
707
+ }
1067
708
  /**
1068
709
  * Generates sticker from given image and sends it (Send Image As Sticker)
1069
710
  *
@@ -1084,134 +725,91 @@ var SenderLayer = /** @class */ (function (_super) {
1084
725
  * @param pathOrBase64 image path imageBase64 A valid png, jpg and webp image is required. You can also send via http/https (http://www.website.com/img.gif)
1085
726
  * @param to chatId '000000000000@c.us'
1086
727
  */
1087
- SenderLayer.prototype.sendImageAsSticker = function (to, pathOrBase64, options) {
1088
- return __awaiter(this, void 0, void 0, function () {
1089
- var base64, fileContent, error, mimeInfo, error, buff, obj, error, webpBase64;
1090
- return __generator(this, function (_a) {
1091
- switch (_a.label) {
1092
- case 0:
1093
- base64 = '';
1094
- if (!pathOrBase64.startsWith('data:')) return [3 /*break*/, 1];
1095
- base64 = pathOrBase64;
1096
- return [3 /*break*/, 5];
1097
- case 1: return [4 /*yield*/, (0, helpers_1.downloadFileToBase64)(pathOrBase64, [
1098
- 'image/gif',
1099
- 'image/png',
1100
- 'image/jpg',
1101
- 'image/jpeg',
1102
- 'image/webp',
1103
- ])];
1104
- case 2:
1105
- fileContent = _a.sent();
1106
- if (!!fileContent) return [3 /*break*/, 4];
1107
- return [4 /*yield*/, (0, helpers_1.fileToBase64)(pathOrBase64)];
1108
- case 3:
1109
- fileContent = _a.sent();
1110
- _a.label = 4;
1111
- case 4:
1112
- if (fileContent) {
1113
- base64 = fileContent;
1114
- }
1115
- _a.label = 5;
1116
- case 5:
1117
- if (!base64) {
1118
- error = new Error('Empty or invalid file or base64');
1119
- Object.assign(error, {
1120
- code: 'empty_file',
1121
- });
1122
- throw error;
1123
- }
1124
- mimeInfo = (0, helpers_1.base64MimeType)(base64);
1125
- if (!mimeInfo || !mimeInfo.includes('image')) {
1126
- error = new Error('Not an image, allowed formats png, jpeg, webp and gif');
1127
- Object.assign(error, {
1128
- code: 'invalid_image',
1129
- });
1130
- throw error;
1131
- }
1132
- buff = Buffer.from(base64.replace(/^data:image\/(png|jpe?g|webp|gif);base64,/, ''), 'base64');
1133
- return [4 /*yield*/, (0, helpers_1.stickerSelect)(buff, 0)];
1134
- case 6:
1135
- obj = _a.sent();
1136
- if (!obj) {
1137
- error = new Error('Error with sharp library, check the console log');
1138
- Object.assign(error, {
1139
- code: 'sharp_error',
1140
- });
1141
- throw error;
1142
- }
1143
- webpBase64 = obj.webpBase64;
1144
- return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
1145
- var to = _a.to, webpBase64 = _a.webpBase64, options = _a.options;
1146
- return WPP.chat.sendFileMessage(to, webpBase64, __assign({ type: 'sticker' }, options));
1147
- }, { to: to, webpBase64: webpBase64, options: options })];
1148
- case 7: return [2 /*return*/, _a.sent()];
1149
- }
728
+ async sendImageAsSticker(to, pathOrBase64, options) {
729
+ let base64 = '';
730
+ if (pathOrBase64.startsWith('data:')) {
731
+ base64 = pathOrBase64;
732
+ }
733
+ else {
734
+ let fileContent = await (0, helpers_1.downloadFileToBase64)(pathOrBase64, [
735
+ 'image/gif',
736
+ 'image/png',
737
+ 'image/jpg',
738
+ 'image/jpeg',
739
+ 'image/webp',
740
+ ]);
741
+ if (!fileContent) {
742
+ fileContent = await (0, helpers_1.fileToBase64)(pathOrBase64);
743
+ }
744
+ if (fileContent) {
745
+ base64 = fileContent;
746
+ }
747
+ }
748
+ if (!base64) {
749
+ const error = new Error('Empty or invalid file or base64');
750
+ Object.assign(error, {
751
+ code: 'empty_file',
1150
752
  });
1151
- });
1152
- };
1153
- SenderLayer.prototype.sendLocation = function (to, latitudeOrOptions, longitude, title) {
1154
- return __awaiter(this, void 0, void 0, function () {
1155
- var options;
1156
- var _this = this;
1157
- return __generator(this, function (_a) {
1158
- switch (_a.label) {
1159
- case 0:
1160
- options = typeof latitudeOrOptions === 'string'
1161
- ? {
1162
- lat: latitudeOrOptions,
1163
- lng: longitude,
1164
- title: title,
1165
- }
1166
- : latitudeOrOptions;
1167
- return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) { return __awaiter(_this, [_a], void 0, function (_b) {
1168
- var result;
1169
- var _c;
1170
- var to = _b.to, options = _b.options;
1171
- return __generator(this, function (_d) {
1172
- switch (_d.label) {
1173
- case 0: return [4 /*yield*/, WPP.chat.sendLocationMessage(to, options)];
1174
- case 1:
1175
- result = _d.sent();
1176
- _c = {
1177
- ack: result.ack,
1178
- id: result.id
1179
- };
1180
- return [4 /*yield*/, result.sendMsgResult];
1181
- case 2: return [2 /*return*/, (_c.sendMsgResult = _d.sent(),
1182
- _c)];
1183
- }
1184
- });
1185
- }); }, { to: to, options: options })];
1186
- case 1: return [2 /*return*/, _a.sent()];
1187
- }
753
+ throw error;
754
+ }
755
+ const mimeInfo = (0, helpers_1.base64MimeType)(base64);
756
+ if (!mimeInfo || !mimeInfo.includes('image')) {
757
+ const error = new Error('Not an image, allowed formats png, jpeg, webp and gif');
758
+ Object.assign(error, {
759
+ code: 'invalid_image',
1188
760
  });
1189
- });
1190
- };
761
+ throw error;
762
+ }
763
+ const buff = Buffer.from(base64.replace(/^data:image\/(png|jpe?g|webp|gif);base64,/, ''), 'base64');
764
+ let obj = await (0, helpers_1.stickerSelect)(buff, 0);
765
+ if (!obj) {
766
+ const error = new Error('Error with sharp library, check the console log');
767
+ Object.assign(error, {
768
+ code: 'sharp_error',
769
+ });
770
+ throw error;
771
+ }
772
+ const { webpBase64 } = obj;
773
+ return await (0, helpers_1.evaluateAndReturn)(this.page, ({ to, webpBase64, options }) => {
774
+ return WPP.chat.sendFileMessage(to, webpBase64, {
775
+ type: 'sticker',
776
+ ...options,
777
+ });
778
+ }, { to, webpBase64, options });
779
+ }
780
+ async sendLocation(to, latitudeOrOptions, longitude, title) {
781
+ const options = typeof latitudeOrOptions === 'string'
782
+ ? {
783
+ lat: latitudeOrOptions,
784
+ lng: longitude,
785
+ title: title,
786
+ }
787
+ : latitudeOrOptions;
788
+ return await (0, helpers_1.evaluateAndReturn)(this.page, async ({ to, options }) => {
789
+ const result = await WPP.chat.sendLocationMessage(to, options);
790
+ return {
791
+ ack: result.ack,
792
+ id: result.id,
793
+ sendMsgResult: await result.sendMsgResult,
794
+ };
795
+ }, { to, options: options });
796
+ }
1191
797
  /**
1192
798
  * Sets a chat status to seen. Marks all messages as ack: 3
1193
799
  * @category Chat
1194
800
  * @param chatId chat id: xxxxx@us.c
1195
801
  */
1196
- SenderLayer.prototype.sendSeen = function (chatId) {
1197
- return __awaiter(this, void 0, void 0, function () {
1198
- return __generator(this, function (_a) {
1199
- return [2 /*return*/, (0, helpers_1.evaluateAndReturn)(this.page, function (chatId) { return WPP.chat.markIsRead(chatId); }, chatId)];
1200
- });
1201
- });
1202
- };
802
+ async sendSeen(chatId) {
803
+ return (0, helpers_1.evaluateAndReturn)(this.page, (chatId) => WPP.chat.markIsRead(chatId), chatId);
804
+ }
1203
805
  /**
1204
806
  * Sets an audio or image view once. Marks message as played
1205
807
  * @category Chat
1206
808
  * @param msgId Message id: xxxxx@us.c
1207
809
  */
1208
- SenderLayer.prototype.markPlayed = function (msgId) {
1209
- return __awaiter(this, void 0, void 0, function () {
1210
- return __generator(this, function (_a) {
1211
- return [2 /*return*/, (0, helpers_1.evaluateAndReturn)(this.page, function (msgId) { return WPP.chat.markPlayed(msgId); }, msgId)];
1212
- });
1213
- });
1214
- };
810
+ async markPlayed(msgId) {
811
+ return (0, helpers_1.evaluateAndReturn)(this.page, (msgId) => WPP.chat.markPlayed(msgId), msgId);
812
+ }
1215
813
  /**
1216
814
  * Starts typing ('Typing...' state)
1217
815
  *
@@ -1227,36 +825,22 @@ var SenderLayer = /** @class */ (function (_super) {
1227
825
  * @param to Chat Id
1228
826
  * @param duration Duration in milliseconds
1229
827
  */
1230
- SenderLayer.prototype.startTyping = function (to, duration) {
1231
- return __awaiter(this, void 0, void 0, function () {
1232
- return __generator(this, function (_a) {
1233
- return [2 /*return*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
1234
- var to = _a.to, duration = _a.duration;
1235
- return WPP.chat.markIsComposing(to, duration);
1236
- }, {
1237
- to: to,
1238
- duration: duration,
1239
- })];
1240
- });
828
+ async startTyping(to, duration) {
829
+ return (0, helpers_1.evaluateAndReturn)(this.page, ({ to, duration }) => WPP.chat.markIsComposing(to, duration), {
830
+ to,
831
+ duration,
1241
832
  });
1242
- };
833
+ }
1243
834
  /**
1244
835
  * Stops typing ('Typing...' state)
1245
836
  * @category Chat
1246
837
  * @param to Chat Id
1247
838
  */
1248
- SenderLayer.prototype.stopTyping = function (to) {
1249
- return __awaiter(this, void 0, void 0, function () {
1250
- return __generator(this, function (_a) {
1251
- return [2 /*return*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
1252
- var to = _a.to;
1253
- return WPP.chat.markIsPaused(to);
1254
- }, {
1255
- to: to,
1256
- })];
1257
- });
839
+ async stopTyping(to) {
840
+ return (0, helpers_1.evaluateAndReturn)(this.page, ({ to }) => WPP.chat.markIsPaused(to), {
841
+ to,
1258
842
  });
1259
- };
843
+ }
1260
844
  /**
1261
845
  * Starts recording ('Recording...' state)
1262
846
  * @example
@@ -1271,92 +855,53 @@ var SenderLayer = /** @class */ (function (_super) {
1271
855
  * @param to Chat Id
1272
856
  * @param duration Duration in milliseconds
1273
857
  */
1274
- SenderLayer.prototype.startRecording = function (to, duration) {
1275
- return __awaiter(this, void 0, void 0, function () {
1276
- return __generator(this, function (_a) {
1277
- return [2 /*return*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
1278
- var to = _a.to, duration = _a.duration;
1279
- return WPP.chat.markIsRecording(to, duration);
1280
- }, {
1281
- to: to,
1282
- duration: duration,
1283
- })];
1284
- });
858
+ async startRecording(to, duration) {
859
+ return (0, helpers_1.evaluateAndReturn)(this.page, ({ to, duration }) => WPP.chat.markIsRecording(to, duration), {
860
+ to,
861
+ duration,
1285
862
  });
1286
- };
863
+ }
1287
864
  /**
1288
865
  * Stops recording ('Recording...' state)
1289
866
  * @deprecated please use {@link stopRecording} this function will be removed in future releases
1290
867
  * @category Chat
1291
868
  * @param to Chat Id
1292
869
  */
1293
- SenderLayer.prototype.stopRecoring = function (to) {
1294
- return __awaiter(this, void 0, void 0, function () {
1295
- return __generator(this, function (_a) {
1296
- return [2 /*return*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
1297
- var to = _a.to;
1298
- return WPP.chat.markIsPaused(to);
1299
- }, {
1300
- to: to,
1301
- })];
1302
- });
870
+ async stopRecoring(to) {
871
+ return (0, helpers_1.evaluateAndReturn)(this.page, ({ to }) => WPP.chat.markIsPaused(to), {
872
+ to,
1303
873
  });
1304
- };
874
+ }
1305
875
  /**
1306
876
  * Stops recording ('Recording...' state)
1307
877
  * @category Chat
1308
878
  * @param to Chat Id
1309
879
  */
1310
- SenderLayer.prototype.stopRecording = function (to) {
1311
- return __awaiter(this, void 0, void 0, function () {
1312
- return __generator(this, function (_a) {
1313
- return [2 /*return*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
1314
- var to = _a.to;
1315
- return WPP.chat.markIsPaused(to);
1316
- }, {
1317
- to: to,
1318
- })];
1319
- });
880
+ async stopRecording(to) {
881
+ return (0, helpers_1.evaluateAndReturn)(this.page, ({ to }) => WPP.chat.markIsPaused(to), {
882
+ to,
1320
883
  });
1321
- };
884
+ }
1322
885
  /**
1323
886
  * Update your online presence
1324
887
  * @category Chat
1325
888
  * @param online true for available presence and false for unavailable
1326
889
  */
1327
- SenderLayer.prototype.setOnlinePresence = function () {
1328
- return __awaiter(this, arguments, void 0, function (online) {
1329
- if (online === void 0) { online = true; }
1330
- return __generator(this, function (_a) {
1331
- return [2 /*return*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
1332
- var online = _a.online;
1333
- return WPP.conn.markAvailable(online);
1334
- }, {
1335
- online: online,
1336
- })];
1337
- });
890
+ async setOnlinePresence(online = true) {
891
+ return (0, helpers_1.evaluateAndReturn)(this.page, ({ online }) => WPP.conn.markAvailable(online), {
892
+ online,
1338
893
  });
1339
- };
894
+ }
1340
895
  /**
1341
896
  * Sends text with tags
1342
897
  * @category Chat
1343
898
  */
1344
- SenderLayer.prototype.sendMentioned = function (to, message, mentioned) {
1345
- return __awaiter(this, void 0, void 0, function () {
1346
- return __generator(this, function (_a) {
1347
- switch (_a.label) {
1348
- case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
1349
- var to = _a.to, message = _a.message, mentioned = _a.mentioned;
1350
- return WPP.chat.sendTextMessage(to, message, {
1351
- detectMentioned: true,
1352
- mentionedList: mentioned,
1353
- });
1354
- }, { to: to, message: message, mentioned: mentioned })];
1355
- case 1: return [2 /*return*/, _a.sent()];
1356
- }
1357
- });
1358
- });
1359
- };
899
+ async sendMentioned(to, message, mentioned) {
900
+ return await (0, helpers_1.evaluateAndReturn)(this.page, ({ to, message, mentioned }) => WPP.chat.sendTextMessage(to, message, {
901
+ detectMentioned: true,
902
+ mentionedList: mentioned,
903
+ }), { to, message, mentioned });
904
+ }
1360
905
  /**
1361
906
  * Sends a list message
1362
907
  *
@@ -1387,44 +932,21 @@ var SenderLayer = /** @class */ (function (_super) {
1387
932
  *
1388
933
  * @category Chat
1389
934
  */
1390
- SenderLayer.prototype.sendListMessage = function (to, options) {
1391
- return __awaiter(this, void 0, void 0, function () {
1392
- var sendResult, result;
1393
- var _this = this;
1394
- return __generator(this, function (_a) {
1395
- switch (_a.label) {
1396
- case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
1397
- var to = _a.to, options = _a.options;
1398
- return WPP.chat.sendListMessage(to, options);
1399
- }, {
1400
- to: to,
1401
- options: options,
1402
- })];
1403
- case 1:
1404
- sendResult = _a.sent();
1405
- return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) { return __awaiter(_this, [_a], void 0, function (_b) {
1406
- var _c, _d, _e, _f;
1407
- var messageId = _b.messageId;
1408
- return __generator(this, function (_g) {
1409
- switch (_g.label) {
1410
- case 0:
1411
- _d = (_c = JSON).parse;
1412
- _f = (_e = JSON).stringify;
1413
- return [4 /*yield*/, WAPI.getMessageById(messageId)];
1414
- case 1: return [2 /*return*/, _d.apply(_c, [_f.apply(_e, [_g.sent()])])];
1415
- }
1416
- });
1417
- }); }, { messageId: sendResult.id })];
1418
- case 2:
1419
- result = (_a.sent());
1420
- if (result['erro'] == true) {
1421
- throw result;
1422
- }
1423
- return [2 /*return*/, result];
1424
- }
1425
- });
935
+ async sendListMessage(to, options) {
936
+ const sendResult = await (0, helpers_1.evaluateAndReturn)(this.page, ({ to, options }) => WPP.chat.sendListMessage(to, options), {
937
+ to,
938
+ options: options,
1426
939
  });
1427
- };
940
+ // I don't know why the evaluate is returning undefined for direct call
941
+ // To solve that, I added `JSON.parse(JSON.stringify(<message>))` to solve that
942
+ const result = (await (0, helpers_1.evaluateAndReturn)(this.page, async ({ messageId }) => {
943
+ return JSON.parse(JSON.stringify(await WAPI.getMessageById(messageId)));
944
+ }, { messageId: sendResult.id }));
945
+ if (result['erro'] == true) {
946
+ throw result;
947
+ }
948
+ return result;
949
+ }
1428
950
  /**
1429
951
  * Send a create poll message
1430
952
  *
@@ -1452,46 +974,23 @@ var SenderLayer = /** @class */ (function (_super) {
1452
974
  *
1453
975
  * @category Chat
1454
976
  */
1455
- SenderLayer.prototype.sendPollMessage = function (chatId, name, choices, options) {
1456
- return __awaiter(this, void 0, void 0, function () {
1457
- var sendResult, result;
1458
- var _this = this;
1459
- return __generator(this, function (_a) {
1460
- switch (_a.label) {
1461
- case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
1462
- var chatId = _a.chatId, name = _a.name, choices = _a.choices, options = _a.options;
1463
- return WPP.chat.sendCreatePollMessage(chatId, name, choices, options);
1464
- }, {
1465
- chatId: chatId,
1466
- name: name,
1467
- choices: choices,
1468
- options: options,
1469
- })];
1470
- case 1:
1471
- sendResult = _a.sent();
1472
- return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) { return __awaiter(_this, [_a], void 0, function (_b) {
1473
- var _c, _d, _e, _f;
1474
- var messageId = _b.messageId;
1475
- return __generator(this, function (_g) {
1476
- switch (_g.label) {
1477
- case 0:
1478
- _d = (_c = JSON).parse;
1479
- _f = (_e = JSON).stringify;
1480
- return [4 /*yield*/, WAPI.getMessageById(messageId)];
1481
- case 1: return [2 /*return*/, _d.apply(_c, [_f.apply(_e, [_g.sent()])])];
1482
- }
1483
- });
1484
- }); }, { messageId: sendResult.id })];
1485
- case 2:
1486
- result = (_a.sent());
1487
- if (result['erro'] == true) {
1488
- throw result;
1489
- }
1490
- return [2 /*return*/, result];
1491
- }
1492
- });
977
+ async sendPollMessage(chatId, name, choices, options) {
978
+ const sendResult = await (0, helpers_1.evaluateAndReturn)(this.page, ({ chatId, name, choices, options }) => WPP.chat.sendCreatePollMessage(chatId, name, choices, options), {
979
+ chatId,
980
+ name,
981
+ choices,
982
+ options: options,
1493
983
  });
1494
- };
984
+ // I don't know why the evaluate is returning undefined for direct call
985
+ // To solve that, I added `JSON.parse(JSON.stringify(<message>))` to solve that
986
+ const result = (await (0, helpers_1.evaluateAndReturn)(this.page, async ({ messageId }) => {
987
+ return JSON.parse(JSON.stringify(await WAPI.getMessageById(messageId)));
988
+ }, { messageId: sendResult.id }));
989
+ if (result['erro'] == true) {
990
+ throw result;
991
+ }
992
+ return result;
993
+ }
1495
994
  /**
1496
995
  * Sets the chat state
1497
996
  * Deprecated in favor of Use startTyping or startRecording functions
@@ -1500,19 +999,11 @@ var SenderLayer = /** @class */ (function (_super) {
1500
999
  * @param chatId
1501
1000
  * @deprecated Deprecated in favor of Use startTyping or startRecording functions
1502
1001
  */
1503
- SenderLayer.prototype.setChatState = function (chatId, chatState) {
1504
- return __awaiter(this, void 0, void 0, function () {
1505
- return __generator(this, function (_a) {
1506
- switch (_a.label) {
1507
- case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
1508
- var chatState = _a.chatState, chatId = _a.chatId;
1509
- WAPI.sendChatstate(chatState, chatId);
1510
- }, { chatState: chatState, chatId: chatId })];
1511
- case 1: return [2 /*return*/, _a.sent()];
1512
- }
1513
- });
1514
- });
1515
- };
1002
+ async setChatState(chatId, chatState) {
1003
+ return await (0, helpers_1.evaluateAndReturn)(this.page, ({ chatState, chatId }) => {
1004
+ WAPI.sendChatstate(chatState, chatId);
1005
+ }, { chatState, chatId });
1006
+ }
1516
1007
  /**
1517
1008
  * Send reaction to message
1518
1009
  * @example
@@ -1527,19 +1018,12 @@ var SenderLayer = /** @class */ (function (_super) {
1527
1018
  * @param to Chat Id
1528
1019
  * @param duration Duration in milliseconds
1529
1020
  */
1530
- SenderLayer.prototype.sendReactionToMessage = function (msgId, reaction) {
1531
- return __awaiter(this, void 0, void 0, function () {
1532
- return __generator(this, function (_a) {
1533
- return [2 /*return*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
1534
- var msgId = _a.msgId, reaction = _a.reaction;
1535
- return WPP.chat.sendReactionToMessage(msgId, reaction);
1536
- }, {
1537
- msgId: msgId,
1538
- reaction: reaction,
1539
- })];
1540
- });
1021
+ async sendReactionToMessage(msgId, reaction) {
1022
+ return (0, helpers_1.evaluateAndReturn)(this.page, ({ msgId, reaction }) => WPP.chat.sendReactionToMessage(msgId, reaction), {
1023
+ msgId,
1024
+ reaction,
1541
1025
  });
1542
- };
1026
+ }
1543
1027
  /**
1544
1028
  * Send an order message
1545
1029
  * To send (prices, tax, shipping or discount), for example: USD 12.90, send them without dots or commas, like: 12900
@@ -1567,45 +1051,21 @@ var SenderLayer = /** @class */ (function (_super) {
1567
1051
  *
1568
1052
  * @category Chat
1569
1053
  */
1570
- SenderLayer.prototype.sendOrderMessage = function (to, items, options) {
1571
- return __awaiter(this, void 0, void 0, function () {
1572
- var sendResult, result;
1573
- var _this = this;
1574
- return __generator(this, function (_a) {
1575
- switch (_a.label) {
1576
- case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
1577
- var to = _a.to, items = _a.items, options = _a.options;
1578
- return WPP.chat.sendChargeMessage(to, items, options);
1579
- }, {
1580
- to: to,
1581
- items: items,
1582
- options: options,
1583
- })];
1584
- case 1:
1585
- sendResult = _a.sent();
1586
- return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) { return __awaiter(_this, [_a], void 0, function (_b) {
1587
- var _c, _d, _e, _f;
1588
- var messageId = _b.messageId;
1589
- return __generator(this, function (_g) {
1590
- switch (_g.label) {
1591
- case 0:
1592
- _d = (_c = JSON).parse;
1593
- _f = (_e = JSON).stringify;
1594
- return [4 /*yield*/, WAPI.getMessageById(messageId)];
1595
- case 1: return [2 /*return*/, _d.apply(_c, [_f.apply(_e, [_g.sent()])])];
1596
- }
1597
- });
1598
- }); }, { messageId: sendResult.id })];
1599
- case 2:
1600
- result = (_a.sent());
1601
- if (result['erro'] == true) {
1602
- throw result;
1603
- }
1604
- return [2 /*return*/, result];
1605
- }
1606
- });
1054
+ async sendOrderMessage(to, items, options) {
1055
+ const sendResult = await (0, helpers_1.evaluateAndReturn)(this.page, ({ to, items, options }) => WPP.chat.sendChargeMessage(to, items, options), {
1056
+ to,
1057
+ items,
1058
+ options,
1607
1059
  });
1608
- };
1609
- return SenderLayer;
1610
- }(listener_layer_1.ListenerLayer));
1060
+ // I don't know why the evaluate is returning undefined for direct call
1061
+ // To solve that, I added `JSON.parse(JSON.stringify(<message>))` to solve that
1062
+ const result = (await (0, helpers_1.evaluateAndReturn)(this.page, async ({ messageId }) => {
1063
+ return JSON.parse(JSON.stringify(await WAPI.getMessageById(messageId)));
1064
+ }, { messageId: sendResult.id }));
1065
+ if (result['erro'] == true) {
1066
+ throw result;
1067
+ }
1068
+ return result;
1069
+ }
1070
+ }
1611
1071
  exports.SenderLayer = SenderLayer;