UNPKG

@tuanltntu/n8n-nodes-bitrix24

Version:

Comprehensive n8n community node for Bitrix24 API integration with CRM, Tasks, Chat, Telephony, and more

129 lines 5.06 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.OpenLinesResourceHandler = void 0; const n8n_workflow_1 = require("n8n-workflow"); const ResourceHandlerBase_1 = require("./ResourceHandlerBase"); /** * Handler for Bitrix24 OpenLines operations */ class OpenLinesResourceHandler extends ResourceHandlerBase_1.ResourceHandlerBase { constructor(executeFunctions, returnData, options = {}) { super(executeFunctions, returnData, options); this.resourceEndpoints = { sendMessage: "imopenlines.session.message.add", getMessages: "imopenlines.session.message.list", createSession: "imopenlines.session.start", closeSession: "imopenlines.session.finish", getSessions: "imopenlines.session.list", }; } /** * Process OpenLines operations */ async process() { for (let i = 0; i < this.items.length; i++) { try { const operation = this.getNodeParameter("operation", i); if (!this.resourceEndpoints[operation]) { throw new n8n_workflow_1.NodeOperationError(this.executeFunctions.getNode(), `The operation "${operation}" is not supported for OpenLines`, { itemIndex: i }); } const endpoint = this.resourceEndpoints[operation]; let responseData; switch (operation) { case "sendMessage": responseData = await this.handleSendMessage(endpoint, i); break; case "getMessages": responseData = await this.handleGetMessages(endpoint, i); break; case "createSession": responseData = await this.handleCreateSession(endpoint, i); break; case "closeSession": responseData = await this.handleCloseSession(endpoint, i); break; case "getSessions": responseData = await this.handleGetSessions(endpoint, i); break; default: throw new n8n_workflow_1.NodeOperationError(this.executeFunctions.getNode(), `The operation "${operation}" is not supported`, { itemIndex: i }); } this.addResponseToReturnData(responseData, i); } catch (error) { if (this.continueOnFail()) { this.addErrorToReturnData(error, i); } else { throw error; } } } return this.returnData; } /** * Handle send message operation */ async handleSendMessage(endpoint, itemIndex) { const sessionId = this.getNodeParameter("sessionId", itemIndex); const message = this.getNodeParameter("message", itemIndex); const chatId = this.getNodeParameter("chatId", itemIndex); const options = this.getNodeParameter("options", itemIndex, {}); const body = { session_id: sessionId, message: message, chat_id: chatId, ...options, }; return this.makeApiCall(endpoint, body); } /** * Handle get messages operation */ async handleGetMessages(endpoint, itemIndex) { const sessionId = this.getNodeParameter("sessionId", itemIndex); const options = this.getNodeParameter("options", itemIndex, {}); const body = { session_id: sessionId, ...options, }; return this.makeApiCall(endpoint, body); } /** * Handle create session operation */ async handleCreateSession(endpoint, itemIndex) { const configId = this.getNodeParameter("configId", itemIndex); const userId = this.getNodeParameter("userId", itemIndex, ""); const options = this.getNodeParameter("options", itemIndex, {}); const body = { config_id: configId, ...options, }; if (userId) { body.user_id = userId; } return this.makeApiCall(endpoint, body); } /** * Handle close session operation */ async handleCloseSession(endpoint, itemIndex) { const sessionId = this.getNodeParameter("sessionId", itemIndex); const options = this.getNodeParameter("options", itemIndex, {}); const body = { session_id: sessionId, ...options, }; return this.makeApiCall(endpoint, body); } /** * Handle get sessions operation */ async handleGetSessions(endpoint, itemIndex) { const options = this.getNodeParameter("options", itemIndex, {}); return this.makeApiCall(endpoint, options); } } exports.OpenLinesResourceHandler = OpenLinesResourceHandler; //# sourceMappingURL=OpenLinesResourceHandler.js.map