@open-wa/wa-automate 4.33.8 → 4.34.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.
@@ -101,6 +101,7 @@ export declare class Client {
101
101
  */
102
102
  getConfig(): ConfigObject;
103
103
  private pup;
104
+ private responseWrap;
104
105
  /**
105
106
  * //////////////////////// LISTENERS
106
107
  */
@@ -700,7 +701,7 @@ export declare class Client {
700
701
  * Returns a PNG DataURL screenshot of the session
701
702
  * @returns `Promise<DataURL>`
702
703
  */
703
- getSnapshot(): Promise<DataURL>;
704
+ getSnapshot(chatId?: ChatId): Promise<DataURL>;
704
705
  /**
705
706
  * Returns an array of group ids where the host account is admin
706
707
  */
@@ -487,36 +487,39 @@ class Client {
487
487
  if (_t && logging) {
488
488
  logging_1.log.info(`OUT ${invocation_id}: ${Date.now() - _t}ms`, { res });
489
489
  }
490
- if (this._createConfig.onError && typeof res == "string" && (res.startsWith("Error") || res.startsWith("ERROR"))) {
491
- const e = this._createConfig.onError;
492
- /**
493
- * Log error
494
- */
495
- if (e == model_1.OnError.LOG_AND_FALSE ||
496
- e == model_1.OnError.LOG_AND_STRING ||
497
- res.includes("get.openwa.dev"))
498
- console.error(res);
499
- /**
500
- * Return res
501
- */
502
- if (e == model_1.OnError.AS_STRING ||
503
- e == model_1.OnError.NOTHING ||
504
- e == model_1.OnError.LOG_AND_STRING)
505
- return res;
506
- /**
507
- * Return false
508
- */
509
- if (e == model_1.OnError.LOG_AND_FALSE ||
510
- e == model_1.OnError.RETURN_FALSE)
511
- return false;
512
- if (e == model_1.OnError.RETURN_ERROR)
513
- return new Error(res);
514
- if (e == model_1.OnError.THROW)
515
- throw new Error(res);
516
- }
517
- return res;
490
+ return this.responseWrap(res);
518
491
  });
519
492
  }
493
+ responseWrap(res) {
494
+ if (this._createConfig.onError && typeof res == "string" && (res.startsWith("Error") || res.startsWith("ERROR"))) {
495
+ const e = this._createConfig.onError;
496
+ /**
497
+ * Log error
498
+ */
499
+ if (e == model_1.OnError.LOG_AND_FALSE ||
500
+ e == model_1.OnError.LOG_AND_STRING ||
501
+ res.includes("get.openwa.dev"))
502
+ console.error(res);
503
+ /**
504
+ * Return res
505
+ */
506
+ if (e == model_1.OnError.AS_STRING ||
507
+ e == model_1.OnError.NOTHING ||
508
+ e == model_1.OnError.LOG_AND_STRING)
509
+ return res;
510
+ /**
511
+ * Return false
512
+ */
513
+ if (e == model_1.OnError.LOG_AND_FALSE ||
514
+ e == model_1.OnError.RETURN_FALSE)
515
+ return false;
516
+ if (e == model_1.OnError.RETURN_ERROR)
517
+ return new Error(res);
518
+ if (e == model_1.OnError.THROW)
519
+ throw new Error(res);
520
+ }
521
+ return res;
522
+ }
520
523
  /**
521
524
  * //////////////////////// LISTENERS
522
525
  */
@@ -1223,10 +1226,9 @@ class Client {
1223
1226
  if (err.includes(res)) {
1224
1227
  let msg = res;
1225
1228
  if (res == err[1])
1226
- msg = `\n${res}. Unlock this feature and support open-wa by getting a license: ${yield this.link()}\n`;
1227
- console.error(msg);
1228
- if (this._createConfig.onError == model_1.OnError.THROW)
1229
- throw new errors_1.CustomError(errors_1.ERROR_NAME.SENDTEXT_FAILURE, msg);
1229
+ msg = `ERROR: ${res}. Unlock this feature and support open-wa by getting a license: ${yield this.link()}`;
1230
+ console.error(`\n${msg}\n`);
1231
+ return this.responseWrap(msg);
1230
1232
  }
1231
1233
  return (err.includes(res) ? false : res);
1232
1234
  });
