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.
76 lines • 2.98 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.validateThreadId = validateThreadId;
exports.validateLimit = validateLimit;
exports.validateLastMsgId = validateLastMsgId;
exports.validateOperation = validateOperation;
exports.parseHistoryParams = parseHistoryParams;
const types_1 = require("./types");
function validateThreadId(threadId) {
if (!threadId || typeof threadId !== 'string') {
throw new Error('Thread ID is required and must be a string');
}
const trimmed = threadId.trim();
if (trimmed.length === 0) {
throw new Error('Thread ID cannot be empty');
}
return trimmed;
}
function validateLimit(limit) {
const num = Number(limit);
if (isNaN(num)) {
throw new Error('Limit must be a valid number');
}
if (num < 1 || num > 100) {
throw new Error('Limit must be between 1 and 100');
}
return Math.floor(num);
}
function validateLastMsgId(msgId) {
if (!msgId || msgId === '') {
return null;
}
if (typeof msgId !== 'string') {
throw new Error('Last Message ID must be a string');
}
return msgId.trim();
}
function validateOperation(operation) {
if (operation !== 'getUserHistory' && operation !== 'getGroupHistory') {
throw new Error('Invalid operation. Must be "getUserHistory" or "getGroupHistory"');
}
return operation;
}
function parseHistoryParams(params) {
const operation = validateOperation(params.operation);
const filterByThreadId = params.filterByThreadId === undefined ? true : Boolean(params.filterByThreadId);
const threadId = filterByThreadId
? validateThreadId(params.threadId)
: typeof params.threadId === 'string'
? params.threadId.trim()
: '';
const fetchAll = Boolean(params.fetchAll);
const limit = params.limit !== undefined ? validateLimit(params.limit) : 20;
const lastMsgId = params.lastMsgId !== undefined ? validateLastMsgId(params.lastMsgId) : null;
const includeReactions = Boolean(params.includeReactions);
const sortOrder = (params.sortOrder === 'asc' || params.sortOrder === 'desc') ? params.sortOrder : 'desc';
const fromDate = typeof params.fromDate === 'number' ? params.fromDate : null;
const toDate = typeof params.toDate === 'number' ? params.toDate : null;
const delayBetweenRequests = typeof params.delayBetweenRequests === 'number' ? params.delayBetweenRequests : 1000;
const maxPages = typeof params.maxPages === 'number' && params.maxPages > 0 ? Math.floor(params.maxPages) : 50;
return {
threadId,
threadType: operation === 'getUserHistory' ? types_1.ThreadType.User : types_1.ThreadType.Group,
filterByThreadId,
limit,
lastMsgId,
includeReactions,
sortOrder,
fromDate,
toDate,
fetchAll,
delayBetweenRequests,
maxPages,
};
}
//# sourceMappingURL=validator.js.map