@wppconnect-team/wppconnect 1.9.0 → 1.9.4

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.9.4 (2021-10-21)
2
+
3
+
4
+
5
+ ## 1.9.3 (2021-10-21)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * Fixed close method ([#579](https://github.com/wppconnect-team/wppconnect/issues/579)) ([ef42485](https://github.com/wppconnect-team/wppconnect/commit/ef42485505e9920b5b7826674949ed9d5e36d4e1))
11
+
12
+
13
+
14
+ ## 1.9.2 (2021-10-12)
15
+
16
+
17
+ ### Features
18
+
19
+ * Added onRevokedMessage (close [#434](https://github.com/wppconnect-team/wppconnect/issues/434)) ([b5df5bb](https://github.com/wppconnect-team/wppconnect/commit/b5df5bbcc3418204744057cf45089c3bb2228c57))
20
+
21
+
22
+
23
+ ## 1.9.1 (2021-10-02)
24
+
25
+
26
+ ### Features
27
+
28
+ * Added option to use setProfilePic using base64 (close [#505](https://github.com/wppconnect-team/wppconnect/issues/505)) ([87f1841](https://github.com/wppconnect-team/wppconnect/commit/87f184128c2b458f128ff26ac9ea081537b4c2a4))
29
+
30
+
31
+
1
32
  # 1.9.0 (2021-10-02)
2
33
 
3
34
 
@@ -56,7 +56,7 @@ export declare class ControlsLayer extends UILayer {
56
56
  * @param keepStarred Keep starred messages
57
57
  * @returns boolean
58
58
  */
59
- clearChat(chatId: string, keepStarred?: boolean): Promise<void>;
59
+ clearChat(chatId: string, keepStarred?: boolean): Promise<boolean>;
60
60
  /**
61
61
  * Deletes message of given message id
62
62
  * @category Chat
@@ -86,7 +86,12 @@ var ControlsLayer = /** @class */ (function (_super) {
86
86
  ControlsLayer.prototype.unblockContact = function (contactId) {
87
87
  return __awaiter(this, void 0, void 0, function () {
88
88
  return __generator(this, function (_a) {
89
- return [2 /*return*/, (0, helpers_1.evaluateAndReturn)(this.page, function (contactId) { return WAPI.unblockContact(contactId); }, contactId)];
89
+ switch (_a.label) {
90
+ case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (contactId) { return WPP.blocklist.unblockContact(contactId); }, contactId)];
91
+ case 1:
92
+ _a.sent();
93
+ return [2 /*return*/, true];
94
+ }
90
95
  });
91
96
  });
92
97
  };
@@ -99,7 +104,12 @@ var ControlsLayer = /** @class */ (function (_super) {
99
104
  ControlsLayer.prototype.blockContact = function (contactId) {
100
105
  return __awaiter(this, void 0, void 0, function () {
101
106
  return __generator(this, function (_a) {
102
- return [2 /*return*/, (0, helpers_1.evaluateAndReturn)(this.page, function (contactId) { return WAPI.blockContact(contactId); }, contactId)];
107
+ switch (_a.label) {
108
+ case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (contactId) { return WPP.blocklist.blockContact(contactId); }, contactId)];
109
+ case 1:
110
+ _a.sent();
111
+ return [2 /*return*/, true];
112
+ }
103
113
  });
104
114
  });
105
115
  };
@@ -124,8 +134,14 @@ var ControlsLayer = /** @class */ (function (_super) {
124
134
  */
125
135
  ControlsLayer.prototype.deleteChat = function (chatId) {
126
136
  return __awaiter(this, void 0, void 0, function () {
137
+ var result;
127
138
  return __generator(this, function (_a) {
128
- return [2 /*return*/, (0, helpers_1.evaluateAndReturn)(this.page, function (chatId) { return WAPI.deleteConversation(chatId); }, chatId)];
139
+ switch (_a.label) {
140
+ case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (chatId) { return WPP.chat.delete(chatId); }, chatId)];
141
+ case 1:
142
+ result = _a.sent();
143
+ return [2 /*return*/, result.status === 200];
144
+ }
129
145
  });
130
146
  });
131
147
  };
@@ -184,13 +200,16 @@ var ControlsLayer = /** @class */ (function (_super) {
184
200
  ControlsLayer.prototype.clearChat = function (chatId, keepStarred) {
185
201
  if (keepStarred === void 0) { keepStarred = true; }
186
202
  return __awaiter(this, void 0, void 0, function () {
203
+ var result;
187
204
  return __generator(this, function (_a) {
188
205
  switch (_a.label) {
189
206
  case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
190
207
  var chatId = _a.chatId, keepStarred = _a.keepStarred;
191
- return WAPI.clearChat(chatId, keepStarred);
208
+ return WPP.chat.clear(chatId, keepStarred);
192
209
  }, { chatId: chatId, keepStarred: keepStarred })];
193
- case 1: return [2 /*return*/, _a.sent()];
210
+ case 1:
211
+ result = _a.sent();
212
+ return [2 /*return*/, result.status === 200];
194
213
  }
195
214
  });
196
215
  });
@@ -84,4 +84,9 @@ export declare class HostLayer {
84
84
  * @category Host
85
85
  */
86
86
  stopPhoneWatchdog(interval: number): Promise<void>;
87
+ /**
88
+ * Check the current session is an MultiDevice session
89
+ * @category Host
90
+ */
91
+ isMultiDevice(): Promise<boolean>;
87
92
  }
@@ -590,6 +590,20 @@ var HostLayer = /** @class */ (function () {
590
590
  });
591
591
  });
592
592
  };
593
+ /**
594
+ * Check the current session is an MultiDevice session
595
+ * @category Host
596
+ */
597
+ HostLayer.prototype.isMultiDevice = function () {
598
+ return __awaiter(this, void 0, void 0, function () {
599
+ return __generator(this, function (_a) {
600
+ switch (_a.label) {
601
+ case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function () { return WPP.auth.isMultiDevice(); })];
602
+ case 1: return [2 /*return*/, _a.sent()];
603
+ }
604
+ });
605
+ });
606
+ };
593
607
  return HostLayer;
