UNPKG

@poli-digital/n8n-nodes-poli

Version:
292 lines 14.1 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Poli = void 0; const ListContacts_operation_1 = require("./ListContacts.operation"); const CreateTag_operation_1 = require("./CreateTag.operation"); const CreateApp_operation_1 = require("./CreateApp.operation"); const ListApps_operation_1 = require("./ListApps.operation"); const ListChannels_operation_1 = require("./ListChannels.operation"); const ListTemplates_operation_1 = require("./ListTemplates.operation"); const ListTags_operation_1 = require("./ListTags.operation"); const ListWebhooks_operation_1 = require("./ListWebhooks.operation"); const CreateWebhook_operation_1 = require("./CreateWebhook.operation"); const SendMessageByContactId_operation_1 = require("./SendMessageByContactId.operation"); const SendMessageByPhoneNumber_operation_1 = require("./SendMessageByPhoneNumber.operation"); const SendTemplateByContactId_operation_1 = require("./SendTemplateByContactId.operation"); const SendTemplateByPhoneNumber_operation_1 = require("./SendTemplateByPhoneNumber.operation"); const AddTagToContact_operation_1 = require("./AddTagToContact.operation"); const ForwardContact_operation_1 = require("./ForwardContact.operation"); const ListAccounts_operation_1 = require("./ListAccounts.operation"); class Poli { constructor() { const nodes = { contact: { list: new ListContacts_operation_1.ListContacts(), addTag: new AddTagToContact_operation_1.AddTagToContact(), forward: new ForwardContact_operation_1.ForwardContact(), }, app: { list: new ListApps_operation_1.ListApps(), create: new CreateApp_operation_1.CreateApp(), }, tag: { list: new ListTags_operation_1.ListTags(), create: new CreateTag_operation_1.CreateTag(), }, message: { sendByContactId: new SendMessageByContactId_operation_1.SendMessageByContactId(), sendByPhone: new SendMessageByPhoneNumber_operation_1.SendMessageByPhoneNumber(), sendTemplateByContactId: new SendTemplateByContactId_operation_1.SendTemplateByContactId(), sendTemplateByPhoneNumber: new SendTemplateByPhoneNumber_operation_1.SendTemplateByPhoneNumber(), }, channel: { list: new ListChannels_operation_1.ListChannels(), }, template: { list: new ListTemplates_operation_1.ListTemplates(), }, webhook: { list: new ListWebhooks_operation_1.ListWebhooks(), create: new CreateWebhook_operation_1.CreateWebhook(), }, account: { list: new ListAccounts_operation_1.ListAccounts(), }, }; const collectProperties = () => { const baseProperties = [ { displayName: 'Resource', name: 'resource', type: 'options', noDataExpression: true, options: [ { name: 'App', value: 'app' }, { name: 'Contact', value: 'contact' }, { name: 'Channel', value: 'channel' }, { name: 'Message', value: 'message' }, { name: 'Tag', value: 'tag' }, { name: 'Template', value: 'template' }, { name: 'Webhook', value: 'webhook' }, { name: 'Account', value: 'account' }, ], default: 'contact', }, { displayName: 'Operation', name: 'operation', type: 'options', noDataExpression: true, displayOptions: { show: { resource: ['contact'] } }, options: [ { name: 'List', value: 'list', description: 'Listar todos os contatos' }, { name: 'Add Tag', value: 'addTag', description: 'Adicionar tag a um contato' }, { name: 'Forward', value: 'forward', description: 'Encaminhar contato' }, ], default: 'list', }, { displayName: 'Operation', name: 'operation', type: 'options', noDataExpression: true, displayOptions: { show: { resource: ['app'] } }, options: [ { name: 'List', value: 'list', description: 'Listar aplicações' }, { name: 'Create', value: 'create', description: 'Criar nova aplicação' }, ], default: 'list', }, { displayName: 'Operation', name: 'operation', type: 'options', noDataExpression: true, displayOptions: { show: { resource: ['tag'] } }, options: [ { name: 'List', value: 'list', description: 'Listar tags' }, { name: 'Create', value: 'create', description: 'Criar nova tag' }, ], default: 'list', }, { displayName: 'Operation', name: 'operation', type: 'options', noDataExpression: true, displayOptions: { show: { resource: ['message'] } }, options: [ { name: 'Send By Contact ID', value: 'sendByContactId', description: 'Enviar mensagem por ID do contato' }, { name: 'Send By Phone', value: 'sendByPhone', description: 'Enviar mensagem por número de telefone' }, { name: 'Send Template By Contact ID', value: 'sendTemplateByContactId', description: 'Enviar template por ID do contato' }, { name: 'Send Template By Phone Number', value: 'sendTemplateByPhoneNumber', description: 'Enviar template por número de telefone' }, ], default: 'sendByContactId', }, { displayName: 'Operation', name: 'operation', type: 'options', noDataExpression: true, displayOptions: { show: { resource: ['channel'] } }, options: [{ name: 'List', value: 'list', description: 'Listar canais' }], default: 'list', }, { displayName: 'Operation', name: 'operation', type: 'options', noDataExpression: true, displayOptions: { show: { resource: ['template'] } }, options: [{ name: 'List', value: 'list', description: 'Listar templates' }], default: 'list', }, { displayName: 'Operation', name: 'operation', type: 'options', noDataExpression: true, displayOptions: { show: { resource: ['webhook'] } }, options: [ { name: 'List', value: 'list', description: 'Listar webhooks' }, { name: 'Create', value: 'create', description: 'Criar webhook' }, ], default: 'list', }, { displayName: 'Operation', name: 'operation', type: 'options', noDataExpression: true, displayOptions: { show: { resource: ['account'] } }, options: [ { name: 'List', value: 'list', description: 'Listar contas da organização' }, ], default: 'list', }, ]; const allProperties = [...baseProperties]; Object.entries(nodes).forEach(([resource, operations]) => { Object.entries(operations).forEach(([operation, nodeInstance]) => { const nodeProperties = nodeInstance.description.properties || []; const specificProperties = nodeProperties.filter((prop) => prop.name !== 'resource' && prop.name !== 'operation'); specificProperties.forEach((prop) => { var _a; let modifiedProp; if (resource === 'contact' && operation === 'forward') { if (prop.name === 'userUuid') { modifiedProp = { ...prop, displayOptions: { show: { resource: ['contact'], operation: ['forward'], forwardType: ['user'], }, }, }; } else if (prop.name === 'teamUuid') { modifiedProp = { ...prop, displayOptions: { show: { resource: ['contact'], operation: ['forward'], forwardType: ['team'], }, }, }; } else { modifiedProp = { ...prop, displayOptions: { show: { resource: [resource], operation: [operation], }, }, }; } } else { modifiedProp = { ...prop, displayOptions: { show: { resource: [resource], operation: [operation], ...(((_a = prop.displayOptions) === null || _a === void 0 ? void 0 : _a.show) || {}), }, }, }; } allProperties.push(modifiedProp); }); }); }); return allProperties; }; this.description = { displayName: 'Poli', name: 'poli', icon: 'file:poli.svg', group: ['output'], version: 1, description: 'Node principal para interagir com a API da Poli', defaults: { name: 'Poli' }, inputs: ['main'], outputs: ['main'], credentials: [{ name: 'poliApi', required: true }], properties: collectProperties(), }; } async execute() { const resource = this.getNodeParameter('resource', 0); const operation = this.getNodeParameter('operation', 0); const nodeMap = { contact: { list: new ListContacts_operation_1.ListContacts(), addTag: new AddTagToContact_operation_1.AddTagToContact(), forward: new ForwardContact_operation_1.ForwardContact(), }, app: { list: new ListApps_operation_1.ListApps(), create: new CreateApp_operation_1.CreateApp(), }, tag: { list: new ListTags_operation_1.ListTags(), create: new CreateTag_operation_1.CreateTag(), }, message: { sendByContactId: new SendMessageByContactId_operation_1.SendMessageByContactId(), sendByPhone: new SendMessageByPhoneNumber_operation_1.SendMessageByPhoneNumber(), sendTemplateByContactId: new SendTemplateByContactId_operation_1.SendTemplateByContactId(), sendTemplateByPhoneNumber: new SendTemplateByPhoneNumber_operation_1.SendTemplateByPhoneNumber(), }, channel: { list: new ListChannels_operation_1.ListChannels(), }, template: { list: new ListTemplates_operation_1.ListTemplates(), }, webhook: { list: new ListWebhooks_operation_1.ListWebhooks(), create: new CreateWebhook_operation_1.CreateWebhook(), }, account: { list: new ListAccounts_operation_1.ListAccounts(), }, }; const resourceNodes = nodeMap[resource]; if (!resourceNodes) throw new Error(`Resource '${resource}' não encontrado`); const targetNode = resourceNodes[operation]; if (!targetNode) throw new Error(`Operação '${operation}' não encontrada para o resource '${resource}'`); return await targetNode.execute.call(this); } } exports.Poli = Poli; //# sourceMappingURL=Poli.node.js.map