UNPKG

n8n-nodes-evolution-api

Version:
104 lines 4.51 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createInstanceBasic = createInstanceBasic; const n8n_workflow_1 = require("n8n-workflow"); const evolutionRequest_1 = require("../evolutionRequest"); async function createInstanceBasic(ef) { try { const instanceName = ef.getNodeParameter('instanceName', 0); const token = ef.getNodeParameter('token', 0) || ''; const number = ef.getNodeParameter('number', 0) || ''; const body = { instanceName, integration: 'WHATSAPP-BAILEYS', }; if (token) { body.token = token; } if (number) { body.number = number; } const instanceSettings = ef.getNodeParameter('options_Create_instance.instanceSettings.settings', 0, {}); if (instanceSettings && Object.keys(instanceSettings).length > 0) { Object.assign(body, instanceSettings); } const proxySettings = ef.getNodeParameter('options_Create_instance.proxy.proxySettings', 0, {}); if (proxySettings && Object.keys(proxySettings).length > 0) { Object.assign(body, { proxyHost: proxySettings.proxyHost || '', proxyPort: proxySettings.proxyPort ? String(proxySettings.proxyPort) : '1234', proxyProtocol: proxySettings.proxyProtocol || '', proxyUsername: proxySettings.proxyUsername || '', proxyPassword: proxySettings.proxyPassword || '', }); } const webhookSettings = ef.getNodeParameter('options_Create_instance.webhook.webhookSettings', 0, {}); if (webhookSettings && Object.keys(webhookSettings).length > 0) { Object.assign(body, { webhook: { url: webhookSettings.webhookUrl || '', byEvents: webhookSettings.webhookByEvents || false, base64: webhookSettings.webhookBase64 || false, events: webhookSettings.webhookEvents || [], }, }); } const rabbitmqSettings = ef.getNodeParameter('options_Create_instance.rabbitmq.rabbitmqSettings', 0, {}); if (rabbitmqSettings && Object.keys(rabbitmqSettings).length > 0) { Object.assign(body, { rabbitmq: { enabled: rabbitmqSettings.rabbitmqEnabled || false, events: rabbitmqSettings.rabbitmqEvents || [], }, }); } const chatwootSettings = ef.getNodeParameter('options_Create_instance.chatwoot.chatwootSettings', 0, {}); if (chatwootSettings && Object.keys(chatwootSettings).length > 0) { Object.assign(body, { chatwootAccountId: chatwootSettings.chatwootAccountId || '', chatwootToken: chatwootSettings.chatwootToken || '', chatwootUrl: chatwootSettings.chatwootUrl || '', chatwootSignMsg: chatwootSettings.chatwootSignMsg !== undefined ? chatwootSettings.chatwootSignMsg : false, }); } const options = { method: 'POST', uri: `/instance/create`, body, json: true, }; const response = await (0, evolutionRequest_1.evolutionRequest)(ef, options); return { json: { success: true, data: response, }, }; } catch (error) { const errorData = { success: false, error: { message: error.message.includes('Could not get parameter') ? 'Parâmetros inválidos ou ausentes' : 'Erro ao criar instância', details: error.message.includes('Could not get parameter') ? 'Verifique se todos os campos obrigatórios foram preenchidos corretamente' : error.message, code: error.code || 'UNKNOWN_ERROR', timestamp: new Date().toISOString(), }, }; if (!ef.continueOnFail()) { throw new n8n_workflow_1.NodeOperationError(ef.getNode(), error.message, { message: errorData.error.message, description: errorData.error.details, }); } return { json: errorData, error: errorData, }; } } //# sourceMappingURL=createInstanceBasic.js.map