n8n-nodes-zalo-nnt
Version:
Unofficial Zalo integration for n8n - Send messages, manage groups, user operations with QR login. No API key required, works via browser simulation.
179 lines • 7.92 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ZaloReminder = void 0;
const n8n_workflow_1 = require("n8n-workflow");
const zca_js_1 = require("zca-js");
const helper_1 = require("../utils/helper");
const ZaloReminder_properties_1 = require("./ZaloReminder.properties");
const utils_1 = require("./utils");
let api;
class ZaloReminder {
constructor() {
this.description = {
displayName: 'Lịch Hẹn Zalo by diginno.net',
name: 'zaloReminder',
icon: 'file:../shared/image.svg',
group: ['transform'],
version: 1,
description: 'Quản lý lịch hẹn (reminders) trong Zalo - cá nhân & nhóm by diginno.net',
defaults: {
name: 'Lịch Hẹn Zalo by diginno.net',
},
inputs: ['main'],
outputs: ['main'],
credentials: [
{
name: 'zaloApi',
required: true,
},
],
properties: ZaloReminder_properties_1.zaloReminderProperties,
};
}
async execute() {
const returnData = [];
const items = this.getInputData();
const zaloCred = await this.getCredentials('zaloApi');
let cookieFromCred = zaloCred.cookie;
try {
cookieFromCred = JSON.parse(zaloCred.cookie);
}
catch {
}
const imeiFromCred = zaloCred.imei;
const userAgentFromCred = zaloCred.userAgent;
try {
const zalo = new zca_js_1.Zalo({
imageMetadataGetter: helper_1.imageMetadataGetter,
});
api = await zalo.login({
cookie: cookieFromCred,
imei: imeiFromCred,
userAgent: userAgentFromCred,
});
if (!api) {
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Failed to initialize Zalo API. Check your credentials.');
}
}
catch (error) {
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Zalo login error: ${error.message}`);
}
for (let i = 0; i < items.length; i++) {
try {
const operation = this.getNodeParameter('operation', i);
let result;
switch (operation) {
case 'create': {
const threadType = this.getNodeParameter('threadType', i, 'user');
const threadId = this.getNodeParameter('threadId', i);
const title = this.getNodeParameter('title', i);
const emoji = this.getNodeParameter('emoji', i, '⏰');
const startTime = this.getNodeParameter('startTime', i, '');
const repeat = this.getNodeParameter('repeat', i, 0);
const input = {
threadId,
threadType,
title,
emoji,
startTime: startTime ? new Date(startTime).getTime() : undefined,
repeat,
};
(0, utils_1.validateCreateReminder)(input);
result = await (0, utils_1.createReminder)(api, input);
break;
}
case 'edit': {
const threadType = this.getNodeParameter('threadType', i, 'user');
const threadId = this.getNodeParameter('threadId', i);
const reminderId = this.getNodeParameter('reminderId', i);
const title = this.getNodeParameter('title', i);
const emoji = this.getNodeParameter('emoji', i, '⏰');
const startTime = this.getNodeParameter('startTime', i, '');
const repeat = this.getNodeParameter('repeat', i, 0);
const input = {
threadId,
threadType,
reminderId,
title,
emoji,
startTime: startTime ? new Date(startTime).getTime() : undefined,
repeat,
};
(0, utils_1.validateEditReminder)(input);
result = await (0, utils_1.editReminder)(api, input);
break;
}
case 'getList': {
const threadType = this.getNodeParameter('threadType', i, 'user');
const threadId = this.getNodeParameter('threadId', i);
const page = this.getNodeParameter('page', i, 1);
const count = this.getNodeParameter('count', i, 20);
const input = {
threadId,
threadType,
page,
count,
};
(0, utils_1.validateGetListReminder)(input);
result = await (0, utils_1.getListReminder)(api, input);
break;
}
case 'get': {
const reminderId = this.getNodeParameter('reminderId', i);
const input = {
reminderId,
};
(0, utils_1.validateReminderId)(reminderId);
result = await (0, utils_1.getReminder)(api, input);
break;
}
case 'remove': {
const threadType = this.getNodeParameter('threadType', i, 'user');
const threadId = this.getNodeParameter('threadId', i);
const reminderId = this.getNodeParameter('reminderId', i);
const input = {
threadId,
threadType,
reminderId,
};
(0, utils_1.validateRemoveReminder)(input);
result = await (0, utils_1.removeReminder)(api, input);
break;
}
case 'getResponses': {
const reminderId = this.getNodeParameter('reminderId', i);
const input = {
reminderId,
};
(0, utils_1.validateReminderId)(reminderId);
result = await (0, utils_1.getReminderResponses)(api, input);
break;
}
default:
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Unknown operation: ${operation}`);
}
returnData.push({
json: result,
pairedItem: { item: i },
});
}
catch (error) {
if (this.continueOnFail()) {
returnData.push({
json: {
success: false,
error: error.message,
},
pairedItem: { item: i },
});
}
else {
throw new n8n_workflow_1.NodeOperationError(this.getNode(), error, { itemIndex: i });
}
}
}
return [returnData];
}
}
exports.ZaloReminder = ZaloReminder;
//# sourceMappingURL=ZaloReminder.node.js.map