@open-wa/wa-automate 4.41.0 → 4.42.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.
@@ -458,7 +458,7 @@ export declare class Client {
458
458
  *
459
459
  * [[Detecting Logouts]]
460
460
  */
461
- forceRefocus(): Promise<void>;
461
+ forceRefocus(): Promise<boolean>;
462
462
  /**
463
463
  * Check if the "Phone not Cconnected" message is showing in the browser. If it is showing, then this will return `true`.
464
464
  *
@@ -469,6 +469,10 @@ export declare class Client {
469
469
  * Runs a health check to help you determine if/when is an appropiate time to restart/refresh the session.
470
470
  */
471
471
  healthCheck(): Promise<HealthCheck>;
472
+ /**
473
+ * Get the stats of the current process and the corresponding browser process.
474
+ */
475
+ getProcessStats(): Promise<any>;
472
476
  /**
473
477
  * A list of participants in the chat who have their live location on. If the chat does not exist, or the chat does not have any contacts actively sharing their live locations, it will return false. If it's a chat with a single contact, there will be only 1 value in the array if the contact has their livelocation on.
474
478
  * Please note. This should only be called once every 30 or so seconds. This forces the phone to grab the latest live location data for the number. This can be used in conjunction with onLiveLocation (this will trigger onLiveLocation).
@@ -566,8 +570,10 @@ export declare class Client {
566
570
  * @param to chat id: `xxxxx@c.us`
567
571
  * @param content text message
568
572
  * @param replyMessageId id of message to reply to
573
+ * @param hideTags Removes all tags within the message
574
+ * @param mentions You can optionally add an array of contact IDs to tag only specific people
569
575
  */
570
- sendReplyWithMentions(to: ChatId, content: Content, replyMessageId: MessageId): Promise<boolean | MessageId>;
576
+ sendReplyWithMentions(to: ChatId, content: Content, replyMessageId: MessageId, hideTags?: boolean, mentions?: ContactId[]): Promise<boolean | MessageId>;
571
577
  /**
572
578
  * [REQUIRES AN INSIDERS LICENSE-KEY](https://gum.co/open-wa?tier=Insiders%20Program)
573
579
  *
@@ -68,6 +68,7 @@ const init_patch_1 = require("../controllers/init_patch");
68
68
  const preProcessors_1 = require("../structures/preProcessors");
69
69
  const tools_1 = require("../utils/tools");
70
70
  const logging_1 = require("../logging/logging");
71
+ const pid_utils_1 = require("../utils/pid_utils");
71
72
  /** @ignore */
72
73
  const pkg = (0, fs_extra_1.readJsonSync)(path.join(__dirname, '../../package.json'));
73
74
  var namespace;
@@ -191,9 +192,11 @@ class Client {
191
192
  const rb = (req === null || req === void 0 ? void 0 : req.body) || {};
192
193
  let { args } = rb;
193
194
  const m = (rb === null || rb === void 0 ? void 0 : rb.method) || this._createConfig.sessionId && this._createConfig.sessionId !== 'session' && req.path.includes(this._createConfig.sessionId) ? req.path.replace(`/${this._createConfig.sessionId}/`, '') : req.path.replace('/', '');
195
+ logging_1.log.info(`MDLWR - ${m} : ${JSON.stringify(rb || {})}`);
194
196
  let methodRequiresArgs = false;
195
197
  if (args && !Array.isArray(args)) {
196
198
  const methodArgs = (0, parse_function_1.default)().parse(this[m]).args;
199
+ logging_1.log.info(`methodArgs: ${methodArgs}`);
197
200
  if ((methodArgs === null || methodArgs === void 0 ? void 0 : methodArgs.length) > 0)
198
201
  methodRequiresArgs = true;
199
202
  args = methodArgs.map(argName => args[argName]);
@@ -1223,7 +1226,8 @@ class Client {
1223
1226
  return __awaiter(this, void 0, void 0, function* () {
1224
1227
  const useHere = yield this._page.evaluate(() => WAPI.getUseHereString());
1225
1228
  yield this._page.waitForFunction(`[...document.querySelectorAll("div[role=button")].find(e=>{return e.innerHTML.toLowerCase().includes("${useHere.toLowerCase()}")})`, { timeout: 0 });
1226
- return yield this._page.evaluate(`[...document.querySelectorAll("div[role=button")].find(e=>{return e.innerHTML.toLowerCase().includes("${useHere.toLowerCase()}")}).click()`);
1229
+ yield this._page.evaluate(`[...document.querySelectorAll("div[role=button")].find(e=>{return e.innerHTML.toLowerCase().includes("${useHere.toLowerCase()}")}).click()`);
1230
+ return true;
1227
1231
  });
1228
1232
  }
1229
1233
  /**
@@ -1234,6 +1238,7 @@ class Client {
1234
1238
  isPhoneDisconnected() {
1235
1239
  return __awaiter(this, void 0, void 0, function* () {
1236
1240
  const phoneNotConnected = yield this._page.evaluate(() => WAPI.getLocaledString('active Internet connection'));
1241
+ //@ts-ignore
1237
1242
  return yield this.pup(`!![...document.querySelectorAll("div")].find(e=>{return e.innerHTML.toLowerCase().includes("${phoneNotConnected.toLowerCase()}")})`);
1238
1243
  });
1239
1244
  }
@@ -1245,6 +1250,14 @@ class Client {
1245
1250
  return yield this._page.evaluate(() => WAPI.healthCheck());
1246
1251
  });
1247
1252
  }
1253
+ /**
1254
+ * Get the stats of the current process and the corresponding browser process.
1255
+ */
1256
+ getProcessStats() {
1257
+ return __awaiter(this, void 0, void 0, function* () {
1258
+ return yield (0, pid_utils_1.pidTreeUsage)([process.pid, this._page.browser().process().pid]);
1259
+ });
1260
+ }
1248
1261
  /**
1249
1262
  * A list of participants in the chat who have their live location on. If the chat does not exist, or the chat does not have any contacts actively sharing their live locations, it will return false. If it's a chat with a single contact, there will be only 1 value in the array if the contact has their livelocation on.
1250
1263
  * Please note. This should only be called once every 30 or so seconds. This forces the phone to grab the latest live location data for the number. This can be used in conjunction with onLiveLocation (this will trigger onLiveLocation).
@@ -1441,15 +1454,17 @@ class Client {
1441
1454
  * @param to chat id: `xxxxx@c.us`
1442
1455
  * @param content text message
1443
1456
  * @param replyMessageId id of message to reply to
1457
+ * @param hideTags Removes all tags within the message
1458
+ * @param mentions You can optionally add an array of contact IDs to tag only specific people
1444
1459
  */
1445
- sendReplyWithMentions(to, content, replyMessageId) {
1460
+ sendReplyWithMentions(to, content, replyMessageId, hideTags, mentions) {
1446
1461
  return __awaiter(this, void 0, void 0, function* () {
1447
1462
  //remove all @c.us from the content
1448
1463
  content = content.replace(/@c.us/, "");
1449
- return yield this.pup(({ to, content, replyMessageId }) => {
1464
+ return yield this.pup(({ to, content, replyMessageId, hideTags, mentions }) => {
1450
1465
  WAPI.sendSeen(to);
1451
- return WAPI.sendReplyWithMentions(to, content, replyMessageId);
1452
- }, { to, content, replyMessageId });
1466
+ return WAPI.sendReplyWithMentions(to, content, replyMessageId, hideTags, mentions);
1467
+ }, { to, content, replyMessageId, hideTags, mentions });
1453
1468
  });
1454
1469
  }
1455
1470
  /**
@@ -67,7 +67,8 @@ function initPage(sessionId, config, qrManager, customUserAgent, spinner, _page,
67
67
  spinner === null || spinner === void 0 ? void 0 : spinner.info(`Browser launched: ${((0, tools_1.now)() - startBrowser).toFixed(0)}ms`);
68
68
  waPage = yield getWAPage(browser);
69
69
  }
70
- yield waPage._client().send('Network.setBypassServiceWorker', { bypass: true });
70
+ //@ts-ignore
71
+ yield (typeof waPage._client === 'function' && waPage._client() || waPage._client).send('Network.setBypassServiceWorker', { bypass: true });
71
72
  const postBrowserLaunchTs = (0, tools_1.now)();
72
73
  waPage.on("framenavigated", (frame) => __awaiter(this, void 0, void 0, function* () {
73
74
  try {
@@ -0,0 +1 @@
1
+ export declare const pidTreeUsage: (pid: any) => Promise<any>;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.pidTreeUsage = void 0;
16
+ const pidtree_1 = __importDefault(require("pidtree"));
17
+ const pidusage_1 = __importDefault(require("pidusage"));
18
+ const pidTreeUsage = (pid) => __awaiter(void 0, void 0, void 0, function* () {
19
+ if (!Array.isArray(pid)) {
20
+ pid = [pid];
21
+ }
22
+ const pids = (yield Promise.all(pid.map(pidtree_1.default))).flat();
23
+ const stats = yield (0, pidusage_1.default)(pids);
24
+ return stats;
25
+ });
26
+ exports.pidTreeUsage = pidTreeUsage;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-wa/wa-automate",
3
- "version": "4.41.0",
3
+ "version": "4.42.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",
@@ -89,7 +89,6 @@
89
89
  "husky": "^7.0.0",
90
90
  "line-reader": "^0.4.0",
91
91
  "marked": "^4.0.10",
92
- "ts-json-schema-generator": "^v1.1.0-next.5",
93
92
  "node-emoji": "^1.10.0",
94
93
  "onchange": "^7.0.2",
95
94
  "precise-commits": "^1.0.2",
@@ -97,6 +96,7 @@
97
96
  "release-it": "^14.0.3",
98
97
  "shelljs": "^0.8.3",
99
98
  "tiny-glob": "^0.2.9",
99
+ "ts-json-schema-generator": "^v1.1.0-next.5",
100
100
  "ts-node": "^10.0.0",
101
101
  "tsc-watch": "^4.0.0",
102
102
  "typeconv": "^1.7.0",
@@ -144,12 +144,14 @@
144
144
  "parse-url": "^5.0.2",
145
145
  "patch-package": "^6.2.2",
146
146
  "pico-s3": "^1.0.1",
147
+ "pidtree": "^0.6.0",
148
+ "pidusage": "^3.0.0",
147
149
  "postman-2-swagger": "^0.5.0",
148
- "puppeteer": "^14.4.1",
150
+ "puppeteer": "15.0.0",
149
151
  "puppeteer-extra": "^3.2.3",
150
- "puppeteer-extra-plugin-block-resources": "^2.3.0",
151
- "puppeteer-extra-plugin-devtools": "^2.3.3",
152
- "puppeteer-extra-plugin-stealth": "^2.9.0",
152
+ "puppeteer-extra-plugin-block-resources": "^2.4.0",
153
+ "puppeteer-extra-plugin-devtools": "^2.4.0",
154
+ "puppeteer-extra-plugin-stealth": "^2.10.1",
153
155
  "puppeteer-page-proxy": "^1.2.8",
154
156
  "qrcode-terminal": "^0.12.0",
155
157
  "qs": "^6.10.1",