@open-wa/wa-automate 4.31.1 → 4.31.5

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.
@@ -319,6 +319,14 @@ export declare class Client {
319
319
  * @emits `<LiveLocationChangedEvent>` LiveLocationChangedEvent
320
320
  */
321
321
  onLiveLocation(chatId: ChatId, fn: (liveLocationChangedEvent: LiveLocationChangedEvent) => void): Promise<boolean>;
322
+ /**
323
+ * Use this simple command to test firing callback events.
324
+ *
325
+ * @param callbackToTest
326
+ * @param testData
327
+ * @returns `false` if the callback was not registered/does not exist
328
+ */
329
+ testCallback(callbackToTest: SimpleListener, testData: any): Promise<boolean>;
322
330
  /**
323
331
  * Set presence to available or unavailable.
324
332
  * @param available if true it will set your presence to 'online', false will set to unavailable (i.e no 'online' on recipients' phone);
@@ -943,6 +943,20 @@ class Client {
943
943
  }, { chatId, funcName }));
944
944
  });
945
945
  }
946
+ /**
947
+ * Use this simple command to test firing callback events.
948
+ *
949
+ * @param callbackToTest
950
+ * @param testData
951
+ * @returns `false` if the callback was not registered/does not exist
952
+ */
953
+ testCallback(callbackToTest, testData) {
954
+ return __awaiter(this, void 0, void 0, function* () {
955
+ return this.pup(({ callbackToTest, testData }) => {
956
+ return WAPI.testCallback(callbackToTest, testData);
957
+ }, { callbackToTest, testData });
958
+ });
959
+ }
946
960
  /**
947
961
  * Set presence to available or unavailable.
948
962
  * @param available if true it will set your presence to 'online', false will set to unavailable (i.e no 'online' on recipients' phone);
@@ -38,6 +38,11 @@ exports.optionList = [{
38
38
  typeLabel: '{blue {underline 8080}}',
39
39
  description: "Set the port for the api. Default to 8002."
40
40
  },
41
+ {
42
+ name: 'forcePort',
43
+ type: Number,
44
+ description: "Sometimes --port is overridden by environmental variables or the config file. Use this flag to force the port to be used."
45
+ },
41
46
  {
42
47
  name: 'api-host',
43
48
  type: String,
@@ -59,6 +64,13 @@ exports.optionList = [{
59
64
  typeLabel: '{yellow {underline https://webhook.site/....}}',
60
65
  description: "Webhook to use for the listeners."
61
66
  },
67
+ {
68
+ name: 'verbose',
69
+ alias: 'v',
70
+ default: false,
71
+ type: Boolean,
72
+ description: "Enable console transport for internal logger."
73
+ },
62
74
  {
63
75
  name: 'ev',
64
76
  alias: 'e',
package/dist/cli/setup.js CHANGED
@@ -161,11 +161,15 @@ const cli = () => {
161
161
  cli_options_1.optionList.filter(option => option.default);
162
162
  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
163
  //firstly set up logger
164
- if (cliConfig === null || cliConfig === void 0 ? void 0 : cliConfig.logging) {
164
+ if ((cliConfig === null || cliConfig === void 0 ? void 0 : cliConfig.logging) || (cliConfig === null || cliConfig === void 0 ? void 0 : cliConfig.verbose)) {
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' });
165
169
  if (Array.isArray(cliConfig === null || cliConfig === void 0 ? void 0 : cliConfig.logging))
166
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'}`);
167
171
  }
168
- const PORT = Number(cliConfig.port || process.env.PORT || 8080);
172
+ const PORT = Number((typeof cliConfig.forcePort === "boolean" && cliConfig.forcePort ? process.env.PORT : cliConfig.forcePort) || cliConfig.port || process.env.PORT || 8080);
169
173
  const spinner = new events_1.Spin(cliConfig.sessionId, 'STARTUP', cliConfig === null || cliConfig === void 0 ? void 0 : cliConfig.disableSpins);
170
174
  const createConfig = Object.assign({}, cliConfig);
171
175
  if (cliConfig === null || cliConfig === void 0 ? void 0 : cliConfig.session) {
@@ -234,7 +238,12 @@ const cli = () => {
234
238
  if (cliConfig.apiHost) {
235
239
  cliConfig.apiHost = cliConfig.apiHost.replace(/\/$/, '');
236
240
  }
241
+ /**
242
+ * Check the port in the config
243
+ */
244
+ cliConfig.port = PORT;
237
245
  if (cliConfig.debug) {
246
+ spinner.succeed(`DEBUG - PORT: ${PORT}`);
238
247
  spinner.succeed(`DEBUG - flags: ${JSON.stringify(cliConfig)}`);
239
248
  const WA_ENV = {};
240
249
  Object.keys(process.env).map(k => {
@@ -132,14 +132,19 @@ function initPage(sessionId, config, customUserAgent, spinner, _page, skipAuth)
132
132
  if (interceptAuthentication || proxyAddr || blockCrashLogs || true) {
133
133
  yield waPage.setRequestInterception(true);
134
134
  waPage.on('response', (response) => __awaiter(this, void 0, void 0, function* () {
135
- if (response.request().url() == "https://web.whatsapp.com/") {
136
- const t = yield response.text();
137
- if (t.includes(`class="no-js"`) && t.includes(`self.`) && !dumbCache) {
138
- //this is a valid response, save it for later
139
- dumbCache = t;
140
- logging_1.log.info("saving valid page to dumb cache");
135
+ try {
136
+ if (response.request().url() == "https://web.whatsapp.com/") {
137
+ const t = yield response.text();
138
+ if (t.includes(`class="no-js"`) && t.includes(`self.`) && !dumbCache) {
139
+ //this is a valid response, save it for later
140
+ dumbCache = t;
141
+ logging_1.log.info("saving valid page to dumb cache");
142
+ }
141
143
  }
142
144
  }
145
+ catch (error) {
146
+ logging_1.log.error("dumb cache error", error);
147
+ }
143
148
  }));
144
149
  const authCompleteEv = new events_1.EvEmitter(sessionId, 'AUTH');
145
150
  waPage.on('request', (request) => __awaiter(this, void 0, void 0, function* () {
@@ -304,7 +309,7 @@ const getSessionDataFilePath = (sessionId, config) => {
304
309
  return false;
305
310
  };
306
311
  exports.getSessionDataFilePath = getSessionDataFilePath;
307
- const addScript = (page, js) => __awaiter(void 0, void 0, void 0, function* () { return page.evaluate(yield script_preloader_1.scriptLoader.getScript(js)); });
312
+ const addScript = (page, js) => __awaiter(void 0, void 0, void 0, function* () { return page.evaluate(yield script_preloader_1.scriptLoader.getScript(js)).catch(e => logging_1.log.error(`Injection error: ${js}`, e)); });
308
313
  exports.addScript = addScript;
309
314
  // (page: Page, js : string) : Promise<unknown> => page.addScriptTag({
310
315
  // path: require.resolve(path.join(__dirname, '../lib', js))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-wa/wa-automate",
3
- "version": "4.31.1",
3
+ "version": "4.31.5",
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",