n8n-nodes-zalo-bot-stephen 0.1.4 → 0.1.5
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/gulpfile.js +4 -1
- package/dist/nodes/ZaloBot/ZaloBot.node.js +12 -11
- package/package.json +1 -1
package/dist/gulpfile.js
CHANGED
|
@@ -3,7 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.buildIcons = exports.build = void 0;
|
|
4
4
|
const gulp_1 = require("gulp");
|
|
5
5
|
function copyIcons() {
|
|
6
|
-
|
|
6
|
+
// Copy icons to dist/icons (standard location)
|
|
7
|
+
(0, gulp_1.src)('icons/**/*').pipe((0, gulp_1.dest)('dist/icons'));
|
|
8
|
+
// Copy icons to dist/nodes/ZaloBot (where n8n looks for file:zalo.svg relative to node file)
|
|
9
|
+
return (0, gulp_1.src)('icons/**/*').pipe((0, gulp_1.dest)('dist/nodes/ZaloBot'));
|
|
7
10
|
}
|
|
8
11
|
exports.build = copyIcons;
|
|
9
12
|
exports.buildIcons = copyIcons;
|
|
@@ -318,6 +318,7 @@ class ZaloBot {
|
|
|
318
318
|
};
|
|
319
319
|
}
|
|
320
320
|
async execute() {
|
|
321
|
+
const executeFunctions = this;
|
|
321
322
|
const items = this.getInputData();
|
|
322
323
|
const returnData = [];
|
|
323
324
|
const credentials = await this.getCredentials('zaloApi');
|
|
@@ -336,7 +337,7 @@ class ZaloBot {
|
|
|
336
337
|
chat_id: chatId,
|
|
337
338
|
text,
|
|
338
339
|
};
|
|
339
|
-
response = await this.makeRequestWithRetry
|
|
340
|
+
response = await this.makeRequestWithRetry(executeFunctions, `${baseUrl}/sendMessage`, 'POST', body);
|
|
340
341
|
}
|
|
341
342
|
else if (operation === 'sendPhoto') {
|
|
342
343
|
const chatId = this.getNodeParameter('chatId', i);
|
|
@@ -368,7 +369,7 @@ class ZaloBot {
|
|
|
368
369
|
if (caption) {
|
|
369
370
|
formData.append('caption', caption);
|
|
370
371
|
}
|
|
371
|
-
response = await this.makeRequestWithRetry
|
|
372
|
+
response = await this.makeRequestWithRetry(executeFunctions, `${baseUrl}/sendPhoto`, 'POST', formData, true);
|
|
372
373
|
}
|
|
373
374
|
else {
|
|
374
375
|
const body = {
|
|
@@ -378,7 +379,7 @@ class ZaloBot {
|
|
|
378
379
|
if (caption) {
|
|
379
380
|
body.caption = caption;
|
|
380
381
|
}
|
|
381
|
-
response = await this.makeRequestWithRetry
|
|
382
|
+
response = await this.makeRequestWithRetry(executeFunctions, `${baseUrl}/sendPhoto`, 'POST', body);
|
|
382
383
|
}
|
|
383
384
|
}
|
|
384
385
|
else if (operation === 'sendSticker') {
|
|
@@ -388,7 +389,7 @@ class ZaloBot {
|
|
|
388
389
|
chat_id: chatId,
|
|
389
390
|
sticker_id: stickerId,
|
|
390
391
|
};
|
|
391
|
-
response = await this.makeRequestWithRetry
|
|
392
|
+
response = await this.makeRequestWithRetry(executeFunctions, `${baseUrl}/sendSticker`, 'POST', body);
|
|
392
393
|
}
|
|
393
394
|
else if (operation === 'sendChatAction') {
|
|
394
395
|
const chatId = this.getNodeParameter('chatId', i);
|
|
@@ -397,7 +398,7 @@ class ZaloBot {
|
|
|
397
398
|
chat_id: chatId,
|
|
398
399
|
action: action,
|
|
399
400
|
};
|
|
400
|
-
response = await this.makeRequestWithRetry
|
|
401
|
+
response = await this.makeRequestWithRetry(executeFunctions, `${baseUrl}/sendChatAction`, 'POST', body);
|
|
401
402
|
}
|
|
402
403
|
else {
|
|
403
404
|
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Unknown operation: ${operation}`);
|
|
@@ -405,7 +406,7 @@ class ZaloBot {
|
|
|
405
406
|
}
|
|
406
407
|
else if (resource === 'bot') {
|
|
407
408
|
if (operation === 'getMe') {
|
|
408
|
-
response = await this.makeRequestWithRetry
|
|
409
|
+
response = await this.makeRequestWithRetry(executeFunctions, `${baseUrl}/getMe`, 'GET');
|
|
409
410
|
}
|
|
410
411
|
else {
|
|
411
412
|
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Unknown operation: ${operation}`);
|
|
@@ -413,7 +414,7 @@ class ZaloBot {
|
|
|
413
414
|
}
|
|
414
415
|
else if (resource === 'webhook') {
|
|
415
416
|
if (operation === 'getWebhookInfo') {
|
|
416
|
-
response = await this.makeRequestWithRetry
|
|
417
|
+
response = await this.makeRequestWithRetry(executeFunctions, `${baseUrl}/getWebhookInfo`, 'GET');
|
|
417
418
|
}
|
|
418
419
|
else if (operation === 'setWebhook') {
|
|
419
420
|
const webhookUrl = this.getNodeParameter('webhookUrl', i);
|
|
@@ -422,10 +423,10 @@ class ZaloBot {
|
|
|
422
423
|
url: webhookUrl,
|
|
423
424
|
secret_token: secretToken,
|
|
424
425
|
};
|
|
425
|
-
response = await this.makeRequestWithRetry
|
|
426
|
+
response = await this.makeRequestWithRetry(executeFunctions, `${baseUrl}/setWebhook`, 'POST', body);
|
|
426
427
|
}
|
|
427
428
|
else if (operation === 'deleteWebhook') {
|
|
428
|
-
response = await this.makeRequestWithRetry
|
|
429
|
+
response = await this.makeRequestWithRetry(executeFunctions, `${baseUrl}/deleteWebhook`, 'POST');
|
|
429
430
|
}
|
|
430
431
|
else {
|
|
431
432
|
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Unknown operation: ${operation}`);
|
|
@@ -461,7 +462,7 @@ class ZaloBot {
|
|
|
461
462
|
}
|
|
462
463
|
return [returnData];
|
|
463
464
|
}
|
|
464
|
-
async makeRequestWithRetry(url, method, body, isMultipart = false, maxRetries = 3) {
|
|
465
|
+
async makeRequestWithRetry(executeFunctions, url, method, body, isMultipart = false, maxRetries = 3) {
|
|
465
466
|
let lastError = null;
|
|
466
467
|
for (let attempt = 1; attempt <= maxRetries; attempt++) {
|
|
467
468
|
try {
|
|
@@ -482,7 +483,7 @@ class ZaloBot {
|
|
|
482
483
|
else {
|
|
483
484
|
options.headers['Content-Type'] = 'application/json';
|
|
484
485
|
}
|
|
485
|
-
const response = await
|
|
486
|
+
const response = await executeFunctions.helpers.httpRequest(options);
|
|
486
487
|
return response;
|
|
487
488
|
}
|
|
488
489
|
catch (error) {
|