@open-wa/wa-automate 4.31.11 → 4.32.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/api/Client.d.ts
CHANGED
@@ -824,10 +824,10 @@ export declare class Client {
|
|
824
824
|
isConnected(): Promise<boolean>;
|
825
825
|
/**
|
826
826
|
* Logs out from the session.
|
827
|
-
*
|
827
|
+
* @param preserveSessionData skip session.data.json file invalidation
|
828
828
|
* Please be careful when using this as it can exit the whole process depending on your config
|
829
829
|
*/
|
830
|
-
logout(): Promise<boolean>;
|
830
|
+
logout(preserveSessionData?: boolean): Promise<boolean>;
|
831
831
|
/**
|
832
832
|
* Retrieves Battery Level
|
833
833
|
* @returns Number
|
@@ -1042,6 +1042,24 @@ export declare class Client {
|
|
1042
1042
|
* @returns message object
|
1043
1043
|
*/
|
1044
1044
|
getMyLastMessage(chatId?: ChatId): Promise<Message>;
|
1045
|
+
/**
|
1046
|
+
* Retrieves the starred messages in a given chat
|
1047
|
+
* @param chatId Chat ID to filter starred messages by
|
1048
|
+
* @returns message object
|
1049
|
+
*/
|
1050
|
+
getStarredMessages(chatId?: ChatId): Promise<Message[]>;
|
1051
|
+
/**
|
1052
|
+
* Star a message
|
1053
|
+
* @param messageId Message ID of the message you want to star
|
1054
|
+
* @returns `true`
|
1055
|
+
*/
|
1056
|
+
starMessage(messageId?: ChatId): Promise<boolean>;
|
1057
|
+
/**
|
1058
|
+
* Unstar a message
|
1059
|
+
* @param messageId Message ID of the message you want to unstar
|
1060
|
+
* @returns `true`
|
1061
|
+
*/
|
1062
|
+
unstarMessage(messageId?: ChatId): Promise<boolean>;
|
1045
1063
|
/**
|
1046
1064
|
*
|
1047
1065
|
* [REQUIRES AN INSIDERS LICENSE-KEY](https://gum.co/open-wa?tier=Insiders%20Program)
|
package/dist/api/Client.js
CHANGED
@@ -266,6 +266,7 @@ class Client {
|
|
266
266
|
this.onLogout(() => __awaiter(this, void 0, void 0, function* () {
|
267
267
|
var _k, _l;
|
268
268
|
yield this.waitAllQEmpty();
|
269
|
+
yield (0, browser_1.invalidateSesssionData)(this._createConfig);
|
269
270
|
if ((_k = this._createConfig) === null || _k === void 0 ? void 0 : _k.deleteSessionDataOnLogout)
|
270
271
|
(0, browser_1.deleteSessionData)(this._createConfig);
|
271
272
|
if ((_l = this._createConfig) === null || _l === void 0 ? void 0 : _l.killClientOnLogout) {
|
@@ -1882,11 +1883,15 @@ class Client {
|
|
1882
1883
|
}
|
1883
1884
|
/**
|
1884
1885
|
* Logs out from the session.
|
1885
|
-
*
|
1886
|
+
* @param preserveSessionData skip session.data.json file invalidation
|
1886
1887
|
* Please be careful when using this as it can exit the whole process depending on your config
|
1887
1888
|
*/
|
1888
|
-
logout() {
|
1889
|
+
logout(preserveSessionData = false) {
|
1889
1890
|
return __awaiter(this, void 0, void 0, function* () {
|
1891
|
+
if (!preserveSessionData) {
|
1892
|
+
logging_1.log.info(`LOGOUT CALLED. INVALIDATING SESSION DATA`);
|
1893
|
+
yield (0, browser_1.invalidateSesssionData)(this._createConfig);
|
1894
|
+
}
|
1890
1895
|
return yield this.pup(() => WAPI.logout());
|
1891
1896
|
});
|
1892
1897
|
}
|
@@ -2228,6 +2233,36 @@ class Client {
|
|
2228
2233
|
return yield this.pup(chatId => WAPI.getMyLastMessage(chatId), chatId);
|
2229
2234
|
});
|
2230
2235
|
}
|
2236
|
+
/**
|
2237
|
+
* Retrieves the starred messages in a given chat
|
2238
|
+
* @param chatId Chat ID to filter starred messages by
|
2239
|
+
* @returns message object
|
2240
|
+
*/
|
2241
|
+
getStarredMessages(chatId) {
|
2242
|
+
return __awaiter(this, void 0, void 0, function* () {
|
2243
|
+
return yield this.pup(chatId => WAPI.getStarredMessages(chatId), chatId);
|
2244
|
+
});
|
2245
|
+
}
|
2246
|
+
/**
|
2247
|
+
* Star a message
|
2248
|
+
* @param messageId Message ID of the message you want to star
|
2249
|
+
* @returns `true`
|
2250
|
+
*/
|
2251
|
+
starMessage(messageId) {
|
2252
|
+
return __awaiter(this, void 0, void 0, function* () {
|
2253
|
+
return yield this.pup(messageId => WAPI.starMessage(messageId), messageId);
|
2254
|
+
});
|
2255
|
+
}
|
2256
|
+
/**
|
2257
|
+
* Unstar a message
|
2258
|
+
* @param messageId Message ID of the message you want to unstar
|
2259
|
+
* @returns `true`
|
2260
|
+
*/
|
2261
|
+
unstarMessage(messageId) {
|
2262
|
+
return __awaiter(this, void 0, void 0, function* () {
|
2263
|
+
return yield this.pup(messageId => WAPI.unstarMessage(messageId), messageId);
|
2264
|
+
});
|
2265
|
+
}
|
2231
2266
|
/**
|
2232
2267
|
*
|
2233
2268
|
* [REQUIRES AN INSIDERS LICENSE-KEY](https://gum.co/open-wa?tier=Insiders%20Program)
|
@@ -5,7 +5,8 @@ import { QRManager } from './auth';
|
|
5
5
|
export declare let BROWSER_START_TS: number;
|
6
6
|
export declare function initPage(sessionId?: string, config?: ConfigObject, qrManager?: QRManager, customUserAgent?: string, spinner?: Spin, _page?: Page, skipAuth?: boolean): Promise<Page>;
|
7
7
|
export declare const deleteSessionData: (config: ConfigObject) => boolean;
|
8
|
-
export declare const
|
8
|
+
export declare const invalidateSesssionData: (config: ConfigObject) => boolean;
|
9
|
+
export declare const getSessionDataFilePath: (sessionId: string, config: ConfigObject) => string | false;
|
9
10
|
export declare const addScript: (page: Page, js: string) => Promise<unknown>;
|
10
11
|
export declare function injectPreApiScripts(page: Page, spinner?: Spin): Promise<Page>;
|
11
12
|
export declare function injectWapi(page: Page, spinner?: Spin, force?: boolean): Promise<Page>;
|
@@ -31,7 +31,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
31
31
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
32
32
|
};
|
33
33
|
Object.defineProperty(exports, "__esModule", { value: true });
|
34
|
-
exports.kill = exports.injectApi = exports.injectWapi = exports.injectPreApiScripts = exports.addScript = exports.getSessionDataFilePath = exports.deleteSessionData = exports.initPage = exports.BROWSER_START_TS = void 0;
|
34
|
+
exports.kill = exports.injectApi = exports.injectWapi = exports.injectPreApiScripts = exports.addScript = exports.getSessionDataFilePath = exports.invalidateSesssionData = exports.deleteSessionData = exports.initPage = exports.BROWSER_START_TS = void 0;
|
35
35
|
const path = __importStar(require("path"));
|
36
36
|
const fs = __importStar(require("fs"));
|
37
37
|
const death_1 = __importDefault(require("death"));
|
@@ -52,7 +52,7 @@ function initPage(sessionId, config, qrManager, customUserAgent, spinner, _page,
|
|
52
52
|
var _a, _b, _c, _d, _e;
|
53
53
|
return __awaiter(this, void 0, void 0, function* () {
|
54
54
|
const setupPromises = [];
|
55
|
-
script_preloader_1.scriptLoader.loadScripts();
|
55
|
+
yield script_preloader_1.scriptLoader.loadScripts();
|
56
56
|
if ((config === null || config === void 0 ? void 0 : config.resizable) === undefined || !(config === null || config === void 0 ? void 0 : config.resizable) == false)
|
57
57
|
config.defaultViewport = null;
|
58
58
|
if (config === null || config === void 0 ? void 0 : config.useStealth) {
|
@@ -268,7 +268,7 @@ const getSessionDataFromFile = (sessionId, config, spinner) => {
|
|
268
268
|
sessionjson = JSON.parse(Buffer.from(s, 'base64').toString('ascii'));
|
269
269
|
}
|
270
270
|
catch (error) {
|
271
|
-
const msg = "Session data json file is corrupted. Please
|
271
|
+
const msg = `${s == "LOGGED OUT" ? "The session was logged out" : "Session data json file is corrupted"}. Please re-scan the QR code.`;
|
272
272
|
if (spinner) {
|
273
273
|
spinner.fail(msg);
|
274
274
|
}
|
@@ -294,6 +294,22 @@ const deleteSessionData = (config) => {
|
|
294
294
|
return true;
|
295
295
|
};
|
296
296
|
exports.deleteSessionData = deleteSessionData;
|
297
|
+
const invalidateSesssionData = (config) => {
|
298
|
+
const sessionjsonpath = (0, exports.getSessionDataFilePath)((config === null || config === void 0 ? void 0 : config.sessionId) || 'session', config);
|
299
|
+
if (typeof sessionjsonpath == 'string' && fs.existsSync(sessionjsonpath)) {
|
300
|
+
const l = `logout detected, invalidating session data file: ${sessionjsonpath}`;
|
301
|
+
console.log(l);
|
302
|
+
logging_1.log.info(l);
|
303
|
+
fs.writeFile(sessionjsonpath, "LOGGED OUT", (err) => {
|
304
|
+
if (err) {
|
305
|
+
console.error(err);
|
306
|
+
return;
|
307
|
+
}
|
308
|
+
});
|
309
|
+
}
|
310
|
+
return true;
|
311
|
+
};
|
312
|
+
exports.invalidateSesssionData = invalidateSesssionData;
|
297
313
|
const getSessionDataFilePath = (sessionId, config) => {
|
298
314
|
var _a, _b;
|
299
315
|
const p = ((_a = require === null || require === void 0 ? void 0 : require.main) === null || _a === void 0 ? void 0 : _a.path) || ((_b = process === null || process === void 0 ? void 0 : process.mainModule) === null || _b === void 0 ? void 0 : _b.path);
|
@@ -338,7 +354,7 @@ function injectWapi(page, spinner, force = false) {
|
|
338
354
|
if (initCheck)
|
339
355
|
return;
|
340
356
|
logging_1.log.info(`WAPI CHECK: ${initCheck}`);
|
341
|
-
if (!
|
357
|
+
if (!initCheck)
|
342
358
|
force = true;
|
343
359
|
if (wapiInjected && !force)
|
344
360
|
return page;
|
@@ -66,8 +66,10 @@ class ScriptLoader {
|
|
66
66
|
return __awaiter(this, void 0, void 0, function* () {
|
67
67
|
if (!this.contentRegistry[scriptName]) {
|
68
68
|
this.contentRegistry[scriptName] = yield read(scriptName);
|
69
|
-
logging_1.log.info(
|
69
|
+
logging_1.log.info(`SCRIPT READY: ${scriptName} ${this.contentRegistry[scriptName].length}`);
|
70
70
|
}
|
71
|
+
else
|
72
|
+
logging_1.log.info(`GET SCRIPT: ${scriptName} ${this.contentRegistry[scriptName].length}`);
|
71
73
|
return this.contentRegistry[scriptName];
|
72
74
|
});
|
73
75
|
}
|
package/package.json
CHANGED