@wppconnect-team/wppconnect 1.22.0 → 1.23.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 +12 -0
- package/dist/api/layers/host.layer.d.ts +18 -8
- package/dist/api/layers/host.layer.js +178 -137
- package/dist/api/layers/listener.layer.js +4 -1
- package/dist/api/whatsapp.d.ts +2 -2
- package/dist/api/whatsapp.js +17 -91
- package/dist/config/create-config.d.ts +2 -0
- package/dist/controllers/auth.d.ts +0 -1
- package/dist/controllers/auth.js +4 -96
- package/dist/controllers/browser.js +4 -13
- package/dist/controllers/initializer.js +13 -8
- package/dist/lib/wapi/wapi.js +1 -1
- package/package.json +24 -24
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
## 1.23.1 (2023-03-25)
|
|
2
|
+
|
|
3
|
+
### Bug Fixes
|
|
4
|
+
|
|
5
|
+
- Fixed multiple inChat emit events ([#1598](https://github.com/wppconnect-team/wppconnect/issues/1598)) ([4900765](https://github.com/wppconnect-team/wppconnect/commit/4900765f20a7c879e597ce01ebcce05bf244006b))
|
|
6
|
+
|
|
7
|
+
# 1.23.0 (2023-03-12)
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
- Reduced the number of log for events ([5b39646](https://github.com/wppconnect-team/wppconnect/commit/5b396467c594396741f61495da1c23bac19c8c94))
|
|
12
|
+
|
|
1
13
|
# 1.22.0 (2023-02-19)
|
|
2
14
|
|
|
3
15
|
### Features
|
|
@@ -1,36 +1,46 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
1
2
|
import { Page } from 'puppeteer';
|
|
3
|
+
import { Logger } from 'winston';
|
|
2
4
|
import { CreateConfig } from '../../config/create-config';
|
|
3
|
-
import { SocketState } from '../model/enum';
|
|
4
|
-
import { ScrapQrcode } from '../model/qrcode';
|
|
5
5
|
import { LogLevel } from '../../utils/logger';
|
|
6
|
-
import { Logger } from 'winston';
|
|
7
6
|
import { CatchQRCallback, HostDevice, LoadingScreenCallback, StatusFindCallback } from '../model';
|
|
8
|
-
import {
|
|
7
|
+
import { SocketState } from '../model/enum';
|
|
8
|
+
import { ScrapQrcode } from '../model/qrcode';
|
|
9
9
|
export declare class HostLayer {
|
|
10
10
|
page: Page;
|
|
11
11
|
readonly session: string;
|
|
12
12
|
readonly options: CreateConfig;
|
|
13
13
|
readonly logger: Logger;
|
|
14
|
-
readonly tokenStore: TokenStore;
|
|
15
14
|
protected autoCloseInterval: any;
|
|
16
15
|
protected autoCloseCalled: boolean;
|
|
17
|
-
protected statusFind?: StatusFindCallback;
|
|
18
16
|
protected isInitialized: boolean;
|
|
19
17
|
protected isInjected: boolean;
|
|
18
|
+
protected isStarted: boolean;
|
|
19
|
+
protected isLogged: boolean;
|
|
20
|
+
protected isInChat: boolean;
|
|
21
|
+
protected checkStartInterval?: NodeJS.Timer;
|
|
22
|
+
protected urlCode: string;
|
|
23
|
+
protected attempt: number;
|
|
24
|
+
catchQR?: CatchQRCallback;
|
|
25
|
+
statusFind?: StatusFindCallback;
|
|
20
26
|
onLoadingScreen?: LoadingScreenCallback;
|
|
21
27
|
constructor(page: Page, session?: string, options?: CreateConfig);
|
|
22
28
|
protected log(level: LogLevel, message: string, meta?: object): void;
|
|
23
29
|
protected initialize(): Promise<void>;
|
|
24
30
|
protected afterPageLoad(): Promise<void>;
|
|
25
31
|
protected afterPageScriptInjected(): Promise<void>;
|
|
32
|
+
start(): Promise<void>;
|
|
33
|
+
protected checkStart(): Promise<void>;
|
|
34
|
+
protected checkQrCode(): Promise<void>;
|
|
35
|
+
protected checkInChat(): Promise<void>;
|
|
26
36
|
protected tryAutoClose(): void;
|
|
27
37
|
protected startAutoClose(time?: number | null): void;
|
|
28
38
|
protected cancelAutoClose(): void;
|
|
29
39
|
getQrCode(): Promise<ScrapQrcode>;
|
|
30
|
-
waitForQrCodeScan(
|
|
40
|
+
waitForQrCodeScan(): Promise<void>;
|
|
31
41
|
waitForInChat(): Promise<boolean>;
|
|
32
42
|
waitForPageLoad(): Promise<void>;
|
|
33
|
-
waitForLogin(
|
|
43
|
+
waitForLogin(): Promise<boolean>;
|
|
34
44
|
/**
|
|
35
45
|
* @category Host
|
|
36
46
|
* @returns Current host device details
|
|
@@ -65,53 +65,30 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
65
65
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
66
66
|
exports.HostLayer = void 0;
|
|
67
67
|
var create_config_1 = require("../../config/create-config");
|
|
68
|
-
var browser_1 = require("../../controllers/browser");
|
|
69
|
-
var helpers_1 = require("../helpers");
|
|
70
68
|
var auth_1 = require("../../controllers/auth");
|
|
71
|
-
var
|
|
69
|
+
var browser_1 = require("../../controllers/browser");
|
|
72
70
|
var logger_1 = require("../../utils/logger");
|
|
73
|
-
var
|
|
71
|
+
var sleep_1 = require("../../utils/sleep");
|
|
72
|
+
var helpers_1 = require("../helpers");
|
|
74
73
|
var HostLayer = /** @class */ (function () {
|
|
75
74
|
function HostLayer(page, session, options) {
|
|
76
75
|
this.page = page;
|
|
77
76
|
this.autoCloseInterval = null;
|
|
78
77
|
this.autoCloseCalled = false;
|
|
79
|
-
this.statusFind = null;
|
|
80
78
|
this.isInitialized = false;
|
|
81
79
|
this.isInjected = false;
|
|
80
|
+
this.isStarted = false;
|
|
81
|
+
this.isLogged = false;
|
|
82
|
+
this.isInChat = false;
|
|
83
|
+
this.checkStartInterval = null;
|
|
84
|
+
this.urlCode = '';
|
|
85
|
+
this.attempt = 0;
|
|
86
|
+
this.catchQR = null;
|
|
87
|
+
this.statusFind = null;
|
|
82
88
|
this.onLoadingScreen = null;
|
|
83
89
|
this.session = session;
|
|
84
90
|
this.options = __assign(__assign({}, create_config_1.defaultOptions), options);
|
|
85
91
|
this.logger = this.options.logger || logger_1.defaultLogger;
|
|
86
|
-
if (typeof this.options.tokenStore === 'string') {
|
|
87
|
-
switch (this.options.tokenStore) {
|
|
88
|
-
case 'memory':
|
|
89
|
-
this.tokenStore = new token_store_1.MemoryTokenStore();
|
|
90
|
-
break;
|
|
91
|
-
case 'file':
|
|
92
|
-
default:
|
|
93
|
-
this.tokenStore = new token_store_1.FileTokenStore({
|
|
94
|
-
path: this.options.folderNameToken,
|
|
95
|
-
});
|
|
96
|
-
break;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
else {
|
|
100
|
-
this.tokenStore = this.options.tokenStore;
|
|
101
|
-
}
|
|
102
|
-
if (!(0, token_store_1.isValidTokenStore)(this.tokenStore)) {
|
|
103
|
-
this.log('warn', 'Invalid tokenStore, using default tokenStore', {
|
|
104
|
-
type: 'tokenStore',
|
|
105
|
-
});
|
|
106
|
-
if (this.options.folderNameToken) {
|
|
107
|
-
this.tokenStore = new token_store_1.FileTokenStore({
|
|
108
|
-
path: this.options.folderNameToken,
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
else {
|
|
112
|
-
this.tokenStore = new token_store_1.MemoryTokenStore();
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
92
|
this.log('info', 'Initializing...');
|
|
116
93
|
this.initialize();
|
|
117
94
|
}
|
|
@@ -120,40 +97,19 @@ var HostLayer = /** @class */ (function () {
|
|
|
120
97
|
this.logger.log(__assign({ level: level, message: message, session: this.session, type: 'client' }, meta));
|
|
121
98
|
};
|
|
122
99
|
HostLayer.prototype.initialize = function () {
|
|
123
|
-
var _a, _b;
|
|
124
100
|
return __awaiter(this, void 0, void 0, function () {
|
|
125
|
-
var sessionToken, isValidToken, hasUserDataDir, clear;
|
|
126
101
|
var _this = this;
|
|
127
|
-
return __generator(this, function (
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
if (isValidToken) {
|
|
139
|
-
this.log('verbose', 'Injecting session token', { type: 'token' });
|
|
140
|
-
}
|
|
141
|
-
hasUserDataDir = !!((_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.puppeteerOptions) === null || _b === void 0 ? void 0 : _b.userDataDir);
|
|
142
|
-
clear = !hasUserDataDir || (hasUserDataDir && !isValidToken);
|
|
143
|
-
this.page.on('close', function () {
|
|
144
|
-
_this.cancelAutoClose();
|
|
145
|
-
_this.log('verbose', 'Page Closed', { type: 'page' });
|
|
146
|
-
});
|
|
147
|
-
return [4 /*yield*/, (0, browser_1.initWhatsapp)(this.page, sessionToken, clear, this.options.whatsappVersion, this.log.bind(this))];
|
|
148
|
-
case 3:
|
|
149
|
-
_c.sent();
|
|
150
|
-
this.page.on('load', function () {
|
|
151
|
-
_this.log('verbose', 'Page loaded', { type: 'page' });
|
|
152
|
-
_this.afterPageLoad();
|
|
153
|
-
});
|
|
154
|
-
this.isInitialized = true;
|
|
155
|
-
return [2 /*return*/];
|
|
156
|
-
}
|
|
102
|
+
return __generator(this, function (_a) {
|
|
103
|
+
this.page.on('close', function () {
|
|
104
|
+
_this.cancelAutoClose();
|
|
105
|
+
_this.log('verbose', 'Page Closed', { type: 'page' });
|
|
106
|
+
});
|
|
107
|
+
this.page.on('load', function () {
|
|
108
|
+
_this.log('verbose', 'Page loaded', { type: 'page' });
|
|
109
|
+
_this.afterPageLoad();
|
|
110
|
+
});
|
|
111
|
+
this.isInitialized = true;
|
|
112
|
+
return [2 /*return*/];
|
|
157
113
|
});
|
|
158
114
|
});
|
|
159
115
|
};
|
|
@@ -209,10 +165,117 @@ var HostLayer = /** @class */ (function () {
|
|
|
209
165
|
_this.log('info', "WA-JS version: ".concat(version));
|
|
210
166
|
})
|
|
211
167
|
.catch(function () { return null; });
|
|
168
|
+
(0, helpers_1.evaluateAndReturn)(this.page, function () {
|
|
169
|
+
WPP.on('conn.auth_code_change', window.checkQrCode);
|
|
170
|
+
}).catch(function () { return null; });
|
|
171
|
+
(0, helpers_1.evaluateAndReturn)(this.page, function () {
|
|
172
|
+
WPP.on('conn.main_ready', window.checkInChat);
|
|
173
|
+
}).catch(function () { return null; });
|
|
174
|
+
this.checkQrCode();
|
|
175
|
+
this.checkInChat();
|
|
176
|
+
return [2 /*return*/];
|
|
177
|
+
});
|
|
178
|
+
});
|
|
179
|
+
};
|
|
180
|
+
HostLayer.prototype.start = function () {
|
|
181
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
182
|
+
var _this = this;
|
|
183
|
+
return __generator(this, function (_a) {
|
|
184
|
+
switch (_a.label) {
|
|
185
|
+
case 0:
|
|
186
|
+
if (this.isStarted) {
|
|
187
|
+
return [2 /*return*/];
|
|
188
|
+
}
|
|
189
|
+
this.isStarted = true;
|
|
190
|
+
return [4 /*yield*/, (0, browser_1.initWhatsapp)(this.page, null, false, this.options.whatsappVersion, this.log.bind(this))];
|
|
191
|
+
case 1:
|
|
192
|
+
_a.sent();
|
|
193
|
+
return [4 /*yield*/, this.page.exposeFunction('checkQrCode', function () { return _this.checkQrCode(); })];
|
|
194
|
+
case 2:
|
|
195
|
+
_a.sent();
|
|
196
|
+
return [4 /*yield*/, this.page.exposeFunction('checkInChat', function () { return _this.checkInChat(); })];
|
|
197
|
+
case 3:
|
|
198
|
+
_a.sent();
|
|
199
|
+
this.checkStartInterval = setInterval(function () { return _this.checkStart(); }, 5000);
|
|
200
|
+
this.page.on('close', function () {
|
|
201
|
+
clearInterval(_this.checkStartInterval);
|
|
202
|
+
});
|
|
203
|
+
return [2 /*return*/];
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
});
|
|
207
|
+
};
|
|
208
|
+
HostLayer.prototype.checkStart = function () {
|
|
209
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
210
|
+
return __generator(this, function (_a) {
|
|
211
|
+
(0, auth_1.needsToScan)(this.page)
|
|
212
|
+
.then(function (need) { })
|
|
213
|
+
.catch(function () { return null; });
|
|
212
214
|
return [2 /*return*/];
|
|
213
215
|
});
|
|
214
216
|
});
|
|
215
217
|
};
|
|
218
|
+
HostLayer.prototype.checkQrCode = function () {
|
|
219
|
+
var _a;
|
|
220
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
221
|
+
var needScan, result, qr;
|
|
222
|
+
return __generator(this, function (_b) {
|
|
223
|
+
switch (_b.label) {
|
|
224
|
+
case 0: return [4 /*yield*/, (0, auth_1.needsToScan)(this.page).catch(function () { return null; })];
|
|
225
|
+
case 1:
|
|
226
|
+
needScan = _b.sent();
|
|
227
|
+
this.isLogged = !needScan;
|
|
228
|
+
if (!needScan) {
|
|
229
|
+
this.attempt = 0;
|
|
230
|
+
return [2 /*return*/];
|
|
231
|
+
}
|
|
232
|
+
return [4 /*yield*/, this.getQrCode()];
|
|
233
|
+
case 2:
|
|
234
|
+
result = _b.sent();
|
|
235
|
+
if (!(result === null || result === void 0 ? void 0 : result.urlCode) || this.urlCode === result.urlCode) {
|
|
236
|
+
return [2 /*return*/];
|
|
237
|
+
}
|
|
238
|
+
this.urlCode = result.urlCode;
|
|
239
|
+
this.attempt++;
|
|
240
|
+
qr = '';
|
|
241
|
+
if (!(this.options.logQR || this.catchQR)) return [3 /*break*/, 4];
|
|
242
|
+
return [4 /*yield*/, (0, auth_1.asciiQr)(this.urlCode)];
|
|
243
|
+
case 3:
|
|
244
|
+
qr = _b.sent();
|
|
245
|
+
_b.label = 4;
|
|
246
|
+
case 4:
|
|
247
|
+
if (this.options.logQR) {
|
|
248
|
+
this.log('info', "Waiting for QRCode Scan (Attempt ".concat(this.attempt, ")...:\n").concat(qr), { code: this.urlCode });
|
|
249
|
+
}
|
|
250
|
+
else {
|
|
251
|
+
this.log('verbose', "Waiting for QRCode Scan: Attempt ".concat(this.attempt));
|
|
252
|
+
}
|
|
253
|
+
(_a = this.catchQR) === null || _a === void 0 ? void 0 : _a.call(this, result.base64Image, qr, this.attempt, result.urlCode);
|
|
254
|
+
return [2 /*return*/];
|
|
255
|
+
}
|
|
256
|
+
});
|
|
257
|
+
});
|
|
258
|
+
};
|
|
259
|
+
HostLayer.prototype.checkInChat = function () {
|
|
260
|
+
var _a;
|
|
261
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
262
|
+
var inChat;
|
|
263
|
+
return __generator(this, function (_b) {
|
|
264
|
+
switch (_b.label) {
|
|
265
|
+
case 0: return [4 /*yield*/, (0, auth_1.isInsideChat)(this.page).catch(function () { return null; })];
|
|
266
|
+
case 1:
|
|
267
|
+
inChat = _b.sent();
|
|
268
|
+
this.isInChat = !!inChat;
|
|
269
|
+
if (!inChat) {
|
|
270
|
+
return [2 /*return*/];
|
|
271
|
+
}
|
|
272
|
+
this.log('http', 'Connected');
|
|
273
|
+
(_a = this.statusFind) === null || _a === void 0 ? void 0 : _a.call(this, 'inChat', this.session);
|
|
274
|
+
return [2 /*return*/];
|
|
275
|
+
}
|
|
276
|
+
});
|
|
277
|
+
});
|
|
278
|
+
};
|
|
216
279
|
HostLayer.prototype.tryAutoClose = function () {
|
|
217
280
|
if (this.autoCloseInterval) {
|
|
218
281
|
this.cancelAutoClose();
|
|
@@ -271,78 +334,58 @@ var HostLayer = /** @class */ (function () {
|
|
|
271
334
|
});
|
|
272
335
|
});
|
|
273
336
|
};
|
|
274
|
-
HostLayer.prototype.waitForQrCodeScan = function (
|
|
337
|
+
HostLayer.prototype.waitForQrCodeScan = function () {
|
|
275
338
|
return __awaiter(this, void 0, void 0, function () {
|
|
276
|
-
var
|
|
339
|
+
var needScan;
|
|
277
340
|
return __generator(this, function (_a) {
|
|
278
341
|
switch (_a.label) {
|
|
279
342
|
case 0:
|
|
280
|
-
|
|
281
|
-
|
|
343
|
+
if (!this.isStarted) {
|
|
344
|
+
throw new Error('waitForQrCodeScan error: Session not started');
|
|
345
|
+
}
|
|
282
346
|
_a.label = 1;
|
|
283
347
|
case 1:
|
|
284
|
-
if (!
|
|
285
|
-
return [4 /*yield*/, (0,
|
|
348
|
+
if (!(!this.page.isClosed() && !this.isLogged)) return [3 /*break*/, 4];
|
|
349
|
+
return [4 /*yield*/, (0, sleep_1.sleep)(200)];
|
|
286
350
|
case 2:
|
|
287
|
-
needsScan = _a.sent();
|
|
288
|
-
if (!needsScan) {
|
|
289
|
-
return [3 /*break*/, 8];
|
|
290
|
-
}
|
|
291
|
-
return [4 /*yield*/, this.getQrCode()];
|
|
292
|
-
case 3:
|
|
293
|
-
result = _a.sent();
|
|
294
|
-
if (!((result === null || result === void 0 ? void 0 : result.urlCode) && urlCode !== result.urlCode)) return [3 /*break*/, 6];
|
|
295
|
-
urlCode = result.urlCode;
|
|
296
|
-
attempt++;
|
|
297
|
-
qr = '';
|
|
298
|
-
if (!(this.options.logQR || catchQR)) return [3 /*break*/, 5];
|
|
299
|
-
return [4 /*yield*/, (0, auth_1.asciiQr)(urlCode)];
|
|
300
|
-
case 4:
|
|
301
|
-
qr = _a.sent();
|
|
302
|
-
_a.label = 5;
|
|
303
|
-
case 5:
|
|
304
|
-
if (this.options.logQR) {
|
|
305
|
-
this.log('info', "Waiting for QRCode Scan (Attempt ".concat(attempt, ")...:\n").concat(qr), { code: urlCode });
|
|
306
|
-
}
|
|
307
|
-
else {
|
|
308
|
-
this.log('verbose', "Waiting for QRCode Scan: Attempt ".concat(attempt));
|
|
309
|
-
}
|
|
310
|
-
if (catchQR) {
|
|
311
|
-
catchQR(result.base64Image, qr, attempt, result.urlCode);
|
|
312
|
-
}
|
|
313
|
-
_a.label = 6;
|
|
314
|
-
case 6: return [4 /*yield*/, (0, sleep_1.sleep)(200)];
|
|
315
|
-
case 7:
|
|
316
351
|
_a.sent();
|
|
352
|
+
return [4 /*yield*/, (0, auth_1.needsToScan)(this.page).catch(function () { return null; })];
|
|
353
|
+
case 3:
|
|
354
|
+
needScan = _a.sent();
|
|
355
|
+
this.isLogged = !needScan;
|
|
317
356
|
return [3 /*break*/, 1];
|
|
318
|
-
case
|
|
357
|
+
case 4: return [2 /*return*/];
|
|
319
358
|
}
|
|
320
359
|
});
|
|
321
360
|
});
|
|
322
361
|
};
|
|
323
362
|
HostLayer.prototype.waitForInChat = function () {
|
|
324
363
|
return __awaiter(this, void 0, void 0, function () {
|
|
325
|
-
var
|
|
364
|
+
var start, inChat;
|
|
326
365
|
return __generator(this, function (_a) {
|
|
327
366
|
switch (_a.label) {
|
|
328
|
-
case 0:
|
|
329
|
-
|
|
330
|
-
|
|
367
|
+
case 0:
|
|
368
|
+
if (!this.isStarted) {
|
|
369
|
+
throw new Error('waitForInChat error: Session not started');
|
|
370
|
+
}
|
|
371
|
+
if (!this.isLogged) {
|
|
372
|
+
return [2 /*return*/, false];
|
|
373
|
+
}
|
|
331
374
|
start = Date.now();
|
|
332
|
-
_a.label =
|
|
333
|
-
case
|
|
334
|
-
if (!(
|
|
335
|
-
if (
|
|
375
|
+
_a.label = 1;
|
|
376
|
+
case 1:
|
|
377
|
+
if (!(!this.page.isClosed() && this.isLogged && !this.isInChat)) return [3 /*break*/, 3];
|
|
378
|
+
if (this.options.deviceSyncTimeout > 0 &&
|
|
379
|
+
Date.now() - start >= this.options.deviceSyncTimeout) {
|
|
336
380
|
return [2 /*return*/, false];
|
|
337
381
|
}
|
|
338
382
|
return [4 /*yield*/, (0, sleep_1.sleep)(1000)];
|
|
339
|
-
case
|
|
383
|
+
case 2:
|
|
340
384
|
_a.sent();
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
case 5: return [2 /*return*/, inChat];
|
|
385
|
+
inChat = (0, auth_1.isInsideChat)(this.page).catch(function () { return null; });
|
|
386
|
+
this.isInChat = !!inChat;
|
|
387
|
+
return [3 /*break*/, 1];
|
|
388
|
+
case 3: return [2 /*return*/, this.isInChat];
|
|
346
389
|
}
|
|
347
390
|
});
|
|
348
391
|
});
|
|
@@ -365,48 +408,48 @@ var HostLayer = /** @class */ (function () {
|
|
|
365
408
|
});
|
|
366
409
|
});
|
|
367
410
|
};
|
|
368
|
-
HostLayer.prototype.waitForLogin = function (
|
|
411
|
+
HostLayer.prototype.waitForLogin = function () {
|
|
412
|
+
var _a, _b, _c, _d, _e, _f;
|
|
369
413
|
return __awaiter(this, void 0, void 0, function () {
|
|
370
414
|
var authenticated, inChat;
|
|
371
|
-
return __generator(this, function (
|
|
372
|
-
switch (
|
|
415
|
+
return __generator(this, function (_g) {
|
|
416
|
+
switch (_g.label) {
|
|
373
417
|
case 0:
|
|
374
|
-
this.statusFind = statusFind;
|
|
375
418
|
this.log('http', 'Waiting page load');
|
|
376
419
|
return [4 /*yield*/, this.waitForPageLoad()];
|
|
377
420
|
case 1:
|
|
378
|
-
|
|
421
|
+
_g.sent();
|
|
379
422
|
this.log('http', 'Checking is logged...');
|
|
380
423
|
return [4 /*yield*/, (0, auth_1.isAuthenticated)(this.page).catch(function () { return null; })];
|
|
381
424
|
case 2:
|
|
382
|
-
authenticated =
|
|
425
|
+
authenticated = _g.sent();
|
|
383
426
|
this.startAutoClose();
|
|
384
427
|
if (!(authenticated === false)) return [3 /*break*/, 6];
|
|
385
428
|
this.log('http', 'Waiting for QRCode Scan...');
|
|
386
|
-
statusFind
|
|
387
|
-
return [4 /*yield*/, this.waitForQrCodeScan(
|
|
429
|
+
(_a = this.statusFind) === null || _a === void 0 ? void 0 : _a.call(this, 'notLogged', this.session);
|
|
430
|
+
return [4 /*yield*/, this.waitForQrCodeScan()];
|
|
388
431
|
case 3:
|
|
389
|
-
|
|
432
|
+
_g.sent();
|
|
390
433
|
this.log('http', 'Checking QRCode status...');
|
|
391
434
|
// Wait for interface update
|
|
392
435
|
return [4 /*yield*/, (0, sleep_1.sleep)(200)];
|
|
393
436
|
case 4:
|
|
394
437
|
// Wait for interface update
|
|
395
|
-
|
|
438
|
+
_g.sent();
|
|
396
439
|
return [4 /*yield*/, (0, auth_1.isAuthenticated)(this.page).catch(function () { return null; })];
|
|
397
440
|
case 5:
|
|
398
|
-
authenticated =
|
|
441
|
+
authenticated = _g.sent();
|
|
399
442
|
if (authenticated === null) {
|
|
400
443
|
this.log('warn', 'Failed to authenticate');
|
|
401
|
-
statusFind
|
|
444
|
+
(_b = this.statusFind) === null || _b === void 0 ? void 0 : _b.call(this, 'qrReadError', this.session);
|
|
402
445
|
}
|
|
403
446
|
else if (authenticated) {
|
|
404
447
|
this.log('http', 'QRCode Success');
|
|
405
|
-
statusFind
|
|
448
|
+
(_c = this.statusFind) === null || _c === void 0 ? void 0 : _c.call(this, 'qrReadSuccess', this.session);
|
|
406
449
|
}
|
|
407
450
|
else {
|
|
408
451
|
this.log('warn', 'QRCode Fail');
|
|
409
|
-
statusFind
|
|
452
|
+
(_d = this.statusFind) === null || _d === void 0 ? void 0 : _d.call(this, 'qrReadFail', this.session);
|
|
410
453
|
this.tryAutoClose();
|
|
411
454
|
throw 'Failed to read the QRCode';
|
|
412
455
|
}
|
|
@@ -414,9 +457,9 @@ var HostLayer = /** @class */ (function () {
|
|
|
414
457
|
case 6:
|
|
415
458
|
if (authenticated === true) {
|
|
416
459
|
this.log('http', 'Authenticated');
|
|
417
|
-
statusFind
|
|
460
|
+
(_e = this.statusFind) === null || _e === void 0 ? void 0 : _e.call(this, 'isLogged', this.session);
|
|
418
461
|
}
|
|
419
|
-
|
|
462
|
+
_g.label = 7;
|
|
420
463
|
case 7:
|
|
421
464
|
if (!(authenticated === true)) return [3 /*break*/, 10];
|
|
422
465
|
// Reinicia o contador do autoclose
|
|
@@ -425,21 +468,19 @@ var HostLayer = /** @class */ (function () {
|
|
|
425
468
|
return [4 /*yield*/, (0, sleep_1.sleep)(200)];
|
|
426
469
|
case 8:
|
|
427
470
|
// Wait for interface update
|
|
428
|
-
|
|
471
|
+
_g.sent();
|
|
429
472
|
this.startAutoClose(this.options.deviceSyncTimeout);
|
|
430
473
|
this.log('http', 'Checking phone is connected...');
|
|
431
474
|
return [4 /*yield*/, this.waitForInChat()];
|
|
432
475
|
case 9:
|
|
433
|
-
inChat =
|
|
476
|
+
inChat = _g.sent();
|
|
434
477
|
if (!inChat) {
|
|
435
478
|
this.log('warn', 'Phone not connected');
|
|
436
|
-
statusFind
|
|
479
|
+
(_f = this.statusFind) === null || _f === void 0 ? void 0 : _f.call(this, 'phoneNotConnected', this.session);
|
|
437
480
|
this.tryAutoClose();
|
|
438
481
|
throw 'Phone not connected';
|
|
439
482
|
}
|
|
440
483
|
this.cancelAutoClose();
|
|
441
|
-
this.log('http', 'Connected');
|
|
442
|
-
statusFind && statusFind('inChat', this.session);
|
|
443
484
|
return [2 /*return*/, true];
|
|
444
485
|
case 10:
|
|
445
486
|
if (authenticated === false) {
|
|
@@ -145,7 +145,10 @@ var ListenerLayer = /** @class */ (function (_super) {
|
|
|
145
145
|
}
|
|
146
146
|
Promise.resolve().then(function () {
|
|
147
147
|
var _a;
|
|
148
|
-
|
|
148
|
+
var count = _this.listenerEmitter.listenerCount(func);
|
|
149
|
+
if (count > 0) {
|
|
150
|
+
_this.log('debug', "Emitting ".concat(func, " event (").concat(count, " registered)"));
|
|
151
|
+
}
|
|
149
152
|
(_a = _this.listenerEmitter).emit.apply(_a, __spreadArray([func], args, false));
|
|
150
153
|
});
|
|
151
154
|
})
|
package/dist/api/whatsapp.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { Page } from 'puppeteer';
|
|
3
|
+
import { CreateConfig } from '../config/create-config';
|
|
3
4
|
import { BusinessLayer } from './layers/business.layer';
|
|
4
5
|
import { GetMessagesParam, Message } from './model';
|
|
5
|
-
import { CreateConfig } from '../config/create-config';
|
|
6
6
|
export declare class Whatsapp extends BusinessLayer {
|
|
7
7
|
page: Page;
|
|
8
8
|
private connected;
|
|
@@ -66,5 +66,5 @@ export declare class Whatsapp extends BusinessLayer {
|
|
|
66
66
|
* @param callId string ID da ligação, caso não passado, todas ligações serão rejeitadas
|
|
67
67
|
* @returns Número de ligações rejeitadas
|
|
68
68
|
*/
|
|
69
|
-
rejectCall(callId?: string): Promise<
|
|
69
|
+
rejectCall(callId?: string): Promise<boolean>;
|
|
70
70
|
}
|