@wppconnect-team/wppconnect 1.14.5 → 1.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ # 1.15.0 (2022-07-20)
2
+
3
+
4
+
1
5
  ## 1.14.5 (2022-07-11)
2
6
 
3
7
 
@@ -152,4 +152,18 @@ export declare class GroupLayer extends RetrieverLayer {
152
152
  * @returns empty object
153
153
  */
154
154
  setGroupProperty(groupId: string, property: GroupProperty, value: boolean): Promise<boolean>;
155
+ /**
156
+ * Set group subject (if allowed)
157
+ * @category Group
158
+ * @param groupId Group ID ('000000-000000@g.us')
159
+ * @param base64 Image in base64 ( data:image/jpeg;base64,..... )
160
+ * @returns empty object
161
+ */
162
+ setGroupIcon(groupId: string, pathOrBase64: string): Promise<{
163
+ eurl: string;
164
+ status: number;
165
+ tag: string;
166
+ token: string;
167
+ _duplicate: boolean;
168
+ }>;
155
169
  }
@@ -386,6 +386,67 @@ var GroupLayer = /** @class */ (function (_super) {
386
386
  });
387
387
  });
388
388
  };
389
+ /**
390
+ * Set group subject (if allowed)
391
+ * @category Group
392
+ * @param groupId Group ID ('000000-000000@g.us')
393
+ * @param base64 Image in base64 ( data:image/jpeg;base64,..... )
394
+ * @returns empty object
395
+ */
396
+ GroupLayer.prototype.setGroupIcon = function (groupId, pathOrBase64) {
397
+ return __awaiter(this, void 0, void 0, function () {
398
+ var base64, fileContent, error, mimeInfo, error;
399
+ return __generator(this, function (_a) {
400
+ switch (_a.label) {
401
+ case 0:
402
+ base64 = '';
403
+ if (!pathOrBase64.startsWith('data:')) return [3 /*break*/, 1];
404
+ base64 = pathOrBase64;
405
+ return [3 /*break*/, 5];
406
+ case 1: return [4 /*yield*/, (0, helpers_1.downloadFileToBase64)(pathOrBase64, [
407
+ 'image/gif',
408
+ 'image/png',
409
+ 'image/jpg',
410
+ 'image/jpeg',
411
+ 'image/webp',
412
+ ])];
413
+ case 2:
414
+ fileContent = _a.sent();
415
+ if (!!fileContent) return [3 /*break*/, 4];
416
+ return [4 /*yield*/, (0, helpers_1.fileToBase64)(pathOrBase64)];
417
+ case 3:
418
+ fileContent = _a.sent();
419
+ _a.label = 4;
420
+ case 4:
421
+ if (fileContent) {
422
+ base64 = fileContent;
423
+ }
424
+ _a.label = 5;
425
+ case 5:
426
+ if (!base64) {
427
+ error = new Error('Empty or invalid file or base64');
428
+ Object.assign(error, {
429
+ code: 'empty_file',
430
+ });
431
+ throw error;
432
+ }
433
+ mimeInfo = (0, helpers_1.base64MimeType)(base64);
434
+ if (!mimeInfo || !mimeInfo.includes('image')) {
435
+ error = new Error('Not an image, allowed formats png, jpeg and webp');
436
+ Object.assign(error, {
437
+ code: 'invalid_image',
438
+ });
439
+ throw error;
440
+ }
441
+ return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
442
+ var groupId = _a.groupId, base64 = _a.base64;
443
+ return WPP.group.setIcon(groupId, base64);
444
+ }, { groupId: groupId, base64: base64 })];
445
+ case 6: return [2 /*return*/, _a.sent()];
446
+ }
447
+ });
448
+ });
449
+ };
389
450
  return GroupLayer;
390
451
  }(retriever_layer_1.RetrieverLayer));
391
452
  exports.GroupLayer = GroupLayer;
