@wppconnect-team/wppconnect 1.14.4 → 1.16.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 +17 -0
- package/dist/api/layers/group.layer.d.ts +14 -0
- package/dist/api/layers/group.layer.js +61 -0
- package/dist/api/layers/host.layer.d.ts +2 -1
- package/dist/api/layers/host.layer.js +6 -1
- package/dist/api/layers/labels.layer.d.ts +63 -0
- package/dist/api/layers/labels.layer.js +191 -0
- package/dist/api/layers/listener.layer.d.ts +17 -2
- package/dist/api/layers/listener.layer.js +62 -19
- package/dist/api/layers/profile.layer.d.ts +2 -2
- package/dist/api/layers/profile.layer.js +2 -2
- package/dist/api/layers/retriever.layer.js +22 -13
- package/dist/api/layers/sender.layer.d.ts +17 -0
- package/dist/api/layers/sender.layer.js +27 -0
- package/dist/api/layers/status.layer.d.ts +37 -0
- package/dist/api/layers/status.layer.js +216 -0
- package/dist/api/model/chat.d.ts +6 -0
- package/dist/api/model/enum/index.d.ts +0 -1
- package/dist/api/model/enum/index.js +1 -3
- package/dist/api/model/group-metadata.d.ts +15 -0
- package/dist/api/model/initializer.d.ts +8 -0
- package/dist/api/model/participant-event.d.ts +4 -3
- package/dist/config/create-config.d.ts +21 -0
- package/dist/config/create-config.js +4 -0
- package/dist/controllers/browser.d.ts +3 -1
- package/dist/controllers/browser.js +59 -2
- package/dist/controllers/initializer.d.ts +2 -2
- package/dist/controllers/initializer.js +3 -1
- package/package.json +33 -39
- package/LICENSE.header +0 -14
- package/dist/api/model/enum/group-change-event.d.ts +0 -6
- package/dist/api/model/enum/group-change-event.js +0 -26
- package/license-checker-config.json +0 -19
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,20 @@
|
|
|
1
|
+
# 1.16.0 (2022-08-05)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* **deps:** update dependency @wppconnect/wa-js to ^2.10.0 ([dc8133a](https://github.com/wppconnect-team/wppconnect/commit/dc8133a2896c011830c874c94c780acd9368a25a))
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
# 1.15.0 (2022-07-20)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## 1.14.5 (2022-07-11)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
1
18
|
## 1.14.4 (2022-06-20)
|
|
2
19
|
|
|
3
20
|
|
|
@@ -152,4 +152,18 @@ export declare class GroupLayer extends RetrieverLayer {
|
|
|
152
152
|
* @returns empty object
|
|
153
153
|
*/
|
|
154
154
|
setGroupProperty(groupId: string, property: GroupProperty, value: boolean): Promise<boolean>;
|
|
155
|
+
/**
|
|
156
|
+
* Set group subject (if allowed)
|
|
157
|
+
* @category Group
|
|
158
|
+
* @param groupId Group ID ('000000-000000@g.us')
|
|
159
|
+
* @param base64 Image in base64 ( data:image/jpeg;base64,..... )
|
|
160
|
+
* @returns empty object
|
|
161
|
+
*/
|
|
162
|
+
setGroupIcon(groupId: string, pathOrBase64: string): Promise<{
|
|
163
|
+
eurl: string;
|
|
164
|
+
status: number;
|
|
165
|
+
tag: string;
|
|
166
|
+
token: string;
|
|
167
|
+
_duplicate: boolean;
|
|
168
|
+
}>;
|
|
155
169
|
}
|
|
@@ -386,6 +386,67 @@ var GroupLayer = /** @class */ (function (_super) {
|
|
|
386
386
|
});
|
|
387
387
|
});
|
|
388
388
|
};
|
|
389
|
+
/**
|
|
390
|
+
* Set group subject (if allowed)
|
|
391
|
+
* @category Group
|
|
392
|
+
* @param groupId Group ID ('000000-000000@g.us')
|
|
393
|
+
* @param base64 Image in base64 ( data:image/jpeg;base64,..... )
|
|
394
|
+
* @returns empty object
|
|
395
|
+
*/
|
|
396
|
+
GroupLayer.prototype.setGroupIcon = function (groupId, pathOrBase64) {
|
|
397
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
398
|
+
var base64, fileContent, error, mimeInfo, error;
|
|
399
|
+
return __generator(this, function (_a) {
|
|
400
|
+
switch (_a.label) {
|
|
401
|
+
case 0:
|
|
402
|
+
base64 = '';
|
|
403
|
+
if (!pathOrBase64.startsWith('data:')) return [3 /*break*/, 1];
|
|
404
|
+
base64 = pathOrBase64;
|
|
405
|
+
return [3 /*break*/, 5];
|
|
406
|
+
case 1: return [4 /*yield*/, (0, helpers_1.downloadFileToBase64)(pathOrBase64, [
|
|
407
|
+
'image/gif',
|
|
408
|
+
'image/png',
|
|
409
|
+
'image/jpg',
|
|
410
|
+
'image/jpeg',
|
|
411
|
+
'image/webp',
|
|
412
|
+
])];
|
|
413
|
+
case 2:
|
|
414
|
+
fileContent = _a.sent();
|
|
415
|
+
if (!!fileContent) return [3 /*break*/, 4];
|
|
416
|
+
return [4 /*yield*/, (0, helpers_1.fileToBase64)(pathOrBase64)];
|
|
417
|
+
case 3:
|
|
418
|
+
fileContent = _a.sent();
|
|
419
|
+
_a.label = 4;
|
|
420
|
+
case 4:
|
|
421
|
+
if (fileContent) {
|
|
422
|
+
base64 = fileContent;
|
|
423
|
+
}
|
|
424
|
+
_a.label = 5;
|
|
425
|
+
case 5:
|
|
426
|
+
if (!base64) {
|
|
427
|
+
error = new Error('Empty or invalid file or base64');
|
|
428
|
+
Object.assign(error, {
|
|
429
|
+
code: 'empty_file',
|
|
430
|
+
});
|
|
431
|
+
throw error;
|
|
432
|
+
}
|
|
433
|
+
mimeInfo = (0, helpers_1.base64MimeType)(base64);
|
|
434
|
+
if (!mimeInfo || !mimeInfo.includes('image')) {
|
|
435
|
+
error = new Error('Not an image, allowed formats png, jpeg and webp');
|
|
436
|
+
Object.assign(error, {
|
|
437
|
+
code: 'invalid_image',
|
|
438
|
+
});
|
|
439
|
+
throw error;
|
|
440
|
+
}
|
|
441
|
+
return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
|
|
442
|
+
var groupId = _a.groupId, base64 = _a.base64;
|
|
443
|
+
return WPP.group.setIcon(groupId, base64);
|
|
444
|
+
}, { groupId: groupId, base64: base64 })];
|
|
445
|
+
case 6: return [2 /*return*/, _a.sent()];
|
|
446
|
+
}
|
|
447
|
+
});
|
|
448
|
+
});
|
|
449
|
+
};
|
|
389
450
|
return GroupLayer;
|
|
390
451
|
}(retriever_layer_1.RetrieverLayer));
|
|
391
452
|
exports.GroupLayer = GroupLayer;
|
|
@@ -4,7 +4,7 @@ import { SocketState } from '../model/enum';
|
|
|
4
4
|
import { ScrapQrcode } from '../model/qrcode';
|
|
5
5
|
import { LogLevel } from '../../utils/logger';
|
|
6
6
|
import { Logger } from 'winston';
|
|
7
|
-
import { CatchQRCallback, HostDevice, StatusFindCallback } from '../model';
|
|
7
|
+
import { CatchQRCallback, HostDevice, LoadingScreenCallback, StatusFindCallback } from '../model';
|
|
8
8
|
import { TokenStore } from '../../token-store';
|
|
9
9
|
export declare class HostLayer {
|
|
10
10
|
page: Page;
|
|
@@ -15,6 +15,7 @@ export declare class HostLayer {
|
|
|
15
15
|
protected autoCloseInterval: any;
|
|
16
16
|
protected autoCloseCalled: boolean;
|
|
17
17
|
protected statusFind?: StatusFindCallback;
|
|
18
|
+
onLoadingScreen?: LoadingScreenCallback;
|
|
18
19
|
constructor(page: Page, session?: string, options?: CreateConfig);
|
|
19
20
|
protected log(level: LogLevel, message: string, meta?: object): void;
|
|
20
21
|
protected initialize(): Promise<void>;
|
|
@@ -77,6 +77,7 @@ var HostLayer = /** @class */ (function () {
|
|
|
77
77
|
this.autoCloseInterval = null;
|
|
78
78
|
this.autoCloseCalled = false;
|
|
79
79
|
this.statusFind = null;
|
|
80
|
+
this.onLoadingScreen = null;
|
|
80
81
|
this.session = session;
|
|
81
82
|
this.options = __assign(__assign({}, create_config_1.defaultOptions), options);
|
|
82
83
|
this.logger = this.options.logger || logger_1.defaultLogger;
|
|
@@ -137,7 +138,7 @@ var HostLayer = /** @class */ (function () {
|
|
|
137
138
|
}
|
|
138
139
|
hasUserDataDir = !!((_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.puppeteerOptions) === null || _b === void 0 ? void 0 : _b.userDataDir);
|
|
139
140
|
clear = !hasUserDataDir || (hasUserDataDir && !isValidToken);
|
|
140
|
-
return [4 /*yield*/, (0, browser_1.initWhatsapp)(this.page, sessionToken, clear, this.options.whatsappVersion)];
|
|
141
|
+
return [4 /*yield*/, (0, browser_1.initWhatsapp)(this.page, sessionToken, clear, this.options.whatsappVersion, this.onLoadingScreen)];
|
|
141
142
|
case 3:
|
|
142
143
|
_c.sent();
|
|
143
144
|
this.page.on('load', function () {
|
|
@@ -163,6 +164,10 @@ var HostLayer = /** @class */ (function () {
|
|
|
163
164
|
this.log('verbose', 'Injecting wapi.js');
|
|
164
165
|
options = {
|
|
165
166
|
deviceName: this.options.deviceName,
|
|
167
|
+
disableGoogleAnalytics: this.options.disableGoogleAnalytics,
|
|
168
|
+
googleAnalyticsId: this.options.googleAnalyticsId,
|
|
169
|
+
linkPreviewApiServers: this.options.linkPreviewApiServers,
|
|
170
|
+
poweredBy: this.options.poweredBy,
|
|
166
171
|
};
|
|
167
172
|
return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (options) {
|
|
168
173
|
window.WPPConfig = options;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { Page } from 'puppeteer';
|
|
2
|
+
import { CreateConfig } from '../../config/create-config';
|
|
3
|
+
import { HostLayer } from './host.layer';
|
|
4
|
+
export declare class LabelsLayer extends HostLayer {
|
|
5
|
+
page: Page;
|
|
6
|
+
constructor(page: Page, session?: string, options?: CreateConfig);
|
|
7
|
+
/**
|
|
8
|
+
* Create New Label
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```javascript
|
|
12
|
+
* client.addNewLabel(`Name of label`);
|
|
13
|
+
* //or
|
|
14
|
+
* client.addNewLabel(`Name of label`, { labelColor: '#dfaef0' });
|
|
15
|
+
* //or
|
|
16
|
+
* client.addNewLabel(`Name of label`, { labelColor: 4292849392 });
|
|
17
|
+
* ```
|
|
18
|
+
* @param name Name of label
|
|
19
|
+
* @param options options of label
|
|
20
|
+
*/
|
|
21
|
+
addNewLabel(name: string, options?: string): Promise<void>;
|
|
22
|
+
/**
|
|
23
|
+
* Add or delete label of chatId
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```javascript
|
|
27
|
+
* client.addOrRemoveLabels(['[number]@c.us','[number]@c.us'],
|
|
28
|
+
* [{labelId:'76', type:'add'},{labelId:'75', type:'remove'}]);
|
|
29
|
+
* //or
|
|
30
|
+
* ```
|
|
31
|
+
* @param name Name of label
|
|
32
|
+
* @param options options to remove or add
|
|
33
|
+
*/
|
|
34
|
+
addOrRemoveLabels(chatIds: string, options: string): Promise<void>;
|
|
35
|
+
/**
|
|
36
|
+
* Get all Labels
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```javascript
|
|
40
|
+
* client.getAllLabels();
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
getAllLabels(): Promise<import("@wppconnect/wa-js/dist/labels").Label[]>;
|
|
44
|
+
/**
|
|
45
|
+
* Delete all Labels
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```javascript
|
|
49
|
+
* client.deleteAllLabels();
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
deleteAllLabels(): Promise<void>;
|
|
53
|
+
/**
|
|
54
|
+
* Add or delete label of chatId
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```javascript
|
|
58
|
+
* client.deleteLabel();
|
|
59
|
+
* ```
|
|
60
|
+
* @param id Id or string to labels to delete
|
|
61
|
+
*/
|
|
62
|
+
deleteLabel(id: string | string[]): Promise<void>;
|
|
63
|
+
}
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* This file is part of WPPConnect.
|
|
4
|
+
*
|
|
5
|
+
* WPPConnect is free software: you can redistribute it and/or modify
|
|
6
|
+
* it under the terms of the GNU Lesser General Public License as published by
|
|
7
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
8
|
+
* (at your option) any later version.
|
|
9
|
+
*
|
|
10
|
+
* WPPConnect is distributed in the hope that it will be useful,
|
|
11
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
* GNU Lesser General Public License for more details.
|
|
14
|
+
*
|
|
15
|
+
* You should have received a copy of the GNU Lesser General Public License
|
|
16
|
+
* along with WPPConnect. If not, see <https://www.gnu.org/licenses/>.
|
|
17
|
+
*/
|
|
18
|
+
var __extends = (this && this.__extends) || (function () {
|
|
19
|
+
var extendStatics = function (d, b) {
|
|
20
|
+
extendStatics = Object.setPrototypeOf ||
|
|
21
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
22
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
23
|
+
return extendStatics(d, b);
|
|
24
|
+
};
|
|
25
|
+
return function (d, b) {
|
|
26
|
+
if (typeof b !== "function" && b !== null)
|
|
27
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
28
|
+
extendStatics(d, b);
|
|
29
|
+
function __() { this.constructor = d; }
|
|
30
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
31
|
+
};
|
|
32
|
+
})();
|
|
33
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
34
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
35
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
36
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
37
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
38
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
39
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
43
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
44
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
45
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
46
|
+
function step(op) {
|
|
47
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
48
|
+
while (_) try {
|
|
49
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
50
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
51
|
+
switch (op[0]) {
|
|
52
|
+
case 0: case 1: t = op; break;
|
|
53
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
54
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
55
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
56
|
+
default:
|
|
57
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
58
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
59
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
60
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
61
|
+
if (t[2]) _.ops.pop();
|
|
62
|
+
_.trys.pop(); continue;
|
|
63
|
+
}
|
|
64
|
+
op = body.call(thisArg, _);
|
|
65
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
66
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
70
|
+
exports.LabelsLayer = void 0;
|
|
71
|
+
var host_layer_1 = require("./host.layer");
|
|
72
|
+
var helpers_1 = require("../helpers");
|
|
73
|
+
var LabelsLayer = /** @class */ (function (_super) {
|
|
74
|
+
__extends(LabelsLayer, _super);
|
|
75
|
+
function LabelsLayer(page, session, options) {
|
|
76
|
+
var _this = _super.call(this, page, session, options) || this;
|
|
77
|
+
_this.page = page;
|
|
78
|
+
return _this;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Create New Label
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```javascript
|
|
85
|
+
* client.addNewLabel(`Name of label`);
|
|
86
|
+
* //or
|
|
87
|
+
* client.addNewLabel(`Name of label`, { labelColor: '#dfaef0' });
|
|
88
|
+
* //or
|
|
89
|
+
* client.addNewLabel(`Name of label`, { labelColor: 4292849392 });
|
|
90
|
+
* ```
|
|
91
|
+
* @param name Name of label
|
|
92
|
+
* @param options options of label
|
|
93
|
+
*/
|
|
94
|
+
LabelsLayer.prototype.addNewLabel = function (name, options) {
|
|
95
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
96
|
+
return __generator(this, function (_a) {
|
|
97
|
+
switch (_a.label) {
|
|
98
|
+
case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
|
|
99
|
+
var name = _a.name, options = _a.options;
|
|
100
|
+
WPP.labels.addNewLabel(name, options);
|
|
101
|
+
}, { name: name, options: options })];
|
|
102
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
};
|
|
107
|
+
/**
|
|
108
|
+
* Add or delete label of chatId
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* ```javascript
|
|
112
|
+
* client.addOrRemoveLabels(['[number]@c.us','[number]@c.us'],
|
|
113
|
+
* [{labelId:'76', type:'add'},{labelId:'75', type:'remove'}]);
|
|
114
|
+
* //or
|
|
115
|
+
* ```
|
|
116
|
+
* @param name Name of label
|
|
117
|
+
* @param options options to remove or add
|
|
118
|
+
*/
|
|
119
|
+
LabelsLayer.prototype.addOrRemoveLabels = function (chatIds, options) {
|
|
120
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
121
|
+
return __generator(this, function (_a) {
|
|
122
|
+
switch (_a.label) {
|
|
123
|
+
case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
|
|
124
|
+
var chatIds = _a.chatIds, options = _a.options;
|
|
125
|
+
WPP.labels.addOrRemoveLabels(chatIds, options);
|
|
126
|
+
}, { chatIds: chatIds, options: options })];
|
|
127
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
};
|
|
132
|
+
/**
|
|
133
|
+
* Get all Labels
|
|
134
|
+
*
|
|
135
|
+
* @example
|
|
136
|
+
* ```javascript
|
|
137
|
+
* client.getAllLabels();
|
|
138
|
+
* ```
|
|
139
|
+
*/
|
|
140
|
+
LabelsLayer.prototype.getAllLabels = function () {
|
|
141
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
142
|
+
return __generator(this, function (_a) {
|
|
143
|
+
return [2 /*return*/, (0, helpers_1.evaluateAndReturn)(this.page, function () { return WPP.labels.getAllLabels(); })];
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
};
|
|
147
|
+
/**
|
|
148
|
+
* Delete all Labels
|
|
149
|
+
*
|
|
150
|
+
* @example
|
|
151
|
+
* ```javascript
|
|
152
|
+
* client.deleteAllLabels();
|
|
153
|
+
* ```
|
|
154
|
+
*/
|
|
155
|
+
LabelsLayer.prototype.deleteAllLabels = function () {
|
|
156
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
157
|
+
return __generator(this, function (_a) {
|
|
158
|
+
switch (_a.label) {
|
|
159
|
+
case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function () {
|
|
160
|
+
WPP.labels.deleteAllLabels();
|
|
161
|
+
})];
|
|
162
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
});
|
|
166
|
+
};
|
|
167
|
+
/**
|
|
168
|
+
* Add or delete label of chatId
|
|
169
|
+
*
|
|
170
|
+
* @example
|
|
171
|
+
* ```javascript
|
|
172
|
+
* client.deleteLabel();
|
|
173
|
+
* ```
|
|
174
|
+
* @param id Id or string to labels to delete
|
|
175
|
+
*/
|
|
176
|
+
LabelsLayer.prototype.deleteLabel = function (id) {
|
|
177
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
178
|
+
return __generator(this, function (_a) {
|
|
179
|
+
switch (_a.label) {
|
|
180
|
+
case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
|
|
181
|
+
var id = _a.id;
|
|
182
|
+
WPP.labels.deleteLabel(id);
|
|
183
|
+
}, { id: id })];
|
|
184
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
};
|
|
189
|
+
return LabelsLayer;
|
|
190
|
+
}(host_layer_1.HostLayer));
|
|
191
|
+
exports.LabelsLayer = LabelsLayer;
|
|
@@ -109,7 +109,7 @@ export declare class ListenerLayer extends ProfileLayer {
|
|
|
109
109
|
* @param to callback
|
|
110
110
|
* @returns Stream of ParticipantEvent
|
|
111
111
|
*/
|
|
112
|
-
onParticipantsChanged(callback: (
|
|
112
|
+
onParticipantsChanged(callback: (evData: ParticipantEvent) => void): {
|
|
113
113
|
dispose: () => void;
|
|
114
114
|
};
|
|
115
115
|
/**
|
|
@@ -118,7 +118,7 @@ export declare class ListenerLayer extends ProfileLayer {
|
|
|
118
118
|
* @param to callback
|
|
119
119
|
* @returns Stream of ParticipantEvent
|
|
120
120
|
*/
|
|
121
|
-
onParticipantsChanged(groupId: string, callback: (
|
|
121
|
+
onParticipantsChanged(groupId: string, callback: (evData: ParticipantEvent) => void): {
|
|
122
122
|
dispose: () => void;
|
|
123
123
|
};
|
|
124
124
|
/**
|
|
@@ -197,4 +197,19 @@ export declare class ListenerLayer extends ProfileLayer {
|
|
|
197
197
|
}) => any): {
|
|
198
198
|
dispose: () => void;
|
|
199
199
|
};
|
|
200
|
+
/**
|
|
201
|
+
* @event Listens to reaction messages
|
|
202
|
+
* @returns Disposable object to stop the listening
|
|
203
|
+
*/
|
|
204
|
+
onReactionMessage(callback: (data: {
|
|
205
|
+
id: string;
|
|
206
|
+
msgId: string;
|
|
207
|
+
reactionText: string;
|
|
208
|
+
read: boolean;
|
|
209
|
+
orphan: number;
|
|
210
|
+
orphanReason: any;
|
|
211
|
+
timestamp: number;
|
|
212
|
+
}) => any): {
|
|
213
|
+
dispose: () => void;
|
|
214
|
+
};
|
|
200
215
|
}
|
|
@@ -80,7 +80,6 @@ exports.ListenerLayer = void 0;
|
|
|
80
80
|
var events_1 = require("events");
|
|
81
81
|
var helpers_1 = require("../helpers");
|
|
82
82
|
var exposed_enum_1 = require("../helpers/exposed.enum");
|
|
83
|
-
var enum_1 = require("../model/enum");
|
|
84
83
|
var profile_layer_1 = require("./profile.layer");
|
|
85
84
|
var ListenerLayer = /** @class */ (function (_super) {
|
|
86
85
|
__extends(ListenerLayer, _super);
|
|
@@ -123,6 +122,7 @@ var ListenerLayer = /** @class */ (function (_super) {
|
|
|
123
122
|
'onAddedToGroup',
|
|
124
123
|
'onIncomingCall',
|
|
125
124
|
'onRevokedMessage',
|
|
125
|
+
'onReactionMessage',
|
|
126
126
|
], false);
|
|
127
127
|
_loop_1 = function (func) {
|
|
128
128
|
var has;
|
|
@@ -169,10 +169,14 @@ var ListenerLayer = /** @class */ (function (_super) {
|
|
|
169
169
|
.evaluate(function () {
|
|
170
170
|
try {
|
|
171
171
|
if (!window['onMessage'].exposed) {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
}
|
|
172
|
+
WPP.on('chat.new_message', function (msg) {
|
|
173
|
+
if (msg.isSentByMe || msg.isStatusV3) {
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
var serialized = WAPI.processMessageObj(msg, false, false);
|
|
177
|
+
if (serialized) {
|
|
178
|
+
window['onMessage'](serialized);
|
|
179
|
+
}
|
|
176
180
|
});
|
|
177
181
|
window['onMessage'].exposed = true;
|
|
178
182
|
}
|
|
@@ -191,7 +195,12 @@ var ListenerLayer = /** @class */ (function (_super) {
|
|
|
191
195
|
}
|
|
192
196
|
try {
|
|
193
197
|
if (!window['onAnyMessage'].exposed) {
|
|
194
|
-
|
|
198
|
+
WPP.on('chat.new_message', function (msg) {
|
|
199
|
+
var serialized = WAPI.processMessageObj(msg, true, false);
|
|
200
|
+
if (serialized) {
|
|
201
|
+
window['onAnyMessage'](serialized);
|
|
202
|
+
}
|
|
203
|
+
});
|
|
195
204
|
window['onAnyMessage'].exposed = true;
|
|
196
205
|
}
|
|
197
206
|
}
|
|
@@ -254,7 +263,7 @@ var ListenerLayer = /** @class */ (function (_super) {
|
|
|
254
263
|
}
|
|
255
264
|
try {
|
|
256
265
|
if (!window['onPresenceChanged'].exposed) {
|
|
257
|
-
|
|
266
|
+
WPP.on('chat.presence_change', window['onPresenceChanged']);
|
|
258
267
|
window['onPresenceChanged'].exposed = true;
|
|
259
268
|
}
|
|
260
269
|
}
|
|
@@ -288,6 +297,37 @@ var ListenerLayer = /** @class */ (function (_super) {
|
|
|
288
297
|
catch (error) {
|
|
289
298
|
console.error(error);
|
|
290
299
|
}
|
|
300
|
+
try {
|
|
301
|
+
if (!window['onReactionMessage'].exposed) {
|
|
302
|
+
WPP.on('chat.new_reaction', function (data) {
|
|
303
|
+
var eventData = {
|
|
304
|
+
id: data.id,
|
|
305
|
+
msgId: data.msgId,
|
|
306
|
+
reactionText: data.reactionText,
|
|
307
|
+
read: data.read,
|
|
308
|
+
orphan: data.orphan,
|
|
309
|
+
orphanReason: data.orphanReason,
|
|
310
|
+
timestamp: data.timestamp,
|
|
311
|
+
};
|
|
312
|
+
window['onReactionMessage'](eventData);
|
|
313
|
+
});
|
|
314
|
+
window['onReactionMessage'].exposed = true;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
catch (error) {
|
|
318
|
+
console.error(error);
|
|
319
|
+
}
|
|
320
|
+
try {
|
|
321
|
+
if (!window['onParticipantsChanged'].exposed) {
|
|
322
|
+
WPP.on('group.participant_changed', function (participantChangedEvent) {
|
|
323
|
+
window['onParticipantsChanged'](participantChangedEvent);
|
|
324
|
+
});
|
|
325
|
+
window['onParticipantsChanged'].exposed = true;
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
catch (error) {
|
|
329
|
+
console.error(error);
|
|
330
|
+
}
|
|
291
331
|
})
|
|
292
332
|
.catch(function () { })];
|
|
293
333
|
case 6:
|
|
@@ -389,21 +429,17 @@ var ListenerLayer = /** @class */ (function (_super) {
|
|
|
389
429
|
callback = groupId;
|
|
390
430
|
groupId = null;
|
|
391
431
|
}
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
// Only group events
|
|
395
|
-
if (message.type !== enum_1.MessageType.GP2 ||
|
|
396
|
-
!subtypeEvents.includes(message.subtype)) {
|
|
397
|
-
return;
|
|
398
|
-
}
|
|
399
|
-
if (groupId && groupId !== message.id) {
|
|
432
|
+
return this.registerEvent(exposed_enum_1.ExposedFn.onParticipantsChanged, function (evData) {
|
|
433
|
+
if (groupId && groupId !== evData.groupId) {
|
|
400
434
|
return;
|
|
401
435
|
}
|
|
402
436
|
callback({
|
|
403
|
-
by:
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
437
|
+
by: evData.author,
|
|
438
|
+
byPushName: evData.authorPushName,
|
|
439
|
+
groupId: evData.groupId,
|
|
440
|
+
action: evData.action,
|
|
441
|
+
operation: evData.operation,
|
|
442
|
+
who: evData.participants,
|
|
407
443
|
});
|
|
408
444
|
});
|
|
409
445
|
};
|
|
@@ -498,6 +534,13 @@ var ListenerLayer = /** @class */ (function (_super) {
|
|
|
498
534
|
ListenerLayer.prototype.onRevokedMessage = function (callback) {
|
|
499
535
|
return this.registerEvent('onRevokedMessage', callback);
|
|
500
536
|
};
|
|
537
|
+
/**
|
|
538
|
+
* @event Listens to reaction messages
|
|
539
|
+
* @returns Disposable object to stop the listening
|
|
540
|
+
*/
|
|
541
|
+
ListenerLayer.prototype.onReactionMessage = function (callback) {
|
|
542
|
+
return this.registerEvent('onReactionMessage', callback);
|
|
543
|
+
};
|
|
501
544
|
return ListenerLayer;
|
|
502
545
|
}(profile_layer_1.ProfileLayer));
|
|
503
546
|
exports.ListenerLayer = ListenerLayer;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Page } from 'puppeteer';
|
|
2
|
-
import { HostLayer } from './host.layer';
|
|
3
2
|
import { CreateConfig } from '../../config/create-config';
|
|
4
|
-
|
|
3
|
+
import { StatusLayer } from './status.layer';
|
|
4
|
+
export declare class ProfileLayer extends StatusLayer {
|
|
5
5
|
page: Page;
|
|
6
6
|
constructor(page: Page, session?: string, options?: CreateConfig);
|
|
7
7
|
/**
|
|
@@ -68,8 +68,8 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
68
68
|
};
|
|
69
69
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
70
70
|
exports.ProfileLayer = void 0;
|
|
71
|
-
var host_layer_1 = require("./host.layer");
|
|
72
71
|
var helpers_1 = require("../helpers");
|
|
72
|
+
var status_layer_1 = require("./status.layer");
|
|
73
73
|
var ProfileLayer = /** @class */ (function (_super) {
|
|
74
74
|
__extends(ProfileLayer, _super);
|
|
75
75
|
function ProfileLayer(page, session, options) {
|
|
@@ -212,5 +212,5 @@ var ProfileLayer = /** @class */ (function (_super) {
|
|
|
212
212
|
});
|
|
213
213
|
};
|
|
214
214
|
return ProfileLayer;
|
|
215
|
-
}(
|
|
215
|
+
}(status_layer_1.StatusLayer));
|
|
216
216
|
exports.ProfileLayer = ProfileLayer;
|
|
@@ -235,21 +235,30 @@ var RetrieverLayer = /** @class */ (function (_super) {
|
|
|
235
235
|
RetrieverLayer.prototype.getAllGroups = function (withNewMessagesOnly) {
|
|
236
236
|
if (withNewMessagesOnly === void 0) { withNewMessagesOnly = false; }
|
|
237
237
|
return __awaiter(this, void 0, void 0, function () {
|
|
238
|
-
var
|
|
238
|
+
var _this = this;
|
|
239
239
|
return __generator(this, function (_a) {
|
|
240
240
|
switch (_a.label) {
|
|
241
|
-
case 0:
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
241
|
+
case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
|
|
242
|
+
var withNewMessagesOnly = _a.withNewMessagesOnly;
|
|
243
|
+
return __awaiter(_this, void 0, void 0, function () {
|
|
244
|
+
var chats, groups;
|
|
245
|
+
return __generator(this, function (_b) {
|
|
246
|
+
switch (_b.label) {
|
|
247
|
+
case 0: return [4 /*yield*/, WPP.chat.list({
|
|
248
|
+
onlyGroups: true,
|
|
249
|
+
onlyWithUnreadMessage: withNewMessagesOnly,
|
|
250
|
+
})];
|
|
251
|
+
case 1:
|
|
252
|
+
chats = _b.sent();
|
|
253
|
+
return [4 /*yield*/, Promise.all(chats.map(function (c) { return WPP.group.ensureGroup(c.id); }))];
|
|
254
|
+
case 2:
|
|
255
|
+
groups = _b.sent();
|
|
256
|
+
return [2 /*return*/, groups.map(function (g) { return WAPI._serializeChatObj(g); })];
|
|
257
|
+
}
|
|
258
|
+
});
|
|
259
|
+
});
|
|
260
|
+
}, { withNewMessagesOnly: withNewMessagesOnly })];
|
|
261
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
253
262
|
}
|
|
254
263
|
});
|
|
255
264
|
});
|