@open-wa/wa-automate 4.28.2 → 4.28.6
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/dist/api/Client.d.ts +7 -1
- package/dist/api/Client.js +16 -3
- package/dist/cli/integrations/chatwoot.js +1 -1
- package/dist/controllers/auth.js +3 -4
- package/dist/controllers/browser.d.ts +1 -1
- package/dist/controllers/browser.js +6 -1
- package/dist/utils/tools.d.ts +2 -0
- package/dist/utils/tools.js +13 -1
- package/package.json +1 -1
package/dist/api/Client.d.ts
CHANGED
@@ -397,7 +397,7 @@ export declare class Client {
|
|
397
397
|
* Shuts down the page and browser
|
398
398
|
* @returns true
|
399
399
|
*/
|
400
|
-
kill(): Promise<boolean>;
|
400
|
+
kill(reason?: string): Promise<boolean>;
|
401
401
|
/**
|
402
402
|
* This is a convinient method to click the `Use Here` button in the WA web session.
|
403
403
|
*
|
@@ -799,6 +799,12 @@ export declare class Client {
|
|
799
799
|
* @returns Boolean
|
800
800
|
*/
|
801
801
|
isConnected(): Promise<boolean>;
|
802
|
+
/**
|
803
|
+
* Logs out from the session.
|
804
|
+
*
|
805
|
+
* Please be careful when using this as it can exit the whole process depending on your config
|
806
|
+
*/
|
807
|
+
logout(): Promise<boolean>;
|
802
808
|
/**
|
803
809
|
* Retrieves Battery Level
|
804
810
|
* @returns Number
|
package/dist/api/Client.js
CHANGED
@@ -267,7 +267,7 @@ class Client {
|
|
267
267
|
if ((_b = this._createConfig) === null || _b === void 0 ? void 0 : _b.killClientOnLogout) {
|
268
268
|
console.log("Session logged out. Killing client");
|
269
269
|
logging_1.log.warn("Session logged out. Killing client");
|
270
|
-
this.kill();
|
270
|
+
this.kill("LOGGED_OUT");
|
271
271
|
}
|
272
272
|
});
|
273
273
|
}
|
@@ -290,7 +290,7 @@ class Client {
|
|
290
290
|
if (!this._refreshing) {
|
291
291
|
console.log("Browser page has closed. Killing client");
|
292
292
|
logging_1.log.warn("Browser page has closed. Killing client");
|
293
|
-
this.kill();
|
293
|
+
this.kill("PAGE_CLOSED");
|
294
294
|
if ((_a = this._createConfig) === null || _a === void 0 ? void 0 : _a.killProcessOnBrowserClose)
|
295
295
|
process.exit();
|
296
296
|
}
|
@@ -1038,7 +1038,7 @@ class Client {
|
|
1038
1038
|
* Shuts down the page and browser
|
1039
1039
|
* @returns true
|
1040
1040
|
*/
|
1041
|
-
kill() {
|
1041
|
+
kill(reason = "MANUALLY_KILLED") {
|
1042
1042
|
var _a, _b, _c, _d, _e, _f, _g;
|
1043
1043
|
return __awaiter(this, void 0, void 0, function* () {
|
1044
1044
|
if (this._currentlyBeingKilled)
|
@@ -1046,6 +1046,9 @@ class Client {
|
|
1046
1046
|
this._currentlyBeingKilled = true;
|
1047
1047
|
console.log('Killing client. Shutting Down');
|
1048
1048
|
logging_1.log.info('Killing client. Shutting Down');
|
1049
|
+
(0, tools_1.processSendData)({
|
1050
|
+
reason
|
1051
|
+
});
|
1049
1052
|
const browser = yield ((_a = this === null || this === void 0 ? void 0 : this._page) === null || _a === void 0 ? void 0 : _a.browser());
|
1050
1053
|
const pid = (browser === null || browser === void 0 ? void 0 : browser.process()) ? (_b = browser === null || browser === void 0 ? void 0 : browser.process()) === null || _b === void 0 ? void 0 : _b.pid : null;
|
1051
1054
|
try {
|
@@ -1807,6 +1810,16 @@ class Client {
|
|
1807
1810
|
return yield this.pup(() => WAPI.isConnected());
|
1808
1811
|
});
|
1809
1812
|
}
|
1813
|
+
/**
|
1814
|
+
* Logs out from the session.
|
1815
|
+
*
|
1816
|
+
* Please be careful when using this as it can exit the whole process depending on your config
|
1817
|
+
*/
|
1818
|
+
logout() {
|
1819
|
+
return __awaiter(this, void 0, void 0, function* () {
|
1820
|
+
return yield this.pup(() => WAPI.logout());
|
1821
|
+
});
|
1822
|
+
}
|
1810
1823
|
/**
|
1811
1824
|
* Retrieves Battery Level
|
1812
1825
|
* @returns Number
|
@@ -84,7 +84,7 @@ const setupChatwootOutgoingMessageHandler = (cliConfig, client) => __awaiter(voi
|
|
84
84
|
const _u = new URL(u);
|
85
85
|
const origin = _u.origin;
|
86
86
|
const port = _u.port || 80;
|
87
|
-
const [accountId, inboxId] = u.match(/\/(app|(api\/v1))\/accounts\/\d*\/inbox\/\d*/g)[0].split('/').filter(Number);
|
87
|
+
const [accountId, inboxId] = u.match(/\/(app|(api\/v1))\/accounts\/\d*\/(inbox|inboxes)\/\d*/g)[0].split('/').filter(Number);
|
88
88
|
// const accountId = u.match(/accounts\/\d*/g) && u.match(/accounts\/\d*/g)[0].replace('accounts/', '')
|
89
89
|
const resolvedInbox = inboxId || u.match(/inboxes\/\d*/g) && u.match(/inboxes\/\d*/g)[0].replace('inboxes/', '');
|
90
90
|
const cwReq = (path, method, data, _headers) => {
|
package/dist/controllers/auth.js
CHANGED
@@ -40,7 +40,6 @@ const tools_1 = require("../utils/tools");
|
|
40
40
|
const browser_1 = require("./browser");
|
41
41
|
const axios_1 = __importDefault(require("axios"));
|
42
42
|
const logging_1 = require("../logging/logging");
|
43
|
-
const timeout = ms => new Promise(resolve => setTimeout(resolve, ms, 'timeout'));
|
44
43
|
/**
|
45
44
|
* Validates if client is authenticated
|
46
45
|
* @returns true if is authenticated, false otherwise
|
@@ -131,8 +130,8 @@ function smartQr(waPage, config, spinner) {
|
|
131
130
|
qrNum++;
|
132
131
|
(0, tools_1.processSend)('ready');
|
133
132
|
if (config.qrMax && qrNum >= config.qrMax) {
|
134
|
-
spinner.info('QR Code limit reached, exiting');
|
135
|
-
yield (0, browser_1.kill)(waPage, null, true);
|
133
|
+
spinner.info('QR Code limit reached, exiting...');
|
134
|
+
yield (0, browser_1.kill)(waPage, null, true, null, "QR_LIMIT_REACHED");
|
136
135
|
}
|
137
136
|
if (config.ezqr || config.inDocker) {
|
138
137
|
const host = 'https://qr.openwa.cloud/';
|
@@ -168,7 +167,7 @@ function smartQr(waPage, config, spinner) {
|
|
168
167
|
const _hasDefaultStateYet = yield waPage.evaluate("!!(window.Store && window.Store.State && window.Store.State.Socket)");
|
169
168
|
if (!_hasDefaultStateYet) {
|
170
169
|
//expecting issue, take a screenshot then wait a few seconds before continuing
|
171
|
-
yield timeout(2000);
|
170
|
+
yield (0, tools_1.timeout)(2000);
|
172
171
|
}
|
173
172
|
return new Promise((resolve) => __awaiter(this, void 0, void 0, function* () {
|
174
173
|
const funcName = '_smartQr';
|
@@ -9,4 +9,4 @@ export declare function injectApi(page: Page): Promise<Page>;
|
|
9
9
|
/**
|
10
10
|
* @internal
|
11
11
|
*/
|
12
|
-
export declare const kill: (p: Page, b?: Browser, exit?: boolean, pid?: number) => Promise<void>;
|
12
|
+
export declare const kill: (p: Page, b?: Browser, exit?: boolean, pid?: number, reason?: string) => Promise<void>;
|
@@ -43,6 +43,7 @@ const pico_s3_1 = require("pico-s3");
|
|
43
43
|
const puppeteer = require('puppeteer-extra');
|
44
44
|
const tree_kill_1 = __importDefault(require("tree-kill"));
|
45
45
|
const logging_1 = require("../logging/logging");
|
46
|
+
const tools_1 = require("../utils/tools");
|
46
47
|
let browser;
|
47
48
|
function initPage(sessionId, config, customUserAgent, spinner, _page, skipAuth) {
|
48
49
|
var _a, _b, _c, _d, _e;
|
@@ -377,7 +378,11 @@ function getWAPage(browser) {
|
|
377
378
|
/**
|
378
379
|
* @internal
|
379
380
|
*/
|
380
|
-
const kill = (p, b, exit, pid) => __awaiter(void 0, void 0, void 0, function* () {
|
381
|
+
const kill = (p, b, exit, pid, reason = "LAUNCH_KILL") => __awaiter(void 0, void 0, void 0, function* () {
|
382
|
+
(0, tools_1.processSendData)({
|
383
|
+
reason
|
384
|
+
});
|
385
|
+
(0, tools_1.timeout)(3000);
|
381
386
|
const killBrowser = (browser) => __awaiter(void 0, void 0, void 0, function* () {
|
382
387
|
if (!browser)
|
383
388
|
return;
|
package/dist/utils/tools.d.ts
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
import { DataURL } from '../api/model';
|
2
2
|
import { AxiosRequestConfig } from 'axios';
|
3
|
+
export declare const timeout: (ms: any) => Promise<unknown>;
|
3
4
|
/**
|
4
5
|
* Use this to generate a more likely valid user agent. It makes sure it has the WA part and replaces any windows or linux os info with mac.
|
5
6
|
* @param useragent Your custom user agent
|
@@ -25,3 +26,4 @@ export declare const getDUrl: (url: string, optionsOverride?: AxiosRequestConfig
|
|
25
26
|
*/
|
26
27
|
export declare const base64MimeType: (dUrl: DataURL) => string;
|
27
28
|
export declare const processSend: (message: string) => void;
|
29
|
+
export declare const processSendData: (data?: any) => void;
|
package/dist/utils/tools.js
CHANGED
@@ -23,8 +23,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
23
23
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
24
24
|
};
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
26
|
-
exports.processSend = exports.base64MimeType = exports.getDUrl = exports.isDataURL = exports.isBase64 = exports.camelize = exports.without = exports.getConfigFromProcessEnv = exports.smartUserAgent = void 0;
|
26
|
+
exports.processSendData = exports.processSend = exports.base64MimeType = exports.getDUrl = exports.isDataURL = exports.isBase64 = exports.camelize = exports.without = exports.getConfigFromProcessEnv = exports.smartUserAgent = exports.timeout = void 0;
|
27
27
|
const axios_1 = __importDefault(require("axios"));
|
28
|
+
//@ts-ignore
|
29
|
+
process.send = process.send || function () { };
|
30
|
+
const timeout = ms => new Promise(resolve => setTimeout(resolve, ms, 'timeout'));
|
31
|
+
exports.timeout = timeout;
|
28
32
|
/**
|
29
33
|
* Use this to generate a more likely valid user agent. It makes sure it has the WA part and replaces any windows or linux os info with mac.
|
30
34
|
* @param useragent Your custom user agent
|
@@ -133,3 +137,11 @@ const processSend = (message) => {
|
|
133
137
|
return;
|
134
138
|
};
|
135
139
|
exports.processSend = processSend;
|
140
|
+
const processSendData = (data = {}) => {
|
141
|
+
process.send({
|
142
|
+
type: 'process:msg',
|
143
|
+
data
|
144
|
+
});
|
145
|
+
return;
|
146
|
+
};
|
147
|
+
exports.processSendData = processSendData;
|
package/package.json
CHANGED