@open-wa/wa-automate 4.28.6 → 4.28.7

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.
Files changed (2) hide show
  1. package/dist/api/Client.js +28 -13
  2. package/package.json +1 -1
@@ -427,9 +427,9 @@ class Client {
427
427
  return rest;
428
428
  }
429
429
  pup(pageFunction, ...args) {
430
- var _a, _b;
430
+ var _a, _b, _c, _d, _e;
431
431
  return __awaiter(this, void 0, void 0, function* () {
432
- const { safeMode, callTimeout, idChecking, logFile, logging } = this._createConfig;
432
+ const { safeMode, callTimeout, idCorrection, logging } = this._createConfig;
433
433
  let _t;
434
434
  if (safeMode) {
435
435
  if (!this._page || this._page.isClosed())
@@ -438,19 +438,34 @@ class Client {
438
438
  if (state !== model_1.STATE.CONNECTED)
439
439
  throw new errors_1.CustomError(errors_1.ERROR_NAME.STATE_ERROR, `state: ${state}`);
440
440
  }
441
- if (idChecking && args[0]) {
442
- Object.entries(args[0]).map(([k, v]) => {
443
- if (["to", "chatId", "groupChatId", "groupId", "contactId"].includes(k) && typeof v == "string" && v) {
444
- args[0][k] = (v === null || v === void 0 ? void 0 : v.includes('-')) ?
445
- //it is a group chat, make sure it has a @g.us at the end
446
- `${v === null || v === void 0 ? void 0 : v.replace(/@(c|g).us/g, '')}@g.us` :
447
- //it is a normal chat, make sure it has a @c.us at the end
448
- `${v === null || v === void 0 ? void 0 : v.replace(/@(c|g).us/g, '')}@c.us`;
449
- }
450
- });
441
+ if (idCorrection && args[0]) {
442
+ const fixId = (id) => {
443
+ var _a;
444
+ let isGroup = false;
445
+ let scrubbedId = (_a = id === null || id === void 0 ? void 0 : id.match(/\d|-/g)) === null || _a === void 0 ? void 0 : _a.join('');
446
+ scrubbedId = scrubbedId.match(/-/g) && scrubbedId.match(/-/g).length == 1 && scrubbedId.split('-')[1].length === 10 ? scrubbedId : scrubbedId.replace(/-/g, '');
447
+ if (scrubbedId.includes('-') || scrubbedId.length === 18)
448
+ isGroup = true;
449
+ const fixed = isGroup ?
450
+ `${scrubbedId === null || scrubbedId === void 0 ? void 0 : scrubbedId.replace(/@(c|g).us/g, '')}@g.us` :
451
+ `${scrubbedId === null || scrubbedId === void 0 ? void 0 : scrubbedId.replace(/@(c|g).us/g, '')}@c.us`;
452
+ logging_1.log.info('Fixed ID', { id, fixed });
453
+ return fixed;
454
+ };
455
+ if (typeof args[0] === 'string' && args[0] && !(args[0].includes("@g.us") || args[0].includes("@c.us")) && ((_c = (_b = (((_a = pageFunction === null || pageFunction === void 0 ? void 0 : pageFunction.toString()) === null || _a === void 0 ? void 0 : _a.match(/[^(]*\(([^)]*)\)/)[1]) || "")) === null || _b === void 0 ? void 0 : _b.replace(/\s/g, '')) === null || _c === void 0 ? void 0 : _c.split(','))) {
456
+ const p = ((pageFunction === null || pageFunction === void 0 ? void 0 : pageFunction.toString().match(/[^(]*\(([^)]*)\)/)[1]) || "").replace(/\s/g, '').split(',');
457
+ if (["to", "chatId", "groupChatId", "groupId", "contactId"].includes(p[0]))
458
+ args[0] = fixId(args[0]);
459
+ }
460
+ else if (typeof args[0] === 'object')
461
+ Object.entries(args[0]).map(([k, v]) => {
462
+ if (["to", "chatId", "groupChatId", "groupId", "contactId"].includes(k) && typeof v == "string" && v && !(v.includes("@g.us") || v.includes("@c.us"))) {
463
+ args[0][k] = fixId(v);
464
+ }
465
+ });
451
466
  }
452
467
  if (logging) {
453
- const wapis = (_b = (((_a = pageFunction === null || pageFunction === void 0 ? void 0 : pageFunction.toString()) === null || _a === void 0 ? void 0 : _a.match(/WAPI\.(\w*)\(/g)) || [])) === null || _b === void 0 ? void 0 : _b.map(s => s.replace(/WAPI|\.|\(/g, ''));
468
+ const wapis = (_e = (((_d = pageFunction === null || pageFunction === void 0 ? void 0 : pageFunction.toString()) === null || _d === void 0 ? void 0 : _d.match(/WAPI\.(\w*)\(/g)) || [])) === null || _e === void 0 ? void 0 : _e.map(s => s.replace(/WAPI|\.|\(/g, ''));
454
469
  _t = Date.now();
455
470
  logging_1.log.info(`Request ${_t}`, Object.assign({ _method: (wapis === null || wapis === void 0 ? void 0 : wapis.length) === 1 ? wapis[0] : wapis }, args[0]));
456
471
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-wa/wa-automate",
3
- "version": "4.28.6",
3
+ "version": "4.28.7",
4
4
  "licenseCheckUrl": "https://openwa.dev/license-check",
5
5
  "brokenMethodReportUrl": "https://openwa.dev/report-bm",
6
6
  "patches": "https://cdn.openwa.dev/patches.json",