@@ -1690,9 +1692,10 @@ class Client {
1690
1692
  * Returns a PNG DataURL screenshot of the session
1691
1693
  * @returns `Promise<DataURL>`
1692
1694
  */
1693
- getSnapshot() {
1695
+ getSnapshot(chatId) {
1694
1696
  return __awaiter(this, void 0, void 0, function* () {
1695
- const screenshot = yield this.getPage().screenshot({
1697
+ const snapshotElement = chatId ? yield this._page.evaluateHandle(({ chatId }) => WAPI.getSnapshotElement(chatId), { chatId }) : this.getPage();
1698
+ const screenshot = yield snapshotElement.screenshot({
1696
1699
  type: "png",
1697
1700
  encoding: "base64"
1698
1701
  });
@@ -3009,8 +3012,8 @@ class Client {
3009
3012
  if ((a === null || a === void 0 ? void 0 : a.stickerMetadata) && typeof (a === null || a === void 0 ? void 0 : a.stickerMetadata) !== "object")
3010
3013
  throw new errors_1.CustomError(errors_1.ERROR_NAME.BAD_STICKER_METADATA, `Received ${typeof (a === null || a === void 0 ? void 0 : a.stickerMetadata)}: ${a === null || a === void 0 ? void 0 : a.stickerMetadata}`);
3011
3014
  }
3012
- if (((_a = a === null || a === void 0 ? void 0 : a.stickerMetadata) === null || _a === void 0 ? void 0 : _a.discord) && ((_b = this._createConfig) === null || _b === void 0 ? void 0 : _b.discord)) {
3013
- a.stickerMetadata = { discord: this._createConfig.discord };
3015
+ if (a.stickerMetadata && ((_a = this._createConfig) === null || _a === void 0 ? void 0 : _a.discord)) {
3016
+ a.stickerMetadata = Object.assign(Object.assign({}, (a.stickerMetadata || {})), { discord: `${((_b = a.stickerMetadata) === null || _b === void 0 ? void 0 : _b.discord) || this._createConfig.discord}` });
3014
3017
  }
3015
3018
  try {
3016
3019
  const { data } = yield axios_1.default.post(`${((fallback ? pkg.stickerUrl : 'https://sticker-api.openwa.dev') || this._createConfig.stickerServerEndpoint).replace(/\/$/, '')}/${func}`, Object.assign(Object.assign({}, a), { sessionInfo, config: this.getConfig() }), {
@@ -378,8 +378,6 @@ function create(config = {}) {
378
378
  config.skipBrokenMethodsCheck = true;
379
379
  // config.skipPatches = true;
380
380
  }
381
- debugInfo.NUM = yield waPage.evaluate(`(window.localStorage['last-wid'] || '').replace('@c.us','').replace(/"/g,"").slice(-4)`);
382
- debugInfo.NUM_HASH = (0, crypto_1.createHash)('md5').update(yield waPage.evaluate(`(window.localStorage['last-wid'] || '').replace('@c.us','').replace(/"/g,"")`), 'utf8').digest('hex');
383
381
  if (config === null || config === void 0 ? void 0 : config.hostNotificationLang) {
384
382
  yield waPage.evaluate(`window.hostlang="${config.hostNotificationLang}"`);
385
383
  }
@@ -388,6 +386,9 @@ function create(config = {}) {
388
386
  yield (0, patch_manager_1.getAndInjectLivePatch)(waPage, spinner, yield patchPromise, config, debugInfo);
389
387
  debugInfo.OW_KEY = yield waPage.evaluate(`window.o()`);
390
388
  }
389
+ const NUM = ((yield waPage.evaluate(`(window.moi() || "").replace('@c.us','').replace(/"/g,"")`)) || "");
390
+ debugInfo.NUM = NUM.slice(-4);
391
+ debugInfo.NUM_HASH = (0, crypto_1.createHash)('md5').update(NUM, 'utf8').digest('hex');
391
392
  if ((config === null || config === void 0 ? void 0 : config.skipBrokenMethodsCheck) !== true)
392
393
  yield (0, launch_checks_1.integrityCheck)(waPage, notifier, spinner, debugInfo);
393
394
  const LAUNCH_TIME_MS = Date.now() - START_TIME;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-wa/wa-automate",
3
- "version": "4.33.8",
3
+ "version": "4.34.2",
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",