n8n-nodes-syncmate 1.0.21 → 1.0.22
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.
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AssistroTokenApi = void 0;
|
|
4
|
+
class AssistroTokenApi {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.name = 'assistroTokenApi';
|
|
7
|
+
this.displayName = 'Assistro API Token';
|
|
8
|
+
this.documentationUrl = 'https://docs.assistro.co/api';
|
|
9
|
+
this.properties = [
|
|
10
|
+
{
|
|
11
|
+
displayName: 'Access Token',
|
|
12
|
+
name: 'accessToken',
|
|
13
|
+
type: 'string',
|
|
14
|
+
typeOptions: { password: true },
|
|
15
|
+
default: '',
|
|
16
|
+
description: 'The JWT Access Token provided by Assistro',
|
|
17
|
+
},
|
|
18
|
+
];
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.AssistroTokenApi = AssistroTokenApi;
|
|
@@ -19,12 +19,42 @@ class WhatsAuto {
|
|
|
19
19
|
outputs: [n8n_workflow_1.NodeConnectionTypes.Main],
|
|
20
20
|
usableAsTool: true,
|
|
21
21
|
credentials: [
|
|
22
|
+
{
|
|
23
|
+
name: 'assistroTokenApi',
|
|
24
|
+
required: true,
|
|
25
|
+
displayOptions: {
|
|
26
|
+
show: {
|
|
27
|
+
authentication: ['jwt'],
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
},
|
|
22
31
|
{
|
|
23
32
|
name: 'assistroOAuth2Api',
|
|
24
33
|
required: true,
|
|
34
|
+
displayOptions: {
|
|
35
|
+
show: {
|
|
36
|
+
authentication: ['oAuth2'],
|
|
37
|
+
},
|
|
38
|
+
},
|
|
25
39
|
},
|
|
26
40
|
],
|
|
27
41
|
properties: [
|
|
42
|
+
{
|
|
43
|
+
displayName: 'Authentication',
|
|
44
|
+
name: 'authentication',
|
|
45
|
+
type: 'options',
|
|
46
|
+
options: [
|
|
47
|
+
{
|
|
48
|
+
name: 'API Token (JWT)',
|
|
49
|
+
value: 'jwt',
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
name: 'OAuth2',
|
|
53
|
+
value: 'oAuth2',
|
|
54
|
+
},
|
|
55
|
+
],
|
|
56
|
+
default: 'jwt',
|
|
57
|
+
},
|
|
28
58
|
{
|
|
29
59
|
displayName: 'Resource',
|
|
30
60
|
name: 'resource',
|
|
@@ -197,9 +227,9 @@ class WhatsAuto {
|
|
|
197
227
|
};
|
|
198
228
|
}
|
|
199
229
|
async execute() {
|
|
200
|
-
var _a, _b, _c;
|
|
201
230
|
const items = this.getInputData();
|
|
202
231
|
const returnData = [];
|
|
232
|
+
const authMethod = this.getNodeParameter('authentication', 0);
|
|
203
233
|
for (let i = 0; i < items.length; i++) {
|
|
204
234
|
try {
|
|
205
235
|
const operation = this.getNodeParameter('operation', i);
|
|
@@ -222,7 +252,7 @@ class WhatsAuto {
|
|
|
222
252
|
}
|
|
223
253
|
body = { msgs: [msgObj] };
|
|
224
254
|
}
|
|
225
|
-
if (operation === 'group') {
|
|
255
|
+
else if (operation === 'group') {
|
|
226
256
|
const groupId = this.getNodeParameter('groupId', i);
|
|
227
257
|
const message = this.getNodeParameter('message', i);
|
|
228
258
|
const mediaFiles = this.getNodeParameter('mediaFiles', i);
|
|
@@ -243,7 +273,7 @@ class WhatsAuto {
|
|
|
243
273
|
}
|
|
244
274
|
body = { msgs: [msgObj] };
|
|
245
275
|
}
|
|
246
|
-
if (operation === 'newsletter') {
|
|
276
|
+
else if (operation === 'newsletter') {
|
|
247
277
|
const newsletterId = this.getNodeParameter('newsletterId', i);
|
|
248
278
|
const message = this.getNodeParameter('newsletterMessage', i);
|
|
249
279
|
let cleanNewsletterId = newsletterId.trim();
|
|
@@ -258,22 +288,42 @@ class WhatsAuto {
|
|
|
258
288
|
}],
|
|
259
289
|
};
|
|
260
290
|
}
|
|
261
|
-
|
|
291
|
+
let endpointUri = '';
|
|
292
|
+
if (authMethod === 'oAuth2') {
|
|
293
|
+
endpointUri = 'https://app.assistro.co/api/v1/wapushplus/singlePass/message';
|
|
294
|
+
}
|
|
295
|
+
else {
|
|
296
|
+
endpointUri = 'https://app.assistro.co/api/v1/wapushplus/single/message';
|
|
297
|
+
}
|
|
298
|
+
const requestOptions = {
|
|
262
299
|
method: 'POST',
|
|
263
|
-
url:
|
|
300
|
+
url: endpointUri,
|
|
264
301
|
headers: {
|
|
265
302
|
'Content-Type': 'application/json',
|
|
266
303
|
'Integration': 'n8n',
|
|
267
304
|
},
|
|
268
305
|
body,
|
|
269
306
|
json: true,
|
|
270
|
-
}
|
|
307
|
+
};
|
|
308
|
+
let response;
|
|
309
|
+
if (authMethod === 'oAuth2') {
|
|
310
|
+
response = await this.helpers.httpRequestWithAuthentication.call(this, 'assistroOAuth2Api', requestOptions);
|
|
311
|
+
}
|
|
312
|
+
else {
|
|
313
|
+
const credentials = await this.getCredentials('assistroTokenApi');
|
|
314
|
+
requestOptions.headers['Authorization'] = `Bearer ${credentials.accessToken}`;
|
|
315
|
+
response = await this.helpers.httpRequest(requestOptions);
|
|
316
|
+
}
|
|
271
317
|
returnData.push({
|
|
272
318
|
json: response,
|
|
273
319
|
pairedItem: { item: i },
|
|
274
320
|
});
|
|
275
321
|
}
|
|
276
322
|
catch (error) {
|
|
323
|
+
console.error(`[WhatsAuto] Item ${i} Failed:`, error.message);
|
|
324
|
+
if (error.response) {
|
|
325
|
+
console.error(`[WhatsAuto] Error Response Body:`, error.response.body);
|
|
326
|
+
}
|
|
277
327
|
if (this.continueOnFail()) {
|
|
278
328
|
returnData.push({
|
|
279
329
|
json: {
|
|
@@ -283,13 +333,8 @@ class WhatsAuto {
|
|
|
283
333
|
});
|
|
284
334
|
continue;
|
|
285
335
|
}
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
}
|
|
289
|
-
if (((_c = error.response) === null || _c === void 0 ? void 0 : _c.status) === 500) {
|
|
290
|
-
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Server error. Your access token may have expired. Please reconnect OAuth credentials.', { itemIndex: i });
|
|
291
|
-
}
|
|
292
|
-
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Failed to send message: ${error.message}`, { itemIndex: i });
|
|
336
|
+
const errorMsg = error.message || 'Unknown error';
|
|
337
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Failed to send message: ${errorMsg}`, { itemIndex: i });
|
|
293
338
|
}
|
|
294
339
|
}
|
|
295
340
|
return [returnData];
|