@wppconnect-team/wppconnect 1.13.2 → 1.14.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.
@@ -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
  });
@@ -152,10 +156,18 @@ var SenderLayer = /** @class */ (function (_super) {
152
156
  * client.sendText('<number>@c.us', 'A simple message');
153
157
  *
154
158
  * // With buttons
155
- * client.sendText('<number>@c.us', 'A simple message with buttons', {
159
+ * client.sendText('<number>@c.us', 'WPPConnect message with buttons', {
156
160
  * useTemplateButtons: true, // False for legacy
157
161
  * buttons: [
158
162
  * {
163
+ * url: 'https://wppconnect-team.github.io/',
164
+ * text: 'WPPConnect Site'
165
+ * },
166
+ * {
167
+ * phoneNumber: '+55 11 22334455',
168
+ * text: 'Call me'
169
+ * },
170
+ * {
159
171
  * id: 'your custom id 1',
160
172
  * text: 'Some text'
161
173
  * },
@@ -352,48 +364,94 @@ var SenderLayer = /** @class */ (function (_super) {
352
364
  };
353
365
  /**
354
366
  * Sends message with thumbnail
367
+ *
368
+ * @deprecated: please use {@link sendText} with options
369
+ *
370
+ * @deprecated
355
371
  * @category Chat
356
- * @param thumb
372
+ * @param pathOrBase64
357
373
  * @param url
358
374
  * @param title
359
375
  * @param description
360
376
  * @param chatId
361
377
  */
362
- SenderLayer.prototype.sendMessageWithThumb = function (thumb, url, title, description, chatId) {
378
+ SenderLayer.prototype.sendMessageWithThumb = function (pathOrBase64, url, title, description, chatId) {
363
379
  return __awaiter(this, void 0, void 0, function () {
364
- var base64;
380
+ var base64, fileContent, error, mimeInfo, error, thumbnail;
365
381
  return __generator(this, function (_a) {
366
382
  switch (_a.label) {
367
- case 0: return [4 /*yield*/, (0, helpers_1.downloadFileToBase64)(thumb, [
383
+ case 0:
384
+ base64 = '';
385
+ if (!pathOrBase64.startsWith('data:')) return [3 /*break*/, 1];
386
+ base64 = pathOrBase64;
387
+ return [3 /*break*/, 5];
388
+ case 1: return [4 /*yield*/, (0, helpers_1.downloadFileToBase64)(pathOrBase64, [
368
389
  'image/gif',
369
390
  'image/png',
370
391
  'image/jpg',
371
392
  'image/jpeg',
372
393
  'image/webp',
373
394
  ])];
374
- case 1:
375
- base64 = _a.sent();
376
- if (!!base64) return [3 /*break*/, 3];
377
- return [4 /*yield*/, (0, helpers_1.fileToBase64)(thumb)];
378
395
  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
- })];
396
+ fileContent = _a.sent();
397
+ if (!!fileContent) return [3 /*break*/, 4];
398
+ return [4 /*yield*/, (0, helpers_1.fileToBase64)(pathOrBase64)];
399
+ case 3:
400
+ fileContent = _a.sent();
401
+ _a.label = 4;
402
+ case 4:
403
+ if (fileContent) {
404
+ base64 = fileContent;
405
+ }
406
+ _a.label = 5;
407
+ case 5:
408
+ if (!base64) {
409
+ error = new Error('Empty or invalid file or base64');
410
+ Object.assign(error, {
411
+ code: 'empty_file',
412
+ });
413
+ throw error;
414
+ }
415
+ mimeInfo = (0, helpers_1.base64MimeType)(base64);
416
+ if (!mimeInfo || !mimeInfo.includes('image')) {
417
+ error = new Error('Not an image, allowed formats png, jpeg, webp and gif');
418
+ Object.assign(error, {
419
+ code: 'invalid_image',
420
+ });
421
+ throw error;
422
+ }
423
+ thumbnail = base64.replace(/^data:image\/(png|jpe?g|webp|gif);base64,/, '');
424
+ return [2 /*return*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
425
+ var thumbnail = _a.thumbnail, url = _a.url, title = _a.title, description = _a.description, chatId = _a.chatId;
426
+ return WPP.chat.sendTextMessage(chatId, url, {
427
+ linkPreview: {
428
+ thumbnail: thumbnail,
429
+ canonicalUrl: url,
430
+ description: description,
431
+ matchedText: url,
432
+ title: title,
433
+ richPreviewType: 0,
434
+ doNotPlayInline: true,
435
+ },
436
+ });
437
+ }, {
438
+ thumbnail: thumbnail,
439
+ url: url,
440
+ title: title,
441
+ description: description,
442
+ chatId: chatId,
443
+ })];
391
444
  }
392
445
  });
393
446
  });
394
447
  };
395
448
  /**
396
449
  * Replies to given mesage id of given chat id
450
+ *
451
+ * Deprecated: Please, use sendText with quotedMsg option
452
+ *
453
+ * @deprecated
454
+ *
397
455
  * @category Chat
398
456
  * @param to Chat id
399
457
  * @param content Message body
@@ -521,86 +579,86 @@ var SenderLayer = /** @class */ (function (_super) {
521
579
  /**
522
580
  * Sends file
523
581
  * base64 parameter should have mime type already defined
582
+ *
583
+ * Deprecated: please use sendFile with options: sendFile(to, content, options)
584
+ *
585
+ * @deprecated
586
+ *
524
587
  * @category Chat
525
- * @param to Chat id
588
+ * @param chatId Chat id
526
589
  * @param base64 base64 data
527
590
  * @param filename
528
591
  * @param caption
529
592
  */
530
- SenderLayer.prototype.sendFileFromBase64 = function (to, base64, filename, caption) {
593
+ SenderLayer.prototype.sendFileFromBase64 = function (chatId, base64, filename, caption) {
531
594
  return __awaiter(this, void 0, void 0, function () {
532
- var mimeType, obj, type, result;
533
595
  return __generator(this, function (_a) {
534
- switch (_a.label) {
535
- case 0:
536
- mimeType = (0, helpers_1.base64MimeType)(base64);
537
- if (!mimeType) {
538
- obj = {
539
- erro: true,
540
- to: to,
541
- text: 'Invalid base64!',
542
- };
543
- throw obj;
544
- }
545
- filename = (0, filename_from_mimetype_1.filenameFromMimeType)(filename, mimeType);
546
- type = 'FileFromBase64';
547
- return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
548
- var to = _a.to, base64 = _a.base64, filename = _a.filename, caption = _a.caption, type = _a.type;
549
- return WAPI.sendFile(base64, to, filename, caption, type);
550
- }, { to: to, base64: base64, filename: filename, caption: caption, type: type })];
551
- case 1:
552
- result = _a.sent();
553
- if (result['erro'] == true) {
554
- throw result;
555
- }
556
- return [2 /*return*/, result];
557
- }
596
+ return [2 /*return*/, this.sendFile(chatId, base64, filename, caption)];
558
597
  });
559
598
  });
560
599
  };
561
- /**
562
- * Sends file from path
563
- * @category Chat
564
- * @param to Chat id
565
- * @param filePath File path
566
- * @param filename
567
- * @param caption
568
- */
569
- SenderLayer.prototype.sendFile = function (to, filePath, filename, caption) {
600
+ SenderLayer.prototype.sendFile = function (to, pathOrBase64, nameOrOptions, caption) {
570
601
  return __awaiter(this, void 0, void 0, function () {
602
+ var options, base64, fileContent, error;
571
603
  var _this = this;
572
604
  return __generator(this, function (_a) {
573
- return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
574
- var base64, obj;
575
- return __generator(this, function (_a) {
576
- switch (_a.label) {
577
- case 0: return [4 /*yield*/, (0, helpers_1.downloadFileToBase64)(filePath)];
578
- case 1:
579
- base64 = _a.sent();
580
- if (!!base64) return [3 /*break*/, 3];
581
- return [4 /*yield*/, (0, helpers_1.fileToBase64)(filePath)];
582
- case 2:
583
- base64 = _a.sent();
584
- _a.label = 3;
585
- case 3:
586
- if (!base64) {
587
- obj = {
588
- erro: true,
589
- to: to,
590
- text: 'No such file or directory, open "' + filePath + '"',
591
- };
592
- return [2 /*return*/, reject(obj)];
593
- }
594
- if (!filename) {
595
- filename = path.basename(filePath);
596
- }
597
- this.sendFileFromBase64(to, base64, filename, caption)
598
- .then(resolve)
599
- .catch(reject);
600
- return [2 /*return*/];
601
- }
602
- });
603
- }); })];
605
+ switch (_a.label) {
606
+ case 0:
607
+ options = { type: 'auto-detect' };
608
+ if (typeof nameOrOptions === 'string') {
609
+ options.filename = nameOrOptions;
610
+ options.caption = caption;
611
+ }
612
+ else if (typeof nameOrOptions === 'object') {
613
+ options = nameOrOptions;
614
+ }
615
+ base64 = '';
616
+ if (!pathOrBase64.startsWith('data:')) return [3 /*break*/, 1];
617
+ base64 = pathOrBase64;
618
+ return [3 /*break*/, 5];
619
+ case 1: return [4 /*yield*/, (0, helpers_1.downloadFileToBase64)(pathOrBase64)];
620
+ case 2:
621
+ fileContent = _a.sent();
622
+ if (!!fileContent) return [3 /*break*/, 4];
623
+ return [4 /*yield*/, (0, helpers_1.fileToBase64)(pathOrBase64)];
624
+ case 3:
625
+ fileContent = _a.sent();
626
+ _a.label = 4;
627
+ case 4:
628
+ if (fileContent) {
629
+ base64 = fileContent;
630
+ }
631
+ _a.label = 5;
632
+ case 5:
633
+ if (!base64) {
634
+ error = new Error('Empty or invalid file or base64');
635
+ Object.assign(error, {
636
+ code: 'empty_file',
637
+ });
638
+ throw error;
639
+ }
640
+ return [2 /*return*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
641
+ var to = _a.to, base64 = _a.base64, options = _a.options;
642
+ return __awaiter(_this, void 0, void 0, function () {
643
+ var result;
644
+ var _b;
645
+ return __generator(this, function (_c) {
646
+ switch (_c.label) {
647
+ case 0: return [4 /*yield*/, WPP.chat.sendFileMessage(to, base64, options)];
648
+ case 1:
649
+ result = _c.sent();
650
+ _b = {
651
+ ack: result.ack,
652
+ id: result.id
653
+ };
654
+ return [4 /*yield*/, result.sendMsgResult];
655
+ case 2: return [2 /*return*/, (_b.sendMsgResult = _c.sent(),
656
+ _b)];
657
+ }
658
+ });
659
+ });
660
+ }, { to: to, base64: base64, options: options })];
661
+ }
604
662
  });
605
663
  });
606
664
  };
@@ -818,52 +876,70 @@ var SenderLayer = /** @class */ (function (_super) {
818
876
  /**
819
877
  * Generates sticker from the provided animated gif image and sends it (Send image as animated sticker)
820
878
  * @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'
879
+ * @param pathOrBase64 image path imageBase64 A valid gif image is required. You can also send via http/https (http://www.website.com/img.gif)
880
+ * @param to chatId '000000000000@c.us'
823
881
  */
824
- SenderLayer.prototype.sendImageAsStickerGif = function (to, path) {
882
+ SenderLayer.prototype.sendImageAsStickerGif = function (to, pathOrBase64) {
825
883
  return __awaiter(this, void 0, void 0, function () {
826
- var b64, buff, mimeInfo, obj, _webb64, _met, result;
884
+ var base64, fileContent, error, mimeInfo, error, buff, obj, error, webpBase64;
827
885
  return __generator(this, function (_a) {
828
886
  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)];
887
+ case 0:
888
+ base64 = '';
889
+ if (!pathOrBase64.startsWith('data:')) return [3 /*break*/, 1];
890
+ base64 = pathOrBase64;
891
+ return [3 /*break*/, 5];
892
+ case 1: return [4 /*yield*/, (0, helpers_1.downloadFileToBase64)(pathOrBase64, [
893
+ 'image/gif',
894
+ 'image/webp',
895
+ ])];
834
896
  case 2:
835
- b64 = _a.sent();
836
- _a.label = 3;
897
+ fileContent = _a.sent();
898
+ if (!!fileContent) return [3 /*break*/, 4];
899
+ return [4 /*yield*/, (0, helpers_1.fileToBase64)(pathOrBase64)];
837
900
  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)];
901
+ fileContent = _a.sent();
902
+ _a.label = 4;
843
903
  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 })];
904
+ if (fileContent) {
905
+ base64 = fileContent;
906
+ }
907
+ _a.label = 5;
852
908
  case 5:
853
- result = _a.sent();
854
- if (result['erro'] == true) {
855
- throw result;
909
+ if (!base64) {
910
+ error = new Error('Empty or invalid file or base64');
911
+ Object.assign(error, {
912
+ code: 'empty_file',
913
+ });
914
+ throw error;
856
915
  }
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*/];
916
+ mimeInfo = (0, helpers_1.base64MimeType)(base64);
917
+ if (!mimeInfo || !mimeInfo.includes('image')) {
918
+ error = new Error('Not an image, allowed formats gig and webp');
919
+ Object.assign(error, {
920
+ code: 'invalid_image',
921
+ });
922
+ throw error;
923
+ }
924
+ buff = Buffer.from(base64.replace(/^data:image\/(gif|webp);base64,/, ''), 'base64');
925
+ return [4 /*yield*/, (0, helpers_1.stickerSelect)(buff, 1)];
926
+ case 6:
927
+ obj = _a.sent();
928
+ if (!obj) {
929
+ error = new Error('Error with sharp library, check the console log');
930
+ Object.assign(error, {
931
+ code: 'sharp_error',
932
+ });
933
+ throw error;
934
+ }
935
+ webpBase64 = obj.webpBase64;
936
+ return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
937
+ var to = _a.to, webpBase64 = _a.webpBase64;
938
+ return WPP.chat.sendFileMessage(to, webpBase64, {
939
+ type: 'sticker',
940
+ });
941
+ }, { to: to, webpBase64: webpBase64 })];
942
+ case 7: return [2 /*return*/, _a.sent()];
867
943
  }
868
944
  });
