@open-wa/wa-automate 4.71.15 → 4.72.1

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.
@@ -191,6 +191,7 @@ export interface ProxyServerCredentials {
191
191
  }
192
192
  export interface ConfigObject {
193
193
  /**
194
+ * @deprecated
194
195
  * The authentication object (as a JSON object or a base64 encoded string) that is required to migrate a session from one instance to another or to just restart an existing instance.
195
196
  * This sessionData is provided in a generated JSON file (it's a json file but contains the JSON data as a base64 encoded string) upon QR scan or an event.
196
197
  *
@@ -223,6 +224,15 @@ export interface ConfigObject {
223
224
  * Setting the sessionData in the environmental variable will override the sessionData object in the config.
224
225
  */
225
226
  sessionData?: SessionData | Base64;
227
+ /**
228
+ * There is a new way to login to your host account by entering a link code after a confirmation step from the host account device. In order to use this feature you MUST set the host account number as a string or number beforehand as a property of the config object.
229
+ *
230
+ * e.g
231
+ * ```
232
+ * linkCode: '1234567890'
233
+ * ```
234
+ */
235
+ linkCode?: string;
226
236
  /**
227
237
  * ALPHA EXPERIMENTAL FEATURE! DO NOT USE IN PRODUCTION, REQUIRES TESTING.
228
238
  *
@@ -187,8 +187,8 @@ const postmanRequestGeneratorGenerator = setup => method => {
187
187
  }
188
188
  },
189
189
  url,
190
- "documentationUrl": `https://docs.openwa.dev/classes/api_Client.Client.html#${method.name}`,
191
- "description": `${method.text}\n[External Documentation](https://docs.openwa.dev/classes/api_Client.Client.html#${method.name})`
190
+ "documentationUrl": `https://docs.openwa.dev/docs/reference/api/Client/classes/Client#${(method.name || "").toLowerCase()}`,
191
+ "description": `${method.text}\n[External Documentation](https://docs.openwa.dev/docs/reference/api/Client/classes/Client#${(method.name || "").toLowerCase()})`
192
192
  };
193
193
  if (!(setup === null || setup === void 0 ? void 0 : setup.key))
194
194
  delete request.auth;
@@ -56,7 +56,7 @@ const generateCollections = (config, spinner) => __awaiter(void 0, void 0, void
56
56
  "description": "All methods from the Client",
57
57
  "externalDocs": {
58
58
  "description": "Find out more",
59
- "url": "https://docs.openwa.dev/classes/api_Client.Client.html"
59
+ "url": "https://docs.openwa.dev/docs/reference/api/Client/classes/Client"
60
60
  }
61
61
  },
62
62
  {
@@ -367,6 +367,7 @@ class ChatwootClient {
367
367
  false;
368
368
  }
369
369
  catch (error) {
370
+ __1.log.error(`CW SEARCH CONTACT ERROR: ${error.message}`);
370
371
  return;
371
372
  }
372
373
  });
@@ -386,6 +387,7 @@ class ChatwootClient {
386
387
  return resolvedConversation;
387
388
  }
388
389
  catch (error) {
390
+ __1.log.error(`CW GET CONVERSATION ERROR: ${error.message}`);
389
391
  return;
390
392
  }
391
393
  });
@@ -400,6 +402,7 @@ class ChatwootClient {
400
402
  return data;
401
403
  }
402
404
  catch (error) {
405
+ __1.log.error(`CW CREATE CONVERSATION ERROR: ${error.message}`);
403
406
  return;
404
407
  }
405
408
  });
@@ -417,6 +420,7 @@ class ChatwootClient {
417
420
  return data.payload.contact;
418
421
  }
419
422
  catch (error) {
423
+ __1.log.error(`CW CREATE CONTACT ERROR: ${error.message}`);
420
424
  return;
421
425
  }
422
426
  });
@@ -430,6 +434,7 @@ class ChatwootClient {
430
434
  return data;
431
435
  }
432
436
  catch (error) {
437
+ __1.log.error(`CW OPEN CONVERSATION ERROR: ${error.message}`);
433
438
  return;
434
439
  }
435
440
  });
@@ -449,6 +454,7 @@ class ChatwootClient {
449
454
  return data;
450
455
  }
451
456
  catch (error) {
457
+ __1.log.error(`CW SEND CONVERSATION MESSAGE ERROR: ${error.message}`);
452
458
  return;
453
459
  }
454
460
  });
@@ -470,6 +476,7 @@ class ChatwootClient {
470
476
  return data;
471
477
  }
472
478
  catch (error) {
479
+ __1.log.error(`CW SEND ATTACHMENT MESSAGE ERROR: ${error.message}`);
473
480
  return;
474
481
  }
475
482
  });
@@ -507,6 +514,9 @@ class ChatwootClient {
507
514
  }
508
515
  else {
509
516
  //create the conversation
517
+ /**
518
+ * TODO: Handle create conversation error
519
+ */
510
520
  convoReg[message.chatId] = (yield this.createConversation(contactReg[message.chatId])).id;
511
521
  isNewConversation = convoReg[message.chatId];
512
522
  }
