@open-wa/wa-automate 4.37.3 → 4.38.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.
@@ -1,5 +1,51 @@
1
- import { getConfigWithCase } from '../src/utils/configSchema'
2
1
  import { writeJsonSync } from 'fs-extra';
2
+ import { createGenerator } from "ts-json-schema-generator";
3
+ import {paramCase, constantCase} from "change-case";
4
+
5
+ const defaultConfig = {
6
+ path: "../api/model/config.ts",
7
+ tsconfig: "../../tsconfig.json",
8
+ type: "ConfigObject",
9
+ };
10
+
11
+ const getConfigWithCase = (config ?: {
12
+ path: string,
13
+ tsconfig: string,
14
+ type: string,
15
+ }) : unknown => {
16
+ if(!config) config = defaultConfig;
17
+ const schema = createGenerator(config).createSchema(config.type);
18
+ const ignoredConfigs = [
19
+ 'useStealth',
20
+ 'chromiumArgs',
21
+ 'executablePath',
22
+ 'skipBrokenMethodsCheck',
23
+ 'inDocker',
24
+ 'autoRefresh',
25
+ 'bypassCSP',
26
+ 'throwErrorOnTosBlock',
27
+ 'killProcessOnBrowserClose',
28
+ 'cloudUploadOptions',
29
+ 'qrRefreshS'
30
+ ]
31
+ //only convert simple types
32
+ // const configs = Object.keys(schema.definitions.ConfigObject.properties).map(key=>({...schema.definitions.ConfigObject.properties[key],key})).filter(({type,key})=>type&&!ignoredConfigs.includes(key));
33
+ const configs = Object.entries((schema.definitions.ConfigObject as any).properties).map(([key,entry] : any)=>{
34
+ if(key==='sessionData') {
35
+ entry.type = 'string';
36
+ entry.description = 'The base64 encoded sessionData used to restore a session.'
37
+ delete entry.anyOf;
38
+ }
39
+ if(key==='licenseKey') {
40
+ entry.type = 'string';
41
+ entry.description = 'The license key to use with the session.'
42
+ delete entry.anyOf;
43
+ }
44
+ return {...entry,key}
45
+ }).filter(({type,key})=>type&&!ignoredConfigs.includes(key));
46
+ const configWithCases = configs.map(o=>({env:`WA_${constantCase(o.key)}`,p:paramCase(o.key),...o}))
47
+ return configWithCases;
48
+ }
3
49
 
