@open-wa/wa-automate 4.23.12 → 4.23.16
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/README.md +5 -19
- package/dist/api/Client.d.ts +6 -0
- package/dist/api/Client.js +10 -0
- package/dist/api/model/chat.d.ts +57 -0
- package/dist/api/model/index.d.ts +4 -0
- package/dist/api/model/index.js +0 -1
- package/dist/api/model/media.d.ts +8 -0
- package/dist/cli/collections.d.ts +1 -0
- package/dist/cli/collections.js +50 -5
- package/dist/cli/index.js +3 -0
- package/dist/cli/setup.js +6 -0
- package/dist/controllers/browser.js +4 -2
- package/dist/controllers/initializer.js +2 -1
- package/package.json +4 -2
package/README.md
CHANGED
@@ -36,24 +36,17 @@
|
|
36
36
|
Use this command to install the library for the first time and to keep the library up to date.
|
37
37
|
|
38
38
|
```bash
|
39
|
-
> npm i --save @open-wa/wa-automate@latest
|
39
|
+
> npm i --save @open-wa/wa-automate@latest
|
40
40
|
```
|
41
41
|
|
42
42
|
## Usage
|
43
43
|
|
44
|
-
|
45
|
-
// import { create, Client } from '@open-wa/wa-automate';
|
46
|
-
const wa = require('@open-wa/wa-automate');
|
44
|
+
## CLI
|
47
45
|
|
48
|
-
|
46
|
+
Want to convert your WA account to an API instantly? You can now with the CLI. For more details see [Easy API](https://docs.openwa.dev/pages/Getting%20Started/quick-run.html)
|
49
47
|
|
50
|
-
|
51
|
-
|
52
|
-
if (message.body === 'Hi') {
|
53
|
-
await client.sendText(message.from, '👋 Hello!');
|
54
|
-
}
|
55
|
-
});
|
56
|
-
}
|
48
|
+
```bash
|
49
|
+
> npx @open-wa/wa-automate --help
|
57
50
|
```
|
58
51
|
|
59
52
|
## Custom Setup
|
@@ -90,13 +83,6 @@ function start(client) {
|
|
90
83
|
|
91
84
|
###### @open-wa/wa-automate will remember the session so there is no need to authenticate every time
|
92
85
|
|
93
|
-
## CLI
|
94
|
-
|
95
|
-
Want to convert your WA account to an API instantly? You can now with the CLI. For more details see [Easy API](https://docs.openwa.dev/pages/Getting%20Started/quick-run.html)
|
96
|
-
|
97
|
-
```bash
|
98
|
-
> npx @open-wa/wa-automate --help
|
99
|
-
```
|
100
86
|
|
101
87
|
## Multi Device Support
|
102
88
|
|
package/dist/api/Client.d.ts
CHANGED
@@ -1198,6 +1198,12 @@ export declare class Client {
|
|
1198
1198
|
* @returns list of messages
|
1199
1199
|
*/
|
1200
1200
|
getIndicatedNewMessages(): Promise<Message[]>;
|
1201
|
+
/**
|
1202
|
+
* Fires all unread messages to the onMessage listener.
|
1203
|
+
* Make sure to call this AFTER setting your listeners.
|
1204
|
+
* @returns array of message IDs
|
1205
|
+
*/
|
1206
|
+
emitUnreadMessages(): Promise<MessageId[]>;
|
1201
1207
|
/**
|
1202
1208
|
* Retrieves all Messages in a chat that have been loaded within the WA web instance.
|
1203
1209
|
*
|
package/dist/api/Client.js
CHANGED
@@ -2410,6 +2410,16 @@ class Client {
|
|
2410
2410
|
return JSON.parse(yield this.pup(() => WAPI.getIndicatedNewMessages()));
|
2411
2411
|
});
|
2412
2412
|
}
|
2413
|
+
/**
|
2414
|
+
* Fires all unread messages to the onMessage listener.
|
2415
|
+
* Make sure to call this AFTER setting your listeners.
|
2416
|
+
* @returns array of message IDs
|
2417
|
+
*/
|
2418
|
+
emitUnreadMessages() {
|
2419
|
+
return __awaiter(this, void 0, void 0, function* () {
|
2420
|
+
return yield this.pup(() => WAPI.emitUnreadMessages());
|
2421
|
+
});
|
2422
|
+
}
|
2413
2423
|
/**
|
2414
2424
|
* Retrieves all Messages in a chat that have been loaded within the WA web instance.
|
2415
2425
|
*
|
package/dist/api/model/chat.d.ts
CHANGED
@@ -5,26 +5,83 @@ export interface Chat {
|
|
5
5
|
archive: boolean;
|
6
6
|
changeNumberNewJid: any;
|
7
7
|
changeNumberOldJid: any;
|
8
|
+
/**
|
9
|
+
* The contact related to this chat
|
10
|
+
*/
|
8
11
|
contact: Contact;
|
12
|
+
/**
|
13
|
+
* Group metadata for this chat
|
14
|
+
*/
|
9
15
|
groupMetadata: GroupMetadata;
|
16
|
+
/**
|
17
|
+
* The id of the chat
|
18
|
+
*/
|
10
19
|
id: ChatId;
|
20
|
+
/**
|
21
|
+
* If the chat is a group chat is restricted
|
22
|
+
*/
|
11
23
|
isAnnounceGrpRestrict: any;
|
24
|
+
/**
|
25
|
+
* The title of the chat
|
26
|
+
*/
|
12
27
|
formattedTitle?: string;
|
28
|
+
/**
|
29
|
+
* Whether your host account is able to send messages to this chat
|
30
|
+
*/
|
13
31
|
canSend?: boolean;
|
32
|
+
/**
|
33
|
+
* Whether the chat is a group chat
|
34
|
+
*/
|
14
35
|
isGroup: boolean;
|
36
|
+
/**
|
37
|
+
* Whether the chat is a group chat and the group is restricted
|
38
|
+
*/
|
15
39
|
isReadOnly: boolean;
|
16
40
|
kind: string;
|
41
|
+
/**
|
42
|
+
* The labels attached to this chat.
|
43
|
+
*/
|
17
44
|
labels: any;
|
45
|
+
/**
|
46
|
+
* The ID of the last message received in this chat
|
47
|
+
*/
|
18
48
|
lastReceivedKey: any;
|
19
49
|
modifyTag: number;
|
50
|
+
/**
|
51
|
+
* The messages in the chat
|
52
|
+
*/
|
20
53
|
msgs: any;
|
54
|
+
/**
|
55
|
+
* The expiration timestamp of the chat mute
|
56
|
+
*/
|
21
57
|
muteExpiration: number;
|
58
|
+
/**
|
59
|
+
* The name of the chat
|
60
|
+
*/
|
22
61
|
name: string;
|
62
|
+
/**
|
63
|
+
* Whether the chat is marked as spam
|
64
|
+
*/
|
23
65
|
notSpam: boolean;
|
66
|
+
/**
|
67
|
+
* Messages that are pending to be sent
|
68
|
+
*/
|
24
69
|
pendingMsgs: boolean;
|
70
|
+
/**
|
71
|
+
* Whether the chat is pinned
|
72
|
+
*/
|
25
73
|
pin: number;
|
74
|
+
/**
|
75
|
+
* The presence state of the chat participant
|
76
|
+
*/
|
26
77
|
presence: any;
|
78
|
+
/**
|
79
|
+
* The timestamp of the last interaction in the chat
|
80
|
+
*/
|
27
81
|
t: number;
|
82
|
+
/**
|
83
|
+
* The number of undread messages in this chat
|
84
|
+
*/
|
28
85
|
unreadCount: number;
|
29
86
|
ack?: any;
|
30
87
|
/**
|
@@ -97,6 +97,10 @@ export declare enum STATE {
|
|
97
97
|
*/
|
98
98
|
DISCONNECTED = "DISCONNECTED"
|
99
99
|
}
|
100
|
+
export declare type EasyApiResponse = {
|
101
|
+
success: boolean;
|
102
|
+
response: any;
|
103
|
+
};
|
100
104
|
export * from './config';
|
101
105
|
export * from './media';
|
102
106
|
export * from './aliases';
|
package/dist/api/model/index.js
CHANGED
@@ -115,7 +115,6 @@ var STATE;
|
|
115
115
|
*/
|
116
116
|
STATE["DISCONNECTED"] = "DISCONNECTED";
|
117
117
|
})(STATE = exports.STATE || (exports.STATE = {}));
|
118
|
-
;
|
119
118
|
__exportStar(require("./config"), exports);
|
120
119
|
__exportStar(require("./media"), exports);
|
121
120
|
__exportStar(require("./aliases"), exports);
|
@@ -44,6 +44,14 @@ export declare type StickerMetadata = {
|
|
44
44
|
* @default `attention`
|
45
45
|
*/
|
46
46
|
cropPosition?: 'top' | 'right top' | 'right' | 'right bottom' | 'bottom' | 'left bottom' | 'left' | 'left top' | 'north' | 'northeast' | 'east' | 'southeast' | 'south' | 'southwest' | 'west' | 'northwest' | 'center' | 'centre' | 'entropy' | 'attention';
|
47
|
+
/**
|
48
|
+
* The corner radius of the sticker when `stickerMetadata.circle` is set to true.
|
49
|
+
* @default `100`
|
50
|
+
* @minimum `1`
|
51
|
+
* @maximum `100`
|
52
|
+
* @multipleOf `1`
|
53
|
+
*/
|
54
|
+
cornerRadius?: number;
|
47
55
|
};
|
48
56
|
export declare type Mp4StickerConversionProcessOptions = {
|
49
57
|
/**
|
package/dist/cli/collections.js
CHANGED
@@ -1,4 +1,23 @@
|
|
1
1
|
"use strict";
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
+
if (k2 === undefined) k2 = k;
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
5
|
+
}) : (function(o, m, k, k2) {
|
6
|
+
if (k2 === undefined) k2 = k;
|
7
|
+
o[k2] = m[k];
|
8
|
+
}));
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
11
|
+
}) : function(o, v) {
|
12
|
+
o["default"] = v;
|
13
|
+
});
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
15
|
+
if (mod && mod.__esModule) return mod;
|
16
|
+
var result = {};
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
18
|
+
__setModuleDefault(result, mod);
|
19
|
+
return result;
|
20
|
+
};
|
2
21
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3
22
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4
23
|
return new (P || (P = Promise))(function (resolve, reject) {
|
@@ -12,14 +31,18 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
31
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
13
32
|
};
|
14
33
|
Object.defineProperty(exports, "__esModule", { value: true });
|
15
|
-
exports.generateCollections = exports.collections = void 0;
|
34
|
+
exports.getTypeSchemas = exports.generateCollections = exports.collections = void 0;
|
16
35
|
const __1 = require("..");
|
17
36
|
const postman_2_swagger_1 = __importDefault(require("postman-2-swagger"));
|
18
37
|
const fs_extra_1 = require("fs-extra");
|
38
|
+
const typeconv_1 = require("typeconv");
|
39
|
+
const fs = __importStar(require("fs"));
|
40
|
+
const glob_promise_1 = __importDefault(require("glob-promise"));
|
19
41
|
exports.collections = {};
|
20
42
|
const generateCollections = (config, spinner) => __awaiter(void 0, void 0, void 0, function* () {
|
21
43
|
let swCol = null;
|
22
44
|
let pmCol = null;
|
45
|
+
const _types = yield exports.getTypeSchemas();
|
23
46
|
spinner.info('Generating Swagger Spec');
|
24
47
|
pmCol = yield __1.generatePostmanJson(config);
|
25
48
|
spinner.succeed(`Postman collection generated: open-wa-${config.sessionId}.postman_collection.json`);
|
@@ -40,6 +63,9 @@ const generateCollections = (config, spinner) => __awaiter(void 0, void 0, void
|
|
40
63
|
"description": "Documentation",
|
41
64
|
"url": swCol.paths[p].post.documentationUrl
|
42
65
|
};
|
66
|
+
swCol.paths[p].post.responses['200'].schema = {
|
67
|
+
"$ref": "#/components/schemas/EasyApiResponse"
|
68
|
+
};
|
43
69
|
swCol.paths[p].post.requestBody = {
|
44
70
|
"description": path.summary,
|
45
71
|
"content": {
|
@@ -55,20 +81,20 @@ const generateCollections = (config, spinner) => __awaiter(void 0, void 0, void
|
|
55
81
|
});
|
56
82
|
delete swCol.swagger;
|
57
83
|
swCol.openapi = "3.0.3";
|
84
|
+
swCol.components = {};
|
85
|
+
swCol.components.schemas = _types;
|
58
86
|
swCol.externalDocs = {
|
59
87
|
"description": "Find more info here",
|
60
88
|
"url": "https://openwa.dev/"
|
61
89
|
};
|
62
90
|
if (config.key) {
|
63
|
-
swCol.components = {
|
64
|
-
"securitySchemes": {
|
91
|
+
swCol.components = Object.assign(Object.assign({}, swCol.components), { "securitySchemes": {
|
65
92
|
"api_key": {
|
66
93
|
"type": "apiKey",
|
67
94
|
"name": "api_key",
|
68
95
|
"in": "header"
|
69
96
|
}
|
70
|
-
}
|
71
|
-
};
|
97
|
+
} });
|
72
98
|
swCol.security = [
|
73
99
|
{
|
74
100
|
"api_key": []
|
@@ -86,3 +112,22 @@ const generateCollections = (config, spinner) => __awaiter(void 0, void 0, void
|
|
86
112
|
return;
|
87
113
|
});
|
88
114
|
exports.generateCollections = generateCollections;
|
115
|
+
const getTypeSchemas = () => __awaiter(void 0, void 0, void 0, function* () {
|
116
|
+
const reader = typeconv_1.getTypeScriptReader();
|
117
|
+
const writer = typeconv_1.getOpenApiWriter({ format: 'json', title: 'My API', version: 'v3.0.3' });
|
118
|
+
const { convert } = typeconv_1.makeConverter(reader, writer, {
|
119
|
+
simplify: true
|
120
|
+
});
|
121
|
+
const s = (yield Promise.all([...(yield glob_promise_1.default('../**/*.d.ts')), ...(yield glob_promise_1.default('../**/message.js')), ...(yield glob_promise_1.default('../**/chat.js'))])).filter(f => !f.includes('node_modules'));
|
122
|
+
const res = {};
|
123
|
+
yield Promise.all(s.map((x) => __awaiter(void 0, void 0, void 0, function* () {
|
124
|
+
var _a, _b;
|
125
|
+
const { data } = yield convert({ data: fs.readFileSync(x, 'utf8') });
|
126
|
+
const schemas = (_b = (_a = JSON.parse(data)) === null || _a === void 0 ? void 0 : _a.components) === null || _b === void 0 ? void 0 : _b.schemas;
|
127
|
+
Object.keys(schemas).forEach(k => {
|
128
|
+
res[k] = schemas[k];
|
129
|
+
});
|
130
|
+
})));
|
131
|
+
return res;
|
132
|
+
});
|
133
|
+
exports.getTypeSchemas = getTypeSchemas;
|
package/dist/cli/index.js
CHANGED
@@ -188,6 +188,9 @@ function start() {
|
|
188
188
|
}
|
189
189
|
else
|
190
190
|
ready(Object.assign(Object.assign(Object.assign(Object.assign({}, cliConfig), createConfig), client.getSessionInfo()), { hostAccountNumber: yield client.getHostNumber() }));
|
191
|
+
if (cliConfig.emitUnread) {
|
192
|
+
yield client.emitUnreadMessages();
|
193
|
+
}
|
191
194
|
}
|
192
195
|
catch (e) {
|
193
196
|
spinner.fail(`Error ${e.message} ${e}`);
|
package/dist/cli/setup.js
CHANGED
@@ -240,6 +240,12 @@ const optionList = [{
|
|
240
240
|
type: Boolean,
|
241
241
|
description: "Automatically reject incoming phone and video calls to the host account."
|
242
242
|
},
|
243
|
+
{
|
244
|
+
name: 'emit-unread',
|
245
|
+
type: Boolean,
|
246
|
+
description: "Emit all unread messages via onMessage webhooks on launch.",
|
247
|
+
default: false
|
248
|
+
},
|
243
249
|
{
|
244
250
|
name: 'skip-url-check',
|
245
251
|
type: Boolean,
|
@@ -305,14 +305,15 @@ function initBrowser(sessionId, config = {}) {
|
|
305
305
|
let args = [...puppeteer_config_1.puppeteerConfig.chromiumArgs, ...((config === null || config === void 0 ? void 0 : config.chromiumArgs) || [])];
|
306
306
|
if (config === null || config === void 0 ? void 0 : config.multiDevice) {
|
307
307
|
args = args.filter(x => x != '--incognito');
|
308
|
-
config["userDataDir"] =
|
308
|
+
config["userDataDir"] = config["userDataDir"] || `${(config === null || config === void 0 ? void 0 : config.inDocker) ? '/sessions' : (config === null || config === void 0 ? void 0 : config.sessionDataPath) || '.'}/_IGNORE_${(config === null || config === void 0 ? void 0 : config.sessionId) || 'session'}`;
|
309
309
|
}
|
310
310
|
if (config === null || config === void 0 ? void 0 : config.corsFix)
|
311
311
|
args.push('--disable-web-security');
|
312
312
|
const browser = (config === null || config === void 0 ? void 0 : config.browserWSEndpoint) ? yield puppeteer.connect(Object.assign({}, config)) : yield puppeteer.launch(Object.assign(Object.assign({ headless: true, args }, config), { devtools: false }));
|
313
313
|
//devtools
|
314
314
|
if (config === null || config === void 0 ? void 0 : config.devtools) {
|
315
|
-
const
|
315
|
+
const _dt = yield Promise.resolve().then(() => __importStar(require('puppeteer-extra-plugin-devtools')));
|
316
|
+
const devtools = _dt.default();
|
316
317
|
if (config.devtools !== 'local' && !((_b = config === null || config === void 0 ? void 0 : config.devtools) === null || _b === void 0 ? void 0 : _b.user) && !((_c = config === null || config === void 0 ? void 0 : config.devtools) === null || _c === void 0 ? void 0 : _c.pass)) {
|
317
318
|
config.devtools = {};
|
318
319
|
config.devtools.user = 'dev';
|
@@ -322,6 +323,7 @@ function initBrowser(sessionId, config = {}) {
|
|
322
323
|
if (config.devtools.user && config.devtools.pass) {
|
323
324
|
devtools.setAuthCredentials(config.devtools.user, config.devtools.pass);
|
324
325
|
}
|
326
|
+
puppeteer.use(devtools);
|
325
327
|
try {
|
326
328
|
// const tunnel = await devtools.createTunnel(browser);
|
327
329
|
const tunnel = config.devtools == 'local' ? devtools.getLocalDevToolsUrl(browser) : (yield devtools.createTunnel(browser)).url;
|
@@ -157,7 +157,8 @@ function create(config = {}) {
|
|
157
157
|
/**
|
158
158
|
* Check if the IGNORE folder exists, therefore, assume that the session is MD.
|
159
159
|
*/
|
160
|
-
|
160
|
+
const mdDir = config["userDataDir"] || `${(config === null || config === void 0 ? void 0 : config.inDocker) ? '/sessions' : (config === null || config === void 0 ? void 0 : config.sessionDataPath) || '.'}/_IGNORE_${(config === null || config === void 0 ? void 0 : config.sessionId) || 'session'}`;
|
161
|
+
if (fs.existsSync(mdDir) && !(config === null || config === void 0 ? void 0 : config.multiDevice)) {
|
161
162
|
spinner.info(`Multi-Device directory detected. multiDevice set to true.`);
|
162
163
|
config.multiDevice = true;
|
163
164
|
}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@open-wa/wa-automate",
|
3
|
-
"version": "4.23.
|
3
|
+
"version": "4.23.16",
|
4
4
|
"licenseCheckUrl": "https://openwa.dev/license-check",
|
5
5
|
"brokenMethodReportUrl": "https://openwa.dev/report-bm",
|
6
6
|
"patches": "https://cdn.openwa.dev/patches.json",
|
@@ -120,6 +120,7 @@
|
|
120
120
|
"find-up": "^5.0.0",
|
121
121
|
"fs-extra": "^10.0.0",
|
122
122
|
"get-port": "^5.1.1",
|
123
|
+
"glob-promise": "^4.2.2",
|
123
124
|
"hasha": "^5.2.0",
|
124
125
|
"image-type": "^4.1.0",
|
125
126
|
"is-url-superb": "^5.0.0",
|
@@ -139,7 +140,7 @@
|
|
139
140
|
"puppeteer": "10.4.0",
|
140
141
|
"puppeteer-extra": "^3.1.9",
|
141
142
|
"puppeteer-extra-plugin-block-resources": "^2.2.7",
|
142
|
-
"puppeteer-extra-plugin-devtools": "^2.
|
143
|
+
"puppeteer-extra-plugin-devtools": "^2.3.3",
|
143
144
|
"puppeteer-extra-plugin-stealth": "^2.4.9",
|
144
145
|
"puppeteer-page-proxy": "^1.2.8",
|
145
146
|
"qrcode-terminal": "^0.12.0",
|
@@ -157,6 +158,7 @@
|
|
157
158
|
"ts-json-schema-generator": "^0.95.0",
|
158
159
|
"ts-morph": "^12.0.0",
|
159
160
|
"type-fest": "^1.1.1",
|
161
|
+
"typeconv": "^1.7.0",
|
160
162
|
"update-notifier": "^5.0.0",
|
161
163
|
"uuid": "^8.3.2",
|
162
164
|
"uuid-apikey": "^1.4.6",
|