@wppconnect-team/wppconnect 1.10.0 → 1.11.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,34 @@
1
+ # 1.11.0 (2021-12-09)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * Fixed initialization of onPresenceChanged (fix [#704](https://github.com/wppconnect-team/wppconnect/issues/704)) ([0470ea8](https://github.com/wppconnect-team/wppconnect/commit/0470ea8a0fd15727f91e18c913b96f3c1e1f79a9))
7
+
8
+
9
+
10
+ ## 1.10.3 (2021-11-18)
11
+
12
+
13
+
14
+ ## 1.10.2 (2021-11-15)
15
+
16
+
17
+ ### Bug Fixes
18
+
19
+ * Fixed call of createWid function (fix [#647](https://github.com/wppconnect-team/wppconnect/issues/647)) ([c381000](https://github.com/wppconnect-team/wppconnect/commit/c3810003a4f145f9c3ec54f49cde97ddbe01a164))
20
+
21
+
22
+
23
+ ## 1.10.1 (2021-11-11)
24
+
25
+
26
+ ### Features
27
+
28
+ * Updated to latest version of WhatsApp ([f6d01a3](https://github.com/wppconnect-team/wppconnect/commit/f6d01a390db9577f46fee0072637ece981e54780))
29
+
30
+
31
+
1
32
  # 1.10.0 (2021-11-06)
2
33
 
3
34
 
@@ -76,7 +76,7 @@ var magix = function (fileData, mediaKeyBase64, mediaType, expectedSize) {
76
76
  var encodedHex = fileData.toString('hex');
77
77
  var encodedBytes = hexToBytes(encodedHex);
78
78
  var mediaKeyBytes = base64ToBytes(mediaKeyBase64);
79
- var info = "WhatsApp " + exports.mediaTypes[mediaType.toUpperCase()] + " Keys";
79
+ var info = "WhatsApp ".concat(exports.mediaTypes[mediaType.toUpperCase()], " Keys");
80
80
  var hash = 'sha256';
81
81
  var salt = new Uint8Array(32);
82
82
  var expandedSize = 112;
@@ -65,7 +65,7 @@ function downloadFileToBase64(_path, _mines) {
65
65
  switch (_a.label) {
66
66
  case 0:
67
67
  if (!Array.isArray(_mines)) {
68
- console.error("set mines string array, not \"" + typeof _mines + "\" ");
68
+ console.error("set mines string array, not \"".concat(typeof _mines, "\" "));
69
69
  return [2 /*return*/, false];
70
70
  }
71
71
  reHttp = /^https?:/;
@@ -89,12 +89,12 @@ function downloadFileToBase64(_path, _mines) {
89
89
  return m.exec(mimeType_1);
90
90
  });
91
91
  if (!isValidMime) {
92
- console.error("Content-Type \"" + mimeType_1 + "\" of " + _path + " is not allowed");
92
+ console.error("Content-Type \"".concat(mimeType_1, "\" of ").concat(_path, " is not allowed"));
93
93
  return [2 /*return*/, false];
94
94
  }
95
95
  }
96
96
  content = Buffer.from(response.data, 'binary').toString('base64');
97
- return [2 /*return*/, "data:" + mimeType_1 + ";base64," + content];
97
+ return [2 /*return*/, "data:".concat(mimeType_1, ";base64,").concat(content)];
98
98
  case 3:
99
99
  error_1 = _a.sent();
100
100
  return [3 /*break*/, 4];
@@ -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 (" + 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());
@@ -101,7 +101,7 @@ function fileToBase64(path, mime) {
101
101
  if (!mime) {
102
102
  mime = 'application/octet-stream';
103
103
  }
104
- data = "data:" + mime + ";base64," + base64;
104
+ data = "data:".concat(mime, ";base64,").concat(base64);
105
105
  return [2 /*return*/, data];
106
106
  case 3: return [2 /*return*/, false];
107
107
  }
@@ -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; } });
@@ -87,7 +87,7 @@ function stickerSelect(_B, _t) {
87
87
  case 6:
88
88
  metadata = _c.sent();
89
89
  if (metadata.width > 512 || metadata.pageHeight > 512) {
90
- console.error("Invalid image size (max 512x512):" + metadata.width + "x" + metadata.pageHeight);
90
+ console.error("Invalid image size (max 512x512):".concat(metadata.width, "x").concat(metadata.pageHeight));
91
91
  return [2 /*return*/, false];
92
92
  }
93
93
  _b = {};
@@ -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
  };
@@ -51,7 +51,15 @@ export declare class GroupLayer extends RetrieverLayer {
51
51
  * @param groupName Group name
52
52
  * @param contacts Contacts that should be added.
53
53
  */
54
- createGroup(groupName: string, contacts: string | string[]): Promise<import("../model").GroupCreation>;
54
+ createGroup(groupName: string, contacts: string | string[]): Promise<{
55
+ gid: import("@wppconnect/wa-js/dist/whatsapp").Wid;
56
+ participants: {
57
+ [key: string]: {
58
+ code: string;
59
+ };
60
+ }[];
61
+ status: number;
62
+ }>;
55
63
  /**
56
64
  * Removes participant from group
57
65
  * @category Group
@@ -188,7 +188,7 @@ var GroupLayer = /** @class */ (function (_super) {
188
188
  switch (_a.label) {
189
189
  case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
190
190
  var groupName = _a.groupName, contacts = _a.contacts;
191
- return WAPI.createGroup(groupName, contacts);
191
+ return WPP.group.create(groupName, contacts);
192
192
  }, { groupName: groupName, contacts: contacts })];
193
193
  case 1: return [2 /*return*/, _a.sent()];
194
194
  }
@@ -171,7 +171,7 @@ var HostLayer = /** @class */ (function () {
171
171
  _this.log('verbose', 'wapi.js injected');
172
172
  _this.getWAVersion()
173
173
  .then(function (version) {
174
- _this.log('info', "WhatsApp WEB version: " + version);
174
+ _this.log('info', "WhatsApp WEB version: ".concat(version));
175
175
  })
176
176
  .catch(function () { return null; });
177
177
  })
@@ -205,7 +205,7 @@ var HostLayer = /** @class */ (function () {
205
205
  var _this = this;
206
206
  if (this.options.autoClose > 0 && !this.autoCloseInterval) {
207
207
  var seconds = Math.round(this.options.autoClose / 1000);
208
- this.log('info', "Auto close configured to " + seconds + "s");
208
+ this.log('info', "Auto close configured to ".concat(seconds, "s"));
209
209
  var remain_1 = seconds;
210
210
  this.autoCloseInterval = setInterval(function () {
211
211
  if (_this.page.isClosed()) {
@@ -214,7 +214,7 @@ var HostLayer = /** @class */ (function () {
214
214
  }
215
215
  remain_1 -= 1;
216
216
  if (remain_1 % 10 === 0 || remain_1 <= 5) {
217
- _this.log('http', "Auto close remain: " + remain_1 + "s");
217
+ _this.log('http', "Auto close remain: ".concat(remain_1, "s"));
218
218
  }
219
219
  if (remain_1 <= 0) {
220
220
  _this.tryAutoClose();
@@ -270,10 +270,10 @@ var HostLayer = /** @class */ (function () {
270
270
  _a.label = 5;
271
271
  case 5:
272
272
  if (this.options.logQR) {
273
- this.log('info', "Waiting for QRCode Scan (Attempt " + attempt + ")...:\n" + qr, { code: urlCode });
273
+ this.log('info', "Waiting for QRCode Scan (Attempt ".concat(attempt, ")...:\n").concat(qr), { code: urlCode });
274
274
  }
275
275
  else {
276
- this.log('verbose', "Waiting for QRCode Scan: Attempt " + attempt);
276
+ this.log('verbose', "Waiting for QRCode Scan: Attempt ".concat(attempt));
277
277
  }
278
278
  if (catchQR) {
279
279
  catchQR(result.base64Image, qr, attempt, result.urlCode);
@@ -510,7 +510,7 @@ var HostLayer = /** @class */ (function () {
510
510
  switch (_a.label) {
511
511
  case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function () {
512
512
  //@ts-ignore
513
- return Store.State.default.state;
513
+ return WPP.whatsapp.State.state;
514
514
  })];
515
515
  case 1: return [2 /*return*/, _a.sent()];
516
516
  }
@@ -89,7 +89,7 @@ var ListenerLayer = /** @class */ (function (_super) {
89
89
  _this.page = page;
90
90
  _this.listenerEmitter = new events_1.EventEmitter();
91
91
  _this.listenerEmitter.on(exposed_enum_1.ExposedFn.onInterfaceChange, function (state) {
92
- _this.log('http', "Current state: " + state.mode + " (" + state.displayInfo + ")");
92
+ _this.log('http', "Current state: ".concat(state.mode, " (").concat(state.displayInfo, ")"));
93
93
  });
94
94
  return _this;
95
95
  }
@@ -117,7 +117,7 @@ var ListenerLayer = /** @class */ (function (_super) {
117
117
  case 1:
118
118
  has = _b.sent();
119
119
  if (!!has) return [3 /*break*/, 3];
120
- this_1.log('debug', "Exposing " + func + " function");
120
+ this_1.log('debug', "Exposing ".concat(func, " function"));
121
121
  return [4 /*yield*/, this_1.page
122
122
  .exposeFunction(func, function () {
123
123
  var _a;
@@ -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
@@ -162,7 +162,9 @@ var RetrieverLayer = /** @class */ (function (_super) {
162
162
  return __awaiter(this, void 0, void 0, function () {
163
163
  return __generator(this, function (_a) {
164
164
  switch (_a.label) {
165
- case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function () { return WAPI.getBlockList(); })];
165
+ case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function () {
166
+ return WPP.blocklist.all().map(function (b) { return b.toString(); });
167
+ })];
166
168
  case 1: return [2 /*return*/, _a.sent()];
167
169
  }
168
170
  });
@@ -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 | string[], name?: string): Promise<object>;
206
+ sendContactVcard(to: string, contactsId: string, name?: string): Promise<void>;
185
207
  /**
186
208
  * Send a list of contact cards
187
209
  * @category Chat
@@ -191,7 +213,7 @@ export declare class SenderLayer extends ListenerLayer {
191
213
  sendContactVcardList(to: string, contacts: (string | {
192
214
  id: string;
193
215
  name: string;
194
- })[]): Promise<object>;
216
+ })[]): Promise<import("@wppconnect/wa-js/dist/chat").SendMessageReturn>;
195
217
  /**
196
218
  * Forwards array of messages (could be ids or message objects)
197
219
  * @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
@@ -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) {
@@ -693,13 +741,10 @@ var SenderLayer = /** @class */ (function (_super) {
693
741
  switch (_a.label) {
694
742
  case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
695
743
  var to = _a.to, contactsId = _a.contactsId, name = _a.name;
696
- return WAPI.sendContactVcard(to, contactsId, name);
744
+ WPP.chat.sendVCardContactMessage(to, { id: contactsId, name: name });
697
745
  }, { to: to, contactsId: contactsId, name: name })];
698
746
  case 1:
699
747
  result = _a.sent();
700
- if (result['erro'] == true) {
701
- throw result;
702
- }
703
748
  return [2 /*return*/, result];
704
749
  }
705
750
  });
@@ -718,13 +763,10 @@ var SenderLayer = /** @class */ (function (_super) {
718
763
  switch (_a.label) {
719
764
  case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
720
765
  var to = _a.to, contacts = _a.contacts;
721
- return WAPI.sendContactVcardList(to, contacts);
766
+ return WPP.chat.sendVCardContactMessage(to, contacts);
722
767
  }, { to: to, contacts: contacts })];
723
768
  case 1:
724
769
  result = _a.sent();
725
- if (result['erro'] == true) {
726
- throw result;
727
- }
728
770
  return [2 /*return*/, result];
729
771
  }
730
772
  });
@@ -899,7 +941,7 @@ var SenderLayer = /** @class */ (function (_super) {
899
941
  SenderLayer.prototype.sendSeen = function (chatId) {
900
942
  return __awaiter(this, void 0, void 0, function () {
901
943
  return __generator(this, function (_a) {
902
- return [2 /*return*/, (0, helpers_1.evaluateAndReturn)(this.page, function (chatId) { return WAPI.sendSeen(chatId); }, chatId)];
944
+ return [2 /*return*/, (0, helpers_1.evaluateAndReturn)(this.page, function (chatId) { return WPP.chat.markIsRead(chatId); }, chatId)];
903
945
  });
904
946
  });
905
947
  };
@@ -908,14 +950,15 @@ var SenderLayer = /** @class */ (function (_super) {
908
950
  * @category Chat
909
951
  * @param chatId
910
952
  */
911
- SenderLayer.prototype.startTyping = function (to) {
953
+ SenderLayer.prototype.startTyping = function (to, duration) {
912
954
  return __awaiter(this, void 0, void 0, function () {
913
955
  return __generator(this, function (_a) {
914
956
  return [2 /*return*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
915
- var to = _a.to;
916
- return WAPI.startTyping(to);
957
+ var to = _a.to, duration = _a.duration;
958
+ return WPP.chat.markIsComposing(to, duration);
917
959
  }, {
918
960
  to: to,
961
+ duration: duration,
919
962
  })];
920
963
  });
921
964
  });
@@ -930,7 +973,42 @@ var SenderLayer = /** @class */ (function (_super) {
930
973
  return __generator(this, function (_a) {
931
974
  return [2 /*return*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
932
975
  var to = _a.to;
933
- return WAPI.stopTyping(to);
976
+ return WPP.chat.markIsPaused(to);
977
+ }, {
978
+ to: to,
979
+ })];
980
+ });
981
+ });
982
+ };
983
+ /**
984
+ * Starts recording ('Recording...' state)
985
+ * @category Chat
986
+ * @param chatId
987
+ */
988
+ SenderLayer.prototype.startRecording = function (to, duration) {
989
+ return __awaiter(this, void 0, void 0, function () {
990
+ return __generator(this, function (_a) {
991
+ return [2 /*return*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
992
+ var to = _a.to, duration = _a.duration;
993
+ return WPP.chat.markIsRecording(to, duration);
994
+ }, {
995
+ to: to,
996
+ duration: duration,
997
+ })];
998
+ });
999
+ });
1000
+ };
1001
+ /**
1002
+ * Stops recording ('Recording...' state)
1003
+ * @category Chat
1004
+ * @param chatId
1005
+ */
1006
+ SenderLayer.prototype.stopRecoring = function (to) {
1007
+ return __awaiter(this, void 0, void 0, function () {
1008
+ return __generator(this, function (_a) {
1009
+ return [2 /*return*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
1010
+ var to = _a.to;
1011
+ return WPP.chat.markIsPaused(to);
934
1012
  }, {
935
1013
  to: to,
936
1014
  })];
@@ -1017,9 +1095,11 @@ var SenderLayer = /** @class */ (function (_super) {
1017
1095
  };
1018
1096
  /**
1019
1097
  * Sets the chat state
1098
+ * Deprecated in favor of Use startTyping or startRecording functions
1020
1099
  * @category Chat
1021
1100
  * @param chatState
1022
1101
  * @param chatId
1102
+ * @deprecated Deprecated in favor of Use startTyping or startRecording functions
1023
1103
  */
1024
1104
  SenderLayer.prototype.setChatState = function (chatId, chatState) {
1025
1105
  return __awaiter(this, void 0, void 0, function () {
@@ -109,6 +109,6 @@ export interface CreateConfig {
109
109
  * Define the connected device name in WhatsApp app
110
110
  * @default 'WPPConnect'
111
111
  */
112
- deviceName?: string;
112
+ deviceName?: string | false;
113
113
  }
114
114
  export declare const defaultOptions: CreateConfig;
@@ -19,6 +19,6 @@ exports.defaultOptions = {
19
19
  waitForLogin: true,
20
20
  logger: logger_1.defaultLogger,
21
21
  tokenStore: 'file',
22
- whatsappVersion: '2.2138.x',
23
- deviceName: 'WPPConnect',
22
+ whatsappVersion: '2.2144.x',
23
+ deviceName: false,
24
24
  };
@@ -235,14 +235,23 @@ function injectApi(page) {
235
235
  .waitForFunction(function () {
236
236
  // @ts-ignore
237
237
  return typeof window.WPP !== 'undefined' && window.WPP.isReady;
238
+ }, {
239
+ timeout: 60000,
238
240
  })
239
241
  .catch(function () { return false; })];
240
242
  case 3:
243
+ _a.sent();
244
+ return [4 /*yield*/, page
245
+ .evaluate(function () {
246
+ WPP.chat.defaultSendMessageOptions.createChat = true;
247
+ })
248
+ .catch(function () { return false; })];
249
+ case 4:
241
250
  _a.sent();
242
251
  return [4 /*yield*/, page.addScriptTag({
243
252
  path: require.resolve(path.join(__dirname, '../../dist/lib/wapi', 'wapi.js')),
244
253
  })];
245
- case 4:
254
+ case 5:
246
255
  _a.sent();
247
256
  return [4 /*yield*/, page
248
257
  .waitForFunction(function () {
@@ -251,7 +260,7 @@ function injectApi(page) {
251
260
  typeof window.Store !== 'undefined');
252
261
  })
253
262
  .catch(function () { return false; })];
254
- case 5:
263
+ case 6:
255
264
  // Make sure WAPI is initialized
256
265
  return [2 /*return*/, _a.sent()];
257
266
  }
@@ -124,7 +124,7 @@ function create(sessionOrOption, catchQR, statusFind, options, browserSessionTok
124
124
  logger.info('Initializing browser...', { session: session, type: 'browser' });
125
125
  return [4 /*yield*/, (0, browser_1.initBrowser)(session, mergedOptions, logger).catch(function (e) {
126
126
  if (mergedOptions.browserWS && mergedOptions.browserWS != '') {
127
- logger.error("Error when try to connect " + mergedOptions.browserWS, {
127
+ logger.error("Error when try to connect ".concat(mergedOptions.browserWS), {
128
128
  session: session,
129
129
  type: 'browser',
130
130
  });