869
945
  });
@@ -871,89 +947,113 @@ var SenderLayer = /** @class */ (function (_super) {
871
947
  /**
872
948
  * Generates sticker from given image and sends it (Send Image As Sticker)
873
949
  * @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)
950
+ * @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
951
  * @param to chatId '000000000000@c.us'
876
952
  */
877
- SenderLayer.prototype.sendImageAsSticker = function (to, path) {
953
+ SenderLayer.prototype.sendImageAsSticker = function (to, pathOrBase64) {
878
954
  return __awaiter(this, void 0, void 0, function () {
879
- var b64, buff, mimeInfo, obj, _webb64, _met, result;
955
+ var base64, fileContent, error, mimeInfo, error, buff, obj, error, webpBase64;
880
956
  return __generator(this, function (_a) {
881
957
  switch (_a.label) {
882
- case 0: return [4 /*yield*/, (0, helpers_1.downloadFileToBase64)(path, [
958
+ case 0:
959
+ base64 = '';
960
+ if (!pathOrBase64.startsWith('data:')) return [3 /*break*/, 1];
961
+ base64 = pathOrBase64;
962
+ return [3 /*break*/, 5];
963
+ case 1: return [4 /*yield*/, (0, helpers_1.downloadFileToBase64)(pathOrBase64, [
883
964
  'image/gif',
884
965
  'image/png',
885
966
  'image/jpg',
886
967
  'image/jpeg',
887
968
  'image/webp',
888
969
  ])];
889
- case 1:
890
- b64 = _a.sent();
891
- if (!!b64) return [3 /*break*/, 3];
892
- return [4 /*yield*/, (0, helpers_1.fileToBase64)(path)];
893
970
  case 2:
894
- b64 = _a.sent();
895
- _a.label = 3;
971
+ fileContent = _a.sent();
972
+ if (!!fileContent) return [3 /*break*/, 4];
973
+ return [4 /*yield*/, (0, helpers_1.fileToBase64)(pathOrBase64)];
896
974
  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)];
975
+ fileContent = _a.sent();
976
+ _a.label = 4;
902
977
  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 })];
978
+ if (fileContent) {
979
+ base64 = fileContent;
980
+ }
981
+ _a.label = 5;
911
982
  case 5:
912
- result = _a.sent();
913
- if (result['erro'] == true) {
914
- throw result;
983
+ if (!base64) {
984
+ error = new Error('Empty or invalid file or base64');
985
+ Object.assign(error, {
986
+ code: 'empty_file',
987
+ });
988
+ throw error;
915
989
  }
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*/];
990
+ mimeInfo = (0, helpers_1.base64MimeType)(base64);
991
+ if (!mimeInfo || !mimeInfo.includes('image')) {
992
+ error = new Error('Not an image, allowed formats png, jpeg, webp and gif');
993
+ Object.assign(error, {
994
+ code: 'invalid_image',
995
+ });
996
+ throw error;
997
+ }
998
+ buff = Buffer.from(base64.replace(/^data:image\/(png|jpe?g|webp|gif);base64,/, ''), 'base64');
999
+ return [4 /*yield*/, (0, helpers_1.stickerSelect)(buff, 0)];
1000
+ case 6:
1001
+ obj = _a.sent();
1002
+ if (!obj) {
1003
+ error = new Error('Error with sharp library, check the console log');
1004
+ Object.assign(error, {
1005
+ code: 'sharp_error',
1006
+ });
1007
+ throw error;
1008
+ }
1009
+ webpBase64 = obj.webpBase64;
1010
+ return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
1011
+ var to = _a.to, webpBase64 = _a.webpBase64;
1012
+ return WPP.chat.sendFileMessage(to, webpBase64, {
1013
+ type: 'sticker',
1014
+ });
1015
+ }, { to: to, webpBase64: webpBase64 })];
1016
+ case 7: return [2 /*return*/, _a.sent()];
926
1017
  }
927
1018
  });
928
1019
  });
