@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.
- package/dist/api/Client.js +28 -13
- package/package.json +1 -1
package/dist/api/Client.js
CHANGED
@@ -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,
|
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 (
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
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 = (
|
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