UNPKG

n8n-nodes-everest-tms

Version:

Everest TMS n8n integration

74 lines 3.35 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.executeWalterOperations = executeWalterOperations; const GenericFunctions_1 = require("../GenericFunctions"); async function executeWalterOperations(itemIndex) { const operation = this.getNodeParameter('operation', itemIndex); if (operation === 'prompt') { const question = this.getNodeParameter('question', itemIndex); const userId = this.getNodeParameter('user_id', itemIndex, 0); const saveToHistory = this.getNodeParameter('save_to_history', itemIndex, true); (0, GenericFunctions_1.validateRequiredFields)({ question }, ['question']); // Check message length (2000 characters max as per PHP code) if (question.length > 2000) { throw new Error('Question too long. Maximum 2000 characters allowed'); } const body = { question, save_to_history: saveToHistory, }; // Add user_id if provided and not 0 if (userId && userId > 0) { body.user_id = userId; } const response = await GenericFunctions_1.everestApiRequest.call(this, 'POST', '/walter/prompt', body); return response; } if (operation === 'say') { const message = this.getNodeParameter('message', itemIndex); const userId = this.getNodeParameter('user_id', itemIndex, 0); const saveToHistory = this.getNodeParameter('save_to_history', itemIndex, true); const commandsData = this.getNodeParameter('commands', itemIndex, {}); (0, GenericFunctions_1.validateRequiredFields)({ message }, ['message']); // Check message length (2000 characters max as per PHP code) if (message.length > 2000) { throw new Error('Message too long. Maximum 2000 characters allowed'); } const body = { message, save_to_history: saveToHistory, }; // Add user_id if provided and not 0 if (userId && userId > 0) { body.user_id = userId; } // Process commands if provided if (commandsData.command && Array.isArray(commandsData.command)) { const commands = []; for (const cmd of commandsData.command) { const commandObj = { command: cmd.command, }; // Parse parameters if provided if (cmd.parameters && typeof cmd.parameters === 'string') { const params = cmd.parameters.split(',').map((p) => p.trim()).filter((p) => p.length > 0); if (params.length > 0) { commandObj.parameters = params; } } commands.push(commandObj); } if (commands.length > 0) { body.commands = commands; } } const response = await GenericFunctions_1.everestApiRequest.call(this, 'POST', '/walter/say', body); return response; } if (operation === 'getCommands') { const response = await GenericFunctions_1.everestApiRequest.call(this, 'GET', '/walter/commands'); return response; } throw new Error(`The operation "${operation}" is not known!`); } //# sourceMappingURL=WalterOperations.js.map