929
1020
  };
930
- /**
931
- * TODO: Fix message not being delivered
932
- * Sends location to given chat id
933
- * @category Chat
934
- * @param to Chat id
935
- * @param latitude Latitude
936
- * @param longitude Longitude
937
- * @param title Text caption
938
- */
939
- SenderLayer.prototype.sendLocation = function (to, latitude, longitude, title) {
1021
+ SenderLayer.prototype.sendLocation = function (to, latitudeOrOptions, longitude, title) {
940
1022
  return __awaiter(this, void 0, void 0, function () {
941
- var result;
1023
+ var options;
1024
+ var _this = this;
942
1025
  return __generator(this, function (_a) {
943
1026
  switch (_a.label) {
944
- case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
945
- var to = _a.to, latitude = _a.latitude, longitude = _a.longitude, title = _a.title;
946
- return WAPI.sendLocation(to, latitude, longitude, title);
947
- }, { to: to, latitude: latitude, longitude: longitude, title: title })];
948
- case 1:
949
- result = _a.sent();
950
- if (result['erro'] == true) {
951
- throw result;
952
- }
953
- else {
954
- return [2 /*return*/, result];
955
- }
956
- return [2 /*return*/];
1027
+ case 0:
1028
+ options = typeof latitudeOrOptions === 'string'
1029
+ ? {
1030
+ lat: latitudeOrOptions,
1031
+ lng: longitude,
1032
+ title: title,
1033
+ }
1034
+ : latitudeOrOptions;
1035
+ return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
1036
+ var to = _a.to, options = _a.options;
1037
+ return __awaiter(_this, void 0, void 0, function () {
1038
+ var result;
1039
+ var _b;
1040
+ return __generator(this, function (_c) {
1041
+ switch (_c.label) {
1042
+ case 0: return [4 /*yield*/, WPP.chat.sendLocationMessage(to, options)];
1043
+ case 1:
1044
+ result = _c.sent();
1045
+ _b = {
1046
+ ack: result.ack,
1047
+ id: result.id
1048
+ };
1049
+ return [4 /*yield*/, result.sendMsgResult];
1050
+ case 2: return [2 /*return*/, (_b.sendMsgResult = _c.sent(),
1051
+ _b)];
1052
+ }
1053
+ });
1054
+ });
1055
+ }, { to: to, options: options })];
1056
+ case 1: return [2 /*return*/, _a.sent()];
957
1057
  }
