@wppconnect-team/wppconnect 2.0.0 → 2.0.2
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/helpers/base64-mimetype.js +2 -2
- package/dist/api/helpers/decrypt.js +65 -72
- package/dist/api/helpers/download-file.js +31 -81
- package/dist/api/helpers/evaluate-and-return.js +98 -93
- package/dist/api/helpers/file-to-base64.js +30 -81
- package/dist/api/helpers/filename-from-mimetype.js +4 -4
- package/dist/api/helpers/scrape-img-qr.js +37 -86
- package/dist/api/helpers/scrape-login.js +12 -57
- package/dist/api/helpers/select-sticker.js +35 -100
- package/dist/api/layers/business.layer.js +29 -134
- package/dist/api/layers/catalog.layer.js +59 -210
- package/dist/api/layers/community.layer.js +29 -120
- package/dist/api/layers/controls.layer.js +62 -262
- package/dist/api/layers/group.layer.js +126 -391
- package/dist/api/layers/host.layer.js +348 -702
- package/dist/api/layers/labels.layer.js +35 -131
- package/dist/api/layers/listener.layer.js +386 -504
- package/dist/api/layers/newsletter.layer.js +20 -89
- package/dist/api/layers/profile.layer.js +73 -184
- package/dist/api/layers/retriever.layer.js +161 -468
- package/dist/api/layers/sender.layer.js +554 -1094
- package/dist/api/layers/status.layer.js +80 -179
- package/dist/api/layers/ui.layer.js +32 -129
- package/dist/api/model/enum/definitions.js +1 -1
- package/dist/api/whatsapp.js +200 -437
- package/dist/config/WAuserAgente.js +1 -1
- package/dist/config/create-config.js +1 -1
- package/dist/config/puppeteer.config.js +1 -1
- package/dist/controllers/auth.js +42 -110
- package/dist/controllers/browser.js +251 -411
- package/dist/controllers/initializer.js +171 -265
- package/dist/controllers/websocket.js +29 -28
- package/dist/controllers/welcome.js +38 -88
- package/dist/token-store/fileTokenStore.js +83 -173
- package/dist/token-store/isValidSessionToken.js +2 -2
- package/dist/token-store/isValidTokenStore.js +2 -2
- package/dist/token-store/memoryTokenStore.js +11 -14
- package/dist/utils/ffmpeg.js +75 -131
- package/dist/utils/logger.js +5 -5
- package/dist/utils/semver.js +6 -6
- package/dist/utils/sleep.js +1 -1
- package/package.json +8 -8
|
@@ -15,313 +15,177 @@
|
|
|
15
15
|
* You should have received a copy of the GNU Lesser General Public License
|
|
16
16
|
* along with WPPConnect. If not, see <https://www.gnu.org/licenses/>.
|
|
17
17
|
*/
|
|
18
|
-
var __assign = (this && this.__assign) || function () {
|
|
19
|
-
__assign = Object.assign || function(t) {
|
|
20
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
21
|
-
s = arguments[i];
|
|
22
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
23
|
-
t[p] = s[p];
|
|
24
|
-
}
|
|
25
|
-
return t;
|
|
26
|
-
};
|
|
27
|
-
return __assign.apply(this, arguments);
|
|
28
|
-
};
|
|
29
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
30
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
31
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
32
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
33
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
34
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
35
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
36
|
-
});
|
|
37
|
-
};
|
|
38
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
39
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
40
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
41
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
42
|
-
function step(op) {
|
|
43
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
44
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
45
|
-
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;
|
|
46
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
47
|
-
switch (op[0]) {
|
|
48
|
-
case 0: case 1: t = op; break;
|
|
49
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
50
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
51
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
52
|
-
default:
|
|
53
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
54
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
55
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
56
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
57
|
-
if (t[2]) _.ops.pop();
|
|
58
|
-
_.trys.pop(); continue;
|
|
59
|
-
}
|
|
60
|
-
op = body.call(thisArg, _);
|
|
61
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
62
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
66
19
|
exports.HostLayer = void 0;
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
20
|
+
const create_config_1 = require("../../config/create-config");
|
|
21
|
+
const auth_1 = require("../../controllers/auth");
|
|
22
|
+
const browser_1 = require("../../controllers/browser");
|
|
23
|
+
const logger_1 = require("../../utils/logger");
|
|
24
|
+
const sleep_1 = require("../../utils/sleep");
|
|
25
|
+
const helpers_1 = require("../helpers");
|
|
26
|
+
class HostLayer {
|
|
27
|
+
page;
|
|
28
|
+
session;
|
|
29
|
+
options;
|
|
30
|
+
logger;
|
|
31
|
+
autoCloseInterval = null;
|
|
32
|
+
autoCloseCalled = false;
|
|
33
|
+
isInitialized = false;
|
|
34
|
+
isInjected = false;
|
|
35
|
+
isStarted = false;
|
|
36
|
+
isLogged = false;
|
|
37
|
+
isInChat = false;
|
|
38
|
+
checkStartInterval = null;
|
|
39
|
+
urlCode = '';
|
|
40
|
+
attempt = 0;
|
|
41
|
+
catchQR = null;
|
|
42
|
+
statusFind = null;
|
|
43
|
+
onLoadingScreen = null;
|
|
44
|
+
catchLinkCode = null;
|
|
45
|
+
constructor(page, session, options) {
|
|
75
46
|
this.page = page;
|
|
76
|
-
this.autoCloseInterval = null;
|
|
77
|
-
this.autoCloseCalled = false;
|
|
78
|
-
this.isInitialized = false;
|
|
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;
|
|
88
|
-
this.onLoadingScreen = null;
|
|
89
|
-
this.catchLinkCode = null;
|
|
90
47
|
this.session = session;
|
|
91
|
-
this.options =
|
|
48
|
+
this.options = { ...create_config_1.defaultOptions, ...options };
|
|
92
49
|
this.logger = this.options.logger || logger_1.defaultLogger;
|
|
93
50
|
this.log('info', 'Initializing...');
|
|
94
51
|
this.initialize();
|
|
95
52
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
return __generator(this, function (_a) {
|
|
104
|
-
this.page.on('close', function () {
|
|
105
|
-
_this.cancelAutoClose();
|
|
106
|
-
_this.log('verbose', 'Page Closed', { type: 'page' });
|
|
107
|
-
});
|
|
108
|
-
this.page.on('load', function () {
|
|
109
|
-
_this.log('verbose', 'Page loaded', { type: 'page' });
|
|
110
|
-
_this.afterPageLoad();
|
|
111
|
-
});
|
|
112
|
-
this.isInitialized = true;
|
|
113
|
-
return [2 /*return*/];
|
|
114
|
-
});
|
|
115
|
-
});
|
|
116
|
-
};
|
|
117
|
-
HostLayer.prototype.afterPageLoad = function () {
|
|
118
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
119
|
-
var options;
|
|
120
|
-
var _this = this;
|
|
121
|
-
return __generator(this, function (_a) {
|
|
122
|
-
switch (_a.label) {
|
|
123
|
-
case 0:
|
|
124
|
-
this.log('verbose', 'Injecting wapi.js');
|
|
125
|
-
options = {
|
|
126
|
-
deviceName: this.options.deviceName,
|
|
127
|
-
disableGoogleAnalytics: this.options.disableGoogleAnalytics,
|
|
128
|
-
googleAnalyticsId: this.options.googleAnalyticsId,
|
|
129
|
-
linkPreviewApiServers: this.options.linkPreviewApiServers,
|
|
130
|
-
poweredBy: this.options.poweredBy,
|
|
131
|
-
};
|
|
132
|
-
return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (options) {
|
|
133
|
-
window.WPPConfig = options;
|
|
134
|
-
}, options)];
|
|
135
|
-
case 1:
|
|
136
|
-
_a.sent();
|
|
137
|
-
this.isInjected = false;
|
|
138
|
-
return [4 /*yield*/, (0, browser_1.injectApi)(this.page, this.onLoadingScreen)
|
|
139
|
-
.then(function () {
|
|
140
|
-
_this.isInjected = true;
|
|
141
|
-
_this.log('verbose', 'wapi.js injected');
|
|
142
|
-
_this.afterPageScriptInjected();
|
|
143
|
-
})
|
|
144
|
-
.catch(function (e) {
|
|
145
|
-
console.log(e);
|
|
146
|
-
_this.log('verbose', 'wapi.js failed');
|
|
147
|
-
_this.log('error', e);
|
|
148
|
-
})];
|
|
149
|
-
case 2:
|
|
150
|
-
_a.sent();
|
|
151
|
-
return [2 /*return*/];
|
|
152
|
-
}
|
|
153
|
-
});
|
|
154
|
-
});
|
|
155
|
-
};
|
|
156
|
-
HostLayer.prototype.afterPageScriptInjected = function () {
|
|
157
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
158
|
-
var _this = this;
|
|
159
|
-
return __generator(this, function (_a) {
|
|
160
|
-
this.getWAVersion()
|
|
161
|
-
.then(function (version) {
|
|
162
|
-
_this.log('info', "WhatsApp WEB version: ".concat(version));
|
|
163
|
-
})
|
|
164
|
-
.catch(function () { return null; });
|
|
165
|
-
this.getWAJSVersion()
|
|
166
|
-
.then(function (version) {
|
|
167
|
-
_this.log('info', "WA-JS version: ".concat(version));
|
|
168
|
-
})
|
|
169
|
-
.catch(function () { return null; });
|
|
170
|
-
(0, helpers_1.evaluateAndReturn)(this.page, function () {
|
|
171
|
-
WPP.on('conn.auth_code_change', window.checkQrCode);
|
|
172
|
-
}).catch(function () { return null; });
|
|
173
|
-
(0, helpers_1.evaluateAndReturn)(this.page, function () {
|
|
174
|
-
WPP.on('conn.main_ready', window.checkInChat);
|
|
175
|
-
}).catch(function () { return null; });
|
|
176
|
-
this.checkInChat();
|
|
177
|
-
this.checkQrCode();
|
|
178
|
-
return [2 /*return*/];
|
|
179
|
-
});
|
|
53
|
+
log(level, message, meta = {}) {
|
|
54
|
+
this.logger.log({
|
|
55
|
+
level,
|
|
56
|
+
message,
|
|
57
|
+
session: this.session,
|
|
58
|
+
type: 'client',
|
|
59
|
+
...meta,
|
|
180
60
|
});
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
switch (_a.label) {
|
|
187
|
-
case 0:
|
|
188
|
-
if (this.isStarted) {
|
|
189
|
-
return [2 /*return*/];
|
|
190
|
-
}
|
|
191
|
-
this.isStarted = true;
|
|
192
|
-
return [4 /*yield*/, (0, browser_1.initWhatsapp)(this.page, null, false, this.options.whatsappVersion, this.options.proxy, this.log.bind(this))];
|
|
193
|
-
case 1:
|
|
194
|
-
_a.sent();
|
|
195
|
-
return [4 /*yield*/, this.page.exposeFunction('checkQrCode', function () { return _this.checkQrCode(); })];
|
|
196
|
-
case 2:
|
|
197
|
-
_a.sent();
|
|
198
|
-
/*await this.page.exposeFunction('loginByCode', (phone: string) =>
|
|
199
|
-
this.loginByCode(phone)
|
|
200
|
-
);*/
|
|
201
|
-
return [4 /*yield*/, this.page.exposeFunction('checkInChat', function () { return _this.checkInChat(); })];
|
|
202
|
-
case 3:
|
|
203
|
-
/*await this.page.exposeFunction('loginByCode', (phone: string) =>
|
|
204
|
-
this.loginByCode(phone)
|
|
205
|
-
);*/
|
|
206
|
-
_a.sent();
|
|
207
|
-
this.checkStartInterval = setInterval(function () { return _this.checkStart(); }, 5000);
|
|
208
|
-
this.page.on('close', function () {
|
|
209
|
-
clearInterval(_this.checkStartInterval);
|
|
210
|
-
});
|
|
211
|
-
return [2 /*return*/];
|
|
212
|
-
}
|
|
213
|
-
});
|
|
214
|
-
});
|
|
215
|
-
};
|
|
216
|
-
HostLayer.prototype.checkStart = function () {
|
|
217
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
218
|
-
return __generator(this, function (_a) {
|
|
219
|
-
(0, auth_1.needsToScan)(this.page)
|
|
220
|
-
.then(function (need) { })
|
|
221
|
-
.catch(function () { return null; });
|
|
222
|
-
return [2 /*return*/];
|
|
223
|
-
});
|
|
61
|
+
}
|
|
62
|
+
async initialize() {
|
|
63
|
+
this.page.on('close', () => {
|
|
64
|
+
this.cancelAutoClose();
|
|
65
|
+
this.log('verbose', 'Page Closed', { type: 'page' });
|
|
224
66
|
});
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
var needScan, result, qr;
|
|
229
|
-
var _a;
|
|
230
|
-
return __generator(this, function (_b) {
|
|
231
|
-
switch (_b.label) {
|
|
232
|
-
case 0: return [4 /*yield*/, (0, auth_1.needsToScan)(this.page).catch(function () { return null; })];
|
|
233
|
-
case 1:
|
|
234
|
-
needScan = _b.sent();
|
|
235
|
-
this.isLogged = !needScan;
|
|
236
|
-
if (!needScan) {
|
|
237
|
-
this.attempt = 0;
|
|
238
|
-
return [2 /*return*/];
|
|
239
|
-
}
|
|
240
|
-
return [4 /*yield*/, this.getQrCode()];
|
|
241
|
-
case 2:
|
|
242
|
-
result = _b.sent();
|
|
243
|
-
if (!(result === null || result === void 0 ? void 0 : result.urlCode) || this.urlCode === result.urlCode) {
|
|
244
|
-
return [2 /*return*/];
|
|
245
|
-
}
|
|
246
|
-
if (typeof this.options.phoneNumber === 'string') {
|
|
247
|
-
return [2 /*return*/, this.loginByCode(this.options.phoneNumber)];
|
|
248
|
-
}
|
|
249
|
-
this.urlCode = result.urlCode;
|
|
250
|
-
this.attempt++;
|
|
251
|
-
qr = '';
|
|
252
|
-
if (!(this.options.logQR || this.catchQR)) return [3 /*break*/, 4];
|
|
253
|
-
return [4 /*yield*/, (0, auth_1.asciiQr)(this.urlCode)];
|
|
254
|
-
case 3:
|
|
255
|
-
qr = _b.sent();
|
|
256
|
-
_b.label = 4;
|
|
257
|
-
case 4:
|
|
258
|
-
if (this.options.logQR) {
|
|
259
|
-
this.log('info', "Waiting for QRCode Scan (Attempt ".concat(this.attempt, ")...:\n").concat(qr), { code: this.urlCode });
|
|
260
|
-
}
|
|
261
|
-
else {
|
|
262
|
-
this.log('verbose', "Waiting for QRCode Scan: Attempt ".concat(this.attempt));
|
|
263
|
-
}
|
|
264
|
-
(_a = this.catchQR) === null || _a === void 0 ? void 0 : _a.call(this, result.base64Image, qr, this.attempt, result.urlCode);
|
|
265
|
-
return [2 /*return*/];
|
|
266
|
-
}
|
|
267
|
-
});
|
|
67
|
+
this.page.on('load', () => {
|
|
68
|
+
this.log('verbose', 'Page loaded', { type: 'page' });
|
|
69
|
+
this.afterPageLoad();
|
|
268
70
|
});
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
}
|
|
295
|
-
else {
|
|
296
|
-
this.log('verbose', "Waiting for Login By Code");
|
|
297
|
-
}
|
|
298
|
-
(_a = this.catchLinkCode) === null || _a === void 0 ? void 0 : _a.call(this, code);
|
|
299
|
-
return [2 /*return*/];
|
|
300
|
-
}
|
|
301
|
-
});
|
|
71
|
+
this.isInitialized = true;
|
|
72
|
+
}
|
|
73
|
+
async afterPageLoad() {
|
|
74
|
+
this.log('verbose', 'Injecting wapi.js');
|
|
75
|
+
const options = {
|
|
76
|
+
deviceName: this.options.deviceName,
|
|
77
|
+
disableGoogleAnalytics: this.options.disableGoogleAnalytics,
|
|
78
|
+
googleAnalyticsId: this.options.googleAnalyticsId,
|
|
79
|
+
linkPreviewApiServers: this.options.linkPreviewApiServers,
|
|
80
|
+
poweredBy: this.options.poweredBy,
|
|
81
|
+
};
|
|
82
|
+
await (0, helpers_1.evaluateAndReturn)(this.page, (options) => {
|
|
83
|
+
window.WPPConfig = options;
|
|
84
|
+
}, options);
|
|
85
|
+
this.isInjected = false;
|
|
86
|
+
await (0, browser_1.injectApi)(this.page, this.onLoadingScreen)
|
|
87
|
+
.then(() => {
|
|
88
|
+
this.isInjected = true;
|
|
89
|
+
this.log('verbose', 'wapi.js injected');
|
|
90
|
+
this.afterPageScriptInjected();
|
|
91
|
+
})
|
|
92
|
+
.catch((e) => {
|
|
93
|
+
console.log(e);
|
|
94
|
+
this.log('verbose', 'wapi.js failed');
|
|
95
|
+
this.log('error', e);
|
|
302
96
|
});
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
97
|
+
}
|
|
98
|
+
async afterPageScriptInjected() {
|
|
99
|
+
this.getWAVersion()
|
|
100
|
+
.then((version) => {
|
|
101
|
+
this.log('info', `WhatsApp WEB version: ${version}`);
|
|
102
|
+
})
|
|
103
|
+
.catch(() => null);
|
|
104
|
+
this.getWAJSVersion()
|
|
105
|
+
.then((version) => {
|
|
106
|
+
this.log('info', `WA-JS version: ${version}`);
|
|
107
|
+
})
|
|
108
|
+
.catch(() => null);
|
|
109
|
+
(0, helpers_1.evaluateAndReturn)(this.page, () => {
|
|
110
|
+
WPP.on('conn.auth_code_change', window.checkQrCode);
|
|
111
|
+
}).catch(() => null);
|
|
112
|
+
(0, helpers_1.evaluateAndReturn)(this.page, () => {
|
|
113
|
+
WPP.on('conn.main_ready', window.checkInChat);
|
|
114
|
+
}).catch(() => null);
|
|
115
|
+
this.checkInChat();
|
|
116
|
+
this.checkQrCode();
|
|
117
|
+
}
|
|
118
|
+
async start() {
|
|
119
|
+
if (this.isStarted) {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
this.isStarted = true;
|
|
123
|
+
await (0, browser_1.initWhatsapp)(this.page, null, false, this.options.whatsappVersion, this.options.proxy, this.log.bind(this));
|
|
124
|
+
await this.page.exposeFunction('checkQrCode', () => this.checkQrCode());
|
|
125
|
+
/*await this.page.exposeFunction('loginByCode', (phone: string) =>
|
|
126
|
+
this.loginByCode(phone)
|
|
127
|
+
);*/
|
|
128
|
+
await this.page.exposeFunction('checkInChat', () => this.checkInChat());
|
|
129
|
+
this.checkStartInterval = setInterval(() => this.checkStart(), 5000);
|
|
130
|
+
this.page.on('close', () => {
|
|
131
|
+
clearInterval(this.checkStartInterval);
|
|
322
132
|
});
|
|
323
|
-
}
|
|
324
|
-
|
|
133
|
+
}
|
|
134
|
+
async checkStart() {
|
|
135
|
+
(0, auth_1.needsToScan)(this.page)
|
|
136
|
+
.then((need) => { })
|
|
137
|
+
.catch(() => null);
|
|
138
|
+
}
|
|
139
|
+
async checkQrCode() {
|
|
140
|
+
const needScan = await (0, auth_1.needsToScan)(this.page).catch(() => null);
|
|
141
|
+
this.isLogged = !needScan;
|
|
142
|
+
if (!needScan) {
|
|
143
|
+
this.attempt = 0;
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
const result = await this.getQrCode();
|
|
147
|
+
if (!result?.urlCode || this.urlCode === result.urlCode) {
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
if (typeof this.options.phoneNumber === 'string') {
|
|
151
|
+
return this.loginByCode(this.options.phoneNumber);
|
|
152
|
+
}
|
|
153
|
+
this.urlCode = result.urlCode;
|
|
154
|
+
this.attempt++;
|
|
155
|
+
let qr = '';
|
|
156
|
+
if (this.options.logQR || this.catchQR) {
|
|
157
|
+
qr = await (0, auth_1.asciiQr)(this.urlCode);
|
|
158
|
+
}
|
|
159
|
+
if (this.options.logQR) {
|
|
160
|
+
this.log('info', `Waiting for QRCode Scan (Attempt ${this.attempt})...:\n${qr}`, { code: this.urlCode });
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
this.log('verbose', `Waiting for QRCode Scan: Attempt ${this.attempt}`);
|
|
164
|
+
}
|
|
165
|
+
this.catchQR?.(result.base64Image, qr, this.attempt, result.urlCode);
|
|
166
|
+
}
|
|
167
|
+
async loginByCode(phone) {
|
|
168
|
+
const code = await (0, helpers_1.evaluateAndReturn)(this.page, async ({ phone }) => {
|
|
169
|
+
return JSON.parse(JSON.stringify(await WPP.conn.genLinkDeviceCodeForPhoneNumber(phone)));
|
|
170
|
+
}, { phone });
|
|
171
|
+
if (this.options.logQR) {
|
|
172
|
+
this.log('info', `Waiting for Login By Code (Code: ${code})\n`);
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
this.log('verbose', `Waiting for Login By Code`);
|
|
176
|
+
}
|
|
177
|
+
this.catchLinkCode?.(code);
|
|
178
|
+
}
|
|
179
|
+
async checkInChat() {
|
|
180
|
+
const inChat = await (0, auth_1.isInsideChat)(this.page).catch(() => null);
|
|
181
|
+
this.isInChat = !!inChat;
|
|
182
|
+
if (!inChat) {
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
this.log('http', 'Connected');
|
|
186
|
+
this.statusFind?.('inChat', this.session);
|
|
187
|
+
}
|
|
188
|
+
tryAutoClose() {
|
|
325
189
|
if (this.autoCloseInterval) {
|
|
326
190
|
this.cancelAutoClose();
|
|
327
191
|
}
|
|
@@ -336,506 +200,288 @@ var HostLayer = /** @class */ (function () {
|
|
|
336
200
|
}
|
|
337
201
|
catch (error) { }
|
|
338
202
|
}
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
var _this = this;
|
|
342
|
-
if (time === void 0) { time = null; }
|
|
203
|
+
}
|
|
204
|
+
startAutoClose(time = null) {
|
|
343
205
|
if (time === null || time === undefined) {
|
|
344
206
|
time = this.options.autoClose;
|
|
345
207
|
}
|
|
346
208
|
if (time > 0 && !this.autoCloseInterval) {
|
|
347
|
-
|
|
348
|
-
this.log('info',
|
|
349
|
-
|
|
350
|
-
this.autoCloseInterval = setInterval(
|
|
351
|
-
if (
|
|
352
|
-
|
|
209
|
+
const seconds = Math.round(time / 1000);
|
|
210
|
+
this.log('info', `Auto close configured to ${seconds}s`);
|
|
211
|
+
let remain = seconds;
|
|
212
|
+
this.autoCloseInterval = setInterval(() => {
|
|
213
|
+
if (this.page.isClosed()) {
|
|
214
|
+
this.cancelAutoClose();
|
|
353
215
|
return;
|
|
354
216
|
}
|
|
355
|
-
|
|
356
|
-
if (
|
|
357
|
-
|
|
217
|
+
remain -= 1;
|
|
218
|
+
if (remain % 10 === 0 || remain <= 5) {
|
|
219
|
+
this.log('http', `Auto close remain: ${remain}s`);
|
|
358
220
|
}
|
|
359
|
-
if (
|
|
360
|
-
|
|
221
|
+
if (remain <= 0) {
|
|
222
|
+
this.tryAutoClose();
|
|
361
223
|
}
|
|
362
224
|
}, 1000);
|
|
363
225
|
}
|
|
364
|
-
}
|
|
365
|
-
|
|
226
|
+
}
|
|
227
|
+
cancelAutoClose() {
|
|
366
228
|
clearInterval(this.autoCloseInterval);
|
|
367
229
|
this.autoCloseInterval = null;
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
this.log('http', typeof this.options.phoneNumber === 'string'
|
|
481
|
-
? 'Checking Login by Code status...'
|
|
482
|
-
: 'Checking QRCode status...');
|
|
483
|
-
// Wait for interface update
|
|
484
|
-
return [4 /*yield*/, (0, sleep_1.sleep)(200)];
|
|
485
|
-
case 4:
|
|
486
|
-
// Wait for interface update
|
|
487
|
-
_g.sent();
|
|
488
|
-
return [4 /*yield*/, (0, auth_1.isAuthenticated)(this.page).catch(function () { return null; })];
|
|
489
|
-
case 5:
|
|
490
|
-
authenticated = _g.sent();
|
|
491
|
-
if (authenticated === null) {
|
|
492
|
-
this.log('warn', 'Failed to authenticate');
|
|
493
|
-
(_b = this.statusFind) === null || _b === void 0 ? void 0 : _b.call(this, 'qrReadError', this.session);
|
|
494
|
-
}
|
|
495
|
-
else if (authenticated) {
|
|
496
|
-
this.log('http', 'Login with success');
|
|
497
|
-
(_c = this.statusFind) === null || _c === void 0 ? void 0 : _c.call(this, 'qrReadSuccess', this.session);
|
|
498
|
-
}
|
|
499
|
-
else {
|
|
500
|
-
this.log('warn', 'Login Fail');
|
|
501
|
-
(_d = this.statusFind) === null || _d === void 0 ? void 0 : _d.call(this, 'qrReadFail', this.session);
|
|
502
|
-
this.tryAutoClose();
|
|
503
|
-
throw new Error('Failed to read the QRCode');
|
|
504
|
-
}
|
|
505
|
-
return [3 /*break*/, 7];
|
|
506
|
-
case 6:
|
|
507
|
-
if (authenticated === true) {
|
|
508
|
-
this.log('http', 'Authenticated');
|
|
509
|
-
(_e = this.statusFind) === null || _e === void 0 ? void 0 : _e.call(this, 'isLogged', this.session);
|
|
510
|
-
}
|
|
511
|
-
_g.label = 7;
|
|
512
|
-
case 7:
|
|
513
|
-
if (!(authenticated === true)) return [3 /*break*/, 10];
|
|
514
|
-
// Reinicia o contador do autoclose
|
|
515
|
-
this.cancelAutoClose();
|
|
516
|
-
// Wait for interface update
|
|
517
|
-
return [4 /*yield*/, (0, sleep_1.sleep)(200)];
|
|
518
|
-
case 8:
|
|
519
|
-
// Wait for interface update
|
|
520
|
-
_g.sent();
|
|
521
|
-
this.startAutoClose(this.options.deviceSyncTimeout);
|
|
522
|
-
this.log('http', 'Checking phone is connected...');
|
|
523
|
-
return [4 /*yield*/, this.waitForInChat()];
|
|
524
|
-
case 9:
|
|
525
|
-
inChat = _g.sent();
|
|
526
|
-
if (!inChat) {
|
|
527
|
-
this.log('warn', 'Phone not connected');
|
|
528
|
-
(_f = this.statusFind) === null || _f === void 0 ? void 0 : _f.call(this, 'phoneNotConnected', this.session);
|
|
529
|
-
this.tryAutoClose();
|
|
530
|
-
throw new Error('Phone not connected');
|
|
531
|
-
}
|
|
532
|
-
this.cancelAutoClose();
|
|
533
|
-
return [2 /*return*/, true];
|
|
534
|
-
case 10:
|
|
535
|
-
if (authenticated === false) {
|
|
536
|
-
this.tryAutoClose();
|
|
537
|
-
this.log('warn', 'Not logged');
|
|
538
|
-
throw new Error('Not logged');
|
|
539
|
-
}
|
|
540
|
-
this.tryAutoClose();
|
|
541
|
-
if (this.autoCloseCalled) {
|
|
542
|
-
this.log('error', 'Auto Close Called');
|
|
543
|
-
throw new Error('Auto Close Called');
|
|
544
|
-
}
|
|
545
|
-
if (this.page.isClosed()) {
|
|
546
|
-
this.log('error', 'Page Closed');
|
|
547
|
-
throw new Error('Page Closed');
|
|
548
|
-
}
|
|
549
|
-
this.log('error', 'Unknow error');
|
|
550
|
-
throw new Error('Unknow error');
|
|
551
|
-
}
|
|
552
|
-
});
|
|
553
|
-
});
|
|
554
|
-
};
|
|
230
|
+
}
|
|
231
|
+
async getQrCode() {
|
|
232
|
+
let qrResult;
|
|
233
|
+
qrResult = await (0, helpers_1.scrapeImg)(this.page).catch(() => undefined);
|
|
234
|
+
return qrResult;
|
|
235
|
+
}
|
|
236
|
+
async waitForQrCodeScan() {
|
|
237
|
+
if (!this.isStarted) {
|
|
238
|
+
throw new Error('waitForQrCodeScan error: Session not started');
|
|
239
|
+
}
|
|
240
|
+
while (!this.page.isClosed() && !this.isLogged) {
|
|
241
|
+
await (0, sleep_1.sleep)(200);
|
|
242
|
+
const needScan = await (0, auth_1.needsToScan)(this.page).catch(() => null);
|
|
243
|
+
this.isLogged = !needScan;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
async waitForInChat() {
|
|
247
|
+
if (!this.isStarted) {
|
|
248
|
+
throw new Error('waitForInChat error: Session not started');
|
|
249
|
+
}
|
|
250
|
+
if (!this.isLogged) {
|
|
251
|
+
return false;
|
|
252
|
+
}
|
|
253
|
+
const start = Date.now();
|
|
254
|
+
while (!this.page.isClosed() && this.isLogged && !this.isInChat) {
|
|
255
|
+
if (this.options.deviceSyncTimeout > 0 &&
|
|
256
|
+
Date.now() - start >= this.options.deviceSyncTimeout) {
|
|
257
|
+
return false;
|
|
258
|
+
}
|
|
259
|
+
await (0, sleep_1.sleep)(1000);
|
|
260
|
+
const inChat = (0, auth_1.isInsideChat)(this.page).catch(() => null);
|
|
261
|
+
this.isInChat = !!inChat;
|
|
262
|
+
}
|
|
263
|
+
return this.isInChat;
|
|
264
|
+
}
|
|
265
|
+
async waitForPageLoad() {
|
|
266
|
+
while (!this.isInjected) {
|
|
267
|
+
await (0, sleep_1.sleep)(200);
|
|
268
|
+
}
|
|
269
|
+
await this.page.waitForFunction(() => WPP.isReady).catch(() => { });
|
|
270
|
+
}
|
|
271
|
+
async waitForLogin() {
|
|
272
|
+
this.log('http', 'Waiting page load');
|
|
273
|
+
await this.waitForPageLoad();
|
|
274
|
+
this.log('http', 'Checking is logged...');
|
|
275
|
+
let authenticated = await (0, auth_1.isAuthenticated)(this.page).catch(() => null);
|
|
276
|
+
this.startAutoClose();
|
|
277
|
+
if (authenticated === false) {
|
|
278
|
+
this.log('http', typeof this.options.phoneNumber === 'string'
|
|
279
|
+
? 'Waiting for Login by Code...'
|
|
280
|
+
: 'Waiting for QRCode Scan...');
|
|
281
|
+
this.statusFind?.('notLogged', this.session);
|
|
282
|
+
await this.waitForQrCodeScan();
|
|
283
|
+
this.log('http', typeof this.options.phoneNumber === 'string'
|
|
284
|
+
? 'Checking Login by Code status...'
|
|
285
|
+
: 'Checking QRCode status...');
|
|
286
|
+
// Wait for interface update
|
|
287
|
+
await (0, sleep_1.sleep)(200);
|
|
288
|
+
authenticated = await (0, auth_1.isAuthenticated)(this.page).catch(() => null);
|
|
289
|
+
if (authenticated === null) {
|
|
290
|
+
this.log('warn', 'Failed to authenticate');
|
|
291
|
+
this.statusFind?.('qrReadError', this.session);
|
|
292
|
+
}
|
|
293
|
+
else if (authenticated) {
|
|
294
|
+
this.log('http', 'Login with success');
|
|
295
|
+
this.statusFind?.('qrReadSuccess', this.session);
|
|
296
|
+
}
|
|
297
|
+
else {
|
|
298
|
+
this.log('warn', 'Login Fail');
|
|
299
|
+
this.statusFind?.('qrReadFail', this.session);
|
|
300
|
+
this.tryAutoClose();
|
|
301
|
+
throw new Error('Failed to read the QRCode');
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
else if (authenticated === true) {
|
|
305
|
+
this.log('http', 'Authenticated');
|
|
306
|
+
this.statusFind?.('isLogged', this.session);
|
|
307
|
+
}
|
|
308
|
+
if (authenticated === true) {
|
|
309
|
+
// Reinicia o contador do autoclose
|
|
310
|
+
this.cancelAutoClose();
|
|
311
|
+
// Wait for interface update
|
|
312
|
+
await (0, sleep_1.sleep)(200);
|
|
313
|
+
this.startAutoClose(this.options.deviceSyncTimeout);
|
|
314
|
+
this.log('http', 'Checking phone is connected...');
|
|
315
|
+
const inChat = await this.waitForInChat();
|
|
316
|
+
if (!inChat) {
|
|
317
|
+
this.log('warn', 'Phone not connected');
|
|
318
|
+
this.statusFind?.('phoneNotConnected', this.session);
|
|
319
|
+
this.tryAutoClose();
|
|
320
|
+
throw new Error('Phone not connected');
|
|
321
|
+
}
|
|
322
|
+
this.cancelAutoClose();
|
|
323
|
+
return true;
|
|
324
|
+
}
|
|
325
|
+
if (authenticated === false) {
|
|
326
|
+
this.tryAutoClose();
|
|
327
|
+
this.log('warn', 'Not logged');
|
|
328
|
+
throw new Error('Not logged');
|
|
329
|
+
}
|
|
330
|
+
this.tryAutoClose();
|
|
331
|
+
if (this.autoCloseCalled) {
|
|
332
|
+
this.log('error', 'Auto Close Called');
|
|
333
|
+
throw new Error('Auto Close Called');
|
|
334
|
+
}
|
|
335
|
+
if (this.page.isClosed()) {
|
|
336
|
+
this.log('error', 'Page Closed');
|
|
337
|
+
throw new Error('Page Closed');
|
|
338
|
+
}
|
|
339
|
+
this.log('error', 'Unknow error');
|
|
340
|
+
throw new Error('Unknow error');
|
|
341
|
+
}
|
|
555
342
|
/**
|
|
556
343
|
* @category Host
|
|
557
344
|
* @returns Current host device details
|
|
558
345
|
*/
|
|
559
|
-
|
|
560
|
-
return
|
|
561
|
-
|
|
562
|
-
switch (_a.label) {
|
|
563
|
-
case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function () { return WAPI.getHost(); })];
|
|
564
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
565
|
-
}
|
|
566
|
-
});
|
|
567
|
-
});
|
|
568
|
-
};
|
|
346
|
+
async getHostDevice() {
|
|
347
|
+
return await (0, helpers_1.evaluateAndReturn)(this.page, () => WAPI.getHost());
|
|
348
|
+
}
|
|
569
349
|
/**
|
|
570
350
|
* @category Host
|
|
571
351
|
* @returns Current wid connected
|
|
572
352
|
*/
|
|
573
|
-
|
|
574
|
-
return
|
|
575
|
-
|
|
576
|
-
switch (_a.label) {
|
|
577
|
-
case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function () { return WAPI.getWid(); })];
|
|
578
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
579
|
-
}
|
|
580
|
-
});
|
|
581
|
-
});
|
|
582
|
-
};
|
|
353
|
+
async getWid() {
|
|
354
|
+
return await (0, helpers_1.evaluateAndReturn)(this.page, () => WAPI.getWid());
|
|
355
|
+
}
|
|
583
356
|
/**
|
|
584
357
|
* Retrieves WA version
|
|
585
358
|
* @category Host
|
|
586
359
|
*/
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
.catch(function () { return null; })];
|
|
594
|
-
case 1:
|
|
595
|
-
_a.sent();
|
|
596
|
-
return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function () { return WAPI.getWAVersion(); })];
|
|
597
|
-
case 2: return [2 /*return*/, _a.sent()];
|
|
598
|
-
}
|
|
599
|
-
});
|
|
600
|
-
});
|
|
601
|
-
};
|
|
360
|
+
async getWAVersion() {
|
|
361
|
+
await this.page
|
|
362
|
+
.waitForFunction(() => WAPI.getWAVersion())
|
|
363
|
+
.catch(() => null);
|
|
364
|
+
return await (0, helpers_1.evaluateAndReturn)(this.page, () => WAPI.getWAVersion());
|
|
365
|
+
}
|
|
602
366
|
/**
|
|
603
367
|
* Retrieves WA-JS version
|
|
604
368
|
* @category Host
|
|
605
369
|
*/
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
case 0: return [4 /*yield*/, this.page.waitForFunction(function () { return WPP.version; }).catch(function () { return null; })];
|
|
611
|
-
case 1:
|
|
612
|
-
_a.sent();
|
|
613
|
-
return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function () { return WPP.version; })];
|
|
614
|
-
case 2: return [2 /*return*/, _a.sent()];
|
|
615
|
-
}
|
|
616
|
-
});
|
|
617
|
-
});
|
|
618
|
-
};
|
|
370
|
+
async getWAJSVersion() {
|
|
371
|
+
await this.page.waitForFunction(() => WPP.version).catch(() => null);
|
|
372
|
+
return await (0, helpers_1.evaluateAndReturn)(this.page, () => WPP.version);
|
|
373
|
+
}
|
|
619
374
|
/**
|
|
620
375
|
* Retrieves the connection state
|
|
621
376
|
* @category Host
|
|
622
377
|
*/
|
|
623
|
-
|
|
624
|
-
return
|
|
625
|
-
return
|
|
626
|
-
switch (_a.label) {
|
|
627
|
-
case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function () {
|
|
628
|
-
return WPP.whatsapp.Socket.state;
|
|
629
|
-
})];
|
|
630
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
631
|
-
}
|
|
632
|
-
});
|
|
378
|
+
async getConnectionState() {
|
|
379
|
+
return await (0, helpers_1.evaluateAndReturn)(this.page, () => {
|
|
380
|
+
return WPP.whatsapp.Socket.state;
|
|
633
381
|
});
|
|
634
|
-
}
|
|
382
|
+
}
|
|
635
383
|
/**
|
|
636
384
|
* Retrieves if the phone is online. Please note that this may not be real time.
|
|
637
385
|
* @category Host
|
|
638
386
|
*/
|
|
639
|
-
|
|
640
|
-
return
|
|
641
|
-
|
|
642
|
-
switch (_a.label) {
|
|
643
|
-
case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function () { return WAPI.isConnected(); })];
|
|
644
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
645
|
-
}
|
|
646
|
-
});
|
|
647
|
-
});
|
|
648
|
-
};
|
|
387
|
+
async isConnected() {
|
|
388
|
+
return await (0, helpers_1.evaluateAndReturn)(this.page, () => WAPI.isConnected());
|
|
389
|
+
}
|
|
649
390
|
/**
|
|
650
391
|
* Check is online
|
|
651
392
|
* @category Host
|
|
652
393
|
*/
|
|
653
|
-
|
|
654
|
-
return
|
|
655
|
-
|
|
656
|
-
switch (_a.label) {
|
|
657
|
-
case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function () { return WPP.conn.isOnline(); })];
|
|
658
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
659
|
-
}
|
|
660
|
-
});
|
|
661
|
-
});
|
|
662
|
-
};
|
|
394
|
+
async isOnline() {
|
|
395
|
+
return await (0, helpers_1.evaluateAndReturn)(this.page, () => WPP.conn.isOnline());
|
|
396
|
+
}
|
|
663
397
|
/**
|
|
664
398
|
* Retrieves if the phone is online. Please note that this may not be real time.
|
|
665
399
|
* @category Host
|
|
666
400
|
*/
|
|
667
|
-
|
|
668
|
-
return
|
|
669
|
-
|
|
670
|
-
switch (_a.label) {
|
|
671
|
-
case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function () { return WAPI.isLoggedIn(); })];
|
|
672
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
673
|
-
}
|
|
674
|
-
});
|
|
675
|
-
});
|
|
676
|
-
};
|
|
401
|
+
async isLoggedIn() {
|
|
402
|
+
return await (0, helpers_1.evaluateAndReturn)(this.page, () => WAPI.isLoggedIn());
|
|
403
|
+
}
|
|
677
404
|
/**
|
|
678
405
|
* Retrieves Battery Level
|
|
679
406
|
* @category Host
|
|
680
407
|
*/
|
|
681
|
-
|
|
682
|
-
return
|
|
683
|
-
|
|
684
|
-
switch (_a.label) {
|
|
685
|
-
case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function () { return WAPI.getBatteryLevel(); })];
|
|
686
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
687
|
-
}
|
|
688
|
-
});
|
|
689
|
-
});
|
|
690
|
-
};
|
|
408
|
+
async getBatteryLevel() {
|
|
409
|
+
return await (0, helpers_1.evaluateAndReturn)(this.page, () => WAPI.getBatteryLevel());
|
|
410
|
+
}
|
|
691
411
|
/**
|
|
692
412
|
* Start phone Watchdog, forcing the phone connection verification.
|
|
693
413
|
*
|
|
694
414
|
* @category Host
|
|
695
415
|
* @param interval interval number in miliseconds
|
|
696
416
|
*/
|
|
697
|
-
|
|
698
|
-
return
|
|
699
|
-
|
|
700
|
-
return __generator(this, function (_a) {
|
|
701
|
-
switch (_a.label) {
|
|
702
|
-
case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (interval) { return WAPI.startPhoneWatchdog(interval); }, interval)];
|
|
703
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
704
|
-
}
|
|
705
|
-
});
|
|
706
|
-
});
|
|
707
|
-
};
|
|
417
|
+
async startPhoneWatchdog(interval = 15000) {
|
|
418
|
+
return await (0, helpers_1.evaluateAndReturn)(this.page, (interval) => WAPI.startPhoneWatchdog(interval), interval);
|
|
419
|
+
}
|
|
708
420
|
/**
|
|
709
421
|
* Stop phone Watchdog, more details in {@link startPhoneWatchdog}
|
|
710
422
|
* @category Host
|
|
711
423
|
*/
|
|
712
|
-
|
|
713
|
-
return
|
|
714
|
-
|
|
715
|
-
switch (_a.label) {
|
|
716
|
-
case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function () { return WAPI.stopPhoneWatchdog(); })];
|
|
717
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
718
|
-
}
|
|
719
|
-
});
|
|
720
|
-
});
|
|
721
|
-
};
|
|
424
|
+
async stopPhoneWatchdog(interval) {
|
|
425
|
+
return await (0, helpers_1.evaluateAndReturn)(this.page, () => WAPI.stopPhoneWatchdog());
|
|
426
|
+
}
|
|
722
427
|
/**
|
|
723
428
|
* Check the current session is an MultiDevice session
|
|
724
429
|
* @category Host
|
|
725
430
|
*/
|
|
726
|
-
|
|
727
|
-
return
|
|
728
|
-
|
|
729
|
-
switch (_a.label) {
|
|
730
|
-
case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function () { return WPP.conn.isMultiDevice(); })];
|
|
731
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
732
|
-
}
|
|
733
|
-
});
|
|
734
|
-
});
|
|
735
|
-
};
|
|
431
|
+
async isMultiDevice() {
|
|
432
|
+
return await (0, helpers_1.evaluateAndReturn)(this.page, () => WPP.conn.isMultiDevice());
|
|
433
|
+
}
|
|
736
434
|
/**
|
|
737
435
|
* Retrieve main interface is authenticated, loaded and synced
|
|
738
436
|
* @category Host
|
|
739
437
|
*/
|
|
740
|
-
|
|
741
|
-
return
|
|
742
|
-
|
|
743
|
-
switch (_a.label) {
|
|
744
|
-
case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function () { return WPP.conn.isMainReady(); })];
|
|
745
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
746
|
-
}
|
|
747
|
-
});
|
|
748
|
-
});
|
|
749
|
-
};
|
|
438
|
+
async isMainReady() {
|
|
439
|
+
return await (0, helpers_1.evaluateAndReturn)(this.page, () => WPP.conn.isMainReady());
|
|
440
|
+
}
|
|
750
441
|
/**
|
|
751
442
|
* Retrieve if is authenticated
|
|
752
443
|
* @category Host
|
|
753
444
|
*/
|
|
754
|
-
|
|
755
|
-
return
|
|
756
|
-
|
|
757
|
-
switch (_a.label) {
|
|
758
|
-
case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function () { return WPP.conn.isAuthenticated(); })];
|
|
759
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
760
|
-
}
|
|
761
|
-
});
|
|
762
|
-
});
|
|
763
|
-
};
|
|
445
|
+
async isAuthenticated() {
|
|
446
|
+
return await (0, helpers_1.evaluateAndReturn)(this.page, () => WPP.conn.isAuthenticated());
|
|
447
|
+
}
|
|
764
448
|
/**
|
|
765
449
|
* Retrieve if main interface is authenticated and loaded, bot not synced
|
|
766
450
|
* @category Host
|
|
767
451
|
*/
|
|
768
|
-
|
|
769
|
-
return
|
|
770
|
-
|
|
771
|
-
switch (_a.label) {
|
|
772
|
-
case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function () { return WPP.conn.isMainLoaded(); })];
|
|
773
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
774
|
-
}
|
|
775
|
-
});
|
|
776
|
-
});
|
|
777
|
-
};
|
|
452
|
+
async isMainLoaded() {
|
|
453
|
+
return await (0, helpers_1.evaluateAndReturn)(this.page, () => WPP.conn.isMainLoaded());
|
|
454
|
+
}
|
|
778
455
|
/**
|
|
779
456
|
* Retrieve if main interface is initializing
|
|
780
457
|
* @category Host
|
|
781
458
|
*/
|
|
782
|
-
|
|
783
|
-
return
|
|
784
|
-
|
|
785
|
-
switch (_a.label) {
|
|
786
|
-
case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function () { return WPP.conn.isMainInit(); })];
|
|
787
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
788
|
-
}
|
|
789
|
-
});
|
|
790
|
-
});
|
|
791
|
-
};
|
|
459
|
+
async isMainInit() {
|
|
460
|
+
return await (0, helpers_1.evaluateAndReturn)(this.page, () => WPP.conn.isMainInit());
|
|
461
|
+
}
|
|
792
462
|
/**
|
|
793
463
|
* Join or leave of WhatsApp Web beta program.
|
|
794
464
|
* Will return the value seted
|
|
795
465
|
* @category Host
|
|
796
466
|
*/
|
|
797
|
-
|
|
798
|
-
return
|
|
799
|
-
|
|
800
|
-
switch (_a.label) {
|
|
801
|
-
case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (value) { return WPP.conn.joinWebBeta(value); }, value)];
|
|
802
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
803
|
-
}
|
|
804
|
-
});
|
|
805
|
-
});
|
|
806
|
-
};
|
|
467
|
+
async joinWebBeta(value) {
|
|
468
|
+
return await (0, helpers_1.evaluateAndReturn)(this.page, (value) => WPP.conn.joinWebBeta(value), value);
|
|
469
|
+
}
|
|
807
470
|
/**
|
|
808
471
|
* Get WhatsApp build constants
|
|
809
472
|
* @category Host
|
|
810
473
|
* @returns Build constants information
|
|
811
474
|
*/
|
|
812
|
-
|
|
813
|
-
return
|
|
814
|
-
|
|
815
|
-
switch (_a.label) {
|
|
816
|
-
case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function () {
|
|
817
|
-
return WPP.conn.getBuildConstants();
|
|
818
|
-
})];
|
|
819
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
820
|
-
}
|
|
821
|
-
});
|
|
822
|
-
});
|
|
823
|
-
};
|
|
475
|
+
async getBuildConstants() {
|
|
476
|
+
return await (0, helpers_1.evaluateAndReturn)(this.page, () => WPP.conn.getBuildConstants());
|
|
477
|
+
}
|
|
824
478
|
/**
|
|
825
479
|
* Check if the account has been migrated to LID
|
|
826
480
|
* @category Host
|
|
827
481
|
* @returns true if the account has been migrated to LID, false otherwise
|
|
828
482
|
*/
|
|
829
|
-
|
|
830
|
-
return
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function () { return WPP.whatsapp.functions.isLidMigrated(); })];
|
|
834
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
835
|
-
}
|
|
836
|
-
});
|
|
837
|
-
});
|
|
838
|
-
};
|
|
839
|
-
return HostLayer;
|
|
840
|
-
}());
|
|
483
|
+
async isLidMigrated() {
|
|
484
|
+
return await (0, helpers_1.evaluateAndReturn)(this.page, () => WPP.whatsapp.functions.isLidMigrated());
|
|
485
|
+
}
|
|
486
|
+
}
|
|
841
487
|
exports.HostLayer = HostLayer;
|