@@ -0,0 +1,63 @@
1
+ import { Page } from 'puppeteer';
2
+ import { CreateConfig } from '../../config/create-config';
3
+ import { HostLayer } from './host.layer';
4
+ export declare class LabelsLayer extends HostLayer {
5
+ page: Page;
6
+ constructor(page: Page, session?: string, options?: CreateConfig);
7
+ /**
8
+ * Create New Label
9
+ *
10
+ * @example
11
+ * ```javascript
12
+ * client.addNewLabel(`Name of label`);
13
+ * //or
14
+ * client.addNewLabel(`Name of label`, { labelColor: '#dfaef0' });
15
+ * //or
16
+ * client.addNewLabel(`Name of label`, { labelColor: 4292849392 });
17
+ * ```
18
+ * @param name Name of label
19
+ * @param options options of label
20
+ */
21
+ addNewLabel(name: string, options?: string): Promise<void>;
22
+ /**
23
+ * Add or delete label of chatId
24
+ *
25
+ * @example
26
+ * ```javascript
27
+ * client.addOrRemoveLabels(['[number]@c.us','[number]@c.us'],
28
+ * [{labelId:'76', type:'add'},{labelId:'75', type:'remove'}]);
29
+ * //or
30
+ * ```
31
+ * @param name Name of label
32
+ * @param options options to remove or add
33
+ */
34
+ addOrRemoveLabels(chatIds: string, options: string): Promise<void>;
35
+ /**
36
+ * Get all Labels
37
+ *
38
+ * @example
39
+ * ```javascript
40
+ * client.getAllLabels();
41
+ * ```
42
+ */
43
+ getAllLabels(): Promise<void>;
44
+ /**
45
+ * Delete all Labels
46
+ *
47
+ * @example
48
+ * ```javascript
49
+ * client.deleteAllLabels();
50
+ * ```
51
+ */
52
+ deleteAllLabels(): Promise<void>;
53
+ /**
54
+ * Add or delete label of chatId
55
+ *
56
+ * @example
57
+ * ```javascript
58
+ * client.deleteLabel();
59
+ * ```
60
+ * @param id Id or string to labels to delete
61
+ */
62
+ deleteLabel(id: string | string[]): Promise<void>;
63
+ }
@@ -0,0 +1,196 @@
1
+ "use strict";
2
+ /*
3
+ * This file is part of WPPConnect.
4
+ *
5
+ * WPPConnect is free software: you can redistribute it and/or modify
6
+ * it under the terms of the GNU Lesser General Public License as published by
7
+ * the Free Software Foundation, either version 3 of the License, or
8
+ * (at your option) any later version.
9
+ *
10
+ * WPPConnect is distributed in the hope that it will be useful,
11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ * GNU Lesser General Public License for more details.
14
+ *
15
+ * You should have received a copy of the GNU Lesser General Public License
16
+ * along with WPPConnect. If not, see <https://www.gnu.org/licenses/>.
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;
44
+ return g = { next: verb(0), "throw": verb(1), "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 (_) 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
+ Object.defineProperty(exports, "__esModule", { value: true });
70
+ exports.LabelsLayer = void 0;
71
+ var host_layer_1 = require("./host.layer");
72
+ var helpers_1 = require("../helpers");
73
+ var LabelsLayer = /** @class */ (function (_super) {
74
+ __extends(LabelsLayer, _super);
75
+ function LabelsLayer(page, session, options) {
76
+ var _this = _super.call(this, page, session, options) || this;
77
+ _this.page = page;
78
+ return _this;
79
+ }
80
+ /**
81
+ * Create New Label
82
+ *
83
+ * @example
84
+ * ```javascript
85
+ * client.addNewLabel(`Name of label`);
86
+ * //or
87
+ * client.addNewLabel(`Name of label`, { labelColor: '#dfaef0' });
88
+ * //or
89
+ * client.addNewLabel(`Name of label`, { labelColor: 4292849392 });
90
+ * ```
91
+ * @param name Name of label
92
+ * @param options options of label
93
+ */
94
+ LabelsLayer.prototype.addNewLabel = function (name, options) {
95
+ return __awaiter(this, void 0, void 0, function () {
96
+ return __generator(this, function (_a) {
97
+ switch (_a.label) {
98
+ case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
99
+ var name = _a.name, options = _a.options;
100
+ WPP.labels.addNewLabel(name, options);
101
+ }, { name: name, options: options })];
102
+ case 1: return [2 /*return*/, _a.sent()];
103
+ }
104
+ });
105
+ });
106
+ };
107
+ /**
108
+ * Add or delete label of chatId
109
+ *
110
+ * @example
111
+ * ```javascript
112
+ * client.addOrRemoveLabels(['[number]@c.us','[number]@c.us'],
113
+ * [{labelId:'76', type:'add'},{labelId:'75', type:'remove'}]);
114
+ * //or
115
+ * ```
116
+ * @param name Name of label
117
+ * @param options options to remove or add
118
+ */
119
+ LabelsLayer.prototype.addOrRemoveLabels = function (chatIds, options) {
120
+ return __awaiter(this, void 0, void 0, function () {
121
+ return __generator(this, function (_a) {
122
+ switch (_a.label) {
123
+ case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
124
+ var chatIds = _a.chatIds, options = _a.options;
125
+ WPP.labels.addOrRemoveLabels(chatIds, options);
126
+ }, { chatIds: chatIds, options: options })];
127
+ case 1: return [2 /*return*/, _a.sent()];
128
+ }
129
+ });
130
+ });
131
+ };
132
+ /**
133
+ * Get all Labels
134
+ *
135
+ * @example
136
+ * ```javascript
137
+ * client.getAllLabels();
138
+ * ```
139
+ */
140
+ LabelsLayer.prototype.getAllLabels = function () {
141
+ return __awaiter(this, void 0, void 0, function () {
142
+ return __generator(this, function (_a) {
143
+ switch (_a.label) {
144
+ case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function () {
145
+ WPP.labels.getAllLabels();
146
+ })];
147
+ case 1: return [2 /*return*/, _a.sent()];
148
+ }
149
+ });
150
+ });
151
+ };
152
+ /**
153
+ * Delete all Labels
154
+ *
155
+ * @example
156
+ * ```javascript
157
+ * client.deleteAllLabels();
158
+ * ```
159
+ */
160
+ LabelsLayer.prototype.deleteAllLabels = function () {
161
+ return __awaiter(this, void 0, void 0, function () {
162
+ return __generator(this, function (_a) {
163
+ switch (_a.label) {
164
+ case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function () {
165
+ WPP.labels.deleteAllLabels();
166
+ })];
167
+ case 1: return [2 /*return*/, _a.sent()];
168
+ }
169
+ });
170
+ });
171
+ };
172
+ /**
173
+ * Add or delete label of chatId
174
+ *
175
+ * @example
176
+ * ```javascript
177
+ * client.deleteLabel();
178
+ * ```
179
+ * @param id Id or string to labels to delete
180
+ */
181
+ LabelsLayer.prototype.deleteLabel = function (id) {
182
+ return __awaiter(this, void 0, void 0, function () {
183
+ return __generator(this, function (_a) {
184
+ switch (_a.label) {
185
+ case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
186
+ var id = _a.id;
187
+ WPP.labels.deleteLabel(id);
188
+ }, { id: id })];
189
+ case 1: return [2 /*return*/, _a.sent()];
190
+ }
191
+ });
192
+ });
193
+ };
194
+ return LabelsLayer;
195
+ }(host_layer_1.HostLayer));
196
+ exports.LabelsLayer = LabelsLayer;
@@ -197,4 +197,19 @@ export declare class ListenerLayer extends ProfileLayer {
197
197
  }) => any): {
198
198
  dispose: () => void;
199
199
  };