958
1058
  });
959
1059
  });
@@ -972,8 +1072,18 @@ var SenderLayer = /** @class */ (function (_super) {
972
1072
  };
973
1073
  /**
974
1074
  * Starts typing ('Typing...' state)
1075
+ *
1076
+ * @example
1077
+ * ```javascript
1078
+ * // Keep sending typing state, use stopTyping to finish
1079
+ * await client.startTyping('[number]@c.us');
1080
+ *
1081
+ * // Keep sending typing state for 5 seconds
1082
+ * await client.startTyping('[number]@c.us', 5000);
1083
+ * ```
975
1084
  * @category Chat
976
- * @param chatId
1085
+ * @param to Chat Id
1086
+ * @param duration Duration um miliseconds
977
1087
  */
978
1088
  SenderLayer.prototype.startTyping = function (to, duration) {
979
1089
  return __awaiter(this, void 0, void 0, function () {
@@ -991,7 +1101,7 @@ var SenderLayer = /** @class */ (function (_super) {
991
1101
  /**
992
1102
  * Stops typing ('Typing...' state)
993
1103
  * @category Chat
994
- * @param chatId
1104
+ * @param to Chat Id
995
1105
  */
996
1106
  SenderLayer.prototype.stopTyping = function (to) {
997
1107
  return __awaiter(this, void 0, void 0, function () {
@@ -1007,8 +1117,17 @@ var SenderLayer = /** @class */ (function (_super) {
1007
1117
  };
1008
1118
  /**
1009
1119
  * Starts recording ('Recording...' state)
1120
+ * @example
1121
+ * ```javascript
1122
+ * // Keep sending recording state, use stopRecoring to finish
1123
+ * await client.startRecording('[number]@c.us');
1124
+ *
1125
+ * // Keep sending typing state for 5 seconds
1126
+ * await client.startRecording('[number]@c.us', 5000);
1127
+ * ```
1010
1128
  * @category Chat
1011
- * @param chatId
1129
+ * @param to Chat Id
1130
+ * @param duration Duration um miliseconds
1012
1131
  */
1013
1132
  SenderLayer.prototype.startRecording = function (to, duration) {
1014
1133
  return __awaiter(this, void 0, void 0, function () {
@@ -1026,7 +1145,7 @@ var SenderLayer = /** @class */ (function (_super) {
1026
1145
  /**
1027
1146
  * Stops recording ('Recording...' state)
1028
1147
  * @category Chat
1029
- * @param chatId
1148
+ * @param to Chat Id
1030
1149
  */
1031
1150
  SenderLayer.prototype.stopRecoring = function (to) {
1032
1151
  return __awaiter(this, void 0, void 0, function () {