@wppconnect-team/wppconnect 1.13.0 → 1.13.3

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,25 @@
1
+ ## 1.13.3 (2022-06-01)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * Clear all token data when disconnected (fix [#1147](https://github.com/wppconnect-team/wppconnect/issues/1147)) ([4abcfed](https://github.com/wppconnect-team/wppconnect/commit/4abcfed97778ddb619df65fec0b1c3d0dc4debac))
7
+
8
+
9
+
10
+ ## 1.13.2 (2022-05-28)
11
+
12
+
13
+ ### Bug Fixes
14
+
15
+ * Migrate archiveChat and pinChat methods to WA-JS ([cee7e1c](https://github.com/wppconnect-team/wppconnect/commit/cee7e1ced23409d66365e42a35602265e0c09536))
16
+
17
+
18
+
19
+ ## 1.13.1 (2022-05-10)
20
+
21
+
22
+
1
23
  # 1.13.0 (2022-04-25)
2
24
 
3
25
 
@@ -39,7 +39,10 @@ export declare class ControlsLayer extends UILayer {
39
39
  * @param option {boolean} true or false
40
40
  * @returns boolean
41
41
  */
42
- archiveChat(chatId: string, option?: boolean): Promise<boolean>;
42
+ archiveChat(chatId: string, option?: boolean): Promise<{
43
+ wid: import("@wppconnect/wa-js/dist/whatsapp").Wid;
44
+ archive: boolean;
45
+ }>;
43
46
  /**
44
47
  * Pin and Unpin chat messages with true or false
45
48
  * @category Chat
@@ -48,7 +51,10 @@ export declare class ControlsLayer extends UILayer {
48
51
  * @param nonExistent {boolean} Pin chat, non-existent (optional)
49
52
  * @returns object
50
53
  */
51
- pinChat(chatId: string, option: boolean, nonExistent?: boolean): Promise<object>;
54
+ pinChat(chatId: string, option: boolean, nonExistent?: boolean): Promise<{
55
+ wid: import("@wppconnect/wa-js/dist/whatsapp").Wid;
56
+ pin: boolean;
57
+ }>;
52
58
  /**
53
59
  * Deletes all messages of given chat
54
60
  * @category Chat
@@ -163,7 +163,7 @@ var ControlsLayer = /** @class */ (function (_super) {
163
163
  return __generator(this, function (_a) {
164
164
  return [2 /*return*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
165
165
  var chatId = _a.chatId, option = _a.option;
166
- return WAPI.archiveChat(chatId, option);
166
+ return WPP.chat.archive(chatId, option);
167
167
  }, { chatId: chatId, option: option })];
168
168
  });
169
169
  });
@@ -178,19 +178,22 @@ var ControlsLayer = /** @class */ (function (_super) {
178
178
  */
179
179
  ControlsLayer.prototype.pinChat = function (chatId, option, nonExistent) {
180
180
  return __awaiter(this, void 0, void 0, function () {
181
- var result;
182
181
  return __generator(this, function (_a) {
183
182
  switch (_a.label) {
184
- case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
185
- var chatId = _a.chatId, option = _a.option, nonExistent = _a.nonExistent;
186
- return WAPI.pinChat(chatId, option, nonExistent);
187
- }, { chatId: chatId, option: option, nonExistent: nonExistent })];
183
+ case 0:
184
+ if (!nonExistent) return [3 /*break*/, 2];
185
+ return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
186
+ var chatId = _a.chatId;
187
+ return WPP.chat.find(chatId);
188
+ }, { chatId: chatId })];
188
189
  case 1:
189
- result = _a.sent();
190
- if (result['erro'] == true) {
191
- throw result;
192
- }
193
- return [2 /*return*/, result];
190
+ _a.sent();
191
+ _a.label = 2;
192
+ case 2: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
193
+ var chatId = _a.chatId, option = _a.option;
194
+ return WPP.chat.pin(chatId, option);
195
+ }, { chatId: chatId, option: option })];
196
+ case 3: return [2 /*return*/, _a.sent()];
194
197
  }
195
198
  });
196
199
  });
@@ -1,7 +1,7 @@
1
1
  import type { ListMessageOptions, TextMessageOptions } from '@wppconnect/wa-js/dist/chat';
2
2
  import { Page } from 'puppeteer';
3
3
  import { CreateConfig } from '../../config/create-config';
4
- import { Message, SendFileResult, SendLinkResult, SendStickerResult } from '../model';
4
+ import { Message, SendFileResult } from '../model';
5
5
  import { ChatState } from '../model/enum';
6
6
  import { ListenerLayer } from './listener.layer';
7
7
  export declare class SenderLayer extends ListenerLayer {
@@ -9,12 +9,16 @@ export declare class SenderLayer extends ListenerLayer {
9
9
  constructor(page: Page, session?: string, options?: CreateConfig);
10
10
  /**
11
11
  * Automatically sends a link with the auto generated link preview. You can also add a custom message to be added.
12
+ *
13
+ * Deprecated: please use {@link sendText}
14
+ *
12
15
  * @category Chat
16
+ * @deprecated
13
17
  * @param chatId
14
18
  * @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
15
- * @param title custom text as the message body, this includes the link or will be attached after the link
19
+ * @param text custom text as the message body, this includes the link or will be attached after the link
16
20
  */
17
- sendLinkPreview(chatId: string, url: string, title: string): Promise<SendLinkResult>;
21
+ sendLinkPreview(chatId: string, url: string, text?: string): Promise<import("@wppconnect/wa-js/dist/chat").SendMessageReturn>;
18
22
  /**
19
23
  * Sends a text message to given chat
20
24
  * @category Chat
@@ -86,14 +90,18 @@ export declare class SenderLayer extends ListenerLayer {
86
90
  }>;
87
91
  /**
88
92
  * Sends message with thumbnail
93
+ *
94
+ * @deprecated: please use {@link sendText} with options
95
+ *
96
+ * @deprecated
89
97
  * @category Chat
90
- * @param thumb
98
+ * @param pathOrBase64
91
99
  * @param url
92
100
  * @param title
93
101
  * @param description
94
102
  * @param chatId
95
103
  */
96
- sendMessageWithThumb(thumb: string, url: string, title: string, description: string, chatId: string): Promise<void>;
104
+ sendMessageWithThumb(pathOrBase64: string, url: string, title: string, description: string, chatId: string): Promise<import("@wppconnect/wa-js/dist/chat").SendMessageReturn>;
97
105
  /**
98
106
  * Replies to given mesage id of given chat id
99
107
  * @category Chat
@@ -227,17 +235,17 @@ export declare class SenderLayer extends ListenerLayer {
227
235
  /**
228
236
  * Generates sticker from the provided animated gif image and sends it (Send image as animated sticker)
229
237
  * @category Chat
230
- * @param path image path imageBase64 A valid gif image is required. You can also send via http/https (http://www.website.com/img.gif)
231
- * @param to chatId '000000000000@c.us'
238
+ * @param pathOrBase64 image path imageBase64 A valid gif image is required. You can also send via http/https (http://www.website.com/img.gif)
239
+ * @param to chatId '000000000000@c.us'
232
240
  */
233
- sendImageAsStickerGif(to: string, path: string): Promise<SendStickerResult | false>;
241
+ sendImageAsStickerGif(to: string, pathOrBase64: string): Promise<import("@wppconnect/wa-js/dist/chat").SendMessageReturn>;
234
242
  /**
235
243
  * Generates sticker from given image and sends it (Send Image As Sticker)
236
244
  * @category Chat
237
- * @param path 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)
245
+ * @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)
238
246
  * @param to chatId '000000000000@c.us'
239
247
  */
240
- sendImageAsSticker(to: string, path: string): Promise<SendStickerResult | false>;
248
+ sendImageAsSticker(to: string, pathOrBase64: string): Promise<import("@wppconnect/wa-js/dist/chat").SendMessageReturn>;
241
249
  /**
242
250
  * TODO: Fix message not being delivered
243
251
  * Sends location to given chat id
@@ -259,26 +267,45 @@ export declare class SenderLayer extends ListenerLayer {
259
267
  }>;
260
268
  /**
261
269
  * Starts typing ('Typing...' state)
270
+ *
271
+ * @example
272
+ * ```javascript
273
+ * // Keep sending typing state, use stopTyping to finish
274
+ * await client.startTyping('[number]@c.us');
275
+ *
276
+ * // Keep sending typing state for 5 seconds
277
+ * await client.startTyping('[number]@c.us', 5000);
278
+ * ```
262
279
  * @category Chat
263
- * @param chatId
280
+ * @param to Chat Id
281
+ * @param duration Duration um miliseconds
264
282
  */
265
283
  startTyping(to: string, duration?: number): Promise<void>;
266
284
  /**
267
285
  * Stops typing ('Typing...' state)
268
286
  * @category Chat
269
- * @param chatId
287
+ * @param to Chat Id
270
288
  */
271
289
  stopTyping(to: string): Promise<void>;
272
290
  /**
273
291
  * Starts recording ('Recording...' state)
292
+ * @example
293
+ * ```javascript
294
+ * // Keep sending recording state, use stopRecoring to finish
295
+ * await client.startRecording('[number]@c.us');
296
+ *
297
+ * // Keep sending typing state for 5 seconds
298
+ * await client.startRecording('[number]@c.us', 5000);
299
+ * ```
274
300
  * @category Chat
275
- * @param chatId
301
+ * @param to Chat Id
302
+ * @param duration Duration um miliseconds
276
303
  */
277
304
  startRecording(to: string, duration?: number): Promise<void>;
278
305
  /**
279
306
  * Stops recording ('Recording...' state)
280
307
  * @category Chat
281
- * @param chatId
308
+ * @param to Chat Id
282
309
  */
283
310
  stopRecoring(to: string): Promise<void>;
284
311
  /**
@@ -116,25 +116,29 @@ var SenderLayer = /** @class */ (function (_super) {
116
116
  }
117
117
  /**
118
118
  * Automatically sends a link with the auto generated link preview. You can also add a custom message to be added.
119
+ *
120
+ * Deprecated: please use {@link sendText}
121
+ *
119
122
  * @category Chat
123
+ * @deprecated
120
124
  * @param chatId
121
125
  * @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
122
- * @param title custom text as the message body, this includes the link or will be attached after the link
126
+ * @param text custom text as the message body, this includes the link or will be attached after the link
123
127
  */
124
- SenderLayer.prototype.sendLinkPreview = function (chatId, url, title) {
128
+ SenderLayer.prototype.sendLinkPreview = function (chatId, url, text) {
129
+ if (text === void 0) { text = ''; }
125
130
  return __awaiter(this, void 0, void 0, function () {
126
- var result;
131
+ var message, result;
127
132
  return __generator(this, function (_a) {
128
133
  switch (_a.label) {
129
- case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
130
- var chatId = _a.chatId, url = _a.url, title = _a.title;
131
- return WAPI.sendLinkPreview(chatId, url, title);
132
- }, { chatId: chatId, url: url, title: title })];
134
+ case 0:
135
+ message = text.includes(url) ? text : "".concat(url, "\n").concat(text);
136
+ return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
137
+ var chatId = _a.chatId, message = _a.message;
138
+ return WPP.chat.sendTextMessage(chatId, message, { linkPreview: true });
139
+ }, { chatId: chatId, message: message })];
133
140
  case 1:
134
141
  result = _a.sent();
135
- if (result['erro'] == true) {
136
- throw result;
137
- }
138
142
  return [2 /*return*/, result];
139
143
  }
140
144
  });
@@ -352,42 +356,83 @@ var SenderLayer = /** @class */ (function (_super) {
352
356
  };
353
357
  /**
354
358
  * Sends message with thumbnail
359
+ *
360
+ * @deprecated: please use {@link sendText} with options
361
+ *
362
+ * @deprecated
355
363
  * @category Chat
356
- * @param thumb
364
+ * @param pathOrBase64
357
365
  * @param url
358
366
  * @param title
359
367
  * @param description
360
368
  * @param chatId
361
369
  */
362
- SenderLayer.prototype.sendMessageWithThumb = function (thumb, url, title, description, chatId) {
370
+ SenderLayer.prototype.sendMessageWithThumb = function (pathOrBase64, url, title, description, chatId) {
363
371
  return __awaiter(this, void 0, void 0, function () {
364
- var base64;
372
+ var base64, fileContent, error, mimeInfo, error, thumbnail;
365
373
  return __generator(this, function (_a) {
366
374
  switch (_a.label) {
367
- case 0: return [4 /*yield*/, (0, helpers_1.downloadFileToBase64)(thumb, [
375
+ case 0:
376
+ base64 = '';
377
+ if (!pathOrBase64.startsWith('data:')) return [3 /*break*/, 1];
378
+ base64 = pathOrBase64;
379
+ return [3 /*break*/, 5];
380
+ case 1: return [4 /*yield*/, (0, helpers_1.downloadFileToBase64)(pathOrBase64, [
368
381
  'image/gif',
369
382
  'image/png',
370
383
  'image/jpg',
371
384
  'image/jpeg',
372
385
  'image/webp',
373
386
  ])];
374
- case 1:
375
- base64 = _a.sent();
376
- if (!!base64) return [3 /*break*/, 3];
377
- return [4 /*yield*/, (0, helpers_1.fileToBase64)(thumb)];
378
387
  case 2:
379
- base64 = _a.sent();
380
- _a.label = 3;
381
- case 3: return [2 /*return*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
382
- var thumb = _a.thumb, url = _a.url, title = _a.title, description = _a.description, chatId = _a.chatId;
383
- WAPI.sendMessageWithThumb(thumb, url, title, description, chatId);
384
- }, {
385
- base64: base64,
386
- url: url,
387
- title: title,
388
- description: description,
389
- chatId: chatId,
390
- })];
388
+ fileContent = _a.sent();
389
+ if (!!fileContent) return [3 /*break*/, 4];
390
+ return [4 /*yield*/, (0, helpers_1.fileToBase64)(pathOrBase64)];
391
+ case 3:
392
+ fileContent = _a.sent();
393
+ _a.label = 4;
394
+ case 4:
395
+ if (fileContent) {
396
+ base64 = fileContent;
397
+ }
398
+ _a.label = 5;
399
+ case 5:
400
+ if (!base64) {
401
+ error = new Error('Empty or invalid file or base64');
402
+ Object.assign(error, {
403
+ code: 'empty_file',
404
+ });
405
+ throw error;
406
+ }
407
+ mimeInfo = (0, helpers_1.base64MimeType)(base64);
408
+ if (!mimeInfo || !mimeInfo.includes('image')) {
409
+ error = new Error('Not an image, allowed formats png, jpeg, webp and gif');
410
+ Object.assign(error, {
411
+ code: 'invalid_image',
412
+ });
413
+ throw error;
414
+ }
415
+ thumbnail = base64.replace(/^data:image\/(png|jpe?g|webp|gif);base64,/, '');
416
+ return [2 /*return*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
417
+ var thumbnail = _a.thumbnail, url = _a.url, title = _a.title, description = _a.description, chatId = _a.chatId;
418
+ return WPP.chat.sendTextMessage(chatId, url, {
419
+ linkPreview: {
420
+ thumbnail: thumbnail,
421
+ canonicalUrl: url,
422
+ description: description,
423
+ matchedText: url,
424
+ title: title,
425
+ richPreviewType: 0,
426
+ doNotPlayInline: true,
427
+ },
428
+ });
429
+ }, {
430
+ thumbnail: thumbnail,
431
+ url: url,
432
+ title: title,
433
+ description: description,
434
+ chatId: chatId,
435
+ })];
391
436
  }
392
437
  });
393
438
  });
@@ -818,52 +863,70 @@ var SenderLayer = /** @class */ (function (_super) {
818
863
  /**
819
864
  * Generates sticker from the provided animated gif image and sends it (Send image as animated sticker)
820
865
  * @category Chat
821
- * @param path image path imageBase64 A valid gif image is required. You can also send via http/https (http://www.website.com/img.gif)
822
- * @param to chatId '000000000000@c.us'
866
+ * @param pathOrBase64 image path imageBase64 A valid gif image is required. You can also send via http/https (http://www.website.com/img.gif)
867
+ * @param to chatId '000000000000@c.us'
823
868
  */
824
- SenderLayer.prototype.sendImageAsStickerGif = function (to, path) {
869
+ SenderLayer.prototype.sendImageAsStickerGif = function (to, pathOrBase64) {
825
870
  return __awaiter(this, void 0, void 0, function () {
826
- var b64, buff, mimeInfo, obj, _webb64, _met, result;
871
+ var base64, fileContent, error, mimeInfo, error, buff, obj, error, webpBase64;
827
872
  return __generator(this, function (_a) {
828
873
  switch (_a.label) {
829
- case 0: return [4 /*yield*/, (0, helpers_1.downloadFileToBase64)(path, ['image/gif', 'image/webp'])];
830
- case 1:
831
- b64 = _a.sent();
832
- if (!!b64) return [3 /*break*/, 3];
833
- return [4 /*yield*/, (0, helpers_1.fileToBase64)(path)];
874
+ case 0:
875
+ base64 = '';
876
+ if (!pathOrBase64.startsWith('data:')) return [3 /*break*/, 1];
877
+ base64 = pathOrBase64;
878
+ return [3 /*break*/, 5];
879
+ case 1: return [4 /*yield*/, (0, helpers_1.downloadFileToBase64)(pathOrBase64, [
880
+ 'image/gif',
881
+ 'image/webp',
882
+ ])];
834
883
  case 2:
835
- b64 = _a.sent();
836
- _a.label = 3;
884
+ fileContent = _a.sent();
885
+ if (!!fileContent) return [3 /*break*/, 4];
886
+ return [4 /*yield*/, (0, helpers_1.fileToBase64)(pathOrBase64)];
837
887
  case 3:
838
- if (!b64) return [3 /*break*/, 9];
839
- buff = Buffer.from(b64.replace(/^data:image\/(gif|webp);base64,/, ''), 'base64');
840
- mimeInfo = (0, helpers_1.base64MimeType)(b64);
841
- if (!(!mimeInfo || mimeInfo.includes('image'))) return [3 /*break*/, 8];
842
- return [4 /*yield*/, (0, helpers_1.stickerSelect)(buff, 1)];
888
+ fileContent = _a.sent();
889
+ _a.label = 4;
843
890
  case 4:
844
- obj = _a.sent();
845
- if (!(typeof obj == 'object')) return [3 /*break*/, 6];
846
- _webb64 = obj['webpBase64'];
847
- _met = obj['metadata'];
848
- return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
849
- var _webb64 = _a._webb64, to = _a.to, _met = _a._met;
850
- return WAPI.sendImageAsSticker(_webb64, to, _met, 'StickerGif');
851
- }, { _webb64: _webb64, to: to, _met: _met })];
891
+ if (fileContent) {
892
+ base64 = fileContent;
893
+ }
894
+ _a.label = 5;
852
895
  case 5:
853
- result = _a.sent();
854
- if (result['erro'] == true) {
855
- throw result;
896
+ if (!base64) {
897
+ error = new Error('Empty or invalid file or base64');
898
+ Object.assign(error, {
899
+ code: 'empty_file',
900
+ });
901
+ throw error;
856
902
  }
857
- return [2 /*return*/, result];
858
- case 6: throw {
859
- error: true,
860
- message: 'Error with sharp library, check the console log',
861
- };
862
- case 7: return [3 /*break*/, 9];
863
- case 8:
864
- console.log('Not an image, allowed format gif');
865
- return [2 /*return*/, false];
866
- case 9: return [2 /*return*/];
903
+ mimeInfo = (0, helpers_1.base64MimeType)(base64);
904
+ if (!mimeInfo || !mimeInfo.includes('image')) {
905
+ error = new Error('Not an image, allowed formats gig and webp');
906
+ Object.assign(error, {
907
+ code: 'invalid_image',
908
+ });
909
+ throw error;
910
+ }
911
+ buff = Buffer.from(base64.replace(/^data:image\/(gif|webp);base64,/, ''), 'base64');
912
+ return [4 /*yield*/, (0, helpers_1.stickerSelect)(buff, 1)];
913
+ case 6:
914
+ obj = _a.sent();
915
+ if (!obj) {
916
+ error = new Error('Error with sharp library, check the console log');
917
+ Object.assign(error, {
918
+ code: 'sharp_error',
919
+ });
920
+ throw error;
921
+ }
922
+ webpBase64 = obj.webpBase64;
923
+ return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
924
+ var to = _a.to, webpBase64 = _a.webpBase64;
925
+ return WPP.chat.sendFileMessage(to, webpBase64, {
926
+ type: 'sticker',
927
+ });
928
+ }, { to: to, webpBase64: webpBase64 })];
929
+ case 7: return [2 /*return*/, _a.sent()];
867
930
  }
868
931
  });
869
932
  });
@@ -871,58 +934,73 @@ var SenderLayer = /** @class */ (function (_super) {
871
934
  /**
872
935
  * Generates sticker from given image and sends it (Send Image As Sticker)
873
936
  * @category Chat
874
- * @param path 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)
937
+ * @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)
875
938
  * @param to chatId '000000000000@c.us'
876
939
  */
877
- SenderLayer.prototype.sendImageAsSticker = function (to, path) {
940
+ SenderLayer.prototype.sendImageAsSticker = function (to, pathOrBase64) {
878
941
  return __awaiter(this, void 0, void 0, function () {
879
- var b64, buff, mimeInfo, obj, _webb64, _met, result;
942
+ var base64, fileContent, error, mimeInfo, error, buff, obj, error, webpBase64;
880
943
  return __generator(this, function (_a) {
881
944
  switch (_a.label) {
882
- case 0: return [4 /*yield*/, (0, helpers_1.downloadFileToBase64)(path, [
945
+ case 0:
946
+ base64 = '';
947
+ if (!pathOrBase64.startsWith('data:')) return [3 /*break*/, 1];
948
+ base64 = pathOrBase64;
949
+ return [3 /*break*/, 5];
950
+ case 1: return [4 /*yield*/, (0, helpers_1.downloadFileToBase64)(pathOrBase64, [
883
951
  'image/gif',
884
952
  'image/png',
885
953
  'image/jpg',
886
954
  'image/jpeg',
887
955
  'image/webp',
888
956
  ])];
889
- case 1:
890
- b64 = _a.sent();
891
- if (!!b64) return [3 /*break*/, 3];
892
- return [4 /*yield*/, (0, helpers_1.fileToBase64)(path)];
893
957
  case 2:
894
- b64 = _a.sent();
895
- _a.label = 3;
958
+ fileContent = _a.sent();
959
+ if (!!fileContent) return [3 /*break*/, 4];
960
+ return [4 /*yield*/, (0, helpers_1.fileToBase64)(pathOrBase64)];
896
961
  case 3:
897
- if (!b64) return [3 /*break*/, 9];
898
- buff = Buffer.from(b64.replace(/^data:image\/(png|jpe?g|webp|gif);base64,/, ''), 'base64');
899
- mimeInfo = (0, helpers_1.base64MimeType)(b64);
900
- if (!(!mimeInfo || mimeInfo.includes('image'))) return [3 /*break*/, 8];
901
- return [4 /*yield*/, (0, helpers_1.stickerSelect)(buff, 0)];
962
+ fileContent = _a.sent();
963
+ _a.label = 4;
902
964
  case 4:
903
- obj = _a.sent();
904
- if (!(typeof obj == 'object')) return [3 /*break*/, 6];
905
- _webb64 = obj['webpBase64'];
906
- _met = obj['metadata'];
907
- return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
908
- var _webb64 = _a._webb64, to = _a.to, _met = _a._met;
909
- return WAPI.sendImageAsSticker(_webb64, to, _met, 'Sticker');
910
- }, { _webb64: _webb64, to: to, _met: _met })];
965
+ if (fileContent) {
966
+ base64 = fileContent;
967
+ }
968
+ _a.label = 5;
911
969
  case 5:
912
- result = _a.sent();
913
- if (result['erro'] == true) {
914
- throw result;
970
+ if (!base64) {
971
+ error = new Error('Empty or invalid file or base64');
972
+ Object.assign(error, {
973
+ code: 'empty_file',
974
+ });
975
+ throw error;
915
976
  }
916
- return [2 /*return*/, result];
917
- case 6: throw {
918
- error: true,
919
- message: 'Error with sharp library, check the console log',
920
- };
921
- case 7: return [3 /*break*/, 9];
922
- case 8:
923
- console.log('Not an image, allowed formats png, jpeg and webp');
924
- return [2 /*return*/, false];
925
- case 9: return [2 /*return*/];
977
+ mimeInfo = (0, helpers_1.base64MimeType)(base64);
978
+ if (!mimeInfo || !mimeInfo.includes('image')) {
979
+ error = new Error('Not an image, allowed formats png, jpeg, webp and gif');
980
+ Object.assign(error, {
981
+ code: 'invalid_image',
982
+ });
983
+ throw error;
984
+ }
985
+ buff = Buffer.from(base64.replace(/^data:image\/(png|jpe?g|webp|gif);base64,/, ''), 'base64');
986
+ return [4 /*yield*/, (0, helpers_1.stickerSelect)(buff, 0)];
987
+ case 6:
988
+ obj = _a.sent();
989
+ if (!obj) {
990
+ error = new Error('Error with sharp library, check the console log');
991
+ Object.assign(error, {
992
+ code: 'sharp_error',
993
+ });
994
+ throw error;
995
+ }
996
+ webpBase64 = obj.webpBase64;
997
+ return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
998
+ var to = _a.to, webpBase64 = _a.webpBase64;
999
+ return WPP.chat.sendFileMessage(to, webpBase64, {
1000
+ type: 'sticker',
1001
+ });
1002
+ }, { to: to, webpBase64: webpBase64 })];
1003
+ case 7: return [2 /*return*/, _a.sent()];
926
1004
  }
927
1005
  });
928
1006
  });
@@ -972,8 +1050,18 @@ var SenderLayer = /** @class */ (function (_super) {
972
1050
  };
973
1051
  /**
974
1052
  * Starts typing ('Typing...' state)
1053
+ *
1054
+ * @example
1055
+ * ```javascript
1056
+ * // Keep sending typing state, use stopTyping to finish
1057
+ * await client.startTyping('[number]@c.us');
1058
+ *
1059
+ * // Keep sending typing state for 5 seconds
1060
+ * await client.startTyping('[number]@c.us', 5000);
1061
+ * ```
975
1062
  * @category Chat
976
- * @param chatId
1063
+ * @param to Chat Id
1064
+ * @param duration Duration um miliseconds
977
1065
  */
978
1066
  SenderLayer.prototype.startTyping = function (to, duration) {
979
1067
  return __awaiter(this, void 0, void 0, function () {
@@ -991,7 +1079,7 @@ var SenderLayer = /** @class */ (function (_super) {
991
1079
  /**
992
1080
  * Stops typing ('Typing...' state)
993
1081
  * @category Chat
994
- * @param chatId
1082
+ * @param to Chat Id
995
1083
  */
996
1084
  SenderLayer.prototype.stopTyping = function (to) {
997
1085
  return __awaiter(this, void 0, void 0, function () {
@@ -1007,8 +1095,17 @@ var SenderLayer = /** @class */ (function (_super) {
1007
1095
  };
1008
1096
  /**
1009
1097
  * Starts recording ('Recording...' state)
1098
+ * @example
1099
+ * ```javascript
1100
+ * // Keep sending recording state, use stopRecoring to finish
1101
+ * await client.startRecording('[number]@c.us');
1102
+ *
1103
+ * // Keep sending typing state for 5 seconds
1104
+ * await client.startRecording('[number]@c.us', 5000);
1105
+ * ```
1010
1106
  * @category Chat
1011
- * @param chatId
1107
+ * @param to Chat Id
1108
+ * @param duration Duration um miliseconds
1012
1109
  */
1013
1110
  SenderLayer.prototype.startRecording = function (to, duration) {
1014
1111
  return __awaiter(this, void 0, void 0, function () {
@@ -1026,7 +1123,7 @@ var SenderLayer = /** @class */ (function (_super) {
1026
1123
  /**
1027
1124
  * Stops recording ('Recording...' state)
1028
1125
  * @category Chat
1029
- * @param chatId
1126
+ * @param to Chat Id
1030
1127
  */
1031
1128
  SenderLayer.prototype.stopRecoring = function (to) {
1032
1129
  return __awaiter(this, void 0, void 0, function () {
@@ -22,11 +22,6 @@ export interface SendFileResult extends ScopeResult {
22
22
  export interface SendStickerResult extends ScopeResult {
23
23
  type: string;
24
24
  }
25
- export interface SendLinkResult extends ScopeResult {
26
- type: string;
27
- url: string;
28
- text: string;
29
- }
30
25
  export interface SendPttResult extends ScopeResult {
31
26
  type: string;
32
27
  filename: string;
@@ -164,15 +164,39 @@ var Whatsapp = /** @class */ (function (_super) {
164
164
  }
165
165
  catch (error) { }
166
166
  }
167
- if (!connected) return [3 /*break*/, 4];
167
+ if (!connected) return [3 /*break*/, 5];
168
168
  return [4 /*yield*/, page.evaluate(function () { return localStorage.clear(); })];
169
169
  case 2:
170
170
  _a.sent();
171
- return [4 /*yield*/, page.reload()];
171
+ return [4 /*yield*/, page.evaluate(function () {
172
+ var promises = [];
173
+ window.indexedDB
174
+ .databases()
175
+ .then(function (dbs) {
176
+ dbs.forEach(function (db) {
177
+ promises.push(new Promise(function (resolve) {
178
+ var r = window.indexedDB.deleteDatabase(db.name);
179
+ r.onerror = r.onblocked = function () {
180
+ this.result.close();
181
+ window.indexedDB.deleteDatabase(db.name);
182
+ resolve();
183
+ };
184
+ r.onsuccess = function () {
185
+ resolve();
186
+ };
187
+ }));
188
+ });
189
+ })
190
+ .catch(function () { return null; });
191
+ return Promise.all(promises);
192
+ })];
172
193
  case 3:
173
194
  _a.sent();
174
- _a.label = 4;
195
+ return [4 /*yield*/, page.reload()];
175
196
  case 4:
197
+ _a.sent();
198
+ _a.label = 5;
199
+ case 5:
176
200
  connected = false;
177
201
  return [2 /*return*/];
178
202
  }
@@ -1,2 +1,2 @@
1
- declare const useragentOverride = "WhatsApp/2.2043.8 Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36";
1
+ declare const useragentOverride = "\"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.54 Safari/537.36";
2
2
  export { useragentOverride };
@@ -17,5 +17,5 @@
17
17
  */
18
18
  Object.defineProperty(exports, "__esModule", { value: true });
19
19
  exports.useragentOverride = void 0;
20
- var useragentOverride = 'WhatsApp/2.2043.8 Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36';
20
+ var useragentOverride = '"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.54 Safari/537.36';
21
21
  exports.useragentOverride = useragentOverride;
@@ -235,6 +235,14 @@ function injectSessionToken(page, token, clear) {
235
235
  if (!clear) return [3 /*break*/, 4];
236
236
  return [4 /*yield*/, page.evaluate(function (session) {
237
237
  localStorage.clear();
238
+ window.indexedDB
239
+ .databases()
240
+ .then(function (dbs) {
241
+ dbs.forEach(function (db) {
242
+ window.indexedDB.deleteDatabase(db.name);
243
+ });
244
+ })
245
+ .catch(function () { return null; });
238
246
  })];
239
247
  case 3:
240
248
  _a.sent();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wppconnect-team/wppconnect",
3
- "version": "1.13.0",
3
+ "version": "1.13.3",
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",
@@ -58,63 +58,63 @@
58
58
  },
59
59
  "homepage": "https://github.com/wppconnect-team/wppconnect#readme",
60
60
  "devDependencies": {
61
- "@babel/core": "^7.17.9",
62
- "@babel/eslint-parser": "^7.17.0",
61
+ "@babel/core": "^7.18.2",
62
+ "@babel/eslint-parser": "^7.18.2",
63
63
  "@babel/eslint-plugin": "^7.17.7",
64
- "@babel/preset-env": "^7.16.11",
65
- "@commitlint/cli": "^16.2.3",
66
- "@commitlint/config-conventional": "^16.2.1",
67
- "@commitlint/cz-commitlint": "^16.2.3",
64
+ "@babel/preset-env": "^7.18.2",
65
+ "@commitlint/cli": "^17.0.1",
66
+ "@commitlint/config-conventional": "^17.0.0",
67
+ "@commitlint/cz-commitlint": "^17.0.0",
68
68
  "@types/atob": "^2.1.2",
69
- "@types/mime-types": "^2.1.0",
69
+ "@types/mime-types": "^2.1.1",
70
70
  "@types/mocha": "^9.1.1",
71
- "@types/node": "^14.18.14",
72
- "@types/rimraf": "^3.0.0",
71
+ "@types/node": "^16.11.38",
72
+ "@types/rimraf": "^3.0.2",
73
73
  "@types/sharp": "^0.30.2",
74
74
  "@types/shelljs": "^0.8.11",
75
75
  "@types/tmp": "^0.2.3",
76
76
  "@types/ws": "^8.5.3",
77
- "@typescript-eslint/eslint-plugin": "^5.20.0",
78
- "@typescript-eslint/parser": "^5.20.0",
77
+ "@typescript-eslint/eslint-plugin": "^5.27.0",
78
+ "@typescript-eslint/parser": "^5.27.0",
79
79
  "babel-loader": "^8.2.5",
80
- "commitizen": "^4.2.3",
81
- "concurrently": "^7.1.0",
80
+ "commitizen": "^4.2.4",
81
+ "concurrently": "^7.2.1",
82
82
  "conventional-changelog-cli": "^2.2.2",
83
- "copy-webpack-plugin": "^10.2.4",
84
- "eslint": "^8.14.0",
83
+ "copy-webpack-plugin": "^11.0.0",
84
+ "eslint": "^8.16.0",
85
85
  "eslint-config-prettier": "^8.5.0",
86
86
  "eslint-plugin-prettier": "^4.0.0",
87
87
  "gulp": "^4.0.2",
88
- "husky": "^7.0.4",
89
- "license-check-and-add": "^4.0.3",
90
- "mocha": "^9.2.2",
88
+ "husky": "^8.0.1",
89
+ "license-check-and-add": "^4.0.5",
90
+ "mocha": "^10.0.0",
91
91
  "prettier": "^2.6.2",
92
92
  "pretty-quick": "^3.1.3",
93
- "regenerator-runtime": "^0.13.7",
94
- "release-it": "^14.14.2",
93
+ "regenerator-runtime": "^0.13.9",
94
+ "release-it": "^15.0.0",
95
95
  "shx": "^0.3.4",
96
- "ts-node": "^10.7.0",
96
+ "ts-node": "^10.8.0",
97
97
  "typedoc": "^0.21.10",
98
98
  "typedoc-plugin-pages": "^1.1.0",
99
- "typescript": "^4.6.3",
100
- "webpack": "^5.72.0",
99
+ "typescript": "^4.7.2",
100
+ "webpack": "^5.72.1",
101
101
  "webpack-cli": "^4.9.2"
102
102
  },
103
103
  "dependencies": {
104
- "@wppconnect/wa-js": "^2.0.0",
105
- "@wppconnect/wa-version": "^1.1.66",
104
+ "@wppconnect/wa-js": "^2.4.1",
105
+ "@wppconnect/wa-version": "^1.1.88",
106
106
  "atob": "^2.1.2",
107
- "axios": "^0.26.1",
107
+ "axios": "^0.27.2",
108
108
  "boxen": "^5.1.2",
109
- "catch-exit": "^1.1.0",
109
+ "catch-exit": "^1.2.2",
110
110
  "chalk": "~4.1.2",
111
- "chrome-launcher": "^0.15.0",
112
- "execa": "^5.0.0",
111
+ "chrome-launcher": "^0.15.1",
112
+ "execa": "^5.1.1",
113
113
  "file-type": "~16.5.3",
114
- "futoin-hkdf": "^1.5.0",
114
+ "futoin-hkdf": "^1.5.1",
115
115
  "latest-version": "^5.1.0",
116
116
  "logform": "^2.4.0",
117
- "lookpath": "^1.2.0",
117
+ "lookpath": "^1.2.2",
118
118
  "mime-types": "^2.1.35",
119
119
  "puppeteer": "*",
120
120
  "puppeteer-extra": "^3.2.3",
@@ -125,14 +125,14 @@
125
125
  "reflect-metadata": "^0.1.13",
126
126
  "rimraf": "^3.0.2",
127
127
  "sanitize-filename": "^1.6.3",
128
- "sharp": "^0.30.4",
128
+ "sharp": "^0.30.6",
129
129
  "tmp": "^0.2.1",
130
130
  "tree-kill": "^1.2.2",
131
131
  "winston": "^3.7.2",
132
- "ws": "^8.5.0"
132
+ "ws": "^8.7.0"
133
133
  },
134
134
  "optionalDependencies": {
135
- "fsevents": "^2.3.1"
135
+ "fsevents": "^2.3.2"
136
136
  },
137
137
  "directories": {
138
138
  "doc": "docs",