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.
51 lines • 1.82 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ZaloConnectionManager = void 0;
const zca_js_1 = require("zca-js");
const n8n_workflow_1 = require("n8n-workflow");
class ZaloConnectionManager {
static parseCredentials(credentials) {
let cookie = credentials.cookie;
try {
cookie = JSON.parse(credentials.cookie);
}
catch {
}
return {
cookie,
imei: credentials.imei,
userAgent: credentials.userAgent,
};
}
static async login(hookFunctions, cookie, imei, userAgent, selfListen) {
const zalo = new zca_js_1.Zalo({ selfListen });
const apiInstance = await zalo.login({
cookie,
imei,
userAgent,
});
if (!apiInstance) {
throw new n8n_workflow_1.NodeOperationError(hookFunctions.getNode(), 'No API instance found. Please make sure to provide valid credentials.');
}
return apiInstance;
}
static handleError(hookFunctions, error, api) {
let errorMessage = 'Zalo connection failed';
if (error instanceof Error) {
errorMessage += `: ${error.message}`;
console.error('[ZaloMessageTrigger] Stack trace:', error.stack);
}
console.error('[ZaloMessageTrigger] Connection error:', error);
if (api) {
try {
api.listener.stop();
}
catch (stopError) {
console.warn('[ZaloMessageTrigger] Error stopping listener:', stopError);
}
}
throw new n8n_workflow_1.NodeOperationError(hookFunctions.getNode(), errorMessage);
}
}
exports.ZaloConnectionManager = ZaloConnectionManager;
//# sourceMappingURL=ZaloConnectionManager.js.map