@open-wa/wa-automate 4.71.14 → 4.72.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.
@@ -701,7 +701,7 @@ export declare class Client {
701
701
  * @param text The text you want to inslude in the message section. THIS HAS TO INCLUDE THE URL otherwise the url will be prepended to the text automatically.
702
702
  * @param chatId The chat you want to send this message to.
703
703
  * @param quotedMsgId [INSIDERS] Send this link preview message in response to a given quoted message
704
- * @param customSize [INSIDERS] Anchor the size of the thumbnail (e.g {height: 100, width: 100})
704
+ * @param customSize [INSIDERS] Anchor the size of the thumbnail
705
705
  */
706
706
  sendMessageWithThumb(thumb: string, url: string, title: string, description: string, text: Content, chatId: ChatId, quotedMsgId?: MessageId, customSize?: {
707
707
  height: number;
@@ -748,7 +748,7 @@ export declare class Client {
748
748
  * @param text string Custom text as body of the message, this needs to include the link or it will be appended after the link.
749
749
  * @param thumbnail string Base64 of the jpeg/png which will be used to override the automatically generated thumbnail.
750
750
  * @param quotedMsgId [INSIDERS] Send this link preview message in response to a given quoted message
751
- * @param customSize [INSIDERS] Anchor the size of the thumbnail (e.g {height: 100, width: 100})
751
+ * @param customSize [INSIDERS] Anchor the size of the thumbnail
752
752
  */
753
753
  sendYoutubeLink(to: ChatId, url: string, text?: Content, thumbnail?: Base64, quotedMsgId?: MessageId, customSize?: {
754
754
  height: number;
@@ -761,7 +761,7 @@ export declare class Client {
761
761
  * @param text string Custom text as body of the message, this needs to include the link or it will be appended after the link.
762
762
  * @param thumbnail Base64 of the jpeg/png which will be used to override the automatically generated thumbnail.
763
763
  * @param quotedMsgId [INSIDERS] Send this link preview message in response to a given quoted message
764
- * @param customSize [INSIDERS] Anchor the size of the thumbnail (e.g {height: 100, width: 100})
764
+ * @param customSize [INSIDERS] Anchor the size of the thumbnail
765
765
  */
766
766
  sendLinkWithAutoPreview(to: ChatId, url: string, text?: Content, thumbnail?: Base64, quotedMsgId?: MessageId, customSize?: {
767
767
  height: number;
@@ -1400,10 +1400,6 @@ export declare class Client {
1400
1400
  *
1401
1401
  * Retrieves the groups that you have in common with a contact
1402
1402
  * @param contactId
1403
- * @returns Promise returning an array of common groups {
1404
- * id:string,
1405
- * title:string
1406
- * }
1407
1403
  */
1408
1404
  getCommonGroups(contactId: ContactId): Promise<{
1409
1405
  id: string;
@@ -1455,8 +1451,7 @@ export declare class Client {
1455
1451
  loadEarlierMessages(contactId: ContactId): Promise<Message[]>;
1456
1452
  /**
1457
1453
  * Get the status of a contact
1458
- * @param contactId {string} to '000000000000@c.us'
1459
- * returns: {id: string,status: string}
1454
+ * @param contactId to '000000000000@c.us'
1460
1455
  */
1461
1456
  getStatus(contactId: ContactId): Promise<{
1462
1457
  id: string;
@@ -1474,8 +1469,18 @@ export declare class Client {
1474
1469
  *
1475
1470
  * Use a raw payload within your open-wa session
1476
1471
  *
1472
+ * @example
1473
+ * If there is a code block, then both TypeDoc and VSCode will treat
1474
+ * text outside of the code block as regular text.
1475
+ *
1476
+ * ```ts
1477
+ * await B('44123456789@c.us', {
1478
+ * test: 1
1479
+ * })
1480
+ * ```
1481
+ * {@link loadAllEarlierMessages}
1477
1482
  * @param chatId
1478
- * @param payload {any}
1483
+ * @param payload
1479
1484
  * returns: MessageId
1480
1485
  */
1481
1486
  B(chatId: ChatId, payload: {
@@ -1853,7 +1858,7 @@ export declare class Client {
1853
1858
  *
1854
1859
  * @param to ChatId The chat id you want to send the webp sticker to
1855
1860
  * @param file [[DataURL]], [[Base64]], URL (string GET), Relative filepath (string), or Buffer of the mp4 file
1856
- * @param messageId message id of the message you want this sticker to reply to. {@license:insiders@}
1861
+ * @param messageId message id of the message you want this sticker to reply to. @license:insiders@
1857
1862
  */
1858
1863
  sendMp4AsSticker(to: ChatId, file: DataURL | Buffer | Base64 | string, processOptions?: Mp4StickerConversionProcessOptions, stickerMetadata?: StickerMetadata, messageId?: MessageId): Promise<MessageId | string | boolean>;
1859
1864
  /**
@@ -1861,7 +1866,7 @@ export declare class Client {
1861
1866
  *
1862
1867
  * @param to ChatId The chat id you want to send the webp sticker to
1863
1868
  * @param emojiId The discord emoji id without indentifying chars. In discord you would write `:who:`, here use `who`
1864
- * @param messageId message id of the message you want this sticker to reply to. {@license:insiders@}
1869
+ * @param messageId message id of the message you want this sticker to reply to. @license:insiders@
1865
1870
  */
1866
1871
  sendEmoji(to: ChatId, emojiId: string, messageId?: MessageId): Promise<MessageId | boolean | string>;
1867
1872
  /**
@@ -1713,7 +1713,7 @@ class Client {
1713
1713
  * @param text The text you want to inslude in the message section. THIS HAS TO INCLUDE THE URL otherwise the url will be prepended to the text automatically.
1714
1714
  * @param chatId The chat you want to send this message to.
1715
1715
  * @param quotedMsgId [INSIDERS] Send this link preview message in response to a given quoted message
1716
- * @param customSize [INSIDERS] Anchor the size of the thumbnail (e.g {height: 100, width: 100})
1716
+ * @param customSize [INSIDERS] Anchor the size of the thumbnail
1717
1717
  */
1718
1718
  sendMessageWithThumb(thumb, url, title, description, text, chatId, quotedMsgId, customSize) {
1719
1719
  return __awaiter(this, void 0, void 0, function* () {
@@ -1841,7 +1841,7 @@ class Client {
1841
1841
  * @param text string Custom text as body of the message, this needs to include the link or it will be appended after the link.
1842
1842
  * @param thumbnail string Base64 of the jpeg/png which will be used to override the automatically generated thumbnail.
1843
1843
  * @param quotedMsgId [INSIDERS] Send this link preview message in response to a given quoted message
1844
- * @param customSize [INSIDERS] Anchor the size of the thumbnail (e.g {height: 100, width: 100})
1844
+ * @param customSize [INSIDERS] Anchor the size of the thumbnail
1845
1845
  */
1846
1846
  sendYoutubeLink(to, url, text = '', thumbnail, quotedMsgId, customSize) {
1847
1847
  return __awaiter(this, void 0, void 0, function* () {
@@ -1855,7 +1855,7 @@ class Client {
1855
1855
  * @param text string Custom text as body of the message, this needs to include the link or it will be appended after the link.
1856
1856
  * @param thumbnail Base64 of the jpeg/png which will be used to override the automatically generated thumbnail.
1857
1857
  * @param quotedMsgId [INSIDERS] Send this link preview message in response to a given quoted message
1858
- * @param customSize [INSIDERS] Anchor the size of the thumbnail (e.g {height: 100, width: 100})
1858
+ * @param customSize [INSIDERS] Anchor the size of the thumbnail
1859
1859
  */
1860
1860
  sendLinkWithAutoPreview(to, url, text, thumbnail, quotedMsgId, customSize) {
1861
1861
  var _a;
@@ -2900,10 +2900,6 @@ class Client {
2900
2900
  *
2901
2901
  * Retrieves the groups that you have in common with a contact
2902
2902
  * @param contactId
2903
- * @returns Promise returning an array of common groups {
2904
- * id:string,
2905
- * title:string
2906
- * }
2907
2903
  */
2908
2904
  getCommonGroups(contactId) {
2909
2905
  return __awaiter(this, void 0, void 0, function* () {
@@ -2984,8 +2980,7 @@ class Client {
2984
2980
  }
2985
2981
  /**
2986
2982
  * Get the status of a contact
2987
- * @param contactId {string} to '000000000000@c.us'
2988
- * returns: {id: string,status: string}
2983
+ * @param contactId to '000000000000@c.us'
2989
2984
  */
2990
2985
  getStatus(contactId) {
2991
2986
  return __awaiter(this, void 0, void 0, function* () {
@@ -3004,8 +2999,18 @@ class Client {
3004
2999
  *
3005
3000
  * Use a raw payload within your open-wa session
3006
3001
  *
3002
+ * @example
3003
+ * If there is a code block, then both TypeDoc and VSCode will treat
3004
+ * text outside of the code block as regular text.
3005
+ *
3006
+ * ```ts
3007
+ * await B('44123456789@c.us', {
3008
+ * test: 1
3009
+ * })
3010
+ * ```
3011
+ * {@link loadAllEarlierMessages}
3007
3012
  * @param chatId
3008
- * @param payload {any}
3013
+ * @param payload
3009
3014
  * returns: MessageId
3010
3015
  */
3011
3016
  B(chatId, payload) {
@@ -3697,7 +3702,7 @@ class Client {
3697
3702
  *
3698
3703
  * @param to ChatId The chat id you want to send the webp sticker to
3699
3704
  * @param file [[DataURL]], [[Base64]], URL (string GET), Relative filepath (string), or Buffer of the mp4 file
3700
- * @param messageId message id of the message you want this sticker to reply to. {@license:insiders@}
3705
+ * @param messageId message id of the message you want this sticker to reply to. @license:insiders@
3701
3706
  */
3702
3707
  sendMp4AsSticker(to, file, processOptions = media_1.defaultProcessOptions, stickerMetadata, messageId) {
3703
3708
  return __awaiter(this, void 0, void 0, function* () {
@@ -3744,7 +3749,7 @@ class Client {
3744
3749
  *
3745
3750
  * @param to ChatId The chat id you want to send the webp sticker to
3746
3751
  * @param emojiId The discord emoji id without indentifying chars. In discord you would write `:who:`, here use `who`
3747
- * @param messageId message id of the message you want this sticker to reply to. {@license:insiders@}
3752
+ * @param messageId message id of the message you want this sticker to reply to. @license:insiders@
3748
3753
  */
3749
3754
  sendEmoji(to, emojiId, messageId) {
3750
3755
  return __awaiter(this, void 0, void 0, function* () {
@@ -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
  {
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
  /**
@@ -145,6 +145,7 @@ class QRManager {
145
145
  }
146
146
  grabAndEmit(qrData, waPage, config, spinner) {
147
147
  return __awaiter(this, void 0, void 0, function* () {
148
+ const isLinkCode = qrData.length === 9;
148
149
  this.qrNum++;
149
150
  if (config.qrMax && this.qrNum > config.qrMax) {
150
151
  spinner.info('QR Code limit reached, exiting...');
@@ -156,9 +157,14 @@ class QRManager {
156
157
  if (qrData) {
157
158
  qrEv.emit(qrData, `qrData`);
158
159
  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
- });
160
+ if (isLinkCode) {
161
+ console.log((0, boxen_1.default)(qrData, { title: `ENTER THIS CODE ON THE HOST ACCOUNT DEVICE: ${config.sessionId}`, padding: 1, titleAlignment: 'center' }));
162
+ }
163
+ else {
164
+ qrcode.generate(qrData, { small: true }, terminalQrCode => {
165
+ console.log((0, boxen_1.default)(terminalQrCode, { title: config.sessionId, padding: 1, titleAlignment: 'center' }));
166
+ });
167
+ }
162
168
  }
163
169
  else {
164
170
  console.log(`New QR Code generated. Not printing in console because qrLogSkip is set to true`);
@@ -172,7 +178,7 @@ class QRManager {
172
178
  this._internalQrPngLoaded = true;
173
179
  }
174
180
  try {
175
- const qrPng = yield waPage.evaluate(`window.getQrPng()`);
181
+ const qrPng = isLinkCode ? qrData : yield waPage.evaluate(`window.getQrPng()`);
176
182
  if (qrPng) {
177
183
  qrEv.emit(qrPng);
178
184
  (0, tools_1.processSend)('ready');
@@ -208,6 +214,30 @@ class QRManager {
208
214
  }
209
215
  });
210
216
  }
217
+ linkCode(waPage, config, spinner) {
218
+ return __awaiter(this, void 0, void 0, function* () {
219
+ const evalResult = yield waPage.evaluate("window.Store && window.Store.State");
220
+ if (evalResult === false) {
221
+ 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');
222
+ 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');
223
+ if (config.throwErrorOnTosBlock)
224
+ throw new Error('TOSBLOCK');
225
+ }
226
+ const isAuthed = yield (0, exports.isAuthenticated)(waPage);
227
+ if (isAuthed)
228
+ return true;
229
+ const _hasDefaultStateYet = yield waPage.evaluate("!!(window.Store && window.Store.State && window.Store.State.Socket)");
230
+ if (!_hasDefaultStateYet) {
231
+ //expecting issue, take a screenshot then wait a few seconds before continuing
232
+ yield (0, tools_1.timeout)(2000);
233
+ }
234
+ spinner.info('Link Code requested, please use the link code to login from your host account device');
235
+ const linkCode = yield waPage.evaluate((number) => window['linkCode'](number), config === null || config === void 0 ? void 0 : config.linkCode);
236
+ spinner === null || spinner === void 0 ? void 0 : spinner.succeed(`Link Code please use this to login from your host account device: ${linkCode}`);
237
+ yield this.grabAndEmit(linkCode, waPage, config, spinner);
238
+ return yield isInsideChat(waPage).toPromise();
239
+ });
240
+ }
211
241
  smartQr(waPage, config, spinner) {
212
242
  return __awaiter(this, void 0, void 0, function* () {
213
243
  const evalResult = yield waPage.evaluate("window.Store && window.Store.State");
@@ -272,6 +302,9 @@ class QRManager {
272
302
  */
273
303
  waitFirstQr(waPage, config, spinner) {
274
304
  return __awaiter(this, void 0, void 0, function* () {
305
+ /**
306
+ * Check if session is authed already
307
+ */
275
308
  const fqr = yield waPage.waitForFunction(`!!(${this.qrCheck})`, {
276
309
  polling: 500,
277
310
  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)
@@ -438,7 +442,7 @@ function create(config = {}) {
438
442
  spinner.emit(debugInfo, "DebugInfo");
439
443
  //@ts-ignore
440
444
  const metrics = yield waPage.evaluate(({ config }) => WAPI.launchMetrics(config), { config });
441
- 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 ") : "";
445
+ const purgedMessage = (metrics === null || metrics === void 0 ? void 0 : metrics.purged) ? Object.entries(metrics.purged).filter(([, e]) => Number(e) > 0).map(([k, e]) => `${e} ${k}`).join(" and ") : "";
442
446
  if (metrics.isMd && !(config === null || config === void 0 ? void 0 : config.multiDevice))
443
447
  spinner.info("!!!Please set multiDevice: true in the config or use the --mutli-Device flag!!!");
444
448
  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`);