UNPKG

n8n-nodes-feishu-fork

Version:

n8n custom nodes for n8n to interact with Feishu/Lark, including Lark Bot, Lark MCP, and Lark Trigger.

75 lines 2.82 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.EventDispatcher = void 0; const cache_1 = require("./cache"); const request_handle_1 = __importDefault(require("./request-handle")); const CAppTicketHandle = 'app_ticket'; const CAppTicket = Symbol('app-ticket'); class EventDispatcher { constructor(params) { this.handles = new Map(); this.logger = params.logger; this.isAnyEvent = params.isAnyEvent; this.requestHandle = new request_handle_1.default({ logger: this.logger, }); this.cache = cache_1.internalCache; this.registerAppTicketHandle(); this.logger.info('event-dispatch is ready'); } registerAppTicketHandle() { this.register({ app_ticket: async (data) => { const { app_ticket, app_id } = data; if (app_ticket) { await this.cache.set(CAppTicket, app_ticket, undefined, { namespace: app_id, }); this.logger.debug('set app ticket'); } else { this.logger.warn('response not include app ticket'); } }, }); } register(handles) { Object.keys(handles).forEach((key) => { if (this.handles.has(key) && key !== CAppTicketHandle) { this.logger.error(`this ${key} handle is registered`); } const handle = handles[key]; if (handle) { this.handles.set(key, handle); } else { this.logger.warn(`Handle for key ${key} is undefined and will not be registered`); } this.logger.debug(`register ${key} handle`); }); return this; } async invoke(data) { var _a; const targetData = (_a = this.requestHandle) === null || _a === void 0 ? void 0 : _a.parse(data); this.logger.debug(`Event data: ${JSON.stringify(targetData)}`); if (this.isAnyEvent) { const ret = await this.handles.get('any_event')(targetData); this.logger.debug(`execute any_event handle`); return ret; } const type = targetData['event_type']; if (this.handles.has(type)) { const ret = await this.handles.get(type)(targetData); this.logger.debug(`execute ${type} handle`); return ret; } this.logger.warn(`no ${type} handle`); return `no ${type} event handle`; } } exports.EventDispatcher = EventDispatcher; //# sourceMappingURL=index.js.map