200
+ /**
201
+ * @event Listens to reaction messages
202
+ * @returns Disposable object to stop the listening
203
+ */
204
+ onReactionMessage(callback: (data: {
205
+ id: string;
206
+ msgId: string;
207
+ reactionText: string;
208
+ read: boolean;
209
+ orphan: number;
210
+ orphanReason: any;
211
+ timestamp: number;
212
+ }) => any): {
213
+ dispose: () => void;
214
+ };
200
215
  }
@@ -123,6 +123,7 @@ var ListenerLayer = /** @class */ (function (_super) {
123
123
  'onAddedToGroup',
124
124
  'onIncomingCall',
125
125
  'onRevokedMessage',
126
+ 'onReactionMessage',
126
127
  ], false);
127
128
  _loop_1 = function (func) {
128
129
  var has;
@@ -297,6 +298,26 @@ var ListenerLayer = /** @class */ (function (_super) {
297
298
  catch (error) {
298
299
  console.error(error);
299
300
  }
301
+ try {
302
+ if (!window['onReactionMessage'].exposed) {
303
+ WPP.on('chat.new_reaction', function (data) {
304
+ var eventData = {
305
+ id: data.id,
306
+ msgId: data.msgId,
307
+ reactionText: data.reactionText,
308
+ read: data.read,
309
+ orphan: data.orphan,
310
+ orphanReason: data.orphanReason,
311
+ timestamp: data.timestamp,
312
+ };
313
+ window['onReactionMessage'](eventData);
314
+ });
315
+ window['onReactionMessage'].exposed = true;
316
+ }
317
+ }
318
+ catch (error) {
319
+ console.error(error);
320
+ }
300
321
  })
301
322
  .catch(function () { })];