594
608
  }());
595
609
  exports.HostLayer = HostLayer;
@@ -184,4 +184,17 @@ export declare class ListenerLayer extends ProfileLayer {
184
184
  * @returns number of unsubscribed
185
185
  */
186
186
  unsubscribePresence(id: string | string[]): Promise<number>;
187
+ /**
188
+ * @event Listens to revoked messages
189
+ * @returns Disposable object to stop the listening
190
+ */
191
+ onRevokedMessage(callback: (data: {
192
+ author?: string;
193
+ from: string;
194
+ to: string;
195
+ id: string;
196
+ refId: String;
197
+ }) => any): {
198
+ dispose: () => void;
199
+ };
187
200
  }
@@ -105,6 +105,7 @@ var ListenerLayer = /** @class */ (function (_super) {
105
105
  functions = __spreadArray(__spreadArray([], Object.values(exposed_enum_1.ExposedFn), true), [
106
106
  'onAddedToGroup',
107
107
  'onIncomingCall',
108
+ 'onRevokedMessage',
108
109
  ], false);
109
110
  _loop_1 = function (func) {
110
111
  var has;
@@ -197,6 +198,20 @@ var ListenerLayer = /** @class */ (function (_super) {
197
198
  window.WAPI.onLiveLocation(window['onLiveLocation']);
198
199
  window['onLiveLocation'].exposed = true;
199
200
  }
201
+ if (!window['onRevokedMessage'].exposed) {
202
+ // @ts-ignore
203
+ WPP.chat.on('msg_revoke', function (data) {
204
+ var eventData = {
205
+ author: data.author,
206
+ from: data.from,
207
+ to: data.to,
208
+ id: data.id._serialized,
209
+ refId: data.refId._serialized,
210
+ };
211
+ window['onRevokedMessage'](eventData);
212
+ });
213
+ window['onRevokedMessage'].exposed = true;
214
+ }
200
215
  })
201
216
  .catch(function () { })];
202
217
  case 6:
@@ -400,6 +415,13 @@ var ListenerLayer = /** @class */ (function (_super) {
400
415
  });
401
416
  });
402
417
  };
418
+ /**
419
+ * @event Listens to revoked messages
420
+ * @returns Disposable object to stop the listening
421
+ */
422
+ ListenerLayer.prototype.onRevokedMessage = function (callback) {
423
+ return this.registerEvent('onRevokedMessage', callback);
424
+ };
403
425
  return ListenerLayer;
404
426
  }(profile_layer_1.ProfileLayer));
405
427
  exports.ListenerLayer = ListenerLayer;
