@open-wa/wa-automate 4.23.14 → 4.23.18

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,24 +36,17 @@
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 --multi-device
39
+ > npm i --save @open-wa/wa-automate@latest
40
40
  ```
41
41
 
42
42
  ## Usage
43
43
 
44
- ```javascript
45
- // import { create, Client } from '@open-wa/wa-automate';
46
- const wa = require('@open-wa/wa-automate');
44
+ ## CLI
47
45
 
48
- wa.create().then(client => start(client));
46
+ Want to convert your WA account to an API instantly? You can now with the CLI. For more details see [Easy API](https://docs.openwa.dev/pages/Getting%20Started/quick-run.html)
49
47
 
50
- function start(client) {
51
- client.onMessage(async message => {
52
- if (message.body === 'Hi') {
53
- await client.sendText(message.from, '👋 Hello!');
54
- }
55
- });
56
- }
48
+ ```bash
49
+ > npx @open-wa/wa-automate --help
57
50
  ```
58
51
 
59
52
  ## Custom Setup
@@ -90,13 +83,6 @@ function start(client) {
90
83
 
91
84
  ###### @open-wa/wa-automate will remember the session so there is no need to authenticate every time
92
85
 
93
- ## CLI
94
-
95
- Want to convert your WA account to an API instantly? You can now with the CLI. For more details see [Easy API](https://docs.openwa.dev/pages/Getting%20Started/quick-run.html)
96
-
97
- ```bash
98
- > npx @open-wa/wa-automate --help
99
- ```
100
86
 
101
87
  ## Multi Device Support
102
88
 
@@ -355,7 +355,8 @@ class Client {
355
355
  const START_TIME = Date.now();
356
356
  spinner.info("Opening session in new tab");
357
357
  const newTab = yield this._page.browser().newPage();
358
- yield newTab.goto(puppeteer_config_1.puppeteerConfig.WAUrl);
358
+ yield browser_1.initPage(this.getSessionId(), this._createConfig, this._createConfig.customUserAgent, spinner, newTab, true);
359
+ // await newTab.goto(puppeteerConfig.WAUrl);
359
360
  //Two promises. One that closes the previous page, one that sets up the new page
360
361
  const closePageOnConflict = () => __awaiter(this, void 0, void 0, function* () {
361
362
  const useHere = yield this._page.evaluate(() => WAPI.getUseHereString());
@@ -5,26 +5,83 @@ export interface Chat {
5
5
  archive: boolean;
6
6
  changeNumberNewJid: any;
7
7
  changeNumberOldJid: any;
8
+ /**
9
+ * The contact related to this chat
10
+ */
8
11
  contact: Contact;
12
+ /**
13
+ * Group metadata for this chat
14
+ */
9
15
  groupMetadata: GroupMetadata;
16
+ /**
17
+ * The id of the chat
18
+ */
10
19
  id: ChatId;
20
+ /**
21
+ * If the chat is a group chat is restricted
22
+ */
11
23
  isAnnounceGrpRestrict: any;
24
+ /**
25
+ * The title of the chat
26
+ */
12
27
  formattedTitle?: string;
28
+ /**
29
+ * Whether your host account is able to send messages to this chat
30
+ */
13
31
  canSend?: boolean;
32
+ /**
33
+ * Whether the chat is a group chat
34
+ */
14
35
  isGroup: boolean;
36
+ /**
37
+ * Whether the chat is a group chat and the group is restricted
38
+ */
15
39
  isReadOnly: boolean;
16
40
  kind: string;
41
+ /**
42
+ * The labels attached to this chat.
43
+ */
17
44
  labels: any;
45
+ /**
46
+ * The ID of the last message received in this chat
47
+ */
18
48
  lastReceivedKey: any;
19
49
  modifyTag: number;
50
+ /**
51
+ * The messages in the chat
52
+ */
20
53
  msgs: any;
54
+ /**
55
+ * The expiration timestamp of the chat mute
56
+ */
21
57
  muteExpiration: number;
58
+ /**
59
+ * The name of the chat
60
+ */
22
61
  name: string;
62
+ /**
63
+ * Whether the chat is marked as spam
64
+ */
23
65
  notSpam: boolean;
66
+ /**
67
+ * Messages that are pending to be sent
68
+ */
24
69
  pendingMsgs: boolean;
70
+ /**
71
+ * Whether the chat is pinned
72
+ */
25
73
  pin: number;
74
+ /**
75
+ * The presence state of the chat participant
76
+ */
26
77
  presence: any;
78
+ /**
79
+ * The timestamp of the last interaction in the chat
80
+ */
27
81
  t: number;
82
+ /**
83
+ * The number of undread messages in this chat
84
+ */
28
85
  unreadCount: number;
29
86
  ack?: any;
30
87
  /**
@@ -44,6 +44,14 @@ export declare type StickerMetadata = {
44
44
  * @default `attention`
45
45
  */
46
46
  cropPosition?: 'top' | 'right top' | 'right' | 'right bottom' | 'bottom' | 'left bottom' | 'left' | 'left top' | 'north' | 'northeast' | 'east' | 'southeast' | 'south' | 'southwest' | 'west' | 'northwest' | 'center' | 'centre' | 'entropy' | 'attention';
47
+ /**
48
+ * The corner radius of the sticker when `stickerMetadata.circle` is set to true.
49
+ * @default `100`
50
+ * @minimum `1`
51
+ * @maximum `100`
52
+ * @multipleOf `1`
53
+ */
54
+ cornerRadius?: number;
47
55
  };
48
56
  export declare type Mp4StickerConversionProcessOptions = {
49
57
  /**
@@ -1,7 +1,7 @@
1
1
  import { Page } from 'puppeteer';
2
2
  import { Spin } from './events';
3
3
  import { ConfigObject } from '../api/model';
4
- export declare function initPage(sessionId?: string, config?: ConfigObject, customUserAgent?: string, spinner?: Spin): Promise<Page>;
4
+ export declare function initPage(sessionId?: string, config?: ConfigObject, customUserAgent?: string, spinner?: Spin, _page?: Page, skipAuth?: boolean): Promise<Page>;
5
5
  export declare const deleteSessionData: (config: ConfigObject) => boolean;
6
6
  export declare const getSessionDataFilePath: (sessionId: string, config: ConfigObject) => string | boolean;
7
7
  export declare const addScript: (page: Page, js: string) => Promise<unknown>;
@@ -42,7 +42,7 @@ const pico_s3_1 = require("pico-s3");
42
42
  // eslint-disable-next-line @typescript-eslint/no-var-requires
43
43
  const puppeteer = require('puppeteer-extra');
44
44
  let browser;
45
- function initPage(sessionId, config, customUserAgent, spinner) {
45
+ function initPage(sessionId, config, customUserAgent, spinner, _page, skipAuth) {
46
46
  var _a, _b, _c, _d, _e;
47
47
  return __awaiter(this, void 0, void 0, function* () {
48
48
  const setupPromises = [];
@@ -52,10 +52,13 @@ function initPage(sessionId, config, customUserAgent, spinner) {
52
52
  const { default: stealth } = yield Promise.resolve().then(() => __importStar(require('puppeteer-extra-plugin-stealth')));
53
53
  puppeteer.use(stealth());
54
54
  }
55
- spinner === null || spinner === void 0 ? void 0 : spinner.info('Launching Browser');
56
- browser = yield initBrowser(sessionId, config);
57
- const waPage = yield getWAPage(browser);
58
- spinner === null || spinner === void 0 ? void 0 : spinner.info('Setting Up Browser');
55
+ let waPage = _page;
56
+ if (!waPage) {
57
+ spinner === null || spinner === void 0 ? void 0 : spinner.info('Launching Browser');
58
+ browser = yield initBrowser(sessionId, config);
59
+ waPage = yield getWAPage(browser);
60
+ }
61
+ spinner === null || spinner === void 0 ? void 0 : spinner.info('Setting Up Page');
59
62
  if (config === null || config === void 0 ? void 0 : config.proxyServerCredentials) {
60
63
  yield waPage.authenticate(config.proxyServerCredentials);
61
64
  }
@@ -115,40 +118,51 @@ function initPage(sessionId, config, customUserAgent, spinner) {
115
118
  request.continue();
116
119
  }));
117
120
  }
118
- spinner === null || spinner === void 0 ? void 0 : spinner.info('Loading session data');
119
- let sessionjson = getSessionDataFromFile(sessionId, config, spinner);
120
- if (!sessionjson && sessionjson !== "" && config.sessionDataBucketAuth) {
121
- try {
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
- 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'));
124
- spinner === null || spinner === void 0 ? void 0 : spinner.succeed('Successfully downloaded session data file from cloud storage!');
125
- }
126
- catch (error) {
127
- spinner === null || spinner === void 0 ? void 0 : spinner.fail(`${error instanceof pico_s3_1.FileNotFoundError ? 'The session data file was not found in the cloud storage bucket' : 'Something went wrong while fetching session data from cloud storage bucket'}. Continuing...`);
128
- }
129
- }
130
- if (sessionjson) {
131
- spinner === null || spinner === void 0 ? void 0 : spinner.info(config.multiDevice ? "multi-device enabled. Session data skipped..." : 'Existing session data detected. Injecting...');
132
- if (!(config === null || config === void 0 ? void 0 : config.multiDevice))
133
- yield waPage.evaluateOnNewDocument(session => {
134
- localStorage.clear();
135
- Object.keys(session).forEach(key => localStorage.setItem(key, session[key]));
136
- }, sessionjson);
137
- spinner === null || spinner === void 0 ? void 0 : spinner.succeed('Existing session data injected');
121
+ if (skipAuth) {
122
+ spinner.info("Skipping Authentication");
138
123
  }
139
124
  else {
140
- if (config === null || config === void 0 ? void 0 : config.multiDevice) {
141
- spinner === null || spinner === void 0 ? void 0 : spinner.info("No session data detected. Opting in for MD.");
142
- spinner === null || spinner === void 0 ? void 0 : spinner.info("Make sure to keep the session alive for at least 5 minutes after scanning the QR code before trying to restart a session!!");
143
- yield waPage.evaluateOnNewDocument(session => {
144
- localStorage.clear();
145
- Object.keys(session).forEach(key => localStorage.setItem(key, session[key]));
146
- }, {
147
- "md-opted-in": "true",
148
- "MdUpgradeWamFlag": "true",
149
- "remember-me": "true"
150
- });
125
+ /**
126
+ * AUTH
127
+ */
128
+ spinner === null || spinner === void 0 ? void 0 : spinner.info('Loading session data');
129
+ let sessionjson = getSessionDataFromFile(sessionId, config, spinner);
130
+ if (!sessionjson && sessionjson !== "" && config.sessionDataBucketAuth) {
131
+ try {
132
+ spinner === null || spinner === void 0 ? void 0 : spinner.info('Unable to find session data file locally, attempting to find session data in cloud storage..');
133
+ 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'));
134
+ spinner === null || spinner === void 0 ? void 0 : spinner.succeed('Successfully downloaded session data file from cloud storage!');
135
+ }
136
+ catch (error) {
137
+ spinner === null || spinner === void 0 ? void 0 : spinner.fail(`${error instanceof pico_s3_1.FileNotFoundError ? 'The session data file was not found in the cloud storage bucket' : 'Something went wrong while fetching session data from cloud storage bucket'}. Continuing...`);
138
+ }
139
+ }
140
+ if (sessionjson) {
141
+ spinner === null || spinner === void 0 ? void 0 : spinner.info(config.multiDevice ? "multi-device enabled. Session data skipped..." : 'Existing session data detected. Injecting...');
142
+ if (!(config === null || config === void 0 ? void 0 : config.multiDevice))
143
+ yield waPage.evaluateOnNewDocument(session => {
144
+ localStorage.clear();
145
+ Object.keys(session).forEach(key => localStorage.setItem(key, session[key]));
146
+ }, sessionjson);
147
+ spinner === null || spinner === void 0 ? void 0 : spinner.succeed('Existing session data injected');
148
+ }
149
+ else {
150
+ if (config === null || config === void 0 ? void 0 : config.multiDevice) {
151
+ spinner === null || spinner === void 0 ? void 0 : spinner.info("No session data detected. Opting in for MD.");
152
+ spinner === null || spinner === void 0 ? void 0 : spinner.info("Make sure to keep the session alive for at least 5 minutes after scanning the QR code before trying to restart a session!!");
153
+ yield waPage.evaluateOnNewDocument(session => {
154
+ localStorage.clear();
155
+ Object.keys(session).forEach(key => localStorage.setItem(key, session[key]));
156
+ }, {
157
+ "md-opted-in": "true",
158
+ "MdUpgradeWamFlag": "true",
159
+ "remember-me": "true"
160
+ });
161
+ }
151
162
  }
163
+ /**
164
+ * END AUTH
165
+ */
152
166
  }
153
167
  if ((config === null || config === void 0 ? void 0 : config.proxyServerCredentials) && !(config === null || config === void 0 ? void 0 : config.useNativeProxy)) {
154
168
  yield proxy(waPage, proxyAddr);
@@ -305,14 +319,15 @@ function initBrowser(sessionId, config = {}) {
305
319
  let args = [...puppeteer_config_1.puppeteerConfig.chromiumArgs, ...((config === null || config === void 0 ? void 0 : config.chromiumArgs) || [])];
306
320
  if (config === null || config === void 0 ? void 0 : config.multiDevice) {
307
321
  args = args.filter(x => x != '--incognito');
308
- config["userDataDir"] = `./_IGNORE_${(config === null || config === void 0 ? void 0 : config.sessionId) || 'session'}`;
322
+ config["userDataDir"] = config["userDataDir"] || `${(config === null || config === void 0 ? void 0 : config.inDocker) ? '/sessions' : (config === null || config === void 0 ? void 0 : config.sessionDataPath) || '.'}/_IGNORE_${(config === null || config === void 0 ? void 0 : config.sessionId) || 'session'}`;
309
323
  }
310
324
  if (config === null || config === void 0 ? void 0 : config.corsFix)
311
325
  args.push('--disable-web-security');
312
326
  const browser = (config === null || config === void 0 ? void 0 : config.browserWSEndpoint) ? yield puppeteer.connect(Object.assign({}, config)) : yield puppeteer.launch(Object.assign(Object.assign({ headless: true, args }, config), { devtools: false }));
313
327
  //devtools
314
328
  if (config === null || config === void 0 ? void 0 : config.devtools) {
315
- const devtools = (yield Promise.resolve().then(() => __importStar(require('puppeteer-extra-plugin-devtools'))))();
329
+ const _dt = yield Promise.resolve().then(() => __importStar(require('puppeteer-extra-plugin-devtools')));
330
+ const devtools = _dt.default();
316
331
  if (config.devtools !== 'local' && !((_b = config === null || config === void 0 ? void 0 : config.devtools) === null || _b === void 0 ? void 0 : _b.user) && !((_c = config === null || config === void 0 ? void 0 : config.devtools) === null || _c === void 0 ? void 0 : _c.pass)) {
317
332
  config.devtools = {};
318
333
  config.devtools.user = 'dev';
@@ -322,6 +337,7 @@ function initBrowser(sessionId, config = {}) {
322
337
  if (config.devtools.user && config.devtools.pass) {
323
338
  devtools.setAuthCredentials(config.devtools.user, config.devtools.pass);
324
339
  }
340
+ puppeteer.use(devtools);
325
341
  try {
326
342
  // const tunnel = await devtools.createTunnel(browser);
327
343
  const tunnel = config.devtools == 'local' ? devtools.getLocalDevToolsUrl(browser) : (yield devtools.createTunnel(browser)).url;
@@ -157,10 +157,11 @@ function create(config = {}) {
157
157
  /**
158
158
  * Check if the IGNORE folder exists, therefore, assume that the session is MD.
159
159
  */
160
- if (fs.existsSync(`./_IGNORE_${(config === null || config === void 0 ? void 0 : config.sessionId) || 'session'}`) && !(config === null || config === void 0 ? void 0 : config.multiDevice)) {
161
- spinner.info(`Multi-Device directory detected. multiDevice set to true.`);
162
- config.multiDevice = true;
163
- }
160
+ // const mdDir = config["userDataDir"] || `${config?.inDocker ? '/sessions' : config?.sessionDataPath || '.' }/_IGNORE_${config?.sessionId || 'session'}`
161
+ // if(fs.existsSync(mdDir) && !config?.multiDevice) {
162
+ // spinner.info(`Multi-Device directory detected. multiDevice set to true.`);
163
+ // config.multiDevice = true;
164
+ // }
164
165
  if ((config === null || config === void 0 ? void 0 : config.multiDevice) && (config === null || config === void 0 ? void 0 : config.chromiumArgs))
165
166
  spinner.info(`Using custom chromium args with multi device will cause issues! Please remove themm`);
166
167
  if ((config === null || config === void 0 ? void 0 : config.multiDevice) && !(config === null || config === void 0 ? void 0 : config.useChrome))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-wa/wa-automate",
3
- "version": "4.23.14",
3
+ "version": "4.23.18",
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",
@@ -140,7 +140,7 @@
140
140
  "puppeteer": "10.4.0",
141
141
  "puppeteer-extra": "^3.1.9",
142
142
  "puppeteer-extra-plugin-block-resources": "^2.2.7",
143
- "puppeteer-extra-plugin-devtools": "^2.2.8",
143
+ "puppeteer-extra-plugin-devtools": "^2.3.3",
144
144
  "puppeteer-extra-plugin-stealth": "^2.4.9",
145
145
  "puppeteer-page-proxy": "^1.2.8",
146
146
  "qrcode-terminal": "^0.12.0",