302
323
  case 6:
@@ -507,6 +528,13 @@ var ListenerLayer = /** @class */ (function (_super) {
507
528
  ListenerLayer.prototype.onRevokedMessage = function (callback) {
508
529
  return this.registerEvent('onRevokedMessage', callback);
509
530
  };
531
+ /**
532
+ * @event Listens to reaction messages
533
+ * @returns Disposable object to stop the listening
534
+ */
535
+ ListenerLayer.prototype.onReactionMessage = function (callback) {
536
+ return this.registerEvent('onReactionMessage', callback);
537
+ };
510
538
  return ListenerLayer;
511
539
  }(profile_layer_1.ProfileLayer));
512
540
  exports.ListenerLayer = ListenerLayer;
@@ -1,7 +1,7 @@
1
1
  import { Page } from 'puppeteer';
2
- import { HostLayer } from './host.layer';
3
2
  import { CreateConfig } from '../../config/create-config';
4
- export declare class ProfileLayer extends HostLayer {
3
+ import { StatusLayer } from './status.layer';
4
+ export declare class ProfileLayer extends StatusLayer {
5
5
  page: Page;
6
6
  constructor(page: Page, session?: string, options?: CreateConfig);
7
7
  /**
@@ -68,8 +68,8 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
68
68
  };
69
69
  Object.defineProperty(exports, "__esModule", { value: true });
70
70
  exports.ProfileLayer = void 0;
71
- var host_layer_1 = require("./host.layer");
72
71
  var helpers_1 = require("../helpers");
72
+ var status_layer_1 = require("./status.layer");
73
73
  var ProfileLayer = /** @class */ (function (_super) {
74
74
  __extends(ProfileLayer, _super);
75
75
  function ProfileLayer(page, session, options) {
@@ -212,5 +212,5 @@ var ProfileLayer = /** @class */ (function (_super) {
212
212
  });
213
213
  };
214
214
  return ProfileLayer;
215
- }(host_layer_1.HostLayer));
215
+ }(status_layer_1.StatusLayer));
216
216
  exports.ProfileLayer = ProfileLayer;
@@ -428,4 +428,21 @@ export declare class SenderLayer extends ListenerLayer {
428
428
  * @deprecated Deprecated in favor of Use startTyping or startRecording functions
429
429
  */
430
430
  setChatState(chatId: string, chatState: ChatState): Promise<void>;
431
+ /**
432
+ * Send reaction to message
433
+ * @example
434
+ * ```javascript
435
+ * // For send Reaction, just to send emoji
436
+ * await client.sendReactionToMessage('[number]@c.us', '🤯');
437
+ *
438
+ * // to remove reacition
439
+ * await client.startRecording('[number]@c.us', false);
440
+ * ```
441
+ * @category Chat
442
+ * @param to Chat Id
443
+ * @param duration Duration um miliseconds
444
+ */
445
+ sendReactionToMessage(msgId: string, reaction: string | false): Promise<{
446
+ sendMsgResult: string;
447
+ }>;
431
448
  }
