@open-wa/wa-automate 4.76.0 → 5.0.0-alpha.2
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 +14 -165
- package/dist/cli-runtime-B7_3MM0c.cjs +798 -0
- package/dist/cli-runtime-B7_3MM0c.cjs.map +1 -0
- package/dist/cli-runtime-CmpYxFCk.d.cts +31 -0
- package/dist/cli-runtime-CmpYxFCk.d.cts.map +1 -0
- package/dist/cli.cjs +17 -0
- package/dist/cli.cjs.map +1 -0
- package/dist/cli.d.cts +2 -0
- package/dist/index.cjs +224 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +81 -0
- package/dist/index.d.cts.map +1 -0
- package/package.json +34 -177
- package/CNAME +0 -1
- package/_tsconfig.docs.json +0 -140
- package/bin/config-schema.json +0 -1
- package/bin/oas-type-schemas.json +0 -1
- package/bin/server.js +0 -45
- package/build/build-config-json-for-bin.ts +0 -56
- package/build/generate-oas-types.ts +0 -31
- package/dist/api/Client.d.ts +0 -2255
- package/dist/api/Client.js +0 -4358
- package/dist/api/functions/exposed.enum.d.ts +0 -7
- package/dist/api/functions/exposed.enum.js +0 -11
- package/dist/api/model/aliases.d.ts +0 -110
- package/dist/api/model/aliases.js +0 -3
- package/dist/api/model/button.d.ts +0 -24
- package/dist/api/model/button.js +0 -2
- package/dist/api/model/call.d.ts +0 -51
- package/dist/api/model/call.js +0 -18
- package/dist/api/model/chat.d.ts +0 -221
- package/dist/api/model/chat.js +0 -52
- package/dist/api/model/config.d.ts +0 -836
- package/dist/api/model/config.js +0 -111
- package/dist/api/model/contact.d.ts +0 -143
- package/dist/api/model/contact.js +0 -2
- package/dist/api/model/errors.d.ts +0 -90
- package/dist/api/model/errors.js +0 -117
- package/dist/api/model/events.d.ts +0 -120
- package/dist/api/model/events.js +0 -127
- package/dist/api/model/group-metadata.d.ts +0 -124
- package/dist/api/model/group-metadata.js +0 -25
- package/dist/api/model/id.d.ts +0 -5
- package/dist/api/model/id.js +0 -2
- package/dist/api/model/index.d.ts +0 -110
- package/dist/api/model/index.js +0 -128
- package/dist/api/model/label.d.ts +0 -24
- package/dist/api/model/label.js +0 -2
- package/dist/api/model/media.d.ts +0 -93
- package/dist/api/model/media.js +0 -12
- package/dist/api/model/message.d.ts +0 -422
- package/dist/api/model/message.js +0 -40
- package/dist/api/model/product.d.ts +0 -141
- package/dist/api/model/product.js +0 -2
- package/dist/api/model/reactions.d.ts +0 -76
- package/dist/api/model/reactions.js +0 -2
- package/dist/api/model/sessionInfo.d.ts +0 -77
- package/dist/api/model/sessionInfo.js +0 -2
- package/dist/build/build-postman.d.ts +0 -1
- package/dist/build/build-postman.js +0 -262
- package/dist/cli/cli-options.d.ts +0 -9
- package/dist/cli/cli-options.js +0 -289
- package/dist/cli/collections.d.ts +0 -2
- package/dist/cli/collections.js +0 -251
- package/dist/cli/file-utils.d.ts +0 -1
- package/dist/cli/file-utils.js +0 -71
- package/dist/cli/index.d.ts +0 -1
- package/dist/cli/index.js +0 -231
- package/dist/cli/integrations/chatwoot.d.ts +0 -49
- package/dist/cli/integrations/chatwoot.js +0 -672
- package/dist/cli/integrations/cloudflare.d.ts +0 -6
- package/dist/cli/integrations/cloudflare.js +0 -76
- package/dist/cli/logo.d.ts +0 -1
- package/dist/cli/logo.js +0 -49
- package/dist/cli/server.d.ts +0 -24
- package/dist/cli/server.js +0 -540
- package/dist/cli/setup.d.ts +0 -30
- package/dist/cli/setup.js +0 -308
- package/dist/config/puppeteer.config.d.ts +0 -11
- package/dist/config/puppeteer.config.js +0 -65
- package/dist/controllers/auth.d.ts +0 -36
- package/dist/controllers/auth.js +0 -322
- package/dist/controllers/browser.d.ts +0 -17
- package/dist/controllers/browser.js +0 -603
- package/dist/controllers/events.d.ts +0 -82
- package/dist/controllers/events.js +0 -173
- package/dist/controllers/init_patch.d.ts +0 -13
- package/dist/controllers/init_patch.js +0 -42
- package/dist/controllers/initializer.d.ts +0 -22
- package/dist/controllers/initializer.js +0 -511
- package/dist/controllers/launch_checks.d.ts +0 -8
- package/dist/controllers/launch_checks.js +0 -130
- package/dist/controllers/patch_manager.d.ts +0 -37
- package/dist/controllers/patch_manager.js +0 -231
- package/dist/controllers/popup/index.d.ts +0 -3
- package/dist/controllers/popup/index.html +0 -168
- package/dist/controllers/popup/index.js +0 -148
- package/dist/controllers/script_preloader.d.ts +0 -17
- package/dist/controllers/script_preloader.js +0 -88
- package/dist/index.d.ts +0 -13
- package/dist/index.js +0 -36
- package/dist/lib/README.md +0 -5
- package/dist/lib/base64.js +0 -1
- package/dist/lib/hash.js +0 -1
- package/dist/lib/jsSha.min.js +0 -1
- package/dist/lib/launch.js +0 -1
- package/dist/lib/qr.min.js +0 -1
- package/dist/lib/wapi.js +0 -2163
- package/dist/logging/custom_transport.d.ts +0 -9
- package/dist/logging/custom_transport.js +0 -35
- package/dist/logging/logging.d.ts +0 -50
- package/dist/logging/logging.js +0 -196
- package/dist/structures/Collector.d.ts +0 -202
- package/dist/structures/Collector.js +0 -391
- package/dist/structures/Dialog.d.ts +0 -55
- package/dist/structures/Dialog.js +0 -21
- package/dist/structures/MessageCollector.d.ts +0 -78
- package/dist/structures/MessageCollector.js +0 -145
- package/dist/structures/preProcessors.d.ts +0 -58
- package/dist/structures/preProcessors.js +0 -181
- package/dist/utils/pid_utils.d.ts +0 -1
- package/dist/utils/pid_utils.js +0 -26
- package/dist/utils/tools.d.ts +0 -152
- package/dist/utils/tools.js +0 -494
- package/tos.md +0 -77
package/dist/cli/collections.js
DELETED
|
@@ -1,251 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
35
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
|
-
};
|
|
37
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
-
exports.generateCollections = exports.collections = void 0;
|
|
39
|
-
const __1 = require("..");
|
|
40
|
-
const postman_2_swagger_1 = __importDefault(require("postman-2-swagger"));
|
|
41
|
-
const path = __importStar(require("path"));
|
|
42
|
-
const fs_extra_1 = require("fs-extra");
|
|
43
|
-
exports.collections = {};
|
|
44
|
-
const generateCollections = (config, spinner) => __awaiter(void 0, void 0, void 0, function* () {
|
|
45
|
-
let swCol = null;
|
|
46
|
-
let pmCol = null;
|
|
47
|
-
//TODO GENERATE TYPE SCHEMAS ON BUILD. AXIOS GET FROM GITHUB!
|
|
48
|
-
const _types = (0, fs_extra_1.readJsonSync)(path.resolve(__dirname, '../../bin/oas-type-schemas.json')) || {};
|
|
49
|
-
spinner.info('Generating Swagger Spec');
|
|
50
|
-
pmCol = yield (0, __1.generatePostmanJson)(config);
|
|
51
|
-
spinner.succeed(`Postman collection generated: open-wa-${config.sessionId}.postman_collection.json`);
|
|
52
|
-
swCol = (0, postman_2_swagger_1.default)(pmCol);
|
|
53
|
-
swCol.tags = [
|
|
54
|
-
{
|
|
55
|
-
"name": "default",
|
|
56
|
-
"description": "All methods from the Client",
|
|
57
|
-
"externalDocs": {
|
|
58
|
-
"description": "Find out more",
|
|
59
|
-
"url": "https://docs.openwa.dev/docs/reference/api/Client/classes/Client"
|
|
60
|
-
}
|
|
61
|
-
},
|
|
62
|
-
{
|
|
63
|
-
"name": "meta",
|
|
64
|
-
"description": "Operations related to generating SDKs for this specific API"
|
|
65
|
-
},
|
|
66
|
-
{
|
|
67
|
-
"name": "media",
|
|
68
|
-
"description": "Access files in the /media folder when messagePreProcessor is set to AUTO_DECRYPT_SAVE"
|
|
69
|
-
}
|
|
70
|
-
];
|
|
71
|
-
/**
|
|
72
|
-
* Fix swagger docs by removing the content type as a required paramater
|
|
73
|
-
*/
|
|
74
|
-
Object.keys(swCol.paths).forEach(p => {
|
|
75
|
-
const path = swCol.paths[p].post;
|
|
76
|
-
if (config.key)
|
|
77
|
-
swCol.paths[p].post.security = [
|
|
78
|
-
{
|
|
79
|
-
"api_key": []
|
|
80
|
-
}
|
|
81
|
-
];
|
|
82
|
-
swCol.paths[p].operationId = swCol.paths[p].nickname = p.replace("/", "");
|
|
83
|
-
swCol.paths[p].post.externalDocs = {
|
|
84
|
-
"description": "Documentation",
|
|
85
|
-
"url": swCol.paths[p].post.documentationUrl
|
|
86
|
-
};
|
|
87
|
-
swCol.paths[p].post.responses['200'].schema = {
|
|
88
|
-
"$ref": "#/components/schemas/EasyApiResponse"
|
|
89
|
-
};
|
|
90
|
-
swCol.paths[p].post.requestBody = {
|
|
91
|
-
"description": path.summary,
|
|
92
|
-
"content": {
|
|
93
|
-
"application/json": {
|
|
94
|
-
"schema": {
|
|
95
|
-
"type": "object"
|
|
96
|
-
},
|
|
97
|
-
example: path.parameters[1].example
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
};
|
|
101
|
-
delete path.parameters;
|
|
102
|
-
});
|
|
103
|
-
const metaPaths = {
|
|
104
|
-
"/media/{fileName}": {
|
|
105
|
-
"get": {
|
|
106
|
-
"summary": "Get a file from the /media folder",
|
|
107
|
-
"description": "Make sure to set messagePreProcessor to AUTO_DECRYPT_SAVE in order to decrypt and save media within the /media folder",
|
|
108
|
-
tags: ["media"],
|
|
109
|
-
"produces": [
|
|
110
|
-
"application/pdf",
|
|
111
|
-
"image/jpeg",
|
|
112
|
-
"image/jpg",
|
|
113
|
-
"image/png",
|
|
114
|
-
"image/webp",
|
|
115
|
-
"audio/mpeg",
|
|
116
|
-
"audio/ogg",
|
|
117
|
-
"audio/vorbis",
|
|
118
|
-
"video/mp4",
|
|
119
|
-
],
|
|
120
|
-
"parameters": [
|
|
121
|
-
{
|
|
122
|
-
"name": "fileName",
|
|
123
|
-
"in": "path",
|
|
124
|
-
"description": "The filename, e.g: 2B8A12C1DAF21D8CA34105560D5B1864.jpeg",
|
|
125
|
-
"required": true,
|
|
126
|
-
"type": "string",
|
|
127
|
-
}
|
|
128
|
-
],
|
|
129
|
-
"responses": {
|
|
130
|
-
"200": {
|
|
131
|
-
"description": "Downloaded file"
|
|
132
|
-
},
|
|
133
|
-
"404": {
|
|
134
|
-
"description": "File not found"
|
|
135
|
-
},
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
},
|
|
139
|
-
"/meta/swagger.json": {
|
|
140
|
-
"get": {
|
|
141
|
-
"description": "Get a swagger/OAS collection json",
|
|
142
|
-
tags: ["meta"],
|
|
143
|
-
"produces": [
|
|
144
|
-
"application/json",
|
|
145
|
-
],
|
|
146
|
-
"responses": {
|
|
147
|
-
"200": {
|
|
148
|
-
"description": "successful request"
|
|
149
|
-
},
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
},
|
|
153
|
-
"/meta/postman.json": {
|
|
154
|
-
"get": {
|
|
155
|
-
"description": "Get a postman collection json",
|
|
156
|
-
tags: ["meta"],
|
|
157
|
-
"produces": [
|
|
158
|
-
"application/json",
|
|
159
|
-
],
|
|
160
|
-
"responses": {
|
|
161
|
-
"200": {
|
|
162
|
-
"description": "successful request"
|
|
163
|
-
},
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
},
|
|
167
|
-
"/meta/basic/commands": {
|
|
168
|
-
get: {
|
|
169
|
-
"description": "Get a list of possible client methods/commands",
|
|
170
|
-
tags: ["meta"],
|
|
171
|
-
"produces": [
|
|
172
|
-
"application/json",
|
|
173
|
-
],
|
|
174
|
-
"responses": {
|
|
175
|
-
"200": {
|
|
176
|
-
"description": "successful request"
|
|
177
|
-
},
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
},
|
|
181
|
-
"/meta/basic/listeners": {
|
|
182
|
-
get: {
|
|
183
|
-
"description": "Get a list of possible listeners",
|
|
184
|
-
tags: ["meta"],
|
|
185
|
-
"produces": [
|
|
186
|
-
"application/json",
|
|
187
|
-
],
|
|
188
|
-
"responses": {
|
|
189
|
-
"200": {
|
|
190
|
-
"description": "successful request"
|
|
191
|
-
},
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
},
|
|
195
|
-
"/meta/codegen/{language}": {
|
|
196
|
-
post: {
|
|
197
|
-
"summary": "Generate SDK",
|
|
198
|
-
"description": "Generate a SDK for this specific API - see https://codegen.openwa.dev/api/gen/clients for list of possible languages",
|
|
199
|
-
tags: ["meta"],
|
|
200
|
-
"parameters": [
|
|
201
|
-
{
|
|
202
|
-
"name": "language",
|
|
203
|
-
"in": "path",
|
|
204
|
-
"description": "The language to generate the SDK for. ",
|
|
205
|
-
"required": true,
|
|
206
|
-
"type": "string",
|
|
207
|
-
}
|
|
208
|
-
],
|
|
209
|
-
"responses": {
|
|
210
|
-
"200": {
|
|
211
|
-
"description": "successful request"
|
|
212
|
-
},
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
};
|
|
217
|
-
swCol.paths = Object.assign(Object.assign({}, swCol.paths), metaPaths);
|
|
218
|
-
delete swCol.swagger;
|
|
219
|
-
swCol.openapi = "3.0.3";
|
|
220
|
-
swCol.components = {};
|
|
221
|
-
swCol.components.schemas = _types;
|
|
222
|
-
swCol.externalDocs = {
|
|
223
|
-
"description": "Find more info here",
|
|
224
|
-
"url": "https://openwa.dev/"
|
|
225
|
-
};
|
|
226
|
-
if (config.key) {
|
|
227
|
-
swCol.components = Object.assign(Object.assign({}, swCol.components), { "securitySchemes": {
|
|
228
|
-
"api_key": {
|
|
229
|
-
"type": "apiKey",
|
|
230
|
-
"name": "api_key",
|
|
231
|
-
"in": "header"
|
|
232
|
-
}
|
|
233
|
-
} });
|
|
234
|
-
swCol.security = [
|
|
235
|
-
{
|
|
236
|
-
"api_key": []
|
|
237
|
-
}
|
|
238
|
-
];
|
|
239
|
-
}
|
|
240
|
-
//Sort alphabetically
|
|
241
|
-
const x = {};
|
|
242
|
-
Object.keys(swCol.paths).sort().map(k => x[k] = swCol.paths[k]);
|
|
243
|
-
swCol.paths = x;
|
|
244
|
-
if (!(config === null || config === void 0 ? void 0 : config.skipSavePostmanCollection))
|
|
245
|
-
(0, fs_extra_1.writeJsonSync)("./open-wa-" + config.sessionId + ".sw_col.json", swCol);
|
|
246
|
-
exports.collections['postman'] = pmCol;
|
|
247
|
-
exports.collections['swagger'] = swCol;
|
|
248
|
-
spinner.succeed('API collections (swagger + postman) generated successfully');
|
|
249
|
-
return;
|
|
250
|
-
});
|
|
251
|
-
exports.generateCollections = generateCollections;
|
package/dist/cli/file-utils.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const tryOpenFileAsObject: (fileLocation: string, needArray?: boolean) => Promise<any>;
|
package/dist/cli/file-utils.js
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
35
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
|
-
};
|
|
37
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
-
exports.tryOpenFileAsObject = void 0;
|
|
39
|
-
const path = __importStar(require("path"));
|
|
40
|
-
const fs = __importStar(require("fs"));
|
|
41
|
-
const json5_1 = __importDefault(require("json5"));
|
|
42
|
-
const logging_1 = require("../logging/logging");
|
|
43
|
-
const tryOpenFileAsObject = (fileLocation, needArray = false) => __awaiter(void 0, void 0, void 0, function* () {
|
|
44
|
-
let res = undefined;
|
|
45
|
-
let fp = undefined;
|
|
46
|
-
const relativePath = path.join(path.resolve(process.cwd(), fileLocation || ''));
|
|
47
|
-
const isJs = fileLocation.endsWith(".js");
|
|
48
|
-
logging_1.log.info(`Checking exists: ${fileLocation || relativePath}`);
|
|
49
|
-
if (fs.existsSync(fileLocation) || fs.existsSync(relativePath)) {
|
|
50
|
-
fp = isJs ? fs.existsSync(relativePath) && relativePath : fs.existsSync(fileLocation) ? fileLocation : relativePath;
|
|
51
|
-
logging_1.log.info("Attempting to open: " + fp);
|
|
52
|
-
try {
|
|
53
|
-
const data = isJs ? (require(fp) || {}).default : json5_1.default.parse(fs.readFileSync(fp, 'utf8'));
|
|
54
|
-
if (data && (Array.isArray(data) == needArray))
|
|
55
|
-
res = data;
|
|
56
|
-
if (data && typeof data === "function") {
|
|
57
|
-
logging_1.log.info("Found config as function, executing.");
|
|
58
|
-
res = yield data(process.env.CURRENT_SESSION_ID || "session");
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
catch (error) {
|
|
62
|
-
throw `Unable to parse config file as JSON. Please make sure ${fp} is a valid JSON config file`;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
else
|
|
66
|
-
return;
|
|
67
|
-
logging_1.log.info(`${fp} is ${res ? 'valid' : 'invalid'}`);
|
|
68
|
-
logging_1.log.info(`contents: ${JSON.stringify(res)}`);
|
|
69
|
-
return res && Object.assign(Object.assign({}, (res || {})), { confPath: fp });
|
|
70
|
-
});
|
|
71
|
-
exports.tryOpenFileAsObject = tryOpenFileAsObject;
|
package/dist/cli/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/cli/index.js
DELETED
|
@@ -1,231 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
const index_1 = require("../index");
|
|
16
|
-
const terminal_link_1 = __importDefault(require("terminal-link"));
|
|
17
|
-
const is_url_superb_1 = __importDefault(require("is-url-superb"));
|
|
18
|
-
const tcp_port_used_1 = __importDefault(require("tcp-port-used"));
|
|
19
|
-
const axios_1 = __importDefault(require("axios"));
|
|
20
|
-
const setup_1 = require("./setup");
|
|
21
|
-
const collections_1 = require("./collections");
|
|
22
|
-
const server_1 = require("./server");
|
|
23
|
-
const chatwoot_1 = require("./integrations/chatwoot");
|
|
24
|
-
let checkUrl = (s) => (typeof s === "string") && (0, is_url_superb_1.default)(s);
|
|
25
|
-
const ready = (config) => __awaiter(void 0, void 0, void 0, function* () {
|
|
26
|
-
(0, index_1.processSend)('ready');
|
|
27
|
-
if (config.readyWebhook)
|
|
28
|
-
yield (0, axios_1.default)({
|
|
29
|
-
method: 'post',
|
|
30
|
-
url: config.readyWebhook,
|
|
31
|
-
data: {
|
|
32
|
-
ts: Date.now(),
|
|
33
|
-
data: Object.assign({}, config),
|
|
34
|
-
sessionId: config.sessionId,
|
|
35
|
-
namespace: "READY"
|
|
36
|
-
}
|
|
37
|
-
}).catch(err => index_1.log.error(`READY WEBHOOK ERROR: ${config.readyWebhook} ${err.message}`));
|
|
38
|
-
});
|
|
39
|
-
function start() {
|
|
40
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
41
|
-
const { cliConfig, createConfig, PORT, spinner } = yield (0, setup_1.cli)();
|
|
42
|
-
process.env.OWA_CLI = "true";
|
|
43
|
-
spinner.start("Launching EASY API");
|
|
44
|
-
if (cliConfig.verbose)
|
|
45
|
-
index_1.log.info(`config: `, { cliConfig, createConfig, PORT });
|
|
46
|
-
(0, server_1.setUpExpressApp)();
|
|
47
|
-
if (cliConfig.cors)
|
|
48
|
-
yield (0, server_1.enableCORSRequests)(cliConfig);
|
|
49
|
-
try {
|
|
50
|
-
const { status, data } = yield axios_1.default.post(`http://localhost:${PORT}/getConnectionState`);
|
|
51
|
-
if (status === 200 && data.response === "CONNECTED") {
|
|
52
|
-
const { data: { response: { sessionId, port, webhook, apiHost } } } = yield axios_1.default.post(`http://localhost:${PORT}/getConfig`);
|
|
53
|
-
if ((createConfig === null || createConfig === void 0 ? void 0 : createConfig.sessionId) == sessionId && createConfig.port === port && createConfig.webhook === webhook && createConfig.apiHost === apiHost) {
|
|
54
|
-
spinner.info('removing popup flag');
|
|
55
|
-
if (createConfig.popup) {
|
|
56
|
-
delete createConfig.popup;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
catch (error) {
|
|
62
|
-
if (error.code === "ECONNREFUSED")
|
|
63
|
-
spinner.info('Selected port is free');
|
|
64
|
-
}
|
|
65
|
-
createConfig.headless = cliConfig.headful != undefined ? !cliConfig.headful : cliConfig.headless;
|
|
66
|
-
if (cliConfig.ev || cliConfig.ev == "") {
|
|
67
|
-
//prepare ef
|
|
68
|
-
if (cliConfig === null || cliConfig === void 0 ? void 0 : cliConfig.ef) {
|
|
69
|
-
if (!Array.isArray(cliConfig.ef))
|
|
70
|
-
cliConfig.ef = [cliConfig.ef];
|
|
71
|
-
cliConfig.ef = cliConfig.ef.flatMap(s => s.split(','));
|
|
72
|
-
}
|
|
73
|
-
if (cliConfig.skipUrlCheck)
|
|
74
|
-
checkUrl = () => true;
|
|
75
|
-
if (!checkUrl(cliConfig.ev))
|
|
76
|
-
spinner.fail("--ev/-e expecting URL - invalid URL.");
|
|
77
|
-
else
|
|
78
|
-
index_1.ev.on('**', (data, sessionId, namespace) => __awaiter(this, void 0, void 0, function* () {
|
|
79
|
-
if (cliConfig === null || cliConfig === void 0 ? void 0 : cliConfig.ef) {
|
|
80
|
-
if (!cliConfig.ef.includes(namespace))
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
if (!cliConfig.allowSessionDataWebhook && (namespace == "sessionData" || namespace == "sessionDataBase64"))
|
|
84
|
-
return;
|
|
85
|
-
const whStart = (0, index_1.now)();
|
|
86
|
-
yield (0, axios_1.default)({
|
|
87
|
-
method: 'post',
|
|
88
|
-
url: cliConfig.ev,
|
|
89
|
-
data: {
|
|
90
|
-
ts: Date.now(),
|
|
91
|
-
data,
|
|
92
|
-
sessionId,
|
|
93
|
-
namespace
|
|
94
|
-
}
|
|
95
|
-
}).then(({ status }) => {
|
|
96
|
-
const t = ((0, index_1.now)() - whStart).toFixed(0);
|
|
97
|
-
index_1.log.info("EV Webhook", namespace, status, t);
|
|
98
|
-
}).catch(err => index_1.log.error(`EV WEBHOOK ERROR: ${cliConfig.ev} ${err.message}`));
|
|
99
|
-
}));
|
|
100
|
-
}
|
|
101
|
-
//These things can be done before the client is created
|
|
102
|
-
if ((cliConfig === null || cliConfig === void 0 ? void 0 : cliConfig.generateApiDocs) || (cliConfig === null || cliConfig === void 0 ? void 0 : cliConfig.stats)) {
|
|
103
|
-
yield (0, collections_1.generateCollections)(Object.assign(Object.assign({}, createConfig), cliConfig), spinner);
|
|
104
|
-
}
|
|
105
|
-
try {
|
|
106
|
-
const client = yield (0, index_1.create)(Object.assign({}, createConfig));
|
|
107
|
-
(0, server_1.setupMetaProcessMiddleware)(client, cliConfig);
|
|
108
|
-
yield (0, server_1.setupHttpServer)(cliConfig);
|
|
109
|
-
if (cliConfig.autoReject) {
|
|
110
|
-
yield client.autoReject(cliConfig.onCall);
|
|
111
|
-
}
|
|
112
|
-
else if (cliConfig.onCall) {
|
|
113
|
-
yield client.onIncomingCall((call) => __awaiter(this, void 0, void 0, function* () {
|
|
114
|
-
yield client.sendText(call.peerJid, cliConfig.onCall);
|
|
115
|
-
}));
|
|
116
|
-
}
|
|
117
|
-
client.onLogout(() => __awaiter(this, void 0, void 0, function* () {
|
|
118
|
-
console.error('!!!! CLIENT LOGGED OUT !!!!');
|
|
119
|
-
if (cliConfig && !cliConfig.noKillOnLogout) {
|
|
120
|
-
yield client.waitAllQEmpty();
|
|
121
|
-
console.error("Shutting down.");
|
|
122
|
-
process.exit();
|
|
123
|
-
}
|
|
124
|
-
}), -1);
|
|
125
|
-
if (cliConfig === null || cliConfig === void 0 ? void 0 : cliConfig.botPressUrl) {
|
|
126
|
-
spinner.info('Setting Up Botpress handler');
|
|
127
|
-
(0, server_1.setupBotPressHandler)(cliConfig, client);
|
|
128
|
-
spinner.succeed('Botpress handler set up successfully');
|
|
129
|
-
}
|
|
130
|
-
if (cliConfig === null || cliConfig === void 0 ? void 0 : cliConfig.twilioWebhook) {
|
|
131
|
-
spinner.info('Setting Up Twilio Compaitible Webhook');
|
|
132
|
-
(0, server_1.setupTwilioCompatibleWebhook)(cliConfig, client);
|
|
133
|
-
spinner.succeed('Twilio Compaitible Webhook set up successfully');
|
|
134
|
-
}
|
|
135
|
-
if (cliConfig === null || cliConfig === void 0 ? void 0 : cliConfig.webhook) {
|
|
136
|
-
if (Array.isArray(cliConfig.webhook)) {
|
|
137
|
-
yield Promise.all(cliConfig.webhook.map(webhook => {
|
|
138
|
-
if (webhook.url && webhook.events)
|
|
139
|
-
return client.registerWebhook(webhook.url, webhook.events, webhook.requestConfig || {});
|
|
140
|
-
}));
|
|
141
|
-
}
|
|
142
|
-
else
|
|
143
|
-
yield client.registerWebhook(cliConfig.webhook, "all");
|
|
144
|
-
}
|
|
145
|
-
if (cliConfig === null || cliConfig === void 0 ? void 0 : cliConfig.keepAlive)
|
|
146
|
-
client.onStateChanged((state) => __awaiter(this, void 0, void 0, function* () {
|
|
147
|
-
if ((state === "CONFLICT" || state === "UNLAUNCHED") && (cliConfig === null || cliConfig === void 0 ? void 0 : cliConfig.keepAlive))
|
|
148
|
-
yield client.forceRefocus();
|
|
149
|
-
}));
|
|
150
|
-
if (!(cliConfig === null || cliConfig === void 0 ? void 0 : cliConfig.noApi)) {
|
|
151
|
-
if (cliConfig === null || cliConfig === void 0 ? void 0 : cliConfig.key) {
|
|
152
|
-
spinner.info(`Please see machine logs to see the API key`);
|
|
153
|
-
console.log(`Please use the following api key for requests as a header:\napi_key: ${cliConfig.key}`);
|
|
154
|
-
(0, server_1.setupAuthenticationLayer)(cliConfig);
|
|
155
|
-
}
|
|
156
|
-
if (cliConfig === null || cliConfig === void 0 ? void 0 : cliConfig.chatwootUrl) {
|
|
157
|
-
spinner.info('Setting Up Chatwoot handler');
|
|
158
|
-
spinner.info(`Make sure to set up the Chatwoot inbox webhook to the following path on this process: /chatwoot${cliConfig.key ? `?api_key=YOUR-API-KEY` : ''}`);
|
|
159
|
-
yield (0, server_1.setupChatwoot)(cliConfig, client);
|
|
160
|
-
spinner.succeed('Chatwoot handler set up successfully');
|
|
161
|
-
}
|
|
162
|
-
(0, server_1.setupRefocusDisengageMiddleware)(cliConfig);
|
|
163
|
-
if (cliConfig && cliConfig.generateApiDocs && collections_1.collections["swagger"]) {
|
|
164
|
-
spinner.info('Setting Up API Explorer');
|
|
165
|
-
(0, server_1.setupApiDocs)(cliConfig);
|
|
166
|
-
spinner.succeed('API Explorer set up successfully');
|
|
167
|
-
}
|
|
168
|
-
if ((cliConfig === null || cliConfig === void 0 ? void 0 : cliConfig.stats) && collections_1.collections["swagger"]) {
|
|
169
|
-
spinner.info('Setting Up API Stats');
|
|
170
|
-
(0, server_1.setupSwaggerStatsMiddleware)(cliConfig);
|
|
171
|
-
spinner.info('API Stats set up successfully');
|
|
172
|
-
}
|
|
173
|
-
if (createConfig.messagePreprocessor === "AUTO_DECRYPT_SAVE") {
|
|
174
|
-
(0, server_1.setupMediaMiddleware)();
|
|
175
|
-
}
|
|
176
|
-
server_1.app.use(client.middleware((cliConfig && cliConfig.useSessionIdInPath), PORT));
|
|
177
|
-
if (cliConfig.socket) {
|
|
178
|
-
spinner.info("Setting up socket");
|
|
179
|
-
yield (0, server_1.setupSocketServer)(cliConfig, client);
|
|
180
|
-
spinner.succeed("Socket ready for connection");
|
|
181
|
-
}
|
|
182
|
-
spinner.info(`...waiting for port ${PORT} to be free`);
|
|
183
|
-
yield tcp_port_used_1.default.waitUntilFree(PORT, 200, 20000).catch(() => {
|
|
184
|
-
spinner.fail(`Port ${PORT} is not available. Closing`);
|
|
185
|
-
process.exit();
|
|
186
|
-
});
|
|
187
|
-
spinner.succeed(`Port ${PORT} is now free.`);
|
|
188
|
-
server_1.server.listen(PORT, () => __awaiter(this, void 0, void 0, function* () {
|
|
189
|
-
spinner.succeed(`\n• Listening on port ${PORT}!`);
|
|
190
|
-
(0, index_1.processSendData)({ port: PORT });
|
|
191
|
-
}));
|
|
192
|
-
process.on('message', function (data) {
|
|
193
|
-
var _a;
|
|
194
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
195
|
-
if (((_a = data === null || data === void 0 ? void 0 : data.data) === null || _a === void 0 ? void 0 : _a.command) === "port_report") {
|
|
196
|
-
const response = { port: PORT };
|
|
197
|
-
(0, index_1.processSendData)(response);
|
|
198
|
-
return response;
|
|
199
|
-
}
|
|
200
|
-
});
|
|
201
|
-
});
|
|
202
|
-
if (cliConfig.tunnel) {
|
|
203
|
-
spinner.info(`\n• Setting up external tunnel`);
|
|
204
|
-
const tunnelUrl = yield (0, server_1.setupTunnel)(cliConfig, PORT);
|
|
205
|
-
spinner.succeed(`\n\t${(0, terminal_link_1.default)('External address', tunnelUrl)}`);
|
|
206
|
-
}
|
|
207
|
-
const apiDocsUrl = cliConfig.apiHost ? `${cliConfig.apiHost}/api-docs/ ` : `${cliConfig.host.includes('http') ? '' : 'http://'}${cliConfig.host}:${PORT}/api-docs/ `;
|
|
208
|
-
const link = (0, terminal_link_1.default)('API Explorer', apiDocsUrl);
|
|
209
|
-
if (cliConfig && cliConfig.generateApiDocs)
|
|
210
|
-
spinner.succeed(`\n\t${link}`);
|
|
211
|
-
if (cliConfig && cliConfig.generateApiDocs && cliConfig.stats) {
|
|
212
|
-
const swaggerStatsUrl = cliConfig.apiHost ? `${cliConfig.apiHost}/swagger-stats/ ` : `${cliConfig.host.includes('http') ? '' : 'http://'}${cliConfig.host}:${PORT}/swagger-stats/ `;
|
|
213
|
-
const statsLink = (0, terminal_link_1.default)('API Stats', swaggerStatsUrl);
|
|
214
|
-
spinner.succeed(`\n\t${statsLink}`);
|
|
215
|
-
}
|
|
216
|
-
if (cliConfig === null || cliConfig === void 0 ? void 0 : cliConfig.chatwootUrl)
|
|
217
|
-
yield (0, chatwoot_1.setupChatwootOutgoingMessageHandler)(cliConfig, client);
|
|
218
|
-
}
|
|
219
|
-
yield ready(Object.assign(Object.assign(Object.assign(Object.assign({}, createConfig), cliConfig), client.getSessionInfo()), { hostAccountNumber: yield client.getHostNumber() }));
|
|
220
|
-
if (cliConfig.emitUnread) {
|
|
221
|
-
yield client.emitUnreadMessages();
|
|
222
|
-
}
|
|
223
|
-
if (!createConfig.licenseKey)
|
|
224
|
-
spinner.succeed(`Use this link to get a license: ${yield client.getLicenseLink()}`);
|
|
225
|
-
}
|
|
226
|
-
catch (e) {
|
|
227
|
-
spinner.fail(`Error ${e.message} ${e}`);
|
|
228
|
-
}
|
|
229
|
-
});
|
|
230
|
-
}
|
|
231
|
-
start();
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { Client } from '../..';
|
|
2
|
-
import { cliFlags } from '../server';
|
|
3
|
-
import { Request, Response } from "express";
|
|
4
|
-
export declare const chatwoot_webhook_check_event_name = "cli.integrations.chatwoot.check";
|
|
5
|
-
export type expressMiddleware = (req: Request, res: Response) => Promise<Response<any, Record<string, any>>>;
|
|
6
|
-
export declare const chatwootMiddleware: (cliConfig: cliFlags, client: Client) => expressMiddleware;
|
|
7
|
-
export declare const setupChatwootOutgoingMessageHandler: (cliConfig: cliFlags, client: Client) => Promise<void>;
|
|
8
|
-
export type ChatwootConfig = {
|
|
9
|
-
/**
|
|
10
|
-
* The URL of the chatwoot inbox. If you want this integration to create & manage the inbox for you, you can omit the inbox part.
|
|
11
|
-
*/
|
|
12
|
-
chatwootUrl: string;
|
|
13
|
-
/**
|
|
14
|
-
* The API access token which you can get from your account menu.
|
|
15
|
-
*/
|
|
16
|
-
chatwootApiAccessToken: string;
|
|
17
|
-
/**
|
|
18
|
-
* The API host which will be used as the webhook address in the Chatwoot inbox.
|
|
19
|
-
*/
|
|
20
|
-
apiHost: string;
|
|
21
|
-
/**
|
|
22
|
-
* Similar to apiHost
|
|
23
|
-
*/
|
|
24
|
-
host: string;
|
|
25
|
-
/**
|
|
26
|
-
* Whether or not to use https for the webhook address
|
|
27
|
-
*/
|
|
28
|
-
https?: boolean;
|
|
29
|
-
/**
|
|
30
|
-
* The certificate for https
|
|
31
|
-
*/
|
|
32
|
-
cert: string;
|
|
33
|
-
/**
|
|
34
|
-
* The private key for https
|
|
35
|
-
*/
|
|
36
|
-
privkey: string;
|
|
37
|
-
/**
|
|
38
|
-
* The API key used to secure the instance webhook address
|
|
39
|
-
*/
|
|
40
|
-
key?: string;
|
|
41
|
-
/**
|
|
42
|
-
* Whether or not to update the webhook address in the Chatwoot inbox on launch
|
|
43
|
-
*/
|
|
44
|
-
forceUpdateCwWebhook?: boolean;
|
|
45
|
-
/**
|
|
46
|
-
* port
|
|
47
|
-
*/
|
|
48
|
-
port: number;
|
|
49
|
-
};
|