@open-wa/wa-automate 4.38.0 → 4.40.0
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/bin/oas-type-schemas.json +1 -1
- package/dist/api/Client.d.ts +16 -15
- package/dist/api/Client.js +43 -16
- package/dist/api/model/button.d.ts +6 -0
- package/dist/api/model/config.d.ts +2 -1
- package/dist/api/model/config.js +1 -0
- package/dist/cli/file-utils.js +11 -3
- package/dist/cli/setup.d.ts +1 -1
- package/dist/cli/setup.js +37 -10
- package/dist/controllers/init_patch.js +1 -1
- package/dist/controllers/patch_manager.js +9 -0
- package/package.json +1 -1
package/dist/api/Client.d.ts
CHANGED
@@ -19,7 +19,7 @@ import { Listener } from 'eventemitter2';
|
|
19
19
|
import PriorityQueue from 'p-queue/dist/priority-queue';
|
20
20
|
import { NextFunction, Request, Response } from 'express';
|
21
21
|
import { Call } from './model/call';
|
22
|
-
import { Button, LocationButtonBody, Section } from './model/button';
|
22
|
+
import { AdvancedButton, Button, LocationButtonBody, Section } from './model/button';
|
23
23
|
import { JsonObject } from 'type-fest';
|
24
24
|
import { ReactionEvent } from './model/reactions';
|
25
25
|
export declare enum namespace {
|
@@ -515,6 +515,21 @@ export declare class Client {
|
|
515
515
|
* @param {string} footer The footer of the buttons message
|
516
516
|
*/
|
517
517
|
sendButtons(to: ChatId, body: string | LocationButtonBody, buttons: Button[], title?: string, footer?: string): Promise<boolean | MessageId>;
|
518
|
+
/**
|
519
|
+
* {@license:insiders@}
|
520
|
+
*
|
521
|
+
* Send advanced buttons with media body. This is an insiders feature for MD accounts.
|
522
|
+
*
|
523
|
+
* Body can be location, image, video or document. Buttons can be quick reply, url or call buttons.
|
524
|
+
*
|
525
|
+
* @param {ChatId} to chat id
|
526
|
+
* @param {string | LocationButtonBody} body The body of the buttons message
|
527
|
+
* @param {AdvancedButton[]} buttons Array of buttons - limit is 3!
|
528
|
+
* @param {string} title The title/header of the buttons message
|
529
|
+
* @param {string} footer The footer of the buttons message
|
530
|
+
* @param {string} filename Required if body is a file!!
|
531
|
+
*/
|
532
|
+
sendAdvancedButtons(to: ChatId, body: string | LocationButtonBody, buttons: AdvancedButton[], text: string, footer: string, filename: string): Promise<boolean | MessageId>;
|
518
533
|
/**
|
519
534
|
* Send a banner image
|
520
535
|
*
|
@@ -527,20 +542,6 @@ export declare class Client {
|
|
527
542
|
/**
|
528
543
|
* {@license:insiders@}
|
529
544
|
*
|
530
|
-
* :::documentation-page{title="Welcome"}
|
531
|
-
*
|
532
|
-
* Please install :inline-code[unified]!
|
533
|
-
*
|
534
|
-
* ::copyright-notice{year="2020"}
|
535
|
-
*
|
536
|
-
* :::
|
537
|
-
* ::license-required[insiders]
|
538
|
-
*
|
539
|
-
* ::span{year="2020"}
|
540
|
-
*
|
541
|
-
* :span{year="2020"}
|
542
|
-
*
|
543
|
-
* <span theme="badge contrast license">Insiders</span>
|
544
545
|
* [REQUIRES AN INSIDERS LICENSE-KEY](https://gum.co/open-wa?tier=Insiders%20Program)
|
545
546
|
*
|
546
547
|
* Send a list message. This will not work when being sent from business accounts!
|
package/dist/api/Client.js
CHANGED
@@ -678,8 +678,8 @@ class Client {
|
|
678
678
|
//do nothing
|
679
679
|
}
|
680
680
|
const m = fil ? [message].filter(typeof fil == "function" ? fil : x => x)[0] : message;
|
681
|
-
|
682
|
-
|
681
|
+
if (m && this._createConfig.messagePreprocessor && preProcessors_1.MessagePreprocessors[this._createConfig.messagePreprocessor] && message.mimetype) {
|
682
|
+
logging_1.log.info(`Preproc START: ${this._createConfig.messagePreprocessor} ${fil} ${message.id} ${m.id}`);
|
683
683
|
logging_1.log.info(`Preproccessing message: ${this._createConfig.messagePreprocessor}`);
|
684
684
|
const preprocres = ((yield preProcessors_1.MessagePreprocessors[this._createConfig.messagePreprocessor](m, this)) || message);
|
685
685
|
delete this._preprocIdempotencyCheck[message.id];
|
@@ -1343,6 +1343,47 @@ class Client {
|
|
1343
1343
|
}, { to, body, buttons, title, footer });
|
1344
1344
|
});
|
1345
1345
|
}
|
1346
|
+
/**
|
1347
|
+
* {@license:insiders@}
|
1348
|
+
*
|
1349
|
+
* Send advanced buttons with media body. This is an insiders feature for MD accounts.
|
1350
|
+
*
|
1351
|
+
* Body can be location, image, video or document. Buttons can be quick reply, url or call buttons.
|
1352
|
+
*
|
1353
|
+
* @param {ChatId} to chat id
|
1354
|
+
* @param {string | LocationButtonBody} body The body of the buttons message
|
1355
|
+
* @param {AdvancedButton[]} buttons Array of buttons - limit is 3!
|
1356
|
+
* @param {string} title The title/header of the buttons message
|
1357
|
+
* @param {string} footer The footer of the buttons message
|
1358
|
+
* @param {string} filename Required if body is a file!!
|
1359
|
+
*/
|
1360
|
+
sendAdvancedButtons(to, body, buttons, text, footer, filename) {
|
1361
|
+
return __awaiter(this, void 0, void 0, function* () {
|
1362
|
+
if (typeof body !== "string" && body.lat) {
|
1363
|
+
//this is a location body
|
1364
|
+
// eslint-disable-next-line no-self-assign
|
1365
|
+
body = body;
|
1366
|
+
}
|
1367
|
+
else if (typeof body == "string" && !(0, tools_1.isDataURL)(body) && !(0, tools_1.isBase64)(body) && !body.includes("data:")) {
|
1368
|
+
//must be a file then
|
1369
|
+
const relativePath = path.join(path.resolve(process.cwd(), body || ''));
|
1370
|
+
if (typeof body == "string" && fs.existsSync(body) || fs.existsSync(relativePath)) {
|
1371
|
+
body = yield (0, datauri_1.default)(fs.existsSync(body) ? body : relativePath);
|
1372
|
+
}
|
1373
|
+
else if (typeof body == "string" && (0, is_url_superb_1.default)(body)) {
|
1374
|
+
body = yield (0, tools_1.getDUrl)(body);
|
1375
|
+
}
|
1376
|
+
else
|
1377
|
+
throw new errors_1.CustomError(errors_1.ERROR_NAME.FILE_NOT_FOUND, `Cannot find file. Make sure the file reference is relative, a valid URL or a valid DataURL: ${body.slice(0, 25)}`);
|
1378
|
+
}
|
1379
|
+
else if (typeof body == "string" && (body.includes("data:") && body.includes("undefined") || body.includes("application/octet-stream") && filename && mime_types_1.default.lookup(filename))) {
|
1380
|
+
body = `data:${mime_types_1.default.lookup(filename)};base64,${body.split(',')[1]}`;
|
1381
|
+
}
|
1382
|
+
return yield this.pup(({ to, body, buttons, text, footer, filename }) => {
|
1383
|
+
return WAPI.sendAdvancedButtons(to, body, buttons, text, footer, filename);
|
1384
|
+
}, { to, body, buttons, text, footer, filename });
|
1385
|
+
});
|
1386
|
+
}
|
1346
1387
|
/**
|
1347
1388
|
* Send a banner image
|
1348
1389
|
*
|
@@ -1361,20 +1402,6 @@ class Client {
|
|
1361
1402
|
/**
|
1362
1403
|
* {@license:insiders@}
|
1363
1404
|
*
|
1364
|
-
* :::documentation-page{title="Welcome"}
|
1365
|
-
*
|
1366
|
-
* Please install :inline-code[unified]!
|
1367
|
-
*
|
1368
|
-
* ::copyright-notice{year="2020"}
|
1369
|
-
*
|
1370
|
-
* :::
|
1371
|
-
* ::license-required[insiders]
|
1372
|
-
*
|
1373
|
-
* ::span{year="2020"}
|
1374
|
-
*
|
1375
|
-
* :span{year="2020"}
|
1376
|
-
*
|
1377
|
-
* <span theme="badge contrast license">Insiders</span>
|
1378
1405
|
* [REQUIRES AN INSIDERS LICENSE-KEY](https://gum.co/open-wa?tier=Insiders%20Program)
|
1379
1406
|
*
|
1380
1407
|
* Send a list message. This will not work when being sent from business accounts!
|
@@ -98,7 +98,8 @@ export declare enum LicenseType {
|
|
98
98
|
TEXT_STORY = "Text Story License Key",
|
99
99
|
IMAGE_STORY = "Image Story License Key",
|
100
100
|
VIDEO_STORY = "Video Story License Key",
|
101
|
-
PREMIUM = "Premium License Key"
|
101
|
+
PREMIUM = "Premium License Key",
|
102
|
+
NONE = "NONE"
|
102
103
|
}
|
103
104
|
export interface SessionData {
|
104
105
|
WABrowserId?: string;
|
package/dist/api/model/config.js
CHANGED
@@ -104,4 +104,5 @@ var LicenseType;
|
|
104
104
|
LicenseType["IMAGE_STORY"] = "Image Story License Key";
|
105
105
|
LicenseType["VIDEO_STORY"] = "Video Story License Key";
|
106
106
|
LicenseType["PREMIUM"] = "Premium License Key";
|
107
|
+
LicenseType["NONE"] = "NONE";
|
107
108
|
})(LicenseType = exports.LicenseType || (exports.LicenseType = {}));
|
package/dist/cli/file-utils.js
CHANGED
@@ -26,13 +26,18 @@ exports.tryOpenFileAsObject = void 0;
|
|
26
26
|
const path = __importStar(require("path"));
|
27
27
|
const fs = __importStar(require("fs"));
|
28
28
|
const json5_1 = __importDefault(require("json5"));
|
29
|
+
const logging_1 = require("../logging/logging");
|
29
30
|
const tryOpenFileAsObject = (fileLocation, needArray = false) => {
|
30
31
|
let res = undefined;
|
32
|
+
let fp = undefined;
|
31
33
|
const relativePath = path.join(path.resolve(process.cwd(), fileLocation || ''));
|
34
|
+
const isJs = fileLocation.endsWith(".js");
|
35
|
+
logging_1.log.info(`Checking exists: ${fileLocation || relativePath}`);
|
32
36
|
if (fs.existsSync(fileLocation) || fs.existsSync(relativePath)) {
|
33
|
-
|
37
|
+
fp = isJs ? fs.existsSync(relativePath) && relativePath : fs.existsSync(fileLocation) ? fileLocation : relativePath;
|
38
|
+
logging_1.log.info("Attempting to open: " + fp);
|
34
39
|
try {
|
35
|
-
const data = json5_1.default.parse(fs.readFileSync(fp, 'utf8'));
|
40
|
+
const data = isJs ? (require(fp) || {}).default : json5_1.default.parse(fs.readFileSync(fp, 'utf8'));
|
36
41
|
if (data && (Array.isArray(data) == needArray))
|
37
42
|
res = data;
|
38
43
|
}
|
@@ -40,6 +45,9 @@ const tryOpenFileAsObject = (fileLocation, needArray = false) => {
|
|
40
45
|
throw `Unable to parse config file as JSON. Please make sure ${fp} is a valid JSON config file`;
|
41
46
|
}
|
42
47
|
}
|
43
|
-
|
48
|
+
else
|
49
|
+
return;
|
50
|
+
logging_1.log.info(`${fp} is ${res ? 'valid' : 'invalid'}`);
|
51
|
+
return res && Object.assign(Object.assign({}, (res || {})), { confPath: fp });
|
44
52
|
};
|
45
53
|
exports.tryOpenFileAsObject = tryOpenFileAsObject;
|
package/dist/cli/setup.d.ts
CHANGED
@@ -19,7 +19,7 @@ export declare const cliOptionNames: import("type-fest").Simplify<import("type-f
|
|
19
19
|
export declare const meowFlags: () => AnyFlags;
|
20
20
|
export declare const helptext: string;
|
21
21
|
export declare const envArgs: () => JsonObject;
|
22
|
-
export declare const configFile: (config
|
22
|
+
export declare const configFile: (config?: string) => JsonObject;
|
23
23
|
export declare const cli: () => {
|
24
24
|
createConfig: ConfigObject;
|
25
25
|
cliConfig: Merge<ConfigObject, {
|
package/dist/cli/setup.js
CHANGED
@@ -126,23 +126,42 @@ exports.envArgs = envArgs;
|
|
126
126
|
const configFile = (config) => {
|
127
127
|
let confFile = {};
|
128
128
|
const conf = config || process.env.WA_CLI_CONFIG;
|
129
|
+
const backup = () => {
|
130
|
+
if (!confFile)
|
131
|
+
confFile = (0, file_utils_1.tryOpenFileAsObject)(`cli.config.json`);
|
132
|
+
if (!confFile)
|
133
|
+
confFile = (0, file_utils_1.tryOpenFileAsObject)(`cli.config.js`);
|
134
|
+
};
|
135
|
+
const attempt = (firstAttempt) => {
|
136
|
+
try {
|
137
|
+
confFile = (0, file_utils_1.tryOpenFileAsObject)(firstAttempt || `cli.config.json`);
|
138
|
+
backup();
|
139
|
+
}
|
140
|
+
catch (error) {
|
141
|
+
logging_1.log.error(error);
|
142
|
+
logging_1.log.error("Trying cli.config.js");
|
143
|
+
backup();
|
144
|
+
}
|
145
|
+
};
|
129
146
|
if (conf) {
|
130
147
|
if ((0, tools_1.isBase64)(conf)) {
|
131
148
|
confFile = JSON.parse(Buffer.from(conf, 'base64').toString('ascii'));
|
132
149
|
}
|
133
150
|
else {
|
134
|
-
|
151
|
+
attempt(conf);
|
135
152
|
if (!confFile)
|
136
153
|
console.error(`Unable to read config file json: ${conf}`);
|
137
154
|
}
|
138
155
|
}
|
139
156
|
else {
|
140
|
-
|
157
|
+
attempt();
|
141
158
|
}
|
159
|
+
logging_1.log.info(`Using config file: ${confFile.confPath || "???"}`);
|
142
160
|
return confFile;
|
143
161
|
};
|
144
162
|
exports.configFile = configFile;
|
145
163
|
const cli = () => {
|
164
|
+
let loggingSetup = false;
|
146
165
|
const _cli = (0, meow_1.default)(exports.helptext, {
|
147
166
|
flags: Object.assign(Object.assign({}, (0, exports.meowFlags)()), { popup: {
|
148
167
|
type: 'boolean',
|
@@ -150,6 +169,21 @@ const cli = () => {
|
|
150
169
|
} }),
|
151
170
|
booleanDefault: undefined
|
152
171
|
});
|
172
|
+
const _setupLogging = (_config) => {
|
173
|
+
if (loggingSetup)
|
174
|
+
return;
|
175
|
+
//firstly set up logger
|
176
|
+
if ((_config === null || _config === void 0 ? void 0 : _config.logging) || (_config === null || _config === void 0 ? void 0 : _config.verbose)) {
|
177
|
+
if (!(_config === null || _config === void 0 ? void 0 : _config.logging) && (_config === null || _config === void 0 ? void 0 : _config.verbose))
|
178
|
+
_config.logging = [];
|
179
|
+
if ((_config === null || _config === void 0 ? void 0 : _config.logging) && !((_config === null || _config === void 0 ? void 0 : _config.logging) || []).find(transport => transport.type === "console"))
|
180
|
+
_config.logging.push({ type: 'console' });
|
181
|
+
if (Array.isArray(_config === null || _config === void 0 ? void 0 : _config.logging))
|
182
|
+
_config.logging = (0, logging_1.setupLogging)(_config === null || _config === void 0 ? void 0 : _config.logging, `easy-api-${(_config === null || _config === void 0 ? void 0 : _config.sessionId) || 'session'}`);
|
183
|
+
loggingSetup = true;
|
184
|
+
}
|
185
|
+
};
|
186
|
+
_setupLogging(_cli.flags);
|
153
187
|
/**
|
154
188
|
* Config order should follow airmanship rules. Least maneuverable to most maneuverable.
|
155
189
|
*
|
@@ -161,14 +195,7 @@ const cli = () => {
|
|
161
195
|
cli_options_1.optionList.filter(option => option.default);
|
162
196
|
const cliConfig = Object.assign(Object.assign(Object.assign({ sessionId: "session" }, nonCliConfigs), _cli.flags), exports.optionKeysWithDefalts.reduce((p, c) => nonCliConfigs.hasOwnProperty(c) ? Object.assign(Object.assign({}, p), { [c]: nonCliConfigs[c] }) : p, {}));
|
163
197
|
//firstly set up logger
|
164
|
-
|
165
|
-
if (!(cliConfig === null || cliConfig === void 0 ? void 0 : cliConfig.logging) && (cliConfig === null || cliConfig === void 0 ? void 0 : cliConfig.verbose))
|
166
|
-
cliConfig.logging = [];
|
167
|
-
if ((cliConfig === null || cliConfig === void 0 ? void 0 : cliConfig.logging) && !((cliConfig === null || cliConfig === void 0 ? void 0 : cliConfig.logging) || []).find(transport => transport.type === "console"))
|
168
|
-
cliConfig.logging.push({ type: 'console' });
|
169
|
-
if (Array.isArray(cliConfig === null || cliConfig === void 0 ? void 0 : cliConfig.logging))
|
170
|
-
cliConfig.logging = (0, logging_1.setupLogging)(cliConfig === null || cliConfig === void 0 ? void 0 : cliConfig.logging, `easy-api-${(cliConfig === null || cliConfig === void 0 ? void 0 : cliConfig.sessionId) || 'session'}`);
|
171
|
-
}
|
198
|
+
_setupLogging(cliConfig);
|
172
199
|
const PORT = Number((typeof cliConfig.forcePort === "boolean" && cliConfig.forcePort ? process.env.PORT : cliConfig.forcePort) || cliConfig.port || process.env.PORT || 8080);
|
173
200
|
const spinner = new events_1.Spin(cliConfig.sessionId, 'STARTUP', cliConfig === null || cliConfig === void 0 ? void 0 : cliConfig.disableSpins);
|
174
201
|
const createConfig = Object.assign({}, cliConfig);
|