@@ -1264,6 +1264,33 @@ var SenderLayer = /** @class */ (function (_super) {
1264
1264
  });
1265
1265
  });
1266
1266
  };
1267
+ /**
1268
+ * Send reaction to message
1269
+ * @example
1270
+ * ```javascript
1271
+ * // For send Reaction, just to send emoji
1272
+ * await client.sendReactionToMessage('[number]@c.us', '🤯');
1273
+ *
1274
+ * // to remove reacition
1275
+ * await client.startRecording('[number]@c.us', false);
1276
+ * ```
1277
+ * @category Chat
1278
+ * @param to Chat Id
1279
+ * @param duration Duration um miliseconds
1280
+ */
1281
+ SenderLayer.prototype.sendReactionToMessage = function (msgId, reaction) {
1282
+ return __awaiter(this, void 0, void 0, function () {
1283
+ return __generator(this, function (_a) {
1284
+ return [2 /*return*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
1285
+ var msgId = _a.msgId, reaction = _a.reaction;
1286
+ return WPP.chat.sendReactionToMessage(msgId, reaction);
1287
+ }, {
1288
+ msgId: msgId,
1289
+ reaction: reaction,
1290
+ })];
1291
+ });
1292
+ });
1293
+ };
1267
1294
  return SenderLayer;
1268
1295
  }(listener_layer_1.ListenerLayer));
1269
1296
  exports.SenderLayer = SenderLayer;
@@ -0,0 +1,37 @@
1
+ import { Page } from 'puppeteer';
2
+ import { CreateConfig } from '../../config/create-config';
3
+ import { LabelsLayer } from './labels.layer';
4
+ export declare class StatusLayer extends LabelsLayer {
5
+ page: Page;
6
+ constructor(page: Page, session?: string, options?: CreateConfig);
7
+ /**
8
+ * Send a image message to status stories
9
+ *
10
+ * @example
11
+ * ```javascript
12
+ * client.sendImageStatus('data:image/jpeg;base64,<a long base64 file...>');
13
+ * ```
14
+ * @param pathOrBase64 Path or base 64 image
15
+ */
16
+ sendImageStatus(pathOrBase64: string): Promise<void>;
17
+ /**
18
+ * Send a video message to status stories
19
+ *
20
+ * @example
21
+ * ```javascript
22
+ * client.sendVideoStatus('data:video/mp4;base64,<a long base64 file...>');
23
+ * ```
24
+ * @param pathOrBase64 Path or base 64 image
25
+ */
26
+ sendVideoStatus(pathOrBase64: string): Promise<void>;
27
+ /**
28
+ * Send a text to status stories
29
+ *
30
+ * @example
31
+ * ```javascript
32
+ * client.sendTextStatus(`Bootstrap primary color: #0275d8`, { backgroundColor: '#0275d8', font: 2});
33
+ * ```
34
+ * @param pathOrBase64 Path or base 64 image
35
+ */
36
+ sendTextStatus(text: string, options: string): Promise<void>;
37
+ }
@@ -0,0 +1,216 @@
1
+ "use strict";
2
+ /*
3
+ * This file is part of WPPConnect.
4
+ *
5
+ * WPPConnect is free software: you can redistribute it and/or modify
6
+ * it under the terms of the GNU Lesser General Public License as published by
7
+ * the Free Software Foundation, either version 3 of the License, or
8
+ * (at your option) any later version.
9
+ *
10
+ * WPPConnect is distributed in the hope that it will be useful,
11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ * GNU Lesser General Public License for more details.
14
+ *
15
+ * You should have received a copy of the GNU Lesser General Public License
16
+ * along with WPPConnect. If not, see <https://www.gnu.org/licenses/>.
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;
44
+ return g = { next: verb(0), "throw": verb(1), "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 (_) 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
+ Object.defineProperty(exports, "__esModule", { value: true });
70
+ exports.StatusLayer = void 0;
71
+ var labels_layer_1 = require("./labels.layer");
72
+ var helpers_1 = require("../helpers");
73
+ var StatusLayer = /** @class */ (function (_super) {
74
+ __extends(StatusLayer, _super);
75
+ function StatusLayer(page, session, options) {
76
+ var _this = _super.call(this, page, session, options) || this;
77
+ _this.page = page;
78
+ return _this;
79
+ }
80
+ /**
81
+ * Send a image message to status stories
82
+ *
83
+ * @example
84
+ * ```javascript
85
+ * client.sendImageStatus('data:image/jpeg;base64,<a long base64 file...>');
86
+ * ```
87
+ * @param pathOrBase64 Path or base 64 image
88
+ */
89
+ StatusLayer.prototype.sendImageStatus = function (pathOrBase64) {
90
+ return __awaiter(this, void 0, void 0, function () {
91
+ var base64, fileContent, error, mimeInfo, error;
92
+ return __generator(this, function (_a) {
93
+ switch (_a.label) {
94
+ case 0:
95
+ base64 = '';
96
+ if (!pathOrBase64.startsWith('data:')) return [3 /*break*/, 1];
97
+ base64 = pathOrBase64;
98
+ return [3 /*break*/, 5];
99
+ case 1: return [4 /*yield*/, (0, helpers_1.downloadFileToBase64)(pathOrBase64, [
100
+ 'image/gif',
101
+ 'image/png',
102
+ 'image/jpg',
103
+ 'image/jpeg',
104
+ 'image/webp',
105
+ ])];
106
+ case 2:
107
+ fileContent = _a.sent();
108
+ if (!!fileContent) return [3 /*break*/, 4];
109
+ return [4 /*yield*/, (0, helpers_1.fileToBase64)(pathOrBase64)];
110
+ case 3:
111
+ fileContent = _a.sent();
112
+ _a.label = 4;
113
+ case 4:
114
+ if (fileContent) {
115
+ base64 = fileContent;
116
+ }
117
+ _a.label = 5;
118
+ case 5:
119
+ if (!base64) {
120
+ error = new Error('Empty or invalid file or base64');
121
+ Object.assign(error, {
122
+ code: 'empty_file',
123
+ });
124
+ throw error;
125
+ }
126
+ mimeInfo = (0, helpers_1.base64MimeType)(base64);
127
+ if (!mimeInfo || !mimeInfo.includes('image')) {
128
+ error = new Error('Not an image, allowed formats png, jpeg and webp');
129
+ Object.assign(error, {
130
+ code: 'invalid_image',
131
+ });
132
+ throw error;
133
+ }
134
+ return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
135
+ var base64 = _a.base64;
136
+ WPP.status.sendImageStatus(base64);
137
+ }, { base64: base64 })];
138
+ case 6: return [2 /*return*/, _a.sent()];
139
+ }
140
+ });
141
+ });
142
+ };
143
+ /**
144
+ * Send a video message to status stories
145
+ *
146
+ * @example
147
+ * ```javascript
148
+ * client.sendVideoStatus('data:video/mp4;base64,<a long base64 file...>');
149
+ * ```
150
+ * @param pathOrBase64 Path or base 64 image
151
+ */
152
+ StatusLayer.prototype.sendVideoStatus = function (pathOrBase64) {
153
+ return __awaiter(this, void 0, void 0, function () {
154
+ var base64, fileContent, error;
155
+ return __generator(this, function (_a) {
156
+ switch (_a.label) {
157
+ case 0:
158
+ base64 = '';
159
+ if (!pathOrBase64.startsWith('data:')) return [3 /*break*/, 1];
160
+ base64 = pathOrBase64;
161
+ return [3 /*break*/, 5];
162
+ case 1: return [4 /*yield*/, (0, helpers_1.downloadFileToBase64)(pathOrBase64)];
163
+ case 2:
164
+ fileContent = _a.sent();
165
+ if (!!fileContent) return [3 /*break*/, 4];
166
+ return [4 /*yield*/, (0, helpers_1.fileToBase64)(pathOrBase64)];
167
+ case 3:
168
+ fileContent = _a.sent();
169
+ _a.label = 4;
170
+ case 4:
171
+ if (fileContent) {
172
+ base64 = fileContent;
173
+ }
174
+ _a.label = 5;
175
+ case 5:
176
+ if (!base64) {
177
+ error = new Error('Empty or invalid file or base64');
178
+ Object.assign(error, {
179
+ code: 'empty_file',
180
+ });
181
+ throw error;
182
+ }
183
+ return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
184
+ var base64 = _a.base64;
185
+ WPP.status.sendVideoStatus(base64);
186
+ }, { base64: base64 })];
187
+ case 6: return [2 /*return*/, _a.sent()];
188
+ }
189
+ });
190
+ });
191
+ };
192
+ /**
193
+ * Send a text to status stories
194
+ *
195
+ * @example
196
+ * ```javascript
197
+ * client.sendTextStatus(`Bootstrap primary color: #0275d8`, { backgroundColor: '#0275d8', font: 2});
198
+ * ```
199
+ * @param pathOrBase64 Path or base 64 image
200
+ */
201
+ StatusLayer.prototype.sendTextStatus = function (text, options) {
202
+ return __awaiter(this, void 0, void 0, function () {
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 text = _a.text, options = _a.options;
207
+ WPP.status.sendTextStatus(text, options);
208
+ }, { text: text, options: options })];
209
+ case 1: return [2 /*return*/, _a.sent()];
210
+ }
211
+ });
212
+ });
213
+ };
214
+ return StatusLayer;
215
+ }(labels_layer_1.LabelsLayer));
216
+ exports.StatusLayer = StatusLayer;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wppconnect-team/wppconnect",
3
- "version": "1.14.5",
3
+ "version": "1.15.0",
4
4
  "description": "WPPConnect is an open source project developed by the JavaScript community with the aim of exporting functions from WhatsApp Web to the node, which can be used to support the creation of any interaction, such as customer service, media sending, intelligence recognition based on phrases artificial and many other things, use your imagination... 😀🤔💭",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -68,7 +68,7 @@
