@open-wa/wa-automate 4.23.5 → 4.23.9

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/README.md CHANGED
@@ -36,7 +36,7 @@
36
36
  Use this command to install the library for the first time and to keep the library up to date.
37
37
 
38
38
  ```bash
39
- > npm i --save @open-wa/wa-automate@latest
39
+ > npm i --save @open-wa/wa-automate@latest --multi-device
40
40
  ```
41
41
 
42
42
  ## Usage
@@ -65,6 +65,7 @@ const wa = require('@open-wa/wa-automate');
65
65
 
66
66
  wa.create({
67
67
  sessionId: "COVID_HELPER",
68
+ multiDevice: true, //required to enable multiDevice support
68
69
  authTimeout: 60, //wait only 60 seconds to get a connection with the host account device
69
70
  blockCrashLogs: true,
70
71
  disableSpins: true,
@@ -97,6 +98,10 @@ Want to convert your WA account to an API instantly? You can now with the CLI. F
97
98
  > npx @open-wa/wa-automate --help
98
99
  ```
99
100
 
101
+ ## Multi Device Support
102
+
103
+ We're currently in a weird transitionary period where some people are being forced to adopt Multi Device (MD). Once the transition is complete, the library default will be to turn on MD support. For now, you have to set it yourself explicitly either by using the `--multi-device` flag (with the [CLI](#CLI)) or setting `multiDevice: true` in your config (with your custom code)
104
+
100
105
  ### Latest Changes
101
106
 
102
107
  With the constant updates from WA. It is advisable to always use the latest version of `@open-wa/wa-automate`.
@@ -158,7 +158,7 @@ export declare class Client {
158
158
  * @param fn callback
159
159
  * @fires [[Message]]
160
160
  */
161
- onButton(fn: (chat: Chat) => void): Promise<Listener | boolean>;
161
+ onButton(fn: (message: Message) => void): Promise<Listener | boolean>;
162
162
  /**
163
163
  * Listens to battery changes
164
164
  *
@@ -210,6 +210,12 @@ export declare class Client {
210
210
  * Listens to new orders. Only works on business accounts
211
211
  */
212
212
  onOrder(fn: (order: Order) => void): Promise<Listener | boolean>;
213
+ /**
214
+ *[REQUIRES AN INSIDERS LICENSE-KEY](https://gum.co/open-wa?tier=Insiders%20Program)
215
+ *
216
+ * Listens to new orders. Only works on business accounts
217
+ */
218
+ onNewProduct(fn: (product: Product) => void): Promise<Listener | boolean>;
213
219
  /**
214
220
  * [REQUIRES AN INSIDERS LICENSE-KEY](https://gum.co/open-wa?tier=Insiders%20Program)
215
221
  *
@@ -767,7 +773,7 @@ export declare class Client {
767
773
  * @param messages this can be any mixture of message ids or message objects
768
774
  * @param skipMyMessages This indicates whether or not to skip your own messages from the array
769
775
  */
770
- forwardMessages(to: ChatId, messages: MessageId | MessageId[], skipMyMessages: boolean): Promise<boolean | string>;
776
+ forwardMessages(to: ChatId, messages: MessageId | MessageId[], skipMyMessages: boolean): Promise<boolean | MessageId[]>;
771
777
  /**
772
778
  * Ghost forwarding is like a normal forward but as if it were sent from the host phone [i.e it doesn't show up as forwarded.]
773
779
  * Any potential abuse of this method will see it become paywalled.
@@ -718,6 +718,16 @@ class Client {
718
718
  return this.registerListener(events_2.SimpleListener.Order, fn);
719
719
  });
720
720
  }
721
+ /**
722
+ *[REQUIRES AN INSIDERS LICENSE-KEY](https://gum.co/open-wa?tier=Insiders%20Program)
723
+ *
724
+ * Listens to new orders. Only works on business accounts
725
+ */
726
+ onNewProduct(fn) {
727
+ return __awaiter(this, void 0, void 0, function* () {
728
+ return this.registerListener(events_2.SimpleListener.NewProduct, fn);
729
+ });
730
+ }
721
731
  /**
722
732
  * [REQUIRES AN INSIDERS LICENSE-KEY](https://gum.co/open-wa?tier=Insiders%20Program)
723
733
  *
@@ -81,5 +81,10 @@ export declare enum SimpleListener {
81
81
  * Requires licence
82
82
  * Represents [[onContactAdded]]
83
83
  */
84
- Order = "onOrder"
84
+ Order = "onOrder",
85
+ /**
86
+ * Requires licence
87
+ * Represents [[onNewProduct]]
88
+ */
89
+ NewProduct = "onNewProduct"
85
90
  }
@@ -89,4 +89,9 @@ var SimpleListener;
89
89
  * Represents [[onContactAdded]]
90
90
  */
91
91
  SimpleListener["Order"] = "onOrder";
92
+ /**
93
+ * Requires licence
94
+ * Represents [[onNewProduct]]
95
+ */
96
+ SimpleListener["NewProduct"] = "onNewProduct";
92
97
  })(SimpleListener = exports.SimpleListener || (exports.SimpleListener = {}));
@@ -15,6 +15,10 @@ export interface Message {
15
15
  * The body of the message. If the message type is `chat` , `body` will be the text of the chat. If the message type is some sort of media, then this body will be the thumbnail of the media.
16
16
  */
17
17
  body: string;
18
+ /**
19
+ * a convenient way to get the main text content from a message.
20
+ */
21
+ text: string;
18
22
  /**
19
23
  * The type of the message, see [[MessageTypes]]
20
24
  */
@@ -117,7 +117,7 @@ function initPage(sessionId, config, customUserAgent, spinner) {
117
117
  }
118
118
  spinner === null || spinner === void 0 ? void 0 : spinner.info('Loading session data');
119
119
  let sessionjson = getSessionDataFromFile(sessionId, config, spinner);
120
- if (!sessionjson && config.sessionDataBucketAuth) {
120
+ if (!sessionjson && sessionjson !== "" && config.sessionDataBucketAuth) {
121
121
  try {
122
122
  spinner === null || spinner === void 0 ? void 0 : spinner.info('Unable to find session data file locally, attempting to find session data in cloud storage..');
123
123
  sessionjson = JSON.parse(Buffer.from(yield pico_s3_1.getTextFile(Object.assign(Object.assign({ directory: '_sessionData' }, JSON.parse(Buffer.from(config.sessionDataBucketAuth, 'base64').toString('ascii'))), { filename: `${config.sessionId || 'session'}.data.json` })), 'base64').toString('ascii'));
@@ -85,7 +85,7 @@ let axios;
85
85
  */
86
86
  //@ts-ignore
87
87
  function create(config = {}) {
88
- var _a, _b;
88
+ var _a, _b, _c;
89
89
  return __awaiter(this, void 0, void 0, function* () {
90
90
  const START_TIME = Date.now();
91
91
  let waPage = undefined;
@@ -369,7 +369,9 @@ function create(config = {}) {
369
369
  //@ts-ignore
370
370
  const metrics = yield waPage.evaluate(({ config }) => WAPI.launchMetrics(config), { config });
371
371
  const purgedMessage = (metrics === null || metrics === void 0 ? void 0 : metrics.purged) ? Object.entries(metrics.purged).filter(([, e]) => e > 0).map(([k, e]) => `${e} ${k}`).join(" and ") : "";
372
- spinner.succeed(`Client loaded for ${metrics.isBiz ? "business" : "normal"} account with ${metrics.contacts} contacts, ${metrics.chats} chats & ${metrics.messages} messages ${purgedMessage ? `+ purged ${purgedMessage} ` : ``}in ${LAUNCH_TIME_MS / 1000}s`);
372
+ if (metrics.isMd && !(config === null || config === void 0 ? void 0 : config.multiDevice))
373
+ spinner.info("!!!Please set multiDevice: true in the config or use the --mutli-Device flag!!!");
374
+ spinner.succeed(`Client loaded for ${metrics.isBiz ? "business" : "normal"} account ${metrics.isMd && "[MD] " || ''}with ${metrics.contacts} contacts, ${metrics.chats} chats & ${metrics.messages} messages ${purgedMessage ? `+ purged ${purgedMessage} ` : ``}in ${LAUNCH_TIME_MS / 1000}s`);
373
375
  if ((config === null || config === void 0 ? void 0 : config.deleteSessionDataOnLogout) || (config === null || config === void 0 ? void 0 : config.killClientOnLogout))
374
376
  config.eventMode = true;
375
377
  const client = new Client_1.Client(waPage, config, debugInfo);
@@ -377,7 +379,9 @@ function create(config = {}) {
377
379
  if ((config === null || config === void 0 ? void 0 : config.licenseKey) || me._serialized !== earlyWid) {
378
380
  yield getAndInjectLicense(waPage, config, me, debugInfo, spinner, me._serialized !== earlyWid ? false : yield licensePromise);
379
381
  }
382
+ spinner.info("Finalizing web session...");
380
383
  yield init_patch_1.injectInitPatch(waPage);
384
+ spinner.info("Finalizing client...");
381
385
  yield client.loaded();
382
386
  if (config.ensureHeadfulIntegrity && !attemptingReauth) {
383
387
  spinner.info("QR scanned for the first time. Refreshing...");
@@ -398,6 +402,10 @@ function create(config = {}) {
398
402
  catch (error) {
399
403
  spinner.emit(error.message);
400
404
  yield kill(waPage);
405
+ if (error.name === "ProtocolError" && ((_c = error.message) === null || _c === void 0 ? void 0 : _c.includes("Target closed"))) {
406
+ spinner.fail(error.message);
407
+ process.exit();
408
+ }
401
409
  if (error.name === "TimeoutError" && (config === null || config === void 0 ? void 0 : config.multiDevice)) {
402
410
  spinner.fail(`Please delete the ${config === null || config === void 0 ? void 0 : config.userDataDir} folder and any related data.json files and try again. It is highly suggested to set useChrome: true also.`);
403
411
  }
package/dist/lib/wapi.js CHANGED
@@ -52,7 +52,7 @@ if (!window.Store||!window.Store.Msg) {
52
52
  { id: "Participants", conditions: (module) => (module.addParticipants && module.removeParticipants && module.promoteParticipants && module.demoteParticipants) ? module : null },
53
53
  { id: "WidFactory", conditions: (module) => (module.isWidlike && module.createWid && module.createWidFromWidLike) ? module : null },
54
54
  { id: "Base", conditions: (module) => (module.setSubProtocol && module.binSend && module.actionNode) ? module : null },
55
- { id: "Versions", conditions: (module) => (module.loadProtoVersions && module.default["15"] && module.default["16"] && module.default["17"]) ? module : null },
55
+ { id: "Versions", conditions: (module) => (module.loadProtoVersions && module.default && module.default["15"] && module.default["16"] && module.default["17"]) ? module : null },
56
56
  { id: "Sticker", conditions: (module) => (module.default && module.default.Sticker) ? module.default.Sticker : null },
57
57
  { id: "MediaUpload", conditions: (module) => (module.default && module.default.mediaUpload) ? module.default : null },
58
58
  { id: "UploadUtils", conditions: (module) => (module.default && module.default.encryptAndUpload) ? module.default : null }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-wa/wa-automate",
3
- "version": "4.23.5",
3
+ "version": "4.23.9",
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",
@@ -81,7 +81,7 @@
81
81
  "ava": "^3.13.0",
82
82
  "changelog-parser": "^2.8.0",
83
83
  "command-line-args": "^5.1.1",
84
- "eslint": "^7.20.0",
84
+ "eslint": "^8.1.0",
85
85
  "husky": "^7.0.0",
86
86
  "line-reader": "^0.4.0",
87
87
  "marked": "^3.0.0",