4
50
  const configWithCases = getConfigWithCase({
5
51
  path: "../src/api/model/config.ts",
@@ -178,6 +178,13 @@ export declare class Client {
178
178
  * @fires [[Message]]
179
179
  */
180
180
  onButton(fn: (message: Message) => void): Promise<Listener | boolean>;
181
+ /**
182
+ * Listens to broadcast messages
183
+ * @event
184
+ * @param fn callback
185
+ * @fires [[Message]]
186
+ */
187
+ onBroadcast(fn: (message: Message) => void): Promise<Listener | boolean>;
181
188
  /**
182
189
  * Listens to battery changes
183
190
  *
@@ -519,6 +526,20 @@ export declare class Client {
519
526
  sendBanner(to: ChatId, base64: Base64): Promise<boolean | MessageId>;
520
527
  /**
521
528
  * {@license:insiders@}
529
+ *
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
+ *
522
543
  * <span theme="badge contrast license">Insiders</span>
523
544
  * [REQUIRES AN INSIDERS LICENSE-KEY](https://gum.co/open-wa?tier=Insiders%20Program)
524
545
  *
@@ -564,7 +585,7 @@ export declare class Client {
564
585
  * @param chatId The chat you want to send this message to.
565
586
  *
566
587
  */
567
- sendMessageWithThumb(thumb: string, url: string, title: string, description: string, text: Content, chatId: ChatId): Promise<MessageId | string | boolean>;
588
+ sendMessageWithThumb(thumb: string, url: string, title: string, description: string, text: Content, chatId: ChatId): Promise<MessageId | boolean>;
568
589
  /**
569
590
  * Sends a location message to given chat
570
591
  * @param to chat id: `xxxxx@c.us`
@@ -1111,8 +1132,7 @@ export declare class Client {
1111
1132
  */
1112
1133
  react(messageId: MessageId, emoji: string): Promise<boolean>;
1113
1134
  /**
1114
- *
1115
- * [REQUIRES AN INSIDERS LICENSE-KEY](https://gum.co/open-wa?tier=Insiders%20Program)
1135
+ * @deprecated
1116
1136
  *
1117
1137
  * Retrieves a message object which results in a valid sticker instead of a blank one. This also works with animated stickers.
1118
1138
  *
@@ -1121,7 +1141,7 @@ export declare class Client {
1121
1141
  * @param messageId The message ID `message.id`
1122
1142
  * @returns message object OR `false`
1123
1143
  */
1124
- getStickerDecryptable(messageId: MessageId): Promise<Message | boolean>;
1144
+ getStickerDecryptable(messageId: MessageId): Promise<Message | false>;
1125
1145
  /**
1126
1146
  *
1127
1147
  * [REQUIRES AN INSIDERS LICENSE-KEY](https://gum.co/open-wa?tier=Insiders%20Program)
@@ -753,6 +753,17 @@ class Client {
753
753
  return this.registerListener(events_2.SimpleListener.Button, fn);
754
754
  });
755
755
  }
756
+ /**
757
+ * Listens to broadcast messages
758
+ * @event
759
+ * @param fn callback
760
+ * @fires [[Message]]
761
+ */
762
+ onBroadcast(fn) {
763
+ return __awaiter(this, void 0, void 0, function* () {
764
+ return this.registerListener(events_2.SimpleListener.Broadcast, fn);
765
+ });
766
+ }
756
767
  /**
757
768
  * Listens to battery changes
758
769
  *
@@ -1349,6 +1360,20 @@ class Client {
1349
1360
  }
1350
1361
  /**
1351
1362
  * {@license:insiders@}
1363
+ *
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
+ *
1352
1377
  * <span theme="badge contrast license">Insiders</span>
1353
1378
  * [REQUIRES AN INSIDERS LICENSE-KEY](https://gum.co/open-wa?tier=Insiders%20Program)
1354
1379
  *
@@ -2397,8 +2422,7 @@ class Client {
2397
2422
  });
2398
2423
  }
2399
2424
  /**
2400
- *
2401
- * [REQUIRES AN INSIDERS LICENSE-KEY](https://gum.co/open-wa?tier=Insiders%20Program)
2425
+ * @deprecated
2402
2426
  *
2403
2427
  * Retrieves a message object which results in a valid sticker instead of a blank one. This also works with animated stickers.
2404
2428
  *
@@ -62,6 +62,10 @@ export declare enum SimpleListener {
62
62
  * Represents [[onButton]]
63
63
  */
64
64
  Button = "onButton",
65
+ /**
66
+ * Represents [[onBroadcast]]
67
+ */
68
+ Broadcast = "onBroadcast",
65
69
  /**
66
70
  * Represents [[onLabel]]
67
71
  */
@@ -69,6 +69,10 @@ var SimpleListener;
69
69
  * Represents [[onButton]]
70
70
  */
71
71
  SimpleListener["Button"] = "onButton";
72
+ /**
73
+ * Represents [[onBroadcast]]
74
+ */
75
+ SimpleListener["Broadcast"] = "onBroadcast";
72
76
  /**
73
77
  * Represents [[onLabel]]
74
78
  */
@@ -38,9 +38,9 @@ const AUTO_DECRYPT = (message, client) => __awaiter(void 0, void 0, void 0, func
38
38
  const AUTO_DECRYPT_SAVE = (message, client) => __awaiter(void 0, void 0, void 0, function* () {
39
39
  if (message.deprecatedMms3Url) {
40
40
  const filename = `${message.id.split("_").slice(-1)[0]}.${mime_1.default.extension(message.mimetype)}`;
41
- const mediaData = yield client.decryptMedia(message);
42
41
  const filePath = `media/${filename}`;
43
42
  try {
43
+ const mediaData = yield client.decryptMedia(message);
44
44
  (0, fs_extra_1.outputFileSync)(filePath, Buffer.from(mediaData.split(",")[1], "base64"));
45
45
  }
46
46
  catch (error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-wa/wa-automate",
3
- "version": "4.37.3",
3
+ "version": "4.38.0",
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",
@@ -89,6 +89,7 @@
89
89
  "husky": "^7.0.0",
90
90
  "line-reader": "^0.4.0",
91
91
  "marked": "^4.0.10",
92
+ "ts-json-schema-generator": "^0.97.0",
92
93
  "node-emoji": "^1.10.0",
93
94
  "onchange": "^7.0.2",
94
95
  "precise-commits": "^1.0.2",
@@ -163,7 +164,6 @@
163
164
  "terminal-link": "^2.1.1",
164
165
  "terminate": "^2.5.0",
165
166
  "traverse": "^0.6.6",
166
- "ts-json-schema-generator": "^0.97.0",
167
167
  "ts-morph": "^12.0.0",
168
168
  "type-fest": "^1.1.1",
169
169
  "update-notifier": "^5.0.0",
@@ -1,5 +0,0 @@
1
- export declare const getConfigWithCase: (config?: {
2
- path: string;
3
- tsconfig: string;
4
- type: string;
5
- }) => unknown;
@@ -1,46 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getConfigWithCase = void 0;
4
- const ts_json_schema_generator_1 = require("ts-json-schema-generator");
5
- const change_case_1 = require("change-case");
6
- const defaultConfig = {
7
- path: "../api/model/config.ts",
8
- tsconfig: "../../tsconfig.json",
9
- type: "ConfigObject",
10
- };
11
- const getConfigWithCase = (config) => {
12
- if (!config)
13
- config = defaultConfig;
14
- const schema = (0, ts_json_schema_generator_1.createGenerator)(config).createSchema(config.type);
15
- const ignoredConfigs = [
16
- 'useStealth',
17
- 'chromiumArgs',
18
- 'executablePath',
19
- 'skipBrokenMethodsCheck',
20
- 'inDocker',
21
- 'autoRefresh',
22
- 'bypassCSP',
23
- 'throwErrorOnTosBlock',
24
- 'killProcessOnBrowserClose',
25
- 'cloudUploadOptions',
26
- 'qrRefreshS'
27
- ];
28
- //only convert simple types
29
- // const configs = Object.keys(schema.definitions.ConfigObject.properties).map(key=>({...schema.definitions.ConfigObject.properties[key],key})).filter(({type,key})=>type&&!ignoredConfigs.includes(key));
30
- const configs = Object.entries(schema.definitions.ConfigObject.properties).map(([key, entry]) => {
31
- if (key === 'sessionData') {
32
- entry.type = 'string';
33
- entry.description = 'The base64 encoded sessionData used to restore a session.';
34
- delete entry.anyOf;
35
- }
36
- if (key === 'licenseKey') {
37
- entry.type = 'string';
38
- entry.description = 'The license key to use with the session.';
39
- delete entry.anyOf;
40
- }
41
- return Object.assign(Object.assign({}, entry), { key });
42
- }).filter(({ type, key }) => type && !ignoredConfigs.includes(key));
43
- const configWithCases = configs.map(o => (Object.assign({ env: `WA_${(0, change_case_1.constantCase)(o.key)}`, p: (0, change_case_1.paramCase)(o.key) }, o)));
44
- return configWithCases;
45
- };
46
- exports.getConfigWithCase = getConfigWithCase;