@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
|
@@ -428,4 +428,21 @@ export declare class SenderLayer extends ListenerLayer {
|
|
|
428
428
|
* @deprecated Deprecated in favor of Use startTyping or startRecording functions
|
|
429
429
|
*/
|
|
430
430
|
setChatState(chatId: string, chatState: ChatState): Promise<void>;
|
|
431
|
+
/**
|
|
432
|
+
* Send reaction to message
|
|
433
|
+
* @example
|
|
434
|
+
* ```javascript
|
|
435
|
+
* // For send Reaction, just to send emoji
|
|
436
|
+
* await client.sendReactionToMessage('[number]@c.us', '🤯');
|
|
437
|
+
*
|
|
438
|
+
* // to remove reacition
|
|
439
|
+
* await client.startRecording('[number]@c.us', false);
|
|
440
|
+
* ```
|
|
441
|
+
* @category Chat
|
|
442
|
+
* @param to Chat Id
|
|
443
|
+
* @param duration Duration um miliseconds
|
|
444
|
+
*/
|
|
445
|
+
sendReactionToMessage(msgId: string, reaction: string | false): Promise<{
|
|
446
|
+
sendMsgResult: string;
|
|
447
|
+
}>;
|
|
431
448
|
}
|
|
@@ -1264,6 +1264,33 @@ var SenderLayer = /** @class */ (function (_super) {
|
|
|
1264
1264
|
});
|
|
1265
1265
|
});
|
|
1266
1266
|
};
|
|
1267
|
+
/**
|
|
1268
|
+
* Send reaction to message
|
|
1269
|
+
* @example
|
|
1270
|
+
* ```javascript
|
|
1271
|
+
* // For send Reaction, just to send emoji
|
|
1272
|
+
* await client.sendReactionToMessage('[number]@c.us', '🤯');
|
|
1273
|
+
*
|
|
1274
|
+
* // to remove reacition
|
|
1275
|
+
* await client.startRecording('[number]@c.us', false);
|
|
1276
|
+
* ```
|
|
1277
|
+
* @category Chat
|
|
1278
|
+
* @param to Chat Id
|
|
1279
|
+
* @param duration Duration um miliseconds
|
|
1280
|
+
*/
|
|
1281
|
+
SenderLayer.prototype.sendReactionToMessage = function (msgId, reaction) {
|
|
1282
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1283
|
+
return __generator(this, function (_a) {
|
|
1284
|
+
return [2 /*return*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
|
|
1285
|
+
var msgId = _a.msgId, reaction = _a.reaction;
|
|
1286
|
+
return WPP.chat.sendReactionToMessage(msgId, reaction);
|
|
1287
|
+
}, {
|
|
1288
|
+
msgId: msgId,
|
|
1289
|
+
reaction: reaction,
|
|
1290
|
+
})];
|
|
1291
|
+
});
|
|
1292
|
+
});
|
|
1293
|
+
};
|
|
1267
1294
|
return SenderLayer;
|
|
1268
1295
|
}(listener_layer_1.ListenerLayer));
|
|
1269
1296
|
exports.SenderLayer = SenderLayer;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Page } from 'puppeteer';
|
|
2
|
+
import { CreateConfig } from '../../config/create-config';
|
|
3
|
+
import { LabelsLayer } from './labels.layer';
|
|
4
|
+
export declare class StatusLayer extends LabelsLayer {
|
|
5
|
+
page: Page;
|
|
6
|
+
constructor(page: Page, session?: string, options?: CreateConfig);
|
|
7
|
+
/**
|
|
8
|
+
* Send a image message to status stories
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```javascript
|
|
12
|
+
* client.sendImageStatus('data:image/jpeg;base64,<a long base64 file...>');
|
|
13
|
+
* ```
|
|
14
|
+
* @param pathOrBase64 Path or base 64 image
|
|
15
|
+
*/
|
|
16
|
+
sendImageStatus(pathOrBase64: string): Promise<void>;
|
|
17
|
+
/**
|
|
18
|
+
* Send a video message to status stories
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```javascript
|
|
22
|
+
* client.sendVideoStatus('data:video/mp4;base64,<a long base64 file...>');
|
|
23
|
+
* ```
|
|
24
|
+
* @param pathOrBase64 Path or base 64 image
|
|
25
|
+
*/
|
|
26
|
+
sendVideoStatus(pathOrBase64: string): Promise<void>;
|
|
27
|
+
/**
|
|
28
|
+
* Send a text to status stories
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```javascript
|
|
32
|
+
* client.sendTextStatus(`Bootstrap primary color: #0275d8`, { backgroundColor: '#0275d8', font: 2});
|
|
33
|
+
* ```
|
|
34
|
+
* @param pathOrBase64 Path or base 64 image
|
|
35
|
+
*/
|
|
36
|
+
sendTextStatus(text: string, options: string): Promise<void>;
|
|
37
|
+
}
|
|
@@ -0,0 +1,216 @@
|
|
|
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.StatusLayer = void 0;
|
|
71
|
+
var labels_layer_1 = require("./labels.layer");
|
|
72
|
+
var helpers_1 = require("../helpers");
|
|
73
|
+
var StatusLayer = /** @class */ (function (_super) {
|
|
74
|
+
__extends(StatusLayer, _super);
|
|
75
|
+
function StatusLayer(page, session, options) {
|
|
76
|
+
var _this = _super.call(this, page, session, options) || this;
|
|
77
|
+
_this.page = page;
|
|
78
|
+
return _this;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Send a image message to status stories
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```javascript
|
|
85
|
+
* client.sendImageStatus('data:image/jpeg;base64,<a long base64 file...>');
|
|
86
|
+
* ```
|
|
87
|
+
* @param pathOrBase64 Path or base 64 image
|
|
88
|
+
*/
|
|
89
|
+
StatusLayer.prototype.sendImageStatus = function (pathOrBase64) {
|
|
90
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
91
|
+
var base64, fileContent, error, mimeInfo, error;
|
|
92
|
+
return __generator(this, function (_a) {
|
|
93
|
+
switch (_a.label) {
|
|
94
|
+
case 0:
|
|
95
|
+
base64 = '';
|
|
96
|
+
if (!pathOrBase64.startsWith('data:')) return [3 /*break*/, 1];
|
|
97
|
+
base64 = pathOrBase64;
|
|
98
|
+
return [3 /*break*/, 5];
|
|
99
|
+
case 1: return [4 /*yield*/, (0, helpers_1.downloadFileToBase64)(pathOrBase64, [
|
|
100
|
+
'image/gif',
|
|
101
|
+
'image/png',
|
|
102
|
+
'image/jpg',
|
|
103
|
+
'image/jpeg',
|
|
104
|
+
'image/webp',
|
|
105
|
+
])];
|
|
106
|
+
case 2:
|
|
107
|
+
fileContent = _a.sent();
|
|
108
|
+
if (!!fileContent) return [3 /*break*/, 4];
|
|
109
|
+
return [4 /*yield*/, (0, helpers_1.fileToBase64)(pathOrBase64)];
|
|
110
|
+
case 3:
|
|
111
|
+
fileContent = _a.sent();
|
|
112
|
+
_a.label = 4;
|
|
113
|
+
case 4:
|
|
114
|
+
if (fileContent) {
|
|
115
|
+
base64 = fileContent;
|
|
116
|
+
}
|
|
117
|
+
_a.label = 5;
|
|
118
|
+
case 5:
|
|
119
|
+
if (!base64) {
|
|
120
|
+
error = new Error('Empty or invalid file or base64');
|
|
121
|
+
Object.assign(error, {
|
|
122
|
+
code: 'empty_file',
|
|
123
|
+
});
|
|
124
|
+
throw error;
|
|
125
|
+
}
|
|
126
|
+
mimeInfo = (0, helpers_1.base64MimeType)(base64);
|
|
127
|
+
if (!mimeInfo || !mimeInfo.includes('image')) {
|
|
128
|
+
error = new Error('Not an image, allowed formats png, jpeg and webp');
|
|
129
|
+
Object.assign(error, {
|
|
130
|
+
code: 'invalid_image',
|
|
131
|
+
});
|
|
132
|
+
throw error;
|
|
133
|
+
}
|
|
134
|
+
return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
|
|
135
|
+
var base64 = _a.base64;
|
|
136
|
+
WPP.status.sendImageStatus(base64);
|
|
137
|
+
}, { base64: base64 })];
|
|
138
|
+
case 6: return [2 /*return*/, _a.sent()];
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
};
|
|
143
|
+
/**
|
|
144
|
+
* Send a video message to status stories
|
|
145
|
+
*
|
|
146
|
+
* @example
|
|
147
|
+
* ```javascript
|
|
148
|
+
* client.sendVideoStatus('data:video/mp4;base64,<a long base64 file...>');
|
|
149
|
+
* ```
|
|
150
|
+
* @param pathOrBase64 Path or base 64 image
|
|
151
|
+
*/
|
|
152
|
+
StatusLayer.prototype.sendVideoStatus = function (pathOrBase64) {
|
|
153
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
154
|
+
var base64, fileContent, error;
|
|
155
|
+
return __generator(this, function (_a) {
|
|
156
|
+
switch (_a.label) {
|
|
157
|
+
case 0:
|
|
158
|
+
base64 = '';
|
|
159
|
+
if (!pathOrBase64.startsWith('data:')) return [3 /*break*/, 1];
|
|
160
|
+
base64 = pathOrBase64;
|
|
161
|
+
return [3 /*break*/, 5];
|
|
162
|
+
case 1: return [4 /*yield*/, (0, helpers_1.downloadFileToBase64)(pathOrBase64)];
|
|
163
|
+
case 2:
|
|
164
|
+
fileContent = _a.sent();
|
|
165
|
+
if (!!fileContent) return [3 /*break*/, 4];
|
|
166
|
+
return [4 /*yield*/, (0, helpers_1.fileToBase64)(pathOrBase64)];
|
|
167
|
+
case 3:
|
|
168
|
+
fileContent = _a.sent();
|
|
169
|
+
_a.label = 4;
|
|
170
|
+
case 4:
|
|
171
|
+
if (fileContent) {
|
|
172
|
+
base64 = fileContent;
|
|
173
|
+
}
|
|
174
|
+
_a.label = 5;
|
|
175
|
+
case 5:
|
|
176
|
+
if (!base64) {
|
|
177
|
+
error = new Error('Empty or invalid file or base64');
|
|
178
|
+
Object.assign(error, {
|
|
179
|
+
code: 'empty_file',
|
|
180
|
+
});
|
|
181
|
+
throw error;
|
|
182
|
+
}
|
|
183
|
+
return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
|
|
184
|
+
var base64 = _a.base64;
|
|
185
|
+
WPP.status.sendVideoStatus(base64);
|
|
186
|
+
}, { base64: base64 })];
|
|
187
|
+
case 6: return [2 /*return*/, _a.sent()];
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
});
|
|
191
|
+
};
|
|
192
|
+
/**
|
|
193
|
+
* Send a text to status stories
|
|
194
|
+
*
|
|
195
|
+
* @example
|
|
196
|
+
* ```javascript
|
|
197
|
+
* client.sendTextStatus(`Bootstrap primary color: #0275d8`, { backgroundColor: '#0275d8', font: 2});
|
|
198
|
+
* ```
|
|
199
|
+
* @param pathOrBase64 Path or base 64 image
|
|
200
|
+
*/
|
|
201
|
+
StatusLayer.prototype.sendTextStatus = function (text, options) {
|
|
202
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
203
|
+
return __generator(this, function (_a) {
|
|
204
|
+
switch (_a.label) {
|
|
205
|
+
case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
|
|
206
|
+
var text = _a.text, options = _a.options;
|
|
207
|
+
WPP.status.sendTextStatus(text, options);
|
|
208
|
+
}, { text: text, options: options })];
|
|
209
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
});
|
|
213
|
+
};
|
|
214
|
+
return StatusLayer;
|
|
215
|
+
}(labels_layer_1.LabelsLayer));
|
|
216
|
+
exports.StatusLayer = StatusLayer;
|
package/dist/api/model/chat.d.ts
CHANGED
|
@@ -16,6 +16,12 @@ export interface Chat {
|
|
|
16
16
|
pin: number;
|
|
17
17
|
msgs: null;
|
|
18
18
|
kind: string;
|
|
19
|
+
isAnnounceGrpRestrict: boolean;
|
|
20
|
+
ephemeralDuration: number;
|
|
21
|
+
hasChatBeenOpened: boolean;
|
|
22
|
+
unreadMentionCount: number;
|
|
23
|
+
hasUnreadMention: boolean;
|
|
24
|
+
archiveAtMentionViewedInDrawer: boolean;
|
|
19
25
|
isBroadcast: boolean;
|
|
20
26
|
isGroup: boolean;
|
|
21
27
|
isReadOnly: boolean;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
export { AckType } from './ack-type';
|
|
2
2
|
export { ChatState } from './chat-state';
|
|
3
|
-
export { GroupChangeEvent } from './group-change-event';
|
|
4
3
|
export { GroupNotificationType } from './group-notification-type';
|
|
5
4
|
export { SocketState, SocketStream } from './socket-state';
|
|
6
5
|
export { MessageType, MediaType } from './message-type';
|
|
@@ -30,13 +30,11 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
30
30
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
31
31
|
};
|
|
32
32
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
33
|
-
exports.MediaType = exports.MessageType = exports.SocketStream = exports.SocketState = exports.GroupNotificationType = exports.
|
|
33
|
+
exports.MediaType = exports.MessageType = exports.SocketStream = exports.SocketState = exports.GroupNotificationType = exports.ChatState = exports.AckType = void 0;
|
|
34
34
|
var ack_type_1 = require("./ack-type");
|
|
35
35
|
Object.defineProperty(exports, "AckType", { enumerable: true, get: function () { return ack_type_1.AckType; } });
|
|
36
36
|
var chat_state_1 = require("./chat-state");
|
|
37
37
|
Object.defineProperty(exports, "ChatState", { enumerable: true, get: function () { return chat_state_1.ChatState; } });
|
|
38
|
-
var group_change_event_1 = require("./group-change-event");
|
|
39
|
-
Object.defineProperty(exports, "GroupChangeEvent", { enumerable: true, get: function () { return group_change_event_1.GroupChangeEvent; } });
|
|
40
38
|
var group_notification_type_1 = require("./group-notification-type");
|
|
41
39
|
Object.defineProperty(exports, "GroupNotificationType", { enumerable: true, get: function () { return group_notification_type_1.GroupNotificationType; } });
|
|
42
40
|
var socket_state_1 = require("./socket-state");
|
|
@@ -3,6 +3,21 @@ export interface GroupMetadata {
|
|
|
3
3
|
id: Wid;
|
|
4
4
|
creation: number;
|
|
5
5
|
owner: Wid;
|
|
6
|
+
desc: string;
|
|
7
|
+
descId: string;
|
|
8
|
+
descTime: number;
|
|
9
|
+
descOwner: Wid;
|
|
10
|
+
restrict: boolean;
|
|
11
|
+
announce: boolean;
|
|
12
|
+
noFrequentlyForwarded: boolean;
|
|
13
|
+
ephemeralDuration: number;
|
|
14
|
+
size: number;
|
|
15
|
+
support: boolean;
|
|
16
|
+
suspended: boolean;
|
|
17
|
+
terminated: boolean;
|
|
18
|
+
isParentGroup: boolean;
|
|
19
|
+
defaultSubgroup: boolean;
|
|
20
|
+
displayCadminPromotion: boolean;
|
|
6
21
|
participants: any[];
|
|
7
22
|
pendingParticipants: any[];
|
|
8
23
|
}
|
|
@@ -9,6 +9,10 @@ export declare type CatchQRCallback = (qrCode: string, asciiQR: string, attempt:
|
|
|
9
9
|
* A callback will be received, informing the customer's status
|
|
10
10
|
*/
|
|
11
11
|
export declare type StatusFindCallback = (status: StatusFind | keyof typeof StatusFind, session: string) => void;
|
|
12
|
+
/**
|
|
13
|
+
* A callback will be received, informing data as percentage and loading screen message
|
|
14
|
+
*/
|
|
15
|
+
export declare type LoadingScreenCallback = (percent: number, message: string) => void;
|
|
12
16
|
export interface CreateOptions extends CreateConfig {
|
|
13
17
|
/**
|
|
14
18
|
* You must pass a string type parameter, this parameter will be the name of the client's session. If the parameter is not passed, the section name will be "session".
|
|
@@ -22,6 +26,10 @@ export interface CreateOptions extends CreateConfig {
|
|
|
22
26
|
* A callback will be received, informing the customer's status
|
|
23
27
|
*/
|
|
24
28
|
statusFind?: StatusFindCallback;
|
|
29
|
+
/**
|
|
30
|
+
* A callback will be received, informing data as percentage and loading screen message
|
|
31
|
+
*/
|
|
32
|
+
onLoadingScreen?: LoadingScreenCallback;
|
|
25
33
|
/**
|
|
26
34
|
* Pass the session token information you can receive this token with the await client.getSessionTokenBrowser () function
|
|
27
35
|
* @deprecated in favor of `sessionToken`
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { GroupChangeEvent } from './enum';
|
|
2
1
|
export interface ParticipantEvent {
|
|
3
|
-
by
|
|
2
|
+
by?: string;
|
|
3
|
+
byPushName?: string;
|
|
4
4
|
groupId: string;
|
|
5
|
-
action:
|
|
5
|
+
action: 'add' | 'remove' | 'demote' | 'promote' | 'leaver' | 'join';
|
|
6
|
+
operation: 'add' | 'remove' | 'demote' | 'promote';
|
|
6
7
|
who: string[];
|
|
7
8
|
}
|
|
@@ -110,5 +110,26 @@ export interface CreateConfig {
|
|
|
110
110
|
* @default 'WPPConnect'
|
|
111
111
|
*/
|
|
112
112
|
deviceName?: string | false;
|
|
113
|
+
/**
|
|
114
|
+
* Set custom Link Preview API servers
|
|
115
|
+
* @default null
|
|
116
|
+
*/
|
|
117
|
+
linkPreviewApiServers?: string[] | null;
|
|
118
|
+
/**
|
|
119
|
+
* Disable custom Google Analytics
|
|
120
|
+
* @default true
|
|
121
|
+
*/
|
|
122
|
+
disableGoogleAnalytics?: boolean;
|
|
123
|
+
/**
|
|
124
|
+
* Custom Google Analytics Tracker Id, like 'G-XXXXXXXXXX'
|
|
125
|
+
* collect analytics data to your GA account
|
|
126
|
+
* @default null
|
|
127
|
+
*/
|
|
128
|
+
googleAnalyticsId?: string | null;
|
|
129
|
+
/**
|
|
130
|
+
* Custom variable for Google Analytics
|
|
131
|
+
* @default 'WPPConnect'
|
|
132
|
+
*/
|
|
133
|
+
poweredBy?: string;
|
|
113
134
|
}
|
|
114
135
|
export declare const defaultOptions: CreateConfig;
|
|
@@ -2,6 +2,7 @@ import { Browser, BrowserContext, Page } from 'puppeteer';
|
|
|
2
2
|
import { CreateConfig } from '../config/create-config';
|
|
3
3
|
import { Logger } from 'winston';
|
|
4
4
|
import { SessionToken } from '../token-store';
|
|
5
|
+
import { LoadingScreenCallback } from '../api/model';
|
|
5
6
|
export declare function unregisterServiceWorker(page: Page): Promise<void>;
|
|
6
7
|
/**
|
|
7
8
|
* Força o carregamento de uma versão específica do WhatsApp WEB
|
|
@@ -9,7 +10,8 @@ export declare function unregisterServiceWorker(page: Page): Promise<void>;
|
|
|
9
10
|
* @param version Versão ou expressão semver
|
|
10
11
|
*/
|
|
11
12
|
export declare function setWhatsappVersion(page: Page, version: string): Promise<void>;
|
|
12
|
-
export declare function initWhatsapp(page: Page, token?: SessionToken, clear?: boolean, version?: string): Promise<Page>;
|
|
13
|
+
export declare function initWhatsapp(page: Page, token?: SessionToken, clear?: boolean, version?: string, onLoadingScreenCallBack?: LoadingScreenCallback): Promise<Page>;
|
|
14
|
+
export declare function onLoadingScreen(page: Page, onLoadingScreenCallBack?: LoadingScreenCallback): Promise<void>;
|
|
13
15
|
export declare function injectApi(page: Page): Promise<boolean | import("puppeteer").JSHandle<unknown>>;
|
|
14
16
|
/**
|
|
15
17
|
* Initializes browser, will try to use chrome as default
|
|
@@ -98,7 +98,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
98
98
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
99
99
|
};
|
|
100
100
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
101
|
-
exports.getOrCreatePage = exports.initBrowser = exports.injectApi = exports.initWhatsapp = exports.setWhatsappVersion = exports.unregisterServiceWorker = void 0;
|
|
101
|
+
exports.getOrCreatePage = exports.initBrowser = exports.injectApi = exports.onLoadingScreen = exports.initWhatsapp = exports.setWhatsappVersion = exports.unregisterServiceWorker = void 0;
|
|
102
102
|
var ChromeLauncher = __importStar(require("chrome-launcher"));
|
|
103
103
|
var os = __importStar(require("os"));
|
|
104
104
|
var path = __importStar(require("path"));
|
|
@@ -176,7 +176,7 @@ function setWhatsappVersion(page, version) {
|
|
|
176
176
|
});
|
|
177
177
|
}
|
|
178
178
|
exports.setWhatsappVersion = setWhatsappVersion;
|
|
179
|
-
function initWhatsapp(page, token, clear, version) {
|
|
179
|
+
function initWhatsapp(page, token, clear, version, onLoadingScreenCallBack) {
|
|
180
180
|
if (clear === void 0) { clear = true; }
|
|
181
181
|
return __awaiter(this, void 0, void 0, function () {
|
|
182
182
|
var timeout;
|
|
@@ -204,6 +204,9 @@ function initWhatsapp(page, token, clear, version) {
|
|
|
204
204
|
})
|
|
205
205
|
.catch(function () { })];
|
|
206
206
|
case 5:
|
|
207
|
+
_a.sent();
|
|
208
|
+
return [4 /*yield*/, onLoadingScreen(page, onLoadingScreenCallBack)];
|
|
209
|
+
case 6:
|
|
207
210
|
_a.sent();
|
|
208
211
|
return [2 /*return*/, page];
|
|
209
212
|
}
|
|
@@ -211,6 +214,60 @@ function initWhatsapp(page, token, clear, version) {
|
|
|
211
214
|
});
|
|
212
215
|
}
|
|
213
216
|
exports.initWhatsapp = initWhatsapp;
|
|
217
|
+
var lastPercent = null;
|
|
218
|
+
var lastPercentMessage = null;
|
|
219
|
+
function onLoadingScreen(page, onLoadingScreenCallBack) {
|
|
220
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
221
|
+
var _this = this;
|
|
222
|
+
return __generator(this, function (_a) {
|
|
223
|
+
switch (_a.label) {
|
|
224
|
+
case 0: return [4 /*yield*/, page.evaluate("function getElementByXpath(path) {\n return document.evaluate(path, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;\n }")];
|
|
225
|
+
case 1:
|
|
226
|
+
_a.sent();
|
|
227
|
+
return [4 /*yield*/, page.exposeFunction('loadingScreen', function (percent, message) { return __awaiter(_this, void 0, void 0, function () {
|
|
228
|
+
return __generator(this, function (_a) {
|
|
229
|
+
if (lastPercent !== percent || lastPercentMessage !== message) {
|
|
230
|
+
onLoadingScreenCallBack && onLoadingScreenCallBack(percent, message);
|
|
231
|
+
lastPercent = percent;
|
|
232
|
+
lastPercentMessage = message;
|
|
233
|
+
}
|
|
234
|
+
return [2 /*return*/];
|
|
235
|
+
});
|
|
236
|
+
}); })];
|
|
237
|
+
case 2:
|
|
238
|
+
_a.sent();
|
|
239
|
+
return [4 /*yield*/, page.evaluate(function (selectors) {
|
|
240
|
+
var observer = new MutationObserver(function () {
|
|
241
|
+
var window2 = window;
|
|
242
|
+
var progressBar = window2.getElementByXpath(selectors.PROGRESS);
|
|
243
|
+
var progressMessage = window2.getElementByXpath(selectors.PROGRESS_MESSAGE);
|
|
244
|
+
if (progressBar) {
|
|
245
|
+
if (this.lastPercent !== progressBar.value ||
|
|
246
|
+
this.lastPercentMessage !== progressMessage.innerText) {
|
|
247
|
+
window2.loadingScreen(progressBar.value, progressMessage.innerText);
|
|
248
|
+
this.lastPercent = progressBar.value;
|
|
249
|
+
this.lastPercentMessage = progressMessage.innerText;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
observer.observe(document, {
|
|
254
|
+
attributes: true,
|
|
255
|
+
childList: true,
|
|
256
|
+
characterData: true,
|
|
257
|
+
subtree: true,
|
|
258
|
+
});
|
|
259
|
+
}, {
|
|
260
|
+
PROGRESS: "//*[@id='app']/div/div/div[2]/progress",
|
|
261
|
+
PROGRESS_MESSAGE: "//*[@id='app']/div/div/div[3]",
|
|
262
|
+
})];
|
|
263
|
+
case 3:
|
|
264
|
+
_a.sent();
|
|
265
|
+
return [2 /*return*/];
|
|
266
|
+
}
|
|
267
|
+
});
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
exports.onLoadingScreen = onLoadingScreen;
|
|
214
271
|
function injectApi(page) {
|
|
215
272
|
return __awaiter(this, void 0, void 0, function () {
|
|
216
273
|
var injected;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Whatsapp } from '../api/whatsapp';
|
|
2
2
|
import { CreateConfig } from '../config/create-config';
|
|
3
|
-
import { CatchQRCallback, CreateOptions, StatusFindCallback } from '../api/model/initializer';
|
|
3
|
+
import { CatchQRCallback, CreateOptions, LoadingScreenCallback, StatusFindCallback } from '../api/model/initializer';
|
|
4
4
|
import { SessionToken } from '../token-store';
|
|
5
5
|
/**
|
|
6
6
|
* Start the bot
|
|
@@ -13,4 +13,4 @@ export declare function create(createOption: CreateOptions): Promise<Whatsapp>;
|
|
|
13
13
|
* @returns Whatsapp page, with this parameter you will be able to access the bot functions
|
|
14
14
|
* @deprecated Deprecated in favor of create with {@link CreateOptions} (e.g., wppconnect.create({session: 'test'})).
|
|
15
15
|
*/
|
|
16
|
-
export declare function create(sessionName: string, catchQR?: CatchQRCallback, statusFind?: StatusFindCallback, options?: CreateConfig, browserSessionToken?: SessionToken): Promise<Whatsapp>;
|
|
16
|
+
export declare function create(sessionName: string, catchQR?: CatchQRCallback, statusFind?: StatusFindCallback, onLoadingScreen?: LoadingScreenCallback, options?: CreateConfig, browserSessionToken?: SessionToken): Promise<Whatsapp>;
|
|
@@ -114,7 +114,7 @@ process.on('unhandledRejection', function (reason, promise) {
|
|
|
114
114
|
}
|
|
115
115
|
logger_1.defaultLogger.error(message);
|
|
116
116
|
});
|
|
117
|
-
function create(sessionOrOption, catchQR, statusFind, options, browserSessionToken) {
|
|
117
|
+
function create(sessionOrOption, catchQR, statusFind, onLoadingScreen, options, browserSessionToken) {
|
|
118
118
|
var _a;
|
|
119
119
|
return __awaiter(this, void 0, void 0, function () {
|
|
120
120
|
var session, usingDeprecatedCreate, mergedOptions, logger, browser, page, client_1, isLogged, waitLoginPromise_1;
|
|
@@ -139,6 +139,7 @@ function create(sessionOrOption, catchQR, statusFind, options, browserSessionTok
|
|
|
139
139
|
session = sessionOrOption.session;
|
|
140
140
|
catchQR = sessionOrOption.catchQR || catchQR;
|
|
141
141
|
statusFind = sessionOrOption.statusFind || statusFind;
|
|
142
|
+
onLoadingScreen = sessionOrOption.onLoadingScreen || onLoadingScreen;
|
|
142
143
|
if (!options.sessionToken) {
|
|
143
144
|
options.sessionToken =
|
|
144
145
|
sessionOrOption.browserSessionToken || browserSessionToken;
|
|
@@ -263,6 +264,7 @@ function create(sessionOrOption, catchQR, statusFind, options, browserSessionTok
|
|
|
263
264
|
case 7:
|
|
264
265
|
if (!page) return [3 /*break*/, 10];
|
|
265
266
|
client_1 = new whatsapp_1.Whatsapp(page, session, mergedOptions);
|
|
267
|
+
client_1.onLoadingScreen = onLoadingScreen;
|
|
266
268
|
if (!mergedOptions.waitForLogin) return [3 /*break*/, 9];
|
|
267
269
|
return [4 /*yield*/, client_1.waitForLogin(catchQR, statusFind)];
|
|
268
270
|
case 8:
|