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.
128 lines • 4.97 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ZaloTag = void 0;
const n8n_workflow_1 = require("n8n-workflow");
const zca_js_1 = require("zca-js");
const branding_1 = require("../shared/branding");
let api;
class ZaloTag {
constructor() {
this.description = {
displayName: 'Zalo Thẻ by diginno.net',
name: 'zaloTag',
group: ['transform'],
version: 1,
description: 'Quản lý thẻ (tag) trong Zalo by diginno.net',
defaults: {
name: 'Zalo Thẻ by diginno.net',
},
icon: 'file:../shared/image.svg',
inputs: ['main'],
outputs: ['main'],
credentials: [
{
name: 'zaloApi',
required: true,
displayName: 'Zalo Credential to connect with',
},
],
properties: [
branding_1.BRANDING_CONFIG,
{
displayName: 'Hành đỘNg',
name: 'action',
type: 'options',
options: [
{
name: 'Danh Sách Thẻ',
value: 'list',
description: 'Liệt kê tất cả các thẻ',
action: 'List',
},
{
name: 'Cập Nhật Danh Sách Thẻ',
value: 'update',
description: 'Cập nhật toàn bộ danh sách thẻ (upstream yêu cầu gửi lại full labelData + version từ lần Danh Sách Thẻ gần nhất)',
action: 'Update',
},
],
default: 'list',
description: 'Hành động cần thực hiện',
},
{
displayName: 'Danh Sách Thẻ (JSON)',
name: 'labelData',
type: 'json',
required: true,
default: '[]',
displayOptions: {
show: {
action: ['update'],
},
},
description: 'Toàn bộ mảng labelData mới (lấy từ kết quả Danh Sách Thẻ, chỉnh sửa rồi gửi lại)',
},
{
displayName: 'Version',
name: 'version',
type: 'number',
required: true,
default: 0,
displayOptions: {
show: {
action: ['update'],
},
},
description: 'Version hiện tại (lấy từ kết quả Danh Sách Thẻ gần nhất)',
},
],
};
}
async execute() {
const items = this.getInputData();
const returnData = [];
const action = this.getNodeParameter('action', 0);
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();
api = await zalo.login({
cookie: cookieFromCred,
imei: imeiFromCred,
userAgent: userAgentFromCred,
});
if (!api) {
throw new n8n_workflow_1.NodeApiError(this.getNode(), {
message: 'Không thể khởi tạo API Zalo. Vui lòng kiểm tra thông tin đăng nhập.',
});
}
}
catch (error) {
throw new n8n_workflow_1.NodeApiError(this.getNode(), error, {
message: `Lỗi đăng nhập Zalo: ${error.message}`,
});
}
for (let i = 0; i < items.length; i++) {
if (action === 'list') {
const response = await api.getLabels();
returnData.push({ json: { success: true, labels: response } });
}
else if (action === 'update') {
const labelData = this.getNodeParameter('labelData', i);
const version = this.getNodeParameter('version', i);
const response = await api.updateLabels({ labelData, version });
returnData.push({ json: { success: true, response } });
}
}
return this.prepareOutputData(returnData);
}
}
exports.ZaloTag = ZaloTag;
//# sourceMappingURL=ZaloTag.node.js.map