@poli-digital/n8n-nodes-poli
Version:
Nó para interagir com a API da Poli
126 lines • 4.39 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.UpdateContact = exports.executeUpdateContact = exports.updateContactFields = void 0;
const n8n_workflow_1 = require("n8n-workflow");
const transport_1 = require("./transport");
const parameterUtils_1 = require("./utils/parameterUtils");
exports.updateContactFields = [
{
displayName: 'Contact UUID',
name: 'contactUuid',
type: 'string',
required: true,
default: '',
description: 'UUID do contato para atualizar',
},
{
displayName: 'Attributes',
name: 'attributes',
type: 'collection',
placeholder: 'Add Attribute',
default: {},
options: [
{
displayName: 'Name',
name: 'name',
type: 'string',
default: '',
description: 'Nome do contato',
},
{
displayName: 'Picture File UUID',
name: 'pictureFileId',
type: 'string',
default: '',
description: 'ID do arquivo da imagem de perfil',
},
],
},
{
displayName: 'Options',
name: 'options',
type: 'collection',
placeholder: 'Add Option',
default: {},
options: [
{
displayName: 'Include',
name: 'include',
type: 'multiOptions',
options: [
{ name: 'Attributes', value: 'attributes' },
{ name: 'Status', value: 'status' },
{ name: 'Tags', value: 'tags' },
{ name: 'Channels', value: 'channels' },
{ name: 'Metadata', value: 'metadata' },
],
default: ['attributes'],
description: 'Dados adicionais para incluir na resposta',
},
],
},
];
async function executeUpdateContact() {
const items = this.getInputData();
const returnData = [];
for (let i = 0; i < items.length; i++) {
try {
const contactUuid = (0, parameterUtils_1.getParameterSafe)(this, 'contactUuid', i, '', true);
const attributes = (0, parameterUtils_1.getParameterSafe)(this, 'attributes', i, {});
const options = (0, parameterUtils_1.getParameterSafe)(this, 'options', i, {});
if (!contactUuid) {
throw new n8n_workflow_1.NodeApiError(this.getNode(), {
message: 'Contact UUID é obrigatório',
});
}
const body = {
attributes: {}
};
if (attributes.name) {
body.attributes.name = attributes.name;
}
if (attributes.pictureFileId) {
body.attributes.picture = {
file_id: attributes.pictureFileId
};
}
const params = new URLSearchParams();
const includeValues = options.include && options.include.length > 0
? options.include
: ['attributes'];
if (includeValues.length > 0) {
params.append('include', includeValues.join(','));
}
const endpoint = `/contacts/${contactUuid}?${params.toString()}`;
const responseData = await transport_1.apiRequest.call(this, 'PUT', endpoint, body);
returnData.push({ json: responseData });
}
catch (error) {
throw new n8n_workflow_1.NodeApiError(this.getNode(), error);
}
}
return [returnData];
}
exports.executeUpdateContact = executeUpdateContact;
class UpdateContact {
constructor() {
this.description = {
displayName: 'Update Contact',
name: 'updateContact',
group: ['output'],
version: 1,
description: 'Update a contact in Poli API',
defaults: {
name: 'Update Contact',
},
inputs: ['main'],
outputs: ['main'],
properties: exports.updateContactFields,
};
}
async execute() {
return executeUpdateContact.call(this);
}
}
exports.UpdateContact = UpdateContact;
//# sourceMappingURL=UpdateContact.operation.js.map