@wppconnect-team/wppconnect 2.3.5 → 2.4.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.
- package/CHANGELOG.md +72 -0
- package/README.md +87 -69
- package/README.pt-BR.md +119 -0
- package/dist/api/helpers/decrypt.js +8 -19
- package/dist/api/helpers/download-file.d.ts +4 -0
- package/dist/api/helpers/download-file.js +12 -0
- package/dist/api/helpers/file-to-base64.d.ts +6 -0
- package/dist/api/helpers/file-to-base64.js +27 -10
- package/dist/api/layers/catalog.layer.d.ts +3 -3
- package/dist/api/layers/catalog.layer.js +2 -2
- package/dist/api/layers/group.layer.js +3 -5
- package/dist/api/layers/host.layer.d.ts +10 -3
- package/dist/api/layers/host.layer.js +56 -25
- package/dist/api/layers/labels.layer.d.ts +34 -12
- package/dist/api/layers/labels.layer.js +36 -18
- package/dist/api/layers/profile.layer.d.ts +1 -1
- package/dist/api/layers/profile.layer.js +1 -3
- package/dist/api/layers/sender.layer.d.ts +4 -6
- package/dist/api/layers/sender.layer.js +6 -7
- package/dist/api/layers/status.layer.d.ts +13 -4
- package/dist/api/layers/status.layer.js +10 -9
- package/dist/api/model/index.d.ts +1 -0
- package/dist/api/model/index.js +1 -0
- package/dist/api/model/label.d.ts +16 -0
- package/dist/api/whatsapp.d.ts +24 -0
- package/dist/api/whatsapp.js +101 -52
- package/dist/config/create-config.d.ts +13 -1
- package/dist/config/create-config.js +2 -2
- package/dist/config/puppeteer.config.d.ts +12 -0
- package/dist/config/puppeteer.config.js +17 -7
- package/dist/controllers/auth.js +3 -1
- package/dist/controllers/browser.d.ts +27 -0
- package/dist/controllers/browser.js +128 -7
- package/dist/controllers/initializer.js +78 -44
- package/dist/lib/wapi/wapi.js +1 -1
- package/documentation/readme-reference.md +118 -0
- package/package.json +19 -19
- package/scripts/docs-redirects.mjs +70 -0
- package/scripts/typedoc-canonical.mjs +49 -0
|
@@ -23,23 +23,30 @@ export declare class HostLayer {
|
|
|
23
23
|
protected qrLoopCancelled: boolean;
|
|
24
24
|
protected isLogged: boolean;
|
|
25
25
|
protected isInChat: boolean;
|
|
26
|
-
protected checkStartInterval?: NodeJS.Timer;
|
|
27
26
|
protected urlCode: string;
|
|
28
27
|
protected attempt: number;
|
|
29
28
|
catchQR?: CatchQRCallback;
|
|
30
29
|
statusFind?: StatusFindCallback;
|
|
31
30
|
onLoadingScreen?: LoadingScreenCallback;
|
|
32
31
|
catchLinkCode?: LinkByCodeCallback;
|
|
32
|
+
protected readonly browserAcquiredHere: boolean;
|
|
33
33
|
constructor(page: Page, session?: string, options?: CreateConfig);
|
|
34
34
|
protected log(level: LogLevel, message: string, meta?: object): void;
|
|
35
35
|
protected initialize(): Promise<void>;
|
|
36
36
|
protected watchDocumentChanges(): Promise<void>;
|
|
37
|
+
/**
|
|
38
|
+
* Exposes a Node callback on the page. A page reused across clients
|
|
39
|
+
* (`browserWS` or an injected `page`) still carries the binding from the
|
|
40
|
+
* previous client, and puppeteer refuses to overwrite it (`... already
|
|
41
|
+
* exists!`). Drop the stale binding first so the newest client's callback
|
|
42
|
+
* wins; any other error propagates unchanged.
|
|
43
|
+
*/
|
|
44
|
+
protected exposePageFunction(name: string, fn: (...args: any[]) => any): Promise<void>;
|
|
37
45
|
protected afterPageLoad(signal?: AbortSignal): Promise<void>;
|
|
38
46
|
protected waitForNavigationCommit(signal?: AbortSignal): Promise<void>;
|
|
39
47
|
protected isInjectionExpired(): boolean;
|
|
40
48
|
protected afterPageScriptInjected(): Promise<void>;
|
|
41
49
|
start(): Promise<void>;
|
|
42
|
-
protected checkStart(): Promise<void>;
|
|
43
50
|
protected checkQrCode(): Promise<void>;
|
|
44
51
|
/**
|
|
45
52
|
* Stop QR attempts and suppress pending QR callbacks for this client.
|
|
@@ -59,7 +66,7 @@ export declare class HostLayer {
|
|
|
59
66
|
protected startAutoClose(time?: number | null): void;
|
|
60
67
|
protected cancelAutoClose(): void;
|
|
61
68
|
getQrCode(): Promise<ScrapQrcode>;
|
|
62
|
-
waitForQrCodeScan(): Promise<void>;
|
|
69
|
+
waitForQrCodeScan(catchQR?: CatchQRCallback): Promise<void>;
|
|
63
70
|
waitForInChat(): Promise<boolean>;
|
|
64
71
|
waitForPageLoad(): Promise<void>;
|
|
65
72
|
waitForLogin(): Promise<boolean>;
|
|
@@ -41,16 +41,17 @@ class HostLayer {
|
|
|
41
41
|
qrLoopCancelled = false;
|
|
42
42
|
isLogged = false;
|
|
43
43
|
isInChat = false;
|
|
44
|
-
checkStartInterval = null;
|
|
45
44
|
urlCode = '';
|
|
46
45
|
attempt = 0;
|
|
47
46
|
catchQR = null;
|
|
48
47
|
statusFind = null;
|
|
49
48
|
onLoadingScreen = null;
|
|
50
49
|
catchLinkCode = null;
|
|
50
|
+
browserAcquiredHere;
|
|
51
51
|
constructor(page, session, options) {
|
|
52
52
|
this.page = page;
|
|
53
53
|
this.session = session;
|
|
54
|
+
this.browserAcquiredHere = options?.__browserAcquiredHere === true;
|
|
54
55
|
this.options = { ...create_config_1.defaultOptions, ...options };
|
|
55
56
|
this.logger = this.options.logger || logger_1.defaultLogger;
|
|
56
57
|
this.log('info', 'Initializing...');
|
|
@@ -114,6 +115,25 @@ class HostLayer {
|
|
|
114
115
|
this.log('warn', 'Could not watch document changes', { error });
|
|
115
116
|
}
|
|
116
117
|
}
|
|
118
|
+
/**
|
|
119
|
+
* Exposes a Node callback on the page. A page reused across clients
|
|
120
|
+
* (`browserWS` or an injected `page`) still carries the binding from the
|
|
121
|
+
* previous client, and puppeteer refuses to overwrite it (`... already
|
|
122
|
+
* exists!`). Drop the stale binding first so the newest client's callback
|
|
123
|
+
* wins; any other error propagates unchanged.
|
|
124
|
+
*/
|
|
125
|
+
async exposePageFunction(name, fn) {
|
|
126
|
+
try {
|
|
127
|
+
await this.page.exposeFunction(name, fn);
|
|
128
|
+
}
|
|
129
|
+
catch (error) {
|
|
130
|
+
if (!/already exists/i.test(error?.message ?? '')) {
|
|
131
|
+
throw error;
|
|
132
|
+
}
|
|
133
|
+
await this.page.removeExposedFunction(name).catch(() => null);
|
|
134
|
+
await this.page.exposeFunction(name, fn);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
117
137
|
async afterPageLoad(signal) {
|
|
118
138
|
if (signal?.aborted) {
|
|
119
139
|
return;
|
|
@@ -211,24 +231,15 @@ class HostLayer {
|
|
|
211
231
|
this.isStarted = true;
|
|
212
232
|
await this.documentWatch;
|
|
213
233
|
await (0, browser_1.initWhatsapp)(this.page, null, false, this.options.whatsappVersion, this.options.proxy, this.log.bind(this));
|
|
214
|
-
await this.
|
|
215
|
-
await this.
|
|
216
|
-
await this.
|
|
217
|
-
await this.
|
|
218
|
-
await this.
|
|
219
|
-
if (!this.qrLoopCancelled) {
|
|
220
|
-
this.checkStartInterval = setInterval(() => this.checkStart(), 5000);
|
|
221
|
-
}
|
|
234
|
+
await this.exposePageFunction('checkQrCode', () => this.checkQrCode());
|
|
235
|
+
await this.exposePageFunction('onLinkCode', (code) => this.onLinkCode(code));
|
|
236
|
+
await this.exposePageFunction('onLinkCodeExpired', () => this.log('warn', 'Login by code expired; call refreshLinkCode() to retry'));
|
|
237
|
+
await this.exposePageFunction('onLinkCodeError', (message) => this.log('error', `Login by code failed: ${message}`));
|
|
238
|
+
await this.exposePageFunction('checkInChat', () => this.checkInChat());
|
|
222
239
|
this.page.on('close', () => {
|
|
223
240
|
this.cancelQrLoop();
|
|
224
|
-
clearInterval(this.checkStartInterval);
|
|
225
241
|
});
|
|
226
242
|
}
|
|
227
|
-
async checkStart() {
|
|
228
|
-
(0, auth_1.needsToScan)(this.page)
|
|
229
|
-
.then((need) => { })
|
|
230
|
-
.catch(() => null);
|
|
231
|
-
}
|
|
232
243
|
async checkQrCode() {
|
|
233
244
|
if (this.qrLoopCancelled || this.page.isClosed())
|
|
234
245
|
return;
|
|
@@ -273,7 +284,6 @@ class HostLayer {
|
|
|
273
284
|
*/
|
|
274
285
|
cancelQrLoop() {
|
|
275
286
|
this.qrLoopCancelled = true;
|
|
276
|
-
clearInterval(this.checkStartInterval);
|
|
277
287
|
}
|
|
278
288
|
async loginByCode(phone) {
|
|
279
289
|
await (0, helpers_1.evaluateAndReturn)(this.page, async ({ phone }) => {
|
|
@@ -298,12 +308,18 @@ class HostLayer {
|
|
|
298
308
|
}
|
|
299
309
|
async checkInChat() {
|
|
300
310
|
const inChat = await (0, auth_1.isInsideChat)(this.page).catch(() => null);
|
|
311
|
+
const wasInChat = this.isInChat;
|
|
301
312
|
this.isInChat = !!inChat;
|
|
302
|
-
if (!inChat) {
|
|
313
|
+
if (!inChat || wasInChat) {
|
|
303
314
|
return;
|
|
304
315
|
}
|
|
305
316
|
this.log('http', 'Connected');
|
|
306
|
-
|
|
317
|
+
try {
|
|
318
|
+
this.statusFind?.('inChat', this.session);
|
|
319
|
+
}
|
|
320
|
+
catch (error) {
|
|
321
|
+
this.log('error', error);
|
|
322
|
+
}
|
|
307
323
|
}
|
|
308
324
|
tryAutoClose() {
|
|
309
325
|
if (this.autoCloseInterval) {
|
|
@@ -315,10 +331,17 @@ class HostLayer {
|
|
|
315
331
|
this.log('info', 'Closing the page');
|
|
316
332
|
this.autoCloseCalled = true;
|
|
317
333
|
this.statusFind && this.statusFind('autocloseCalled', this.session);
|
|
318
|
-
|
|
319
|
-
this.page.close()
|
|
320
|
-
|
|
321
|
-
|
|
334
|
+
void Promise.resolve()
|
|
335
|
+
.then(() => this.page.close())
|
|
336
|
+
.catch(async (error) => {
|
|
337
|
+
this.log('error', error);
|
|
338
|
+
if (this.browserAcquiredHere) {
|
|
339
|
+
await (0, browser_1.closeBrowser)(this.page.browser());
|
|
340
|
+
}
|
|
341
|
+
})
|
|
342
|
+
.catch((error) => {
|
|
343
|
+
this.log('error', error);
|
|
344
|
+
});
|
|
322
345
|
}
|
|
323
346
|
}
|
|
324
347
|
startAutoClose(time = null) {
|
|
@@ -353,7 +376,10 @@ class HostLayer {
|
|
|
353
376
|
qrResult = await (0, helpers_1.scrapeImg)(this.page).catch(() => undefined);
|
|
354
377
|
return qrResult;
|
|
355
378
|
}
|
|
356
|
-
async waitForQrCodeScan() {
|
|
379
|
+
async waitForQrCodeScan(catchQR) {
|
|
380
|
+
if (catchQR) {
|
|
381
|
+
this.catchQR = catchQR;
|
|
382
|
+
}
|
|
357
383
|
if (!this.isStarted) {
|
|
358
384
|
throw new Error('waitForQrCodeScan error: Session not started');
|
|
359
385
|
}
|
|
@@ -379,8 +405,9 @@ class HostLayer {
|
|
|
379
405
|
return false;
|
|
380
406
|
}
|
|
381
407
|
await (0, sleep_1.sleep)(1000);
|
|
382
|
-
|
|
383
|
-
|
|
408
|
+
// main_ready may already have fired on the QR screen, so pairing can
|
|
409
|
+
// finish without another event. Publish only the verified transition.
|
|
410
|
+
await this.checkInChat();
|
|
384
411
|
}
|
|
385
412
|
return this.isInChat;
|
|
386
413
|
}
|
|
@@ -448,6 +475,10 @@ class HostLayer {
|
|
|
448
475
|
this.statusFind?.('isLogged', this.session);
|
|
449
476
|
}
|
|
450
477
|
if (authenticated === true) {
|
|
478
|
+
// A stored session takes the "Authenticated" branch above without going
|
|
479
|
+
// through waitForQrCodeScan(), so nothing else may have recorded the
|
|
480
|
+
// login yet. waitForInChat() bails out early when isLogged is false.
|
|
481
|
+
this.isLogged = true;
|
|
451
482
|
// Reinicia o contador do autoclose
|
|
452
483
|
this.cancelAutoClose();
|
|
453
484
|
// Wait for interface update
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Page } from 'puppeteer';
|
|
2
2
|
import { CreateConfig } from '../../config/create-config';
|
|
3
|
+
import { AddOrRemoveLabelsOptions, DeleteLabelReturn, EditLabelOptions, Label, NewLabelOptions } from '../model';
|
|
3
4
|
import { ListsLayer } from './lists.layer';
|
|
4
5
|
export declare class LabelsLayer extends ListsLayer {
|
|
5
6
|
page: Page;
|
|
@@ -19,7 +20,21 @@ export declare class LabelsLayer extends ListsLayer {
|
|
|
19
20
|
* @param name Name of label
|
|
20
21
|
* @param options options of label
|
|
21
22
|
*/
|
|
22
|
-
addNewLabel(name: string, options?: string): Promise<
|
|
23
|
+
addNewLabel(name: string, options?: NewLabelOptions | string): Promise<Label>;
|
|
24
|
+
/**
|
|
25
|
+
* Edit an existing Label
|
|
26
|
+
* @category Labels
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```javascript
|
|
30
|
+
* client.editLabel('1', { name: 'New label name' });
|
|
31
|
+
* //or
|
|
32
|
+
* client.editLabel('1', { labelColor: '#dfaef0' });
|
|
33
|
+
* ```
|
|
34
|
+
* @param id Id of label
|
|
35
|
+
* @param options options of label
|
|
36
|
+
*/
|
|
37
|
+
editLabel(id: string, options?: EditLabelOptions): Promise<Label>;
|
|
23
38
|
/**
|
|
24
39
|
* Add or delete label of chatId
|
|
25
40
|
* @category Labels
|
|
@@ -36,10 +51,7 @@ export declare class LabelsLayer extends ListsLayer {
|
|
|
36
51
|
* @param chatIds ChatIds
|
|
37
52
|
* @param options options to remove or add
|
|
38
53
|
*/
|
|
39
|
-
addOrRemoveLabels(chatIds: string, options:
|
|
40
|
-
labelId: string;
|
|
41
|
-
type: 'add' | 'remove';
|
|
42
|
-
}[]): Promise<void>;
|
|
54
|
+
addOrRemoveLabels(chatIds: string | string[], options: AddOrRemoveLabelsOptions | AddOrRemoveLabelsOptions[]): Promise<any>;
|
|
43
55
|
/**
|
|
44
56
|
* Get all Labels
|
|
45
57
|
*
|
|
@@ -48,7 +60,7 @@ export declare class LabelsLayer extends ListsLayer {
|
|
|
48
60
|
* client.getAllLabels();
|
|
49
61
|
* ```
|
|
50
62
|
*/
|
|
51
|
-
getAllLabels(): Promise<
|
|
63
|
+
getAllLabels(): Promise<Label[]>;
|
|
52
64
|
/**
|
|
53
65
|
* Get Label by id
|
|
54
66
|
* @category Labels
|
|
@@ -59,7 +71,17 @@ export declare class LabelsLayer extends ListsLayer {
|
|
|
59
71
|
* client.getLabelById('1');
|
|
60
72
|
* ```
|
|
61
73
|
*/
|
|
62
|
-
getLabelById(id: string): Promise<
|
|
74
|
+
getLabelById(id: string): Promise<Label>;
|
|
75
|
+
/**
|
|
76
|
+
* Get color palette for labels
|
|
77
|
+
* @category Labels
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* ```javascript
|
|
81
|
+
* client.getLabelColorPalette();
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
getLabelColorPalette(): Promise<string[]>;
|
|
63
85
|
/**
|
|
64
86
|
* Delete all Labels
|
|
65
87
|
* @category Labels
|
|
@@ -69,16 +91,16 @@ export declare class LabelsLayer extends ListsLayer {
|
|
|
69
91
|
* client.deleteAllLabels();
|
|
70
92
|
* ```
|
|
71
93
|
*/
|
|
72
|
-
deleteAllLabels(): Promise<
|
|
94
|
+
deleteAllLabels(): Promise<DeleteLabelReturn[]>;
|
|
73
95
|
/**
|
|
74
|
-
*
|
|
96
|
+
* Delete label(s) by id
|
|
75
97
|
* @category Labels
|
|
76
98
|
*
|
|
77
99
|
* @example
|
|
78
100
|
* ```javascript
|
|
79
|
-
* client.deleteLabel();
|
|
101
|
+
* client.deleteLabel('1');
|
|
80
102
|
* ```
|
|
81
|
-
* @param id Id or string
|
|
103
|
+
* @param id Id or string array of labels to delete
|
|
82
104
|
*/
|
|
83
|
-
deleteLabel(id: string | string[]): Promise<
|
|
105
|
+
deleteLabel(id: string | string[]): Promise<DeleteLabelReturn | DeleteLabelReturn[]>;
|
|
84
106
|
}
|
|
@@ -41,9 +41,23 @@ class LabelsLayer extends lists_layer_1.ListsLayer {
|
|
|
41
41
|
* @param options options of label
|
|
42
42
|
*/
|
|
43
43
|
async addNewLabel(name, options) {
|
|
44
|
-
return await (0, helpers_1.evaluateAndReturn)(this.page, ({ name, options }) => {
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
return await (0, helpers_1.evaluateAndReturn)(this.page, ({ name, options }) => WPP.labels.addNewLabel(name, options), { name, options });
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Edit an existing Label
|
|
48
|
+
* @category Labels
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```javascript
|
|
52
|
+
* client.editLabel('1', { name: 'New label name' });
|
|
53
|
+
* //or
|
|
54
|
+
* client.editLabel('1', { labelColor: '#dfaef0' });
|
|
55
|
+
* ```
|
|
56
|
+
* @param id Id of label
|
|
57
|
+
* @param options options of label
|
|
58
|
+
*/
|
|
59
|
+
async editLabel(id, options) {
|
|
60
|
+
return await (0, helpers_1.evaluateAndReturn)(this.page, ({ id, options }) => WPP.labels.editLabel(id, options), { id, options });
|
|
47
61
|
}
|
|
48
62
|
/**
|
|
49
63
|
* Add or delete label of chatId
|
|
@@ -62,9 +76,7 @@ class LabelsLayer extends lists_layer_1.ListsLayer {
|
|
|
62
76
|
* @param options options to remove or add
|
|
63
77
|
*/
|
|
64
78
|
async addOrRemoveLabels(chatIds, options) {
|
|
65
|
-
return await (0, helpers_1.evaluateAndReturn)(this.page, ({ chatIds, options }) => {
|
|
66
|
-
WPP.labels.addOrRemoveLabels(chatIds, options);
|
|
67
|
-
}, { chatIds, options });
|
|
79
|
+
return await (0, helpers_1.evaluateAndReturn)(this.page, ({ chatIds, options }) => WPP.labels.addOrRemoveLabels(chatIds, options), { chatIds, options });
|
|
68
80
|
}
|
|
69
81
|
/**
|
|
70
82
|
* Get all Labels
|
|
@@ -88,9 +100,19 @@ class LabelsLayer extends lists_layer_1.ListsLayer {
|
|
|
88
100
|
* ```
|
|
89
101
|
*/
|
|
90
102
|
async getLabelById(id) {
|
|
91
|
-
return await (0, helpers_1.evaluateAndReturn)(this.page, ({ id }) => {
|
|
92
|
-
|
|
93
|
-
|
|
103
|
+
return await (0, helpers_1.evaluateAndReturn)(this.page, ({ id }) => WPP.labels.getLabelById(id), { id });
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Get color palette for labels
|
|
107
|
+
* @category Labels
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* ```javascript
|
|
111
|
+
* client.getLabelColorPalette();
|
|
112
|
+
* ```
|
|
113
|
+
*/
|
|
114
|
+
async getLabelColorPalette() {
|
|
115
|
+
return (0, helpers_1.evaluateAndReturn)(this.page, () => WPP.labels.getLabelColorPalette());
|
|
94
116
|
}
|
|
95
117
|
/**
|
|
96
118
|
* Delete all Labels
|
|
@@ -102,24 +124,20 @@ class LabelsLayer extends lists_layer_1.ListsLayer {
|
|
|
102
124
|
* ```
|
|
103
125
|
*/
|
|
104
126
|
async deleteAllLabels() {
|
|
105
|
-
return await (0, helpers_1.evaluateAndReturn)(this.page, () =>
|
|
106
|
-
WPP.labels.deleteAllLabels();
|
|
107
|
-
});
|
|
127
|
+
return await (0, helpers_1.evaluateAndReturn)(this.page, () => WPP.labels.deleteAllLabels());
|
|
108
128
|
}
|
|
109
129
|
/**
|
|
110
|
-
*
|
|
130
|
+
* Delete label(s) by id
|
|
111
131
|
* @category Labels
|
|
112
132
|
*
|
|
113
133
|
* @example
|
|
114
134
|
* ```javascript
|
|
115
|
-
* client.deleteLabel();
|
|
135
|
+
* client.deleteLabel('1');
|
|
116
136
|
* ```
|
|
117
|
-
* @param id Id or string
|
|
137
|
+
* @param id Id or string array of labels to delete
|
|
118
138
|
*/
|
|
119
139
|
async deleteLabel(id) {
|
|
120
|
-
return await (0, helpers_1.evaluateAndReturn)(this.page, ({ id }) => {
|
|
121
|
-
WPP.labels.deleteLabel(id);
|
|
122
|
-
}, { id });
|
|
140
|
+
return await (0, helpers_1.evaluateAndReturn)(this.page, ({ id }) => WPP.labels.deleteLabel(id), { id });
|
|
123
141
|
}
|
|
124
142
|
}
|
|
125
143
|
exports.LabelsLayer = LabelsLayer;
|
|
@@ -17,7 +17,7 @@ export declare class ProfileLayer extends StatusLayer {
|
|
|
17
17
|
* @category Profile
|
|
18
18
|
* @param status
|
|
19
19
|
*/
|
|
20
|
-
setProfileStatus(status: string): Promise<
|
|
20
|
+
setProfileStatus(status: string): Promise<boolean>;
|
|
21
21
|
/**
|
|
22
22
|
* Gets current user profile status
|
|
23
23
|
* @category Profile
|
|
@@ -45,9 +45,7 @@ class ProfileLayer extends status_layer_1.StatusLayer {
|
|
|
45
45
|
* @param status
|
|
46
46
|
*/
|
|
47
47
|
async setProfileStatus(status) {
|
|
48
|
-
return await (0, helpers_1.evaluateAndReturn)(this.page, ({ status }) => {
|
|
49
|
-
WPP.profile.setMyStatus(status);
|
|
50
|
-
}, { status });
|
|
48
|
+
return await (0, helpers_1.evaluateAndReturn)(this.page, ({ status }) => WPP.profile.setMyStatus(status), { status });
|
|
51
49
|
}
|
|
52
50
|
/**
|
|
53
51
|
* Gets current user profile status
|
|
@@ -334,16 +334,14 @@ export declare class SenderLayer extends ListenerLayer {
|
|
|
334
334
|
forwardMessage(toChatId: string, msgId: string | string[], options?: ForwardMessagesOptions): Promise<boolean>;
|
|
335
335
|
/**
|
|
336
336
|
* Forwards array of messages (could be ids or message objects)
|
|
337
|
-
*
|
|
338
|
-
*
|
|
339
|
-
* forwardMessagesV2 is used to forward multiple messages
|
|
340
|
-
* Also, it fixes how we pass the arguments to the whatsapp original function
|
|
341
|
-
* From positional args to named args (object)
|
|
337
|
+
* Accepts a single message ID or an array and forwards them through the
|
|
338
|
+
* native batch API.
|
|
342
339
|
* @category Chat
|
|
343
340
|
* @param to Chat id
|
|
344
341
|
* @param messages Array of messages ids to be forwarded
|
|
345
342
|
* @param options
|
|
346
|
-
* @returns array
|
|
343
|
+
* @returns Messages that could not be forwarded. An empty array means all
|
|
344
|
+
* messages were forwarded.
|
|
347
345
|
*/
|
|
348
346
|
forwardMessagesV2(toChatId: string, messages: string | string[], options?: ForwardMessagesOptions): Promise<Array<any>>;
|
|
349
347
|
/**
|
|
@@ -611,19 +611,18 @@ class SenderLayer extends listener_layer_1.ListenerLayer {
|
|
|
611
611
|
}
|
|
612
612
|
/**
|
|
613
613
|
* Forwards array of messages (could be ids or message objects)
|
|
614
|
-
*
|
|
615
|
-
*
|
|
616
|
-
* forwardMessagesV2 is used to forward multiple messages
|
|
617
|
-
* Also, it fixes how we pass the arguments to the whatsapp original function
|
|
618
|
-
* From positional args to named args (object)
|
|
614
|
+
* Accepts a single message ID or an array and forwards them through the
|
|
615
|
+
* native batch API.
|
|
619
616
|
* @category Chat
|
|
620
617
|
* @param to Chat id
|
|
621
618
|
* @param messages Array of messages ids to be forwarded
|
|
622
619
|
* @param options
|
|
623
|
-
* @returns array
|
|
620
|
+
* @returns Messages that could not be forwarded. An empty array means all
|
|
621
|
+
* messages were forwarded.
|
|
624
622
|
*/
|
|
625
623
|
async forwardMessagesV2(toChatId, messages, options) {
|
|
626
|
-
|
|
624
|
+
const messageIds = Array.isArray(messages) ? messages : [messages];
|
|
625
|
+
return (0, helpers_1.evaluateAndReturn)(this.page, ({ toChatId, messages, options }) => WPP.chat.forwardMessages(toChatId, messages, options), { toChatId, messages: messageIds, options });
|
|
627
626
|
}
|
|
628
627
|
/**
|
|
629
628
|
* Generates sticker from the provided animated gif image and sends it (Send image as animated sticker)
|
|
@@ -23,7 +23,10 @@ export declare class StatusLayer extends LabelsLayer {
|
|
|
23
23
|
*/
|
|
24
24
|
sendImageStatus(pathOrBase64: string, options?: SendStatusOptions & {
|
|
25
25
|
caption?: string;
|
|
26
|
-
}): Promise<
|
|
26
|
+
}): Promise<{
|
|
27
|
+
ack: any;
|
|
28
|
+
id: any;
|
|
29
|
+
}>;
|
|
27
30
|
/**
|
|
28
31
|
* Send a video message to status stories
|
|
29
32
|
* @category Status
|
|
@@ -41,7 +44,10 @@ export declare class StatusLayer extends LabelsLayer {
|
|
|
41
44
|
*/
|
|
42
45
|
sendVideoStatus(pathOrBase64: string, options?: SendStatusOptions & {
|
|
43
46
|
caption?: string;
|
|
44
|
-
}): Promise<
|
|
47
|
+
}): Promise<{
|
|
48
|
+
ack: any;
|
|
49
|
+
id: any;
|
|
50
|
+
}>;
|
|
45
51
|
/**
|
|
46
52
|
* Send a text to status stories
|
|
47
53
|
* @category Status
|
|
@@ -55,7 +61,10 @@ export declare class StatusLayer extends LabelsLayer {
|
|
|
55
61
|
sendTextStatus(text: string, options: {
|
|
56
62
|
backgroundColor?: string;
|
|
57
63
|
font?: number;
|
|
58
|
-
}): Promise<
|
|
64
|
+
}): Promise<{
|
|
65
|
+
ack: any;
|
|
66
|
+
id: any;
|
|
67
|
+
}>;
|
|
59
68
|
/**
|
|
60
69
|
* Mark status as read/seen
|
|
61
70
|
* @category Status
|
|
@@ -67,5 +76,5 @@ export declare class StatusLayer extends LabelsLayer {
|
|
|
67
76
|
* @param chatId Chat ID of contact
|
|
68
77
|
* @param statusId ID of status msg
|
|
69
78
|
*/
|
|
70
|
-
sendReadStatus(chatId: string, statusId: string): Promise<
|
|
79
|
+
sendReadStatus(chatId: string, statusId: string): Promise<any>;
|
|
71
80
|
}
|
|
@@ -76,8 +76,9 @@ class StatusLayer extends labels_layer_1.LabelsLayer {
|
|
|
76
76
|
});
|
|
77
77
|
throw error;
|
|
78
78
|
}
|
|
79
|
-
return await (0, helpers_1.evaluateAndReturn)(this.page, ({ base64, options }) => {
|
|
80
|
-
WPP.status.sendImageStatus(base64, options);
|
|
79
|
+
return await (0, helpers_1.evaluateAndReturn)(this.page, async ({ base64, options }) => {
|
|
80
|
+
const result = await WPP.status.sendImageStatus(base64, options);
|
|
81
|
+
return { ack: result?.ack, id: result?.id };
|
|
81
82
|
}, { base64, options });
|
|
82
83
|
}
|
|
83
84
|
/**
|
|
@@ -116,8 +117,9 @@ class StatusLayer extends labels_layer_1.LabelsLayer {
|
|
|
116
117
|
});
|
|
117
118
|
throw error;
|
|
118
119
|
}
|
|
119
|
-
return await (0, helpers_1.evaluateAndReturn)(this.page, ({ base64, options }) => {
|
|
120
|
-
WPP.status.sendVideoStatus(base64, options);
|
|
120
|
+
return await (0, helpers_1.evaluateAndReturn)(this.page, async ({ base64, options }) => {
|
|
121
|
+
const result = await WPP.status.sendVideoStatus(base64, options);
|
|
122
|
+
return { ack: result?.ack, id: result?.id };
|
|
121
123
|
}, { base64, options });
|
|
122
124
|
}
|
|
123
125
|
/**
|
|
@@ -131,8 +133,9 @@ class StatusLayer extends labels_layer_1.LabelsLayer {
|
|
|
131
133
|
* @param pathOrBase64 Path or base 64 image
|
|
132
134
|
*/
|
|
133
135
|
async sendTextStatus(text, options) {
|
|
134
|
-
return await (0, helpers_1.evaluateAndReturn)(this.page, ({ text, options }) => {
|
|
135
|
-
WPP.status.sendTextStatus(text, options);
|
|
136
|
+
return await (0, helpers_1.evaluateAndReturn)(this.page, async ({ text, options }) => {
|
|
137
|
+
const result = await WPP.status.sendTextStatus(text, options);
|
|
138
|
+
return { ack: result?.ack, id: result?.id };
|
|
136
139
|
}, { text, options });
|
|
137
140
|
}
|
|
138
141
|
/**
|
|
@@ -147,9 +150,7 @@ class StatusLayer extends labels_layer_1.LabelsLayer {
|
|
|
147
150
|
* @param statusId ID of status msg
|
|
148
151
|
*/
|
|
149
152
|
async sendReadStatus(chatId, statusId) {
|
|
150
|
-
return await (0, helpers_1.evaluateAndReturn)(this.page, ({ chatId, statusId }) => {
|
|
151
|
-
WPP.status.sendReadStatus(chatId, statusId);
|
|
152
|
-
}, { chatId, statusId });
|
|
153
|
+
return await (0, helpers_1.evaluateAndReturn)(this.page, ({ chatId, statusId }) => WPP.status.sendReadStatus(chatId, statusId), { chatId, statusId });
|
|
153
154
|
}
|
|
154
155
|
}
|
|
155
156
|
exports.StatusLayer = StatusLayer;
|
package/dist/api/model/index.js
CHANGED
|
@@ -4,4 +4,20 @@ export interface Label {
|
|
|
4
4
|
color: number | null;
|
|
5
5
|
count: number;
|
|
6
6
|
hexColor: string;
|
|
7
|
+
colorIndex?: number;
|
|
8
|
+
}
|
|
9
|
+
export interface NewLabelOptions {
|
|
10
|
+
labelColor?: string | number;
|
|
11
|
+
}
|
|
12
|
+
export interface EditLabelOptions {
|
|
13
|
+
name?: string;
|
|
14
|
+
labelColor?: string | number;
|
|
15
|
+
}
|
|
16
|
+
export interface AddOrRemoveLabelsOptions {
|
|
17
|
+
labelId: string;
|
|
18
|
+
type: 'add' | 'remove';
|
|
19
|
+
}
|
|
20
|
+
export interface DeleteLabelReturn {
|
|
21
|
+
id: string;
|
|
22
|
+
deleteLabelResult: any;
|
|
7
23
|
}
|
package/dist/api/whatsapp.d.ts
CHANGED
|
@@ -2,11 +2,35 @@ import { Page } from 'puppeteer';
|
|
|
2
2
|
import { CreateConfig } from '../config/create-config';
|
|
3
3
|
import { BusinessLayer } from './layers/business.layer';
|
|
4
4
|
import { GetMessagesParam, Message } from './model';
|
|
5
|
+
/** Per-request timeout so a single fetch cannot hang a send indefinitely. */
|
|
6
|
+
export declare const DECRYPT_TIMEOUT_MS = 30000;
|
|
7
|
+
/**
|
|
8
|
+
* GETs a URL until HTTP 200, retrying transient failures (including a rejected
|
|
9
|
+
* status) with linear backoff. Replaces an unbounded `while` loop that wedged
|
|
10
|
+
* `decryptFile` forever on a persistently failing download. Each attempt is
|
|
11
|
+
* bounded by `timeout` (defaults to {@link DECRYPT_TIMEOUT_MS}) so a stalled
|
|
12
|
+
* response cannot hang either.
|
|
13
|
+
*/
|
|
14
|
+
export declare function getUntilOk(url: string, options?: any, maxAttempts?: number): Promise<any>;
|
|
5
15
|
export declare class Whatsapp extends BusinessLayer {
|
|
6
16
|
page: Page;
|
|
17
|
+
/**
|
|
18
|
+
* The page binding exposed by `wireConnectionEvents` can only be registered
|
|
19
|
+
* once per page, but a page may be reused by a later client. This maps each
|
|
20
|
+
* page to the callback of the client that most recently wired it, so the
|
|
21
|
+
* existing binding can be redirected to the current client.
|
|
22
|
+
*/
|
|
23
|
+
private static readonly connectionDispatchers;
|
|
7
24
|
private connected;
|
|
8
25
|
constructor(page: Page, session?: string, options?: CreateConfig);
|
|
9
26
|
protected afterPageScriptInjected(): Promise<void>;
|
|
27
|
+
/**
|
|
28
|
+
* Forwards wa-js connection events to the Node side instead of polling
|
|
29
|
+
* `WPP.conn.isRegistered()` every second. Re-registered after every page
|
|
30
|
+
* load, since the in-page listeners do not survive navigation.
|
|
31
|
+
*/
|
|
32
|
+
protected wireConnectionEvents(): Promise<void>;
|
|
33
|
+
protected onConnectionChange(isRegistered: boolean): void;
|
|
10
34
|
/**
|
|
11
35
|
* Decrypts message file
|
|
12
36
|
* @param data Message object
|