@open-wa/wa-automate 4.31.12 → 4.32.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.
@@ -689,9 +689,13 @@ export declare class Client {
689
689
  */
690
690
  getSnapshot(): Promise<DataURL>;
691
691
  /**
692
- * Returns an array of group ids where the host device is admin
692
+ * Returns an array of group ids where the host account is admin
693
693
  */
694
694
  iAmAdmin(): Promise<GroupChatId[]>;
695
+ /**
696
+ * Returns an array of group ids where the host account has been kicked
697
+ */
698
+ getKickedGroups(): Promise<GroupChatId[]>;
695
699
  /**
696
700
  * Syncs contacts with phone. This promise does not resolve so it will instantly return true.
697
701
  */
@@ -824,10 +828,10 @@ export declare class Client {
824
828
  isConnected(): Promise<boolean>;
825
829
  /**
826
830
  * Logs out from the session.
827
- *
831
+ * @param preserveSessionData skip session.data.json file invalidation
828
832
  * Please be careful when using this as it can exit the whole process depending on your config
829
833
  */
830
- logout(): Promise<boolean>;
834
+ logout(preserveSessionData?: boolean): Promise<boolean>;
831
835
  /**
832
836
  * Retrieves Battery Level
833
837
  * @returns Number
@@ -1042,6 +1046,24 @@ export declare class Client {
1042
1046
  * @returns message object
1043
1047
  */
1044
1048
  getMyLastMessage(chatId?: ChatId): Promise<Message>;
1049
+ /**
1050
+ * Retrieves the starred messages in a given chat
1051
+ * @param chatId Chat ID to filter starred messages by
1052
+ * @returns message object
1053
+ */
1054
+ getStarredMessages(chatId?: ChatId): Promise<Message[]>;
1055
+ /**
1056
+ * Star a message
1057
+ * @param messageId Message ID of the message you want to star
1058
+ * @returns `true`
1059
+ */
1060
+ starMessage(messageId?: ChatId): Promise<boolean>;
1061
+ /**
1062
+ * Unstar a message
1063
+ * @param messageId Message ID of the message you want to unstar
1064
+ * @returns `true`
1065
+ */
1066
+ unstarMessage(messageId?: ChatId): Promise<boolean>;
1045
1067
  /**
1046
1068
  *
1047
1069
  * [REQUIRES AN INSIDERS LICENSE-KEY](https://gum.co/open-wa?tier=Insiders%20Program)
@@ -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) {
@@ -1664,13 +1665,21 @@ class Client {
1664
1665
  });
1665
1666
  }
1666
1667
  /**
1667
- * Returns an array of group ids where the host device is admin
1668
+ * Returns an array of group ids where the host account is admin
1668
1669
  */
1669
1670
  iAmAdmin() {
1670
1671
  return __awaiter(this, void 0, void 0, function* () {
1671
1672
  return yield this.pup(() => WAPI.iAmAdmin());
1672
1673
  });
1673
1674
  }
1675
+ /**
1676
+ * Returns an array of group ids where the host account has been kicked
1677
+ */
1678
+ getKickedGroups() {
1679
+ return __awaiter(this, void 0, void 0, function* () {
1680
+ return yield this.pup(() => WAPI.getKickedGroups());
1681
+ });
1682
+ }
1674
1683
  /**
1675
1684
  * Syncs contacts with phone. This promise does not resolve so it will instantly return true.
1676
1685
  */
@@ -1882,11 +1891,15 @@ class Client {
1882
1891
  }
1883
1892
  /**
1884
1893
  * Logs out from the session.
1885
- *
1894
+ * @param preserveSessionData skip session.data.json file invalidation
1886
1895
  * Please be careful when using this as it can exit the whole process depending on your config
1887
1896
  */
1888
- logout() {
1897
+ logout(preserveSessionData = false) {
1889
1898
  return __awaiter(this, void 0, void 0, function* () {
1899
+ if (!preserveSessionData) {
1900
+ logging_1.log.info(`LOGOUT CALLED. INVALIDATING SESSION DATA`);
1901
+ yield (0, browser_1.invalidateSesssionData)(this._createConfig);
1902
+ }
1890
1903
  return yield this.pup(() => WAPI.logout());
1891
1904
  });
1892
1905
  }
@@ -2228,6 +2241,36 @@ class Client {
2228
2241
  return yield this.pup(chatId => WAPI.getMyLastMessage(chatId), chatId);
2229
2242
  });
2230
2243
  }
2244
+ /**
2245
+ * Retrieves the starred messages in a given chat
2246
+ * @param chatId Chat ID to filter starred messages by
2247
+ * @returns message object
2248
+ */
2249
+ getStarredMessages(chatId) {
2250
+ return __awaiter(this, void 0, void 0, function* () {
2251
+ return yield this.pup(chatId => WAPI.getStarredMessages(chatId), chatId);
2252
+ });
2253
+ }
2254
+ /**
2255
+ * Star a message
2256
+ * @param messageId Message ID of the message you want to star
2257
+ * @returns `true`
2258
+ */
2259
+ starMessage(messageId) {
2260
+ return __awaiter(this, void 0, void 0, function* () {
2261
+ return yield this.pup(messageId => WAPI.starMessage(messageId), messageId);
2262
+ });
2263
+ }
2264
+ /**
2265
+ * Unstar a message
2266
+ * @param messageId Message ID of the message you want to unstar
2267
+ * @returns `true`
2268
+ */
2269
+ unstarMessage(messageId) {
2270
+ return __awaiter(this, void 0, void 0, function* () {
2271
+ return yield this.pup(messageId => WAPI.unstarMessage(messageId), messageId);
2272
+ });
2273
+ }
2231
2274
  /**
2232
2275
  *
2233
2276
  * [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 getSessionDataFilePath: (sessionId: string, config: ConfigObject) => string | boolean;
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"));
@@ -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 reauthenticate.";
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);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-wa/wa-automate",
3
- "version": "4.31.12",
3
+ "version": "4.32.1",
4
4
  "licenseCheckUrl": "https://funcs.openwa.dev/license-check",
5
5
  "brokenMethodReportUrl": "https://funcs.openwa.dev/report-bm",
6
6
  "patches": "https://cdn.openwa.dev/patches.json",