@@ -29,7 +29,7 @@ export declare class ProfileLayer extends HostLayer {
29
29
  * @category Profile
30
30
  * @param name
31
31
  */
32
- setProfilePic(path: string, to?: string): Promise<boolean>;
32
+ setProfilePic(pathOrBase64: string, to?: string): Promise<boolean>;
33
33
  /**
34
34
  * Sets current user profile name
35
35
  * @category Profile
@@ -131,35 +131,57 @@ var ProfileLayer = /** @class */ (function (_super) {
131
131
  * @category Profile
132
132
  * @param name
133
133
  */
134
- ProfileLayer.prototype.setProfilePic = function (path, to) {
134
+ ProfileLayer.prototype.setProfilePic = function (pathOrBase64, to) {
135
135
  return __awaiter(this, void 0, void 0, function () {
136
- var b64, buff, mimeInfo, _webb64_96, _webb64_640, obj;
136
+ var base64, fileContent, error, mimeInfo, error, buff, _webb64_96, _webb64_640, obj;
137
137
  return __generator(this, function (_a) {
138
138
  switch (_a.label) {
139
- case 0: return [4 /*yield*/, (0, helpers_1.downloadFileToBase64)(path, [
139
+ case 0:
140
+ base64 = '';
141
+ if (!pathOrBase64.startsWith('data:')) return [3 /*break*/, 1];
142
+ base64 = pathOrBase64;
143
+ return [3 /*break*/, 5];
144
+ case 1: return [4 /*yield*/, (0, helpers_1.downloadFileToBase64)(pathOrBase64, [
140
145
  'image/gif',
141
146
  'image/png',
142
147
  'image/jpg',
143
148
  'image/jpeg',
144
149
  'image/webp',
145
150
  ])];
146
- case 1:
147
- b64 = _a.sent();
148
- if (!!b64) return [3 /*break*/, 3];
149
- return [4 /*yield*/, (0, helpers_1.fileToBase64)(path)];
150
151
  case 2:
151
- b64 = _a.sent();
152
- _a.label = 3;
152
+ fileContent = _a.sent();
153
+ if (!!fileContent) return [3 /*break*/, 4];
154
+ return [4 /*yield*/, (0, helpers_1.fileToBase64)(pathOrBase64)];
153
155
  case 3:
154
- if (!b64) return [3 /*break*/, 8];
155
- buff = Buffer.from(b64.replace(/^data:image\/(png|jpe?g|webp);base64,/, ''), 'base64');
156
- mimeInfo = (0, helpers_1.base64MimeType)(b64);
157
- if (!(!mimeInfo || mimeInfo.includes('image'))) return [3 /*break*/, 7];
158
- return [4 /*yield*/, (0, helpers_1.resizeImg)(buff, { width: 96, height: 96 })];
156
+ fileContent = _a.sent();
157
+ _a.label = 4;
159
158
  case 4:
159
+ if (fileContent) {
160
+ base64 = fileContent;
161
+ }
162
+ _a.label = 5;
163
+ case 5:
164
+ if (!base64) {
165
+ error = new Error('Empty or invalid file or base64');
166
+ Object.assign(error, {
167
+ code: 'empty_file',
168
+ });
169
+ throw error;
170
+ }
171
+ mimeInfo = (0, helpers_1.base64MimeType)(base64);
172
+ if (!mimeInfo || !mimeInfo.includes('image')) {
173
+ error = new Error('Not an image, allowed formats png, jpeg and webp');
174
+ Object.assign(error, {
175
+ code: 'invalid_image',
176
+ });
177
+ throw error;
178
+ }
179
+ buff = Buffer.from(base64.replace(/^data:image\/(png|jpe?g|webp);base64,/, ''), 'base64');
180
+ return [4 /*yield*/, (0, helpers_1.resizeImg)(buff, { width: 96, height: 96 })];
181
+ case 6:
160
182
  _webb64_96 = _a.sent();
161
183
  return [4 /*yield*/, (0, helpers_1.resizeImg)(buff, { width: 640, height: 640 })];
162
- case 5:
184
+ case 7:
163
185
  _webb64_640 = _a.sent();
164
186
  obj = { a: _webb64_640, b: _webb64_96 };
165
187
  return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
@@ -169,11 +191,7 @@ var ProfileLayer = /** @class */ (function (_super) {
169
191
  obj: obj,
170
192
  to: to,
171
193
  })];
172
- case 6: return [2 /*return*/, _a.sent()];
173
- case 7:
174
- console.log('Not an image, allowed formats png, jpeg and webp');
175
- return [2 /*return*/, false];
176
- case 8: return [2 /*return*/];
194
+ case 8: return [2 /*return*/, _a.sent()];
177
195
  }
178
196
  });
179
197
  });
@@ -1,3 +1,4 @@
1
+ import { ListMessageOptions } from '@wppconnect/wa-js/dist/chat';
1
2
  import { Page } from 'puppeteer';
2
3
  import { CreateConfig } from '../../config/create-config';
3
4
  import { Message, SendFileResult, SendLinkResult, SendStickerResult } from '../model';
@@ -225,6 +226,37 @@ export declare class SenderLayer extends ListenerLayer {
225
226
  * @category Chat
226
227
  */
227
228
  sendMentioned(to: string, message: string, mentioned: string[]): Promise<void>;
229
+ /**
230
+ * Sends a list message
231
+ *
232
+ * ```typescript
233
+ * // Example
234
+ * client.sendListMessage('<number>@c.us', {
235
+ * buttonText: 'Click here',
236
+ * description: 'Choose one option',
237
+ * sections: [
238
+ * {
239
+ * title: 'Section 1',
240
+ * rows: [
241
+ * {
242
+ * rowId: 'my_custom_id',
243
+ * title: 'Test 1',
244
+ * description: 'Description 1',
245
+ * },
246
+ * {
247
+ * rowId: '2',
248
+ * title: 'Test 2',
249
+ * description: 'Description 2',
250
+ * },
251
+ * ],
252
+ * },
253
+ * ],
254
+ * });
255
+ * ```
256
+ *
257
+ * @category Chat
258
+ */
259
+ sendListMessage(to: string, options: ListMessageOptions): Promise<void>;
228
260
  /**
229
261
  * Sets the chat state
230
262
  * @category Chat
@@ -891,6 +891,49 @@ var SenderLayer = /** @class */ (function (_super) {
891
891
  });
892
892
  });
893
893
  };
894
+ /**
895
+ * Sends a list message
896
+ *
897
+ * ```typescript
898
+ * // Example
899
+ * client.sendListMessage('<number>@c.us', {
900
+ * buttonText: 'Click here',
901
+ * description: 'Choose one option',
902
+ * sections: [
903
+ * {
904
+ * title: 'Section 1',
905
+ * rows: [
906
+ * {
907
+ * rowId: 'my_custom_id',
908
+ * title: 'Test 1',
909
+ * description: 'Description 1',
910
+ * },
911
+ * {
912
+ * rowId: '2',
913
+ * title: 'Test 2',
914
+ * description: 'Description 2',
915
+ * },
916
+ * ],
917
+ * },
918
+ * ],
919
+ * });
920
+ * ```
921
+ *
922
+ * @category Chat
923
+ */
924
+ SenderLayer.prototype.sendListMessage = function (to, options) {
925
+ return __awaiter(this, void 0, void 0, function () {
926
+ return __generator(this, function (_a) {
927
+ switch (_a.label) {
928
+ case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
929
+ var to = _a.to, options = _a.options;
930
+ WPP.chat.sendListMessage(to, options);
931
+ }, { to: to, options: options })];
932
+ case 1: return [2 /*return*/, _a.sent()];
933
+ }
934
+ });
935
+ });
936
+ };
894
937
  /**
895
938
  * Sets the chat state
896
939
  * @category Chat
@@ -34,7 +34,7 @@ export declare class Whatsapp extends BusinessLayer {
34
34
  * Logout whastapp
35
35
  * @returns boolean
36
36
  */
37
- logout(): Promise<boolean>;
37
+ logout(): Promise<any>;
38
38
  /**
39
39
  * Closes page and browser
40
40
  * @internal
@@ -255,7 +255,7 @@ var Whatsapp = /** @class */ (function (_super) {
255
255
  return __awaiter(this, void 0, void 0, function () {
256
256
  return __generator(this, function (_a) {
257
257
  switch (_a.label) {
258
- case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function () { return WAPI.logout(); })];
258
+ case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function () { return WPP.auth.logout(); })];
259
259
  case 1: return [2 /*return*/, _a.sent()];
260
260
  }
261
261
  });
@@ -267,51 +267,27 @@ var Whatsapp = /** @class */ (function (_super) {
267
267
  */
268
268
  Whatsapp.prototype.close = function () {
269
269
  return __awaiter(this, void 0, void 0, function () {
270
- var closing, error_1;
271
- var _this = this;
270
+ var browser, process_1;
272
271
  return __generator(this, function (_a) {
273
272
  switch (_a.label) {
274
273
  case 0:
275
- closing = function (waPage) { return __awaiter(_this, void 0, void 0, function () {
276
- var browser, pid;
277
- return __generator(this, function (_a) {
278
- switch (_a.label) {
279
- case 0:
280
- if (!waPage) return [3 /*break*/, 6];
281
- return [4 /*yield*/, waPage.browser()];
282
- case 1:
283
- browser = _a.sent();
284
- pid = browser.process() ? browser === null || browser === void 0 ? void 0 : browser.process().pid : null;
285
- if (!!waPage.isClosed()) return [3 /*break*/, 3];
286
- return [4 /*yield*/, waPage.close()];
287
- case 2:
288
- _a.sent();
289
- _a.label = 3;
290
- case 3:
291
- if (!browser) return [3 /*break*/, 5];
292
- return [4 /*yield*/, browser.close()];
293
- case 4:
294
- _a.sent();
295
- _a.label = 5;
296
- case 5:
297
- if (pid)
298
- treekill(pid, 'SIGKILL');
299
- _a.label = 6;
300
- case 6: return [2 /*return*/];
301
- }
302
- });
303
- }); };
304
- _a.label = 1;
274
+ browser = this.page.browser();
275
+ if (!!this.page.isClosed()) return [3 /*break*/, 2];
276
+ return [4 /*yield*/, this.page.close().catch(function () { return null; })];
305
277
  case 1:
306
- _a.trys.push([1, 3, , 4]);
307
- return [4 /*yield*/, closing(this.page)];
308
- case 2:
309
278
  _a.sent();
310
- return [3 /*break*/, 4];
279
+ _a.label = 2;
280
+ case 2: return [4 /*yield*/, browser.close().catch(function () { return null; })];
311
281
  case 3:
312
- error_1 = _a.sent();
313
- return [3 /*break*/, 4];
314
- case 4: return [2 /*return*/, true];
282
+ _a.sent();
283
+ try {
284
+ process_1 = browser.process();
285
+ if (process_1) {
286
+ treekill(process_1.pid, 'SIGKILL');
287
+ }
288
+ }
289
+ catch (error) { }
290
+ return [2 /*return*/, true];
315
291
  }
316
292
  });
317
293
  });
@@ -358,7 +334,7 @@ var Whatsapp = /** @class */ (function (_super) {
358
334
  */
359
335
  Whatsapp.prototype.decryptFile = function (message) {
360
336
  return __awaiter(this, void 0, void 0, function () {
361
- var mediaUrl, options, haventGottenImageYet, res, error_2, buff;
337
+ var mediaUrl, options, haventGottenImageYet, res, error_1, buff;
362
338
  return __generator(this, function (_a) {
363
339
  switch (_a.label) {
364
340
  case 0:
@@ -386,7 +362,7 @@ var Whatsapp = /** @class */ (function (_super) {
386
362
  case 6: return [3 /*break*/, 2];
387
363
  case 7: return [3 /*break*/, 9];
388
364
  case 8:
389
- error_2 = _a.sent();
365
+ error_1 = _a.sent();
390
366
  throw 'Error trying to download the file.';
391
367
  case 9:
392
368
  buff = Buffer.from(res.data, 'binary');
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import type * as WAJS from '@wppconnect/wa-js';
1
2
  export * from './api/model';
2
3
  export * from './api/model/enum';
3
4
  export { Whatsapp } from './api/whatsapp';
@@ -5,3 +6,4 @@ export { CreateConfig } from './config/create-config';
5
6
  export { create } from './controllers/initializer';
6
7
  export { defaultLogger } from './utils/logger';
7
8
  export * as tokenStore from './token-store';
9
+ export type { WAJS };
package/dist/index.js CHANGED
@@ -23,22 +23,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  };
24
24
  Object.defineProperty(exports, "__esModule", { value: true });
25
25
  exports.tokenStore = exports.defaultLogger = exports.create = exports.Whatsapp = void 0;
26
- /*
27
- * This file is part of WPPConnect.
28
- *
29
- * WPPConnect is free software: you can redistribute it and/or modify
30
- * it under the terms of the GNU Lesser General Public License as published by
31
- * the Free Software Foundation, either version 3 of the License, or
32
- * (at your option) any later version.
33
- *
34
- * WPPConnect is distributed in the hope that it will be useful,
35
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
36
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
37
- * GNU Lesser General Public License for more details.
38
- *
39
- * You should have received a copy of the GNU Lesser General Public License
40
- * along with WPPConnect. If not, see <https://www.gnu.org/licenses/>.
41
- */
42
26
  __exportStar(require("./api/model"), exports);
43
27
  __exportStar(require("./api/model/enum"), exports);
44
28
  var whatsapp_1 = require("./api/whatsapp");