68
68
  "@types/atob": "^2.1.2",
69
69
  "@types/mime-types": "^2.1.1",
70
70
  "@types/mocha": "^9.1.1",
71
- "@types/node": "^16.11.43",
71
+ "@types/node": "^16.11.45",
72
72
  "@types/rimraf": "^3.0.2",
73
73
  "@types/sharp": "^0.30.4",
74
74
  "@types/shelljs": "^0.8.11",
@@ -118,9 +118,9 @@
118
118
  "mime-types": "^2.1.35",
119
119
  "puppeteer": "*",
120
120
  "puppeteer-extra": "^3.3.4",
121
- "puppeteer-extra-plugin-stealth": "^2.10.1",
122
- "puppeteer-extra-plugin-user-data-dir": "^2.3.1",
123
- "puppeteer-extra-plugin-user-preferences": "^2.3.1",
121
+ "puppeteer-extra-plugin-stealth": "^2.11.0",
122
+ "puppeteer-extra-plugin-user-data-dir": "^2.4.0",
123
+ "puppeteer-extra-plugin-user-preferences": "^2.4.0",
124
124
  "qrcode-terminal": "^0.12.0",
125
125
  "reflect-metadata": "^0.1.13",
126
126
  "rimraf": "^3.0.2",
@@ -129,7 +129,7 @@
129
129
  "tmp": "^0.2.1",
130
130
  "tree-kill": "^1.2.2",
131
131
  "winston": "^3.8.1",
132
- "ws": "^8.8.0"
132
+ "ws": "^8.8.1"
133
133
  },
134
134
  "optionalDependencies": {
135
135
  "fsevents": "^2.3.2"