@wppconnect-team/wppconnect 1.10.3 → 1.12.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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,34 @@
1
+ ## 1.12.1 (2022-01-14)
2
+
3
+
4
+
5
+ # 1.12.0 (2022-01-08)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * Fixed downloadMedia (fix [#463](https://github.com/wppconnect-team/wppconnect/issues/463)) ([ea9ba75](https://github.com/wppconnect-team/wppconnect/commit/ea9ba75ec3e24103a7ccf55b0df43ffc8d46271b))
11
+
12
+
13
+
14
+ ## 1.11.1 (2021-12-09)
15
+
16
+
17
+ ### Bug Fixes
18
+
19
+ * Fixed getNumberProfile function (fix [#717](https://github.com/wppconnect-team/wppconnect/issues/717)) ([89a0720](https://github.com/wppconnect-team/wppconnect/commit/89a072066991213d301739b0788d19f05a9b0912))
20
+
21
+
22
+
23
+ # 1.11.0 (2021-12-09)
24
+
25
+
26
+ ### Bug Fixes
27
+
28
+ * Fixed initialization of onPresenceChanged (fix [#704](https://github.com/wppconnect-team/wppconnect/issues/704)) ([0470ea8](https://github.com/wppconnect-team/wppconnect/commit/0470ea8a0fd15727f91e18c913b96f3c1e1f79a9))
29
+
30
+
31
+
1
32
  ## 1.10.3 (2021-11-18)
2
33
 
3
34
 
@@ -94,7 +94,7 @@ function evaluateAndReturn(page, pageFunction) {
94
94
  throw new Error('Passed function is not well-serializable!');
95
95
  }
96
96
  }
97
- func = new Function("\n var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\n return new (P || (P = Promise))(function (resolve, reject) {\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\n step((generator = generator.apply(thisArg, _arguments || [])).next());\n });\n };\n var __generator = (this && this.__generator) || function (thisArg, body) {\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\n function verb(n) { return function (v) { return step([n, v]); }; }\n function step(op) {\n if (f) throw new TypeError(\"Generator is already executing.\");\n while (_) try {\n 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;\n if (y = 0, t) op = [op[0] & 2, t.value];\n switch (op[0]) {\n case 0: case 1: t = op; break;\n case 4: _.label++; return { value: op[1], done: false };\n case 5: _.label++; y = op[1]; op = [0]; continue;\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\n default:\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\n if (t[2]) _.ops.pop();\n _.trys.pop(); continue;\n }\n op = body.call(thisArg, _);\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\n }\n };\n var _this; // for arrow function\n\n return new Promise(async (resolve) => {\n try {\n return resolve(await (".concat(functionText, ").apply(this, arguments));\n } catch (error) {\n return resolve({\n __error: JSON.parse(JSON.stringify(error, Object.getOwnPropertyNames(error))),\n });\n }\n });"));
97
+ func = new Function("\n var __assign = (this && this.__assign) || function () {\n __assign = Object.assign || function(t) {\n for (var s, i = 1, n = arguments.length; i < n; i++) {\n s = arguments[i];\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))\n t[p] = s[p];\n }\n return t;\n };\n return __assign.apply(this, arguments);\n };\n\n var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\n return new (P || (P = Promise))(function (resolve, reject) {\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\n step((generator = generator.apply(thisArg, _arguments || [])).next());\n });\n };\n var __generator = (this && this.__generator) || function (thisArg, body) {\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\n function verb(n) { return function (v) { return step([n, v]); }; }\n function step(op) {\n if (f) throw new TypeError(\"Generator is already executing.\");\n while (_) try {\n 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;\n if (y = 0, t) op = [op[0] & 2, t.value];\n switch (op[0]) {\n case 0: case 1: t = op; break;\n case 4: _.label++; return { value: op[1], done: false };\n case 5: _.label++; y = op[1]; op = [0]; continue;\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\n default:\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\n if (t[2]) _.ops.pop();\n _.trys.pop(); continue;\n }\n op = body.call(thisArg, _);\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\n }\n };\n var _this; // for arrow function\n\n return new Promise(async (resolve) => {\n try {\n return resolve(await (".concat(functionText, ").apply(this, arguments));\n } catch (error) {\n return resolve({\n __error: JSON.parse(JSON.stringify(error, Object.getOwnPropertyNames(error))),\n });\n }\n });"));
98
98
  return [4 /*yield*/, page.evaluate.apply(page, __spreadArray([func], args, false))];
99
99
  case 1:
100
100
  result = (_a.sent());
@@ -4,5 +4,4 @@ export { downloadFileToBase64 } from './download-file';
4
4
  export { stickerSelect, resizeImg } from './select-sticker';
5
5
  export { scrapeImg } from './scrape-img-qr';
6
6
  export { scrapeLogin } from './scrape-login';
7
- export { scrapeDesconnected } from './scrape-desconnect';
8
7
  export { evaluateAndReturn } from './evaluate-and-return';
@@ -16,7 +16,7 @@
16
16
  * along with WPPConnect. If not, see <https://www.gnu.org/licenses/>.
17
17
  */
18
18
  Object.defineProperty(exports, "__esModule", { value: true });
19
- exports.evaluateAndReturn = exports.scrapeDesconnected = exports.scrapeLogin = exports.scrapeImg = exports.resizeImg = exports.stickerSelect = exports.downloadFileToBase64 = exports.base64MimeType = exports.fileToBase64 = void 0;
19
+ exports.evaluateAndReturn = exports.scrapeLogin = exports.scrapeImg = exports.resizeImg = exports.stickerSelect = exports.downloadFileToBase64 = exports.base64MimeType = exports.fileToBase64 = void 0;
20
20
  var file_to_base64_1 = require("./file-to-base64");
21
21
  Object.defineProperty(exports, "fileToBase64", { enumerable: true, get: function () { return file_to_base64_1.fileToBase64; } });
22
22
  var base64_mimetype_1 = require("./base64-mimetype");
@@ -30,7 +30,5 @@ var scrape_img_qr_1 = require("./scrape-img-qr");
30
30
  Object.defineProperty(exports, "scrapeImg", { enumerable: true, get: function () { return scrape_img_qr_1.scrapeImg; } });
31
31
  var scrape_login_1 = require("./scrape-login");
32
32
  Object.defineProperty(exports, "scrapeLogin", { enumerable: true, get: function () { return scrape_login_1.scrapeLogin; } });
33
- var scrape_desconnect_1 = require("./scrape-desconnect");
34
- Object.defineProperty(exports, "scrapeDesconnected", { enumerable: true, get: function () { return scrape_desconnect_1.scrapeDesconnected; } });
35
33
  var evaluate_and_return_1 = require("./evaluate-and-return");
36
34
  Object.defineProperty(exports, "evaluateAndReturn", { enumerable: true, get: function () { return evaluate_and_return_1.evaluateAndReturn; } });
@@ -122,7 +122,12 @@ var ControlsLayer = /** @class */ (function (_super) {
122
122
  ControlsLayer.prototype.markUnseenMessage = function (contactId) {
123
123
  return __awaiter(this, void 0, void 0, function () {
124
124
  return __generator(this, function (_a) {
125
- return [2 /*return*/, (0, helpers_1.evaluateAndReturn)(this.page, function (contactId) { return WAPI.markUnseenMessage(contactId); }, contactId)];
125
+ switch (_a.label) {
126
+ case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (contactId) { return WPP.chat.markIsUnread(contactId); }, contactId)];
127
+ case 1:
128
+ _a.sent();
129
+ return [2 /*return*/, true];
130
+ }
126
131
  });
127
132
  });
128
133
  };
@@ -509,8 +509,7 @@ var HostLayer = /** @class */ (function () {
509
509
  return __generator(this, function (_a) {
510
510
  switch (_a.label) {
511
511
  case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function () {
512
- //@ts-ignore
513
- return Store.State.default.state;
512
+ return WPP.whatsapp.State.state;
514
513
  })];
515
514
  case 1: return [2 /*return*/, _a.sent()];
516
515
  }
@@ -199,7 +199,6 @@ var ListenerLayer = /** @class */ (function (_super) {
199
199
  window['onLiveLocation'].exposed = true;
200
200
  }
201
201
  if (!window['onRevokedMessage'].exposed) {
202
- // @ts-ignore
203
202
  WPP.chat.on('msg_revoke', function (data) {
204
203
  var eventData = {
205
204
  author: data.author,
@@ -30,7 +30,7 @@ export declare class RetrieverLayer extends SenderLayer {
30
30
  * @category Blocklist
31
31
  * @returns array of [0,1,2,3....]
32
32
  */
33
- getBlockList(): Promise<import("../model").Contact[]>;
33
+ getBlockList(): Promise<string[]>;
34
34
  /**
35
35
  * Retrieves all chats
36
36
  * @category Chat
@@ -115,6 +115,9 @@ export declare class RetrieverLayer extends SenderLayer {
115
115
  getStatus(contactId: string): Promise<import("../model").ContactStatus>;
116
116
  /**
117
117
  * Checks if a number is a valid whatsapp number
118
+ *
119
+ * Deprecated in favor of checkNumberStatus
120
+ * @deprecated Deprecated in favor of checkNumberStatus
118
121
  * @category Contact
119
122
  * @param contactId, you need to include the @c.us at the end.
120
123
  * @returns contact detial as promise
@@ -112,28 +112,35 @@ var RetrieverLayer = /** @class */ (function (_super) {
112
112
  _a.label = 2;
113
113
  case 2: return [4 /*yield*/, this.isMultiDevice()];
114
114
  case 3:
115
- if (_a.sent()) {
116
- return [2 /*return*/, {
117
- WABrowserId: 'MultiDevice',
118
- WASecretBundle: 'MultiDevice',
119
- WAToken1: 'MultiDevice',
120
- WAToken2: 'MultiDevice',
121
- }];
122
- }
115
+ if (!_a.sent()) return [3 /*break*/, 5];
123
116
  return [4 /*yield*/, this.page
124
117
  .evaluate(function () {
125
118
  if (window.localStorage) {
126
119
  return {
127
- WABrowserId: window.localStorage.getItem('WABrowserId'),
128
- WASecretBundle: window.localStorage.getItem('WASecretBundle'),
129
- WAToken1: window.localStorage.getItem('WAToken1'),
130
- WAToken2: window.localStorage.getItem('WAToken2'),
120
+ WABrowserId: window.localStorage.getItem('WABrowserId') || 'MultiDevice',
121
+ WASecretBundle: 'MultiDevice',
122
+ WAToken1: 'MultiDevice',
123
+ WAToken2: 'MultiDevice',
131
124
  };
132
125
  }
133
126
  return null;
134
127
  })
135
128
  .catch(function () { return null; })];
136
129
  case 4: return [2 /*return*/, _a.sent()];
130
+ case 5: return [4 /*yield*/, this.page
131
+ .evaluate(function () {
132
+ if (window.localStorage) {
133
+ return {
134
+ WABrowserId: window.localStorage.getItem('WABrowserId'),
135
+ WASecretBundle: window.localStorage.getItem('WASecretBundle'),
136
+ WAToken1: window.localStorage.getItem('WAToken1'),
137
+ WAToken2: window.localStorage.getItem('WAToken2'),
138
+ };
139
+ }
140
+ return null;
141
+ })
142
+ .catch(function () { return null; })];
143
+ case 6: return [2 /*return*/, _a.sent()];
137
144
  }
138
145
  });
139
146
  });
@@ -162,7 +169,9 @@ var RetrieverLayer = /** @class */ (function (_super) {
162
169
  return __awaiter(this, void 0, void 0, function () {
163
170
  return __generator(this, function (_a) {
164
171
  switch (_a.label) {
165
- case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function () { return WAPI.getBlockList(); })];
172
+ case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function () {
173
+ return WPP.blocklist.all().map(function (b) { return b.toString(); });
174
+ })];
166
175
  case 1: return [2 /*return*/, _a.sent()];
167
176
  }
168
177
  });
@@ -361,6 +370,9 @@ var RetrieverLayer = /** @class */ (function (_super) {
361
370
  };
362
371
  /**
363
372
  * Checks if a number is a valid whatsapp number
373
+ *
374
+ * Deprecated in favor of checkNumberStatus
375
+ * @deprecated Deprecated in favor of checkNumberStatus
364
376
  * @category Contact
365
377
  * @param contactId, you need to include the @c.us at the end.
366
378
  * @returns contact detial as promise
@@ -1,4 +1,4 @@
1
- import { ListMessageOptions } from '@wppconnect/wa-js/dist/chat';
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
4
  import { Message, SendFileResult, SendLinkResult, SendStickerResult } from '../model';
@@ -20,8 +20,30 @@ export declare class SenderLayer extends ListenerLayer {
20
20
  * @category Chat
21
21
  * @param to chat id: xxxxx@us.c
22
22
  * @param content text message
23
+ *
24
+ * @example
25
+ * ```javascript
26
+ * // Simple message
27
+ * client.sendText('<number>@c.us', 'A simple message');
28
+ *
29
+ * // With buttons
30
+ * client.sendText('<number>@c.us', 'A simple message with buttons', {
31
+ * buttons: [
32
+ * {
33
+ * id: 'your custom id 1',
34
+ * text: 'Some text'
35
+ * },
36
+ * {
37
+ * id: 'another id 2',
38
+ * text: 'Another text'
39
+ * }
40
+ * ],
41
+ * title: 'Title text' // Optional
42
+ * footer: 'Footer text' // Optional
43
+ * });
44
+ * ```
23
45
  */
24
- sendText(to: string, content: string): Promise<Message>;
46
+ sendText(to: string, content: string, options?: TextMessageOptions): Promise<Message>;
25
47
  /**
26
48
  *
27
49
  * @category Chat
@@ -181,7 +203,7 @@ export declare class SenderLayer extends ListenerLayer {
181
203
  * @param to Chat id
182
204
  * @param contactsId Example: 0000@c.us | [000@c.us, 1111@c.us]
183
205
  */
184
- sendContactVcard(to: string, contactsId: string, name?: string): Promise<void>;
206
+ sendContactVcard(to: string, contactsId: string, name?: string): Promise<import("@wppconnect/wa-js/dist/chat").SendMessageReturn>;
185
207
  /**
186
208
  * Send a list of contact cards
187
209
  * @category Chat
@@ -230,19 +252,34 @@ export declare class SenderLayer extends ListenerLayer {
230
252
  * @category Chat
231
253
  * @param chatId chat id: xxxxx@us.c
232
254
  */
233
- sendSeen(chatId: string): Promise<void>;
255
+ sendSeen(chatId: string): Promise<{
256
+ wid: import("@wppconnect/wa-js/dist/whatsapp").Wid;
257
+ unreadCount: number;
258
+ }>;
234
259
  /**
235
260
  * Starts typing ('Typing...' state)
236
261
  * @category Chat
237
262
  * @param chatId
238
263
  */
239
- startTyping(to: string): Promise<void>;
264
+ startTyping(to: string, duration?: number): Promise<void>;
240
265
  /**
241
266
  * Stops typing ('Typing...' state)
242
267
  * @category Chat
243
268
  * @param chatId
244
269
  */
245
270
  stopTyping(to: string): Promise<void>;
271
+ /**
272
+ * Starts recording ('Recording...' state)
273
+ * @category Chat
274
+ * @param chatId
275
+ */
276
+ startRecording(to: string, duration?: number): Promise<void>;
277
+ /**
278
+ * Stops recording ('Recording...' state)
279
+ * @category Chat
280
+ * @param chatId
281
+ */
282
+ stopRecoring(to: string): Promise<void>;
246
283
  /**
247
284
  * Update your online presence
248
285
  * @category Chat
@@ -253,7 +290,7 @@ export declare class SenderLayer extends ListenerLayer {
253
290
  * Sends text with tags
254
291
  * @category Chat
255
292
  */
256
- sendMentioned(to: string, message: string, mentioned: string[]): Promise<void>;
293
+ sendMentioned(to: string, message: string, mentioned: string[]): Promise<import("@wppconnect/wa-js/dist/chat").SendMessageReturn>;
257
294
  /**
258
295
  * Sends a list message
259
296
  *
@@ -287,9 +324,11 @@ export declare class SenderLayer extends ListenerLayer {
287
324
  sendListMessage(to: string, options: ListMessageOptions): Promise<void>;
288
325
  /**
289
326
  * Sets the chat state
327
+ * Deprecated in favor of Use startTyping or startRecording functions
290
328
  * @category Chat
291
329
  * @param chatState
292
330
  * @param chatId
331
+ * @deprecated Deprecated in favor of Use startTyping or startRecording functions
293
332
  */
294
333
  setChatState(chatId: string, chatState: ChatState): Promise<void>;
295
334
  }
@@ -30,6 +30,17 @@ var __extends = (this && this.__extends) || (function () {
30
30
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
31
31
  };
32
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
+ };
33
44
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
34
45
  if (k2 === undefined) k2 = k;
35
46
  Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
@@ -130,19 +141,56 @@ var SenderLayer = /** @class */ (function (_super) {
130
141
  * @category Chat
131
142
  * @param to chat id: xxxxx@us.c
132
143
  * @param content text message
144
+ *
145
+ * @example
146
+ * ```javascript
147
+ * // Simple message
148
+ * client.sendText('<number>@c.us', 'A simple message');
149
+ *
150
+ * // With buttons
151
+ * client.sendText('<number>@c.us', 'A simple message with buttons', {
152
+ * buttons: [
153
+ * {
154
+ * id: 'your custom id 1',
155
+ * text: 'Some text'
156
+ * },
157
+ * {
158
+ * id: 'another id 2',
159
+ * text: 'Another text'
160
+ * }
161
+ * ],
162
+ * title: 'Title text' // Optional
163
+ * footer: 'Footer text' // Optional
164
+ * });
165
+ * ```
133
166
  */
134
- SenderLayer.prototype.sendText = function (to, content) {
167
+ SenderLayer.prototype.sendText = function (to, content, options) {
135
168
  return __awaiter(this, void 0, void 0, function () {
136
- var messageId, result;
169
+ var sendResult, result;
170
+ var _this = this;
137
171
  return __generator(this, function (_a) {
138
172
  switch (_a.label) {
139
173
  case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
140
- var to = _a.to, content = _a.content;
141
- return WAPI.sendMessage(to, content);
142
- }, { to: to, content: content })];
174
+ var to = _a.to, content = _a.content, options = _a.options;
175
+ return WPP.chat.sendTextMessage(to, content, __assign(__assign({}, options), { waitForAck: true }));
176
+ }, { to: to, content: content, options: options })];
143
177
  case 1:
144
- messageId = _a.sent();
145
- return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (messageId) { return WAPI.getMessageById(messageId); }, messageId)];
178
+ sendResult = _a.sent();
179
+ return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
180
+ var messageId = _a.messageId;
181
+ return __awaiter(_this, void 0, void 0, function () {
182
+ var _b, _c, _d, _e;
183
+ return __generator(this, function (_f) {
184
+ switch (_f.label) {
185
+ case 0:
186
+ _c = (_b = JSON).parse;
187
+ _e = (_d = JSON).stringify;
188
+ return [4 /*yield*/, WAPI.getMessageById(messageId)];
189
+ case 1: return [2 /*return*/, _c.apply(_b, [_e.apply(_d, [_f.sent()])])];
190
+ }
191
+ });
192
+ });
193
+ }, { messageId: sendResult.id })];
146
194
  case 2:
147
195
  result = (_a.sent());
148
196
  if (result['erro'] == true) {
@@ -308,17 +356,34 @@ var SenderLayer = /** @class */ (function (_super) {
308
356
  */
309
357
  SenderLayer.prototype.sendMessageWithThumb = function (thumb, url, title, description, chatId) {
310
358
  return __awaiter(this, void 0, void 0, function () {
359
+ var base64;
311
360
  return __generator(this, function (_a) {
312
- return [2 /*return*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
313
- var thumb = _a.thumb, url = _a.url, title = _a.title, description = _a.description, chatId = _a.chatId;
314
- WAPI.sendMessageWithThumb(thumb, url, title, description, chatId);
315
- }, {
316
- thumb: thumb,
317
- url: url,
318
- title: title,
319
- description: description,
320
- chatId: chatId,
321
- })];
361
+ switch (_a.label) {
362
+ case 0: return [4 /*yield*/, (0, helpers_1.downloadFileToBase64)(thumb, [
363
+ 'image/gif',
364
+ 'image/png',
365
+ 'image/jpg',
366
+ 'image/jpeg',
367
+ 'image/webp',
368
+ ])];
369
+ case 1:
370
+ base64 = _a.sent();
371
+ if (!!base64) return [3 /*break*/, 3];
372
+ return [4 /*yield*/, (0, helpers_1.fileToBase64)(thumb)];
373
+ case 2:
374
+ base64 = _a.sent();
375
+ _a.label = 3;
376
+ case 3: return [2 /*return*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
377
+ var thumb = _a.thumb, url = _a.url, title = _a.title, description = _a.description, chatId = _a.chatId;
378
+ WAPI.sendMessageWithThumb(thumb, url, title, description, chatId);
379
+ }, {
380
+ base64: base64,
381
+ url: url,
382
+ title: title,
383
+ description: description,
384
+ chatId: chatId,
385
+ })];
386
+ }
322
387
  });
323
388
  });
324
389
  };
@@ -693,7 +758,10 @@ var SenderLayer = /** @class */ (function (_super) {
693
758
  switch (_a.label) {
694
759
  case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
695
760
  var to = _a.to, contactsId = _a.contactsId, name = _a.name;
696
- WPP.chat.sendVCardContactMessage(to, { id: contactsId, name: name });
761
+ return WPP.chat.sendVCardContactMessage(to, {
762
+ id: contactsId,
763
+ name: name,
764
+ });
697
765
  }, { to: to, contactsId: contactsId, name: name })];
698
766
  case 1:
699
767
  result = _a.sent();
@@ -893,7 +961,7 @@ var SenderLayer = /** @class */ (function (_super) {
893
961
  SenderLayer.prototype.sendSeen = function (chatId) {
894
962
  return __awaiter(this, void 0, void 0, function () {
895
963
  return __generator(this, function (_a) {
896
- return [2 /*return*/, (0, helpers_1.evaluateAndReturn)(this.page, function (chatId) { return WAPI.sendSeen(chatId); }, chatId)];
964
+ return [2 /*return*/, (0, helpers_1.evaluateAndReturn)(this.page, function (chatId) { return WPP.chat.markIsRead(chatId); }, chatId)];
897
965
  });
898
966
  });
899
967
  };
@@ -902,14 +970,15 @@ var SenderLayer = /** @class */ (function (_super) {
902
970
  * @category Chat
903
971
  * @param chatId
904
972
  */
905
- SenderLayer.prototype.startTyping = function (to) {
973
+ SenderLayer.prototype.startTyping = function (to, duration) {
906
974
  return __awaiter(this, void 0, void 0, function () {
907
975
  return __generator(this, function (_a) {
908
976
  return [2 /*return*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
909
- var to = _a.to;
910
- return WAPI.startTyping(to);
977
+ var to = _a.to, duration = _a.duration;
978
+ return WPP.chat.markIsComposing(to, duration);
911
979
  }, {
912
980
  to: to,
981
+ duration: duration,
913
982
  })];
914
983
  });
915
984
  });
@@ -924,7 +993,42 @@ var SenderLayer = /** @class */ (function (_super) {
924
993
  return __generator(this, function (_a) {
925
994
  return [2 /*return*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
926
995
  var to = _a.to;
927
- return WAPI.stopTyping(to);
996
+ return WPP.chat.markIsPaused(to);
997
+ }, {
998
+ to: to,
999
+ })];
1000
+ });
1001
+ });
1002
+ };
1003
+ /**
1004
+ * Starts recording ('Recording...' state)
1005
+ * @category Chat
1006
+ * @param chatId
1007
+ */
1008
+ SenderLayer.prototype.startRecording = function (to, duration) {
1009
+ return __awaiter(this, void 0, void 0, function () {
1010
+ return __generator(this, function (_a) {
1011
+ return [2 /*return*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
1012
+ var to = _a.to, duration = _a.duration;
1013
+ return WPP.chat.markIsRecording(to, duration);
1014
+ }, {
1015
+ to: to,
1016
+ duration: duration,
1017
+ })];
1018
+ });
1019
+ });
1020
+ };
1021
+ /**
1022
+ * Stops recording ('Recording...' state)
1023
+ * @category Chat
1024
+ * @param chatId
1025
+ */
1026
+ SenderLayer.prototype.stopRecoring = function (to) {
1027
+ return __awaiter(this, void 0, void 0, function () {
1028
+ return __generator(this, function (_a) {
1029
+ return [2 /*return*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
1030
+ var to = _a.to;
1031
+ return WPP.chat.markIsPaused(to);
928
1032
  }, {
929
1033
  to: to,
930
1034
  })];
@@ -959,7 +1063,10 @@ var SenderLayer = /** @class */ (function (_super) {
959
1063
  switch (_a.label) {
960
1064
  case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
961
1065
  var to = _a.to, message = _a.message, mentioned = _a.mentioned;
962
- WAPI.sendMessageMentioned(to, message, mentioned);
1066
+ return WPP.chat.sendTextMessage(to, message, {
1067
+ detectMentioned: true,
1068
+ mentionedList: mentioned,
1069
+ });
963
1070
  }, { to: to, message: message, mentioned: mentioned })];
964
1071
  case 1: return [2 /*return*/, _a.sent()];
965
1072
  }
@@ -1011,9 +1118,11 @@ var SenderLayer = /** @class */ (function (_super) {
1011
1118
  };
1012
1119
  /**
1013
1120
  * Sets the chat state
1121
+ * Deprecated in favor of Use startTyping or startRecording functions
1014
1122
  * @category Chat
1015
1123
  * @param chatState
1016
1124
  * @param chatId
1125
+ * @deprecated Deprecated in favor of Use startTyping or startRecording functions
1017
1126
  */
1018
1127
  SenderLayer.prototype.setChatState = function (chatId, chatState) {
1019
1128
  return __awaiter(this, void 0, void 0, function () {
@@ -34,7 +34,7 @@ export declare class Whatsapp extends BusinessLayer {
34
34
  * Logout whastapp
35
35
  * @returns boolean
36
36
  */
37
- logout(): Promise<any>;
37
+ logout(): Promise<boolean>;
38
38
  /**
39
39
  * Closes page and browser
40
40
  * @internal
@@ -198,24 +198,22 @@ var Whatsapp = /** @class */ (function (_super) {
198
198
  */
199
199
  Whatsapp.prototype.downloadMedia = function (messageId) {
200
200
  return __awaiter(this, void 0, void 0, function () {
201
- var result;
201
+ var _this = this;
202
202
  return __generator(this, function (_a) {
203
203
  switch (_a.label) {
204
204
  case 0:
205
205
  if (typeof messageId !== 'string') {
206
206
  messageId = messageId.id;
207
207
  }
208
- return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (messageId) {
209
- return WAPI.downloadMedia(messageId).catch(function (e) { return ({
210
- __error: e,
211
- }); });
212
- }, messageId)];
213
- case 1:
214
- result = _a.sent();
215
- if (typeof result == 'object' && '__error' in result) {
216
- throw result.__error;
217
- }
218
- return [2 /*return*/, result];
208
+ return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (messageId) { return __awaiter(_this, void 0, void 0, function () { var _a, _b; return __generator(this, function (_c) {
209
+ switch (_c.label) {
210
+ case 0:
211
+ _b = (_a = WPP.util).blobToBase64;
212
+ return [4 /*yield*/, WPP.chat.downloadMedia(messageId)];
213
+ case 1: return [2 /*return*/, _b.apply(_a, [_c.sent()])];
214
+ }
215
+ }); }); }, messageId)];
216
+ case 1: return [2 /*return*/, _a.sent()];
219
217
  }
220
218
  });
221
219
  });
@@ -233,8 +233,9 @@ function injectApi(page) {
233
233
  _a.sent();
234
234
  return [4 /*yield*/, page
235
235
  .waitForFunction(function () {
236
- // @ts-ignore
237
236
  return typeof window.WPP !== 'undefined' && window.WPP.isReady;
237
+ }, {
238
+ timeout: 60000,
238
239
  })
239
240
  .catch(function () { return false; })];
240
241
  case 3:
@@ -253,7 +254,6 @@ function injectApi(page) {
253
254
  _a.sent();
254
255
  return [4 /*yield*/, page
255
256
  .waitForFunction(function () {
256
- // @ts-ignore
257
257
  return (typeof window.WAPI !== 'undefined' &&
258
258
  typeof window.Store !== 'undefined');
259
259
  })