@open-wa/wa-automate 4.27.2 → 4.27.6
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/dist/cli/index.js
CHANGED
@@ -113,12 +113,6 @@ function start() {
|
|
113
113
|
process.exit();
|
114
114
|
}
|
115
115
|
}));
|
116
|
-
if (cliConfig === null || cliConfig === void 0 ? void 0 : cliConfig.chatwootUrl) {
|
117
|
-
spinner.info('Setting Up Chatwoot handler');
|
118
|
-
spinner.info('Make sure to set up the Chatwoot inbox webhook to the following path on this process: /chatwoot');
|
119
|
-
yield server_1.setupChatwoot(cliConfig, client);
|
120
|
-
spinner.succeed('Chatwoot handler set up successfully');
|
121
|
-
}
|
122
116
|
if (cliConfig === null || cliConfig === void 0 ? void 0 : cliConfig.botPressUrl) {
|
123
117
|
spinner.info('Setting Up Botpress handler');
|
124
118
|
server_1.setupBotPressHandler(cliConfig, client);
|
@@ -150,6 +144,12 @@ function start() {
|
|
150
144
|
console.log(`Please use the following api key for requests as a header:\napi_key: ${cliConfig.key}`);
|
151
145
|
server_1.setupAuthenticationLayer(cliConfig);
|
152
146
|
}
|
147
|
+
if (cliConfig === null || cliConfig === void 0 ? void 0 : cliConfig.chatwootUrl) {
|
148
|
+
spinner.info('Setting Up Chatwoot handler');
|
149
|
+
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` : ''}`);
|
150
|
+
yield server_1.setupChatwoot(cliConfig, client);
|
151
|
+
spinner.succeed('Chatwoot handler set up successfully');
|
152
|
+
}
|
153
153
|
server_1.setupRefocusDisengageMiddleware(cliConfig);
|
154
154
|
if (cliConfig && cliConfig.generateApiDocs && collections_1.collections["swagger"]) {
|
155
155
|
spinner.info('Setting Up API Explorer');
|
@@ -14,11 +14,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
15
15
|
exports.setupChatwootOutgoingMessageHandler = exports.chatwootMiddleware = void 0;
|
16
16
|
const axios_1 = __importDefault(require("axios"));
|
17
|
+
const form_data_1 = __importDefault(require("form-data"));
|
18
|
+
const mime_types_1 = __importDefault(require("mime-types"));
|
17
19
|
const chatwootMiddleware = (cliConfig, client) => {
|
18
20
|
return (req, res) => __awaiter(void 0, void 0, void 0, function* () {
|
19
21
|
const processMesssage = () => __awaiter(void 0, void 0, void 0, function* () {
|
20
22
|
const promises = [];
|
21
23
|
const { body } = req;
|
24
|
+
if (!body)
|
25
|
+
return;
|
26
|
+
if (!body.conversation)
|
27
|
+
return;
|
22
28
|
const m = body.conversation.messages[0];
|
23
29
|
const contact = (body.conversation.meta.sender.phone_number || "").replace('+', '');
|
24
30
|
if (body.message_type === "incoming" ||
|
@@ -81,16 +87,14 @@ const setupChatwootOutgoingMessageHandler = (cliConfig, client) => __awaiter(voi
|
|
81
87
|
const [accountId, inboxId] = u.match(/\/(app|(api\/v1))\/accounts\/\d*\/inbox\/\d*/g)[0].split('/').filter(Number);
|
82
88
|
// const accountId = u.match(/accounts\/\d*/g) && u.match(/accounts\/\d*/g)[0].replace('accounts/', '')
|
83
89
|
const resolvedInbox = inboxId || u.match(/inboxes\/\d*/g) && u.match(/inboxes\/\d*/g)[0].replace('inboxes/', '');
|
84
|
-
const cwReq = (path, method, data) => {
|
90
|
+
const cwReq = (path, method, data, _headers) => {
|
85
91
|
const url = `${origin}/api/v1/accounts/${accountId}/${path}`.replace('app.bentonow.com', 'chat.bentonow.com');
|
86
|
-
console.log(url,
|
92
|
+
// console.log(url,method,data)
|
87
93
|
return axios_1.default({
|
88
94
|
method,
|
89
95
|
data,
|
90
96
|
url,
|
91
|
-
headers: {
|
92
|
-
api_access_token
|
93
|
-
}
|
97
|
+
headers: Object.assign({ api_access_token }, _headers)
|
94
98
|
});
|
95
99
|
};
|
96
100
|
const contactReg = {
|
@@ -128,7 +132,7 @@ const setupChatwootOutgoingMessageHandler = (cliConfig, client) => __awaiter(voi
|
|
128
132
|
const getContactConversation = (number) => __awaiter(void 0, void 0, void 0, function* () {
|
129
133
|
try {
|
130
134
|
const { data } = yield cwReq(`contacts/${contactReg[number]}/conversations`, 'get');
|
131
|
-
return data.payload[0];
|
135
|
+
return data.payload.sort((a, b) => a.id - b.id)[0];
|
132
136
|
}
|
133
137
|
catch (error) {
|
134
138
|
return;
|
@@ -140,7 +144,7 @@ const setupChatwootOutgoingMessageHandler = (cliConfig, client) => __awaiter(voi
|
|
140
144
|
contact_id,
|
141
145
|
"inbox_id": resolvedInbox
|
142
146
|
});
|
143
|
-
return data
|
147
|
+
return data;
|
144
148
|
}
|
145
149
|
catch (error) {
|
146
150
|
return;
|
@@ -173,6 +177,25 @@ const setupChatwootOutgoingMessageHandler = (cliConfig, client) => __awaiter(voi
|
|
173
177
|
return;
|
174
178
|
}
|
175
179
|
});
|
180
|
+
const sendAttachmentMessage = (content, contactId, message) => __awaiter(void 0, void 0, void 0, function* () {
|
181
|
+
// decrypt message
|
182
|
+
const file = yield client.decryptMedia(message);
|
183
|
+
let formData = new form_data_1.default();
|
184
|
+
formData.append('attachments[]', Buffer.from(file.split(',')[1], 'base64'), {
|
185
|
+
knownLength: 1,
|
186
|
+
filename: `${message.t}.${mime_types_1.default.extension(message.mimetype)}`,
|
187
|
+
contentType: (file.match(/[^:\s*]\w+\/[\w-+\d.]+(?=[;| ])/) || ["application/octet-stream"])[0]
|
188
|
+
});
|
189
|
+
formData.append('content', content);
|
190
|
+
formData.append('message_type', 'incoming');
|
191
|
+
try {
|
192
|
+
const { data } = yield cwReq(`conversations/${convoReg[contactId]}/messages`, 'post', formData, formData.getHeaders());
|
193
|
+
return data;
|
194
|
+
}
|
195
|
+
catch (error) {
|
196
|
+
return;
|
197
|
+
}
|
198
|
+
});
|
176
199
|
// const inboxId = s.match(/conversations\/\d*/g) && s.match(/conversations\/\d*/g)[0].replace('conversations/','')
|
177
200
|
/**
|
178
201
|
* Update the chatwoot contact and conversation registries
|
@@ -209,6 +232,7 @@ const setupChatwootOutgoingMessageHandler = (cliConfig, client) => __awaiter(voi
|
|
209
232
|
* Does the conversation exist in
|
210
233
|
*/
|
211
234
|
let text = message.body;
|
235
|
+
let hasAttachments = false;
|
212
236
|
switch (message.type) {
|
213
237
|
case 'location':
|
214
238
|
text = `${message.lat},${message.lng}`;
|
@@ -221,14 +245,22 @@ const setupChatwootOutgoingMessageHandler = (cliConfig, client) => __awaiter(voi
|
|
221
245
|
case 'audio':
|
222
246
|
case 'ptt':
|
223
247
|
case 'video':
|
224
|
-
if (message.cloudUrl)
|
248
|
+
if (message.cloudUrl) {
|
225
249
|
text = `FILE:\t${message.cloudUrl}\n\nMESSAGE:\t${message.text}`;
|
250
|
+
}
|
251
|
+
else {
|
252
|
+
text = message.text;
|
253
|
+
hasAttachments = true;
|
254
|
+
}
|
226
255
|
break;
|
227
256
|
default:
|
228
257
|
text = message.body || "__UNHANDLED__";
|
229
258
|
break;
|
230
259
|
}
|
231
|
-
|
260
|
+
if (hasAttachments)
|
261
|
+
yield sendAttachmentMessage(text, message.from, message);
|
262
|
+
else
|
263
|
+
yield sendConversationMessage(text, message.from, message);
|
232
264
|
}));
|
233
265
|
});
|
234
266
|
exports.setupChatwootOutgoingMessageHandler = setupChatwootOutgoingMessageHandler;
|
package/dist/cli/server.js
CHANGED
@@ -71,7 +71,10 @@ const setupAuthenticationLayer = (cliConfig) => {
|
|
71
71
|
return next();
|
72
72
|
}
|
73
73
|
const apiKey = req.get('key') || req.get('api_key');
|
74
|
-
if (
|
74
|
+
if (req.path.includes('chatwoot') && req.query['api_key'] && req.query['api_key'] == cliConfig.key) {
|
75
|
+
next();
|
76
|
+
}
|
77
|
+
else if (!apiKey || apiKey !== cliConfig.key) {
|
75
78
|
res.status(401).json({ error: 'unauthorised' });
|
76
79
|
}
|
77
80
|
else {
|
package/dist/controllers/auth.js
CHANGED
@@ -79,6 +79,9 @@ const waitForRipeSession = (waPage) => __awaiter(void 0, void 0, void 0, functio
|
|
79
79
|
});
|
80
80
|
exports.waitForRipeSession = waitForRipeSession;
|
81
81
|
const sessionDataInvalid = (waPage) => __awaiter(void 0, void 0, void 0, function* () {
|
82
|
+
yield waPage
|
83
|
+
.waitForFunction('!window.getQrPng', { timeout: 0, polling: 'mutation' });
|
84
|
+
yield browser_1.injectApi(waPage);
|
82
85
|
yield waPage
|
83
86
|
.waitForFunction('!window.getQrPng', { timeout: 0, polling: 'mutation' });
|
84
87
|
//if the code reaches here it means the browser was refreshed. Nuke the session data and restart `create`
|
@@ -290,6 +290,8 @@ function initBrowser(sessionId, config = {}) {
|
|
290
290
|
if (!_savedPath) {
|
291
291
|
const chromeLauncher = yield Promise.resolve().then(() => __importStar(require('chrome-launcher')));
|
292
292
|
config.executablePath = chromeLauncher.Launcher.getInstallations()[0];
|
293
|
+
if (!config.executablePath)
|
294
|
+
delete config.executablePath;
|
293
295
|
yield storage.setItem('executablePath', config.executablePath);
|
294
296
|
}
|
295
297
|
else
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@open-wa/wa-automate",
|
3
|
-
"version": "4.27.
|
3
|
+
"version": "4.27.6",
|
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",
|
@@ -67,6 +67,7 @@
|
|
67
67
|
"@types/cross-spawn": "^6.0.2",
|
68
68
|
"@types/death": "^1.1.1",
|
69
69
|
"@types/express": "^4.17.11",
|
70
|
+
"@types/form-data": "^2.5.0",
|
70
71
|
"@types/fs-extra": "^9.0.11",
|
71
72
|
"@types/line-reader": "0.0.34",
|
72
73
|
"@types/localtunnel": "^2.0.1",
|
@@ -119,6 +120,7 @@
|
|
119
120
|
"express": "^4.17.1",
|
120
121
|
"express-robots-txt": "^1.0.0",
|
121
122
|
"find-up": "^5.0.0",
|
123
|
+
"form-data": "^4.0.0",
|
122
124
|
"fs-extra": "^10.0.0",
|
123
125
|
"get-port": "^5.1.1",
|
124
126
|
"hasha": "^5.2.0",
|