package/dist/cli/setup.js CHANGED
@@ -116,7 +116,7 @@ exports.helptext = (0, command_line_usage_1.default)([{
116
116
  ]
117
117
  },
118
118
  {
119
- content: `Please check here for more information on some of the above mentioned parameters: {underline https://docs.openwa.dev/interfaces/api_model_config.configobject}`
119
+ content: `Please check here for more information on some of the above mentioned parameters: {underline https://docs.openwa.dev/docs/reference/api/model/config/interfaces/ConfigObject}`
120
120
  },
121
121
  {
122
122
  content: 'Project home: {underline https://github.com/open-wa/wa-automate-nodejs}'
@@ -25,6 +25,7 @@ export declare class QRManager {
25
25
  setConfig(config: any): void;
26
26
  qrEvF(config?: ConfigObject): any;
27
27
  grabAndEmit(qrData: any, waPage: Page, config: ConfigObject, spinner: Spin): Promise<void>;
28
+ linkCode(waPage: Page, config?: ConfigObject, spinner?: Spin): Promise<boolean | void | string>;
28
29
  smartQr(waPage: Page, config?: ConfigObject, spinner?: Spin): Promise<boolean | void | string>;
29
30
  emitFirst(waPage: Page, config?: ConfigObject, spinner?: Spin): Promise<void>;
30
31
  /**
@@ -67,8 +67,11 @@ const needsToScan = (waPage) => {
67
67
  // }).catch(() => resolve(true))
68
68
  // ]).catch(() => { })
69
69
  // console.log("🚀 ~ needsToScan ~ raceResult:", raceResult)
70
- const elementResult = yield waPage.waitForSelector("canvas[aria-label='Scan me!']", { timeout: 0 }).catch(() => { });
71
- console.log("🚀 ~ needsToScan ~ elementResult:", elementResult);
70
+ const elementResult = yield Promise.race([
71
+ waPage.waitForSelector("canvas[aria-label='Scan this QR code to link a device!']", { timeout: 0 }).catch(() => { }),
72
+ waPage.waitForSelector("canvas[aria-label]", { timeout: 0 }).catch(() => { })
73
+ ]);
74
+ logging_1.log.info("🚀 ~ needsToScan ~ elementResult:", elementResult);
72
75
  resolve(false);
73
76
  }
74
77
  catch (error) {
@@ -145,6 +148,7 @@ class QRManager {
145
148
  }
146
149
  grabAndEmit(qrData, waPage, config, spinner) {
147
150
  return __awaiter(this, void 0, void 0, function* () {
151
+ const isLinkCode = qrData.length === 9;
148
152
  this.qrNum++;
149
153
  if (config.qrMax && this.qrNum > config.qrMax) {
150
154
  spinner.info('QR Code limit reached, exiting...');
@@ -156,9 +160,14 @@ class QRManager {
156
160
  if (qrData) {
157
161
  qrEv.emit(qrData, `qrData`);
158
162
  if (!config.qrLogSkip) {
159
- qrcode.generate(qrData, { small: true }, terminalQrCode => {
160
- console.log((0, boxen_1.default)(terminalQrCode, { title: config.sessionId, padding: 1, titleAlignment: 'center' }));
161
- });
163
+ if (isLinkCode) {
164
+ console.log((0, boxen_1.default)(qrData, { title: `ENTER THIS CODE ON THE HOST ACCOUNT DEVICE: ${config.sessionId}`, padding: 1, titleAlignment: 'center' }));
165
+ }
166
+ else {
167
+ qrcode.generate(qrData, { small: true }, terminalQrCode => {
168
+ console.log((0, boxen_1.default)(terminalQrCode, { title: config.sessionId, padding: 1, titleAlignment: 'center' }));
169
+ });
170
+ }
162
171
  }
163
172
  else {
164
173
  console.log(`New QR Code generated. Not printing in console because qrLogSkip is set to true`);
@@ -172,7 +181,7 @@ class QRManager {
172
181
  this._internalQrPngLoaded = true;
173
182
  }
174
183
  try {
175
- const qrPng = yield waPage.evaluate(`window.getQrPng()`);
184
+ const qrPng = isLinkCode ? qrData : yield waPage.evaluate(`window.getQrPng()`);
176
185
  if (qrPng) {
177
186
  qrEv.emit(qrPng);
178
187
  (0, tools_1.processSend)('ready');
@@ -208,6 +217,30 @@ class QRManager {
208
217
  }
209
218
  });
210
219
  }
220
+ linkCode(waPage, config, spinner) {
221
+ return __awaiter(this, void 0, void 0, function* () {
222
+ const evalResult = yield waPage.evaluate("window.Store && window.Store.State");
223
+ if (evalResult === false) {
224
+ console.log('Seems as though you have been TOS_BLOCKed, unable to refresh QR Code. Please see https://github.com/open-wa/wa-automate-nodejs#best-practice for information on how to prevent this from happeing. You will most likely not get a QR Code');
225
+ logging_1.log.warn('Seems as though you have been TOS_BLOCKed, unable to refresh QR Code. Please see https://github.com/open-wa/wa-automate-nodejs#best-practice for information on how to prevent this from happeing. You will most likely not get a QR Code');
226
+ if (config.throwErrorOnTosBlock)
227
+ throw new Error('TOSBLOCK');
228
+ }
229
+ const isAuthed = yield (0, exports.isAuthenticated)(waPage);
230
+ if (isAuthed)
231
+ return true;
232
+ const _hasDefaultStateYet = yield waPage.evaluate("!!(window.Store && window.Store.State && window.Store.State.Socket)");
233
+ if (!_hasDefaultStateYet) {
234
+ //expecting issue, take a screenshot then wait a few seconds before continuing
235
+ yield (0, tools_1.timeout)(2000);
236
+ }
237
+ spinner.info('Link Code requested, please use the link code to login from your host account device');
238
+ const linkCode = yield waPage.evaluate((number) => window['linkCode'](number), config === null || config === void 0 ? void 0 : config.linkCode);
239
+ spinner === null || spinner === void 0 ? void 0 : spinner.succeed(`Link Code please use this to login from your host account device: ${linkCode}`);
240
+ yield this.grabAndEmit(linkCode, waPage, config, spinner);
241
+ return yield isInsideChat(waPage).toPromise();
242
+ });
243
+ }
211
244
  smartQr(waPage, config, spinner) {
212
245
  return __awaiter(this, void 0, void 0, function* () {
213
246
  const evalResult = yield waPage.evaluate("window.Store && window.Store.State");
@@ -272,6 +305,9 @@ class QRManager {
272
305
  */
273
306
  waitFirstQr(waPage, config, spinner) {
274
307
  return __awaiter(this, void 0, void 0, function* () {
308
+ /**
309
+ * Check if session is authed already
310
+ */
275
311
  const fqr = yield waPage.waitForFunction(`!!(${this.qrCheck})`, {
276
312
  polling: 500,
277
313
  timeout: 10000
@@ -298,7 +298,11 @@ function create(config = {}) {
298
298
  else {
299
299
  spinner.info('Authenticate to continue');
300
300
  const race = [];
301
- race.push(qrManager.smartQr(waPage, config, spinner));
301
+ if (config === null || config === void 0 ? void 0 : config.linkCode) {
302
+ race.push(qrManager.linkCode(waPage, config, spinner));
303
+ }
304
+ else
305
+ race.push(qrManager.smartQr(waPage, config, spinner));
302
306
  if ((config === null || config === void 0 ? void 0 : config.qrTimeout) !== 0) {
303
307
  let to = ((config === null || config === void 0 ? void 0 : config.qrTimeout) || 60) * 1000;
304
308
  if (config === null || config === void 0 ? void 0 : config.multiDevice)