@open-wa/wa-automate 4.52.0 → 4.53.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -184,6 +184,13 @@ export declare class Client {
184
184
  * @fires [[Message]]
185
185
  */
186
186
  onButton(fn: (message: Message) => void): Promise<Listener | boolean>;
187
+ /**
188
+ * Listens to poll vote events
189
+ * @event
190
+ * @param fn callback
191
+ * @fires [[PollData]]
192
+ */
193
+ onPollVote(fn: (pollDate: PollData) => void): Promise<Listener | boolean>;
187
194
  /**
188
195
  * Listens to broadcast messages
189
196
  * @event
@@ -1731,7 +1738,7 @@ export declare class Client {
1731
1738
  * @deprecated
1732
1739
  * Alias for deleteStory
1733
1740
  */
1734
- deleteStatus: (statusesToDelete: string | string[]) => Promise<boolean>;
1741
+ deleteStatus(statusesToDelete: string | string[]): Promise<boolean>;
1735
1742
  /**
1736
1743
  * {@license:restricted@}
1737
1744
  *
@@ -1743,7 +1750,7 @@ export declare class Client {
1743
1750
  * @deprecated
1744
1751
  * Alias for deleteStory
1745
1752
  */
1746
- deleteAllStatus: () => Promise<boolean>;
1753
+ deleteAllStatus(): Promise<boolean>;
1747
1754
  /**
1748
1755
  * {@license:restricted@}
1749
1756
  *
@@ -1756,7 +1763,7 @@ export declare class Client {
1756
1763
  * @deprecated
1757
1764
  * Alias for deleteStory
1758
1765
  */
1759
- getMyStatusArray: () => Promise<Message[]>;
1766
+ getMyStatusArray(): Promise<Message[]>;
1760
1767
  /**
1761
1768
  * {@license:restricted@}
1762
1769
  *
@@ -112,21 +112,6 @@ class Client {
112
112
  * Note: This would be much simpler if eventMode was the default (and only) listener strategy.
113
113
  */
114
114
  this._registeredWebhookListeners = {};
115
- /**
116
- * @deprecated
117
- * Alias for deleteStory
118
- */
119
- this.deleteStatus = this.deleteStory;
120
- /**
121
- * @deprecated
122
- * Alias for deleteStory
123
- */
124
- this.deleteAllStatus = this.deleteAllStories;
125
- /**
126
- * @deprecated
127
- * Alias for deleteStory
128
- */
129
- this.getMyStatusArray = this.getMyStoryArray;
130
115
  /**
131
116
  * This exposes a simple express middlware that will allow users to quickly boot up an api based off this client. Checkout demo/index.ts for an example
132
117
  * How to use the middleware:
@@ -824,6 +809,17 @@ class Client {
824
809
  return this.registerListener(events_2.SimpleListener.Button, fn);
825
810
  });
826
811
  }
812
+ /**
813
+ * Listens to poll vote events
814
+ * @event
815
+ * @param fn callback
816
+ * @fires [[PollData]]
817
+ */
818
+ onPollVote(fn) {
819
+ return __awaiter(this, void 0, void 0, function* () {
820
+ return this.registerListener(events_2.SimpleListener.PollVote, fn);
821
+ });
822
+ }
827
823
  /**
828
824
  * Listens to broadcast messages
829
825
  * @event
@@ -3594,6 +3590,15 @@ class Client {
3594
3590
  return yield this.pup(({ statusesToDelete }) => WAPI.deleteStatus(statusesToDelete), { statusesToDelete });
3595
3591
  });
3596
3592
  }
3593
+ /**
3594
+ * @deprecated
3595
+ * Alias for deleteStory
3596
+ */
3597
+ deleteStatus(statusesToDelete) {
3598
+ return __awaiter(this, void 0, void 0, function* () {
3599
+ return yield this.deleteStory(statusesToDelete);
3600
+ });
3601
+ }
3597
3602
  /**
3598
3603
  * {@license:restricted@}
3599
3604
  *
@@ -3605,6 +3610,15 @@ class Client {
3605
3610
  return yield this.pup(() => WAPI.deleteAllStatus());
3606
3611
  });
3607
3612
  }
3613
+ /**
3614
+ * @deprecated
3615
+ * Alias for deleteStory
3616
+ */
3617
+ deleteAllStatus() {
3618
+ return __awaiter(this, void 0, void 0, function* () {
3619
+ return yield this.deleteAllStories();
3620
+ });
3621
+ }
3608
3622
  /**
3609
3623
  * {@license:restricted@}
3610
3624
  *
@@ -3617,6 +3631,15 @@ class Client {
3617
3631
  return yield this.pup(() => WAPI.getMyStatusArray());
3618
3632
  });
3619
3633
  }
3634
+ /**
3635
+ * @deprecated
3636
+ * Alias for deleteStory
3637
+ */
3638
+ getMyStatusArray() {
3639
+ return __awaiter(this, void 0, void 0, function* () {
3640
+ return yield this.getMyStoryArray();
3641
+ });
3642
+ }
3620
3643
  /**
3621
3644
  * {@license:restricted@}
3622
3645
  *
@@ -66,6 +66,10 @@ export declare enum SimpleListener {
66
66
  * Represents [[onButton]]
67
67
  */
68
68
  Button = "onButton",
69
+ /**
70
+ * Represents [[onButton]]
71
+ */
72
+ PollVote = "onPollVote",
69
73
  /**
70
74
  * Represents [[onBroadcast]]
71
75
  */
@@ -73,6 +73,10 @@ var SimpleListener;
73
73
  * Represents [[onButton]]
74
74
  */
75
75
  SimpleListener["Button"] = "onButton";
76
+ /**
77
+ * Represents [[onButton]]
78
+ */
79
+ SimpleListener["PollVote"] = "onPollVote";
76
80
  /**
77
81
  * Represents [[onBroadcast]]
78
82
  */
@@ -51,7 +51,7 @@ const tools_1 = require("../utils/tools");
51
51
  const script_preloader_1 = require("./script_preloader");
52
52
  const patch_manager_1 = require("./patch_manager");
53
53
  const init_patch_1 = require("./init_patch");
54
- let browser, wapiInjected = false, dumbCache = undefined, wapiAttempts = 1;
54
+ let browser, wapiInjected = false, pageCache = undefined, wapiAttempts = 1;
55
55
  exports.BROWSER_START_TS = 0;
56
56
  function initPage(sessionId, config, qrManager, customUserAgent, spinner, _page, skipAuth) {
57
57
  var _a, _b, _c, _d, _e;
@@ -132,32 +132,50 @@ function initPage(sessionId, config, qrManager, customUserAgent, spinner, _page,
132
132
  if (proxyAddr) {
133
133
  proxy = (yield Promise.resolve().then(() => __importStar(require('smashah-puppeteer-page-proxy')))).default;
134
134
  }
135
+ /**
136
+ * Detect a locally cached page
137
+ */
138
+ if (process.env.WA_LOCAL_PAGE_CACHE) {
139
+ const localPageCacheExists = yield (0, tools_1.pathExists)(process.env.WA_LOCAL_PAGE_CACHE, true);
140
+ logging_1.log.info(`Local page cache env var set: ${process.env.WA_LOCAL_PAGE_CACHE} ${localPageCacheExists}`);
141
+ if (localPageCacheExists) {
142
+ logging_1.log.info(`Local page cache file exists. Loading...`);
143
+ pageCache = yield fs.readFile(process.env.WA_LOCAL_PAGE_CACHE, "utf8");
144
+ }
145
+ }
135
146
  if (interceptAuthentication || proxyAddr || blockCrashLogs || true) {
136
147
  yield waPage.setRequestInterception(true);
137
148
  waPage.on('response', (response) => __awaiter(this, void 0, void 0, function* () {
138
149
  try {
139
150
  if (response.request().url() == "https://web.whatsapp.com/") {
140
151
  const t = yield response.text();
141
- if (t.includes(`class="no-js"`) && t.includes(`self.`) && !dumbCache) {
152
+ if (t.includes(`class="no-js"`) && t.includes(`self.`) && !pageCache) {
142
153
  //this is a valid response, save it for later
143
- dumbCache = t;
154
+ pageCache = t;
144
155
  logging_1.log.info("saving valid page to dumb cache");
156
+ /**
157
+ * Save locally
158
+ */
159
+ if (process.env.WA_LOCAL_PAGE_CACHE) {
160
+ logging_1.log.info(`Writing page cache to local file: ${process.env.WA_LOCAL_PAGE_CACHE}`);
161
+ yield fs.writeFile(process.env.WA_LOCAL_PAGE_CACHE, pageCache);
162
+ }
145
163
  }
146
164
  }
147
165
  }
148
166
  catch (error) {
149
- logging_1.log.error("dumb cache error", error);
167
+ logging_1.log.error("page cache error", error);
150
168
  }
151
169
  }));
152
170
  const authCompleteEv = new events_1.EvEmitter(sessionId, 'AUTH');
153
171
  waPage.on('request', (request) => __awaiter(this, void 0, void 0, function* () {
154
172
  //local refresh cache:
155
- if (request.url() === "https://web.whatsapp.com/" && dumbCache) {
156
- //if the dumbCache isn't set and this response includes
157
- logging_1.log.info("reviving page from dumb cache");
173
+ if (request.url() === "https://web.whatsapp.com/" && pageCache) {
174
+ //if the pageCache isn't set and this response includes
175
+ logging_1.log.info("reviving page from page cache");
158
176
  return yield request.respond({
159
177
  status: 200,
160
- body: dumbCache
178
+ body: pageCache
161
179
  });
162
180
  }
163
181
  if (interceptAuthentication &&
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-wa/wa-automate",
3
- "version": "4.52.0",
3
+ "version": "4.53.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",