diff --git a/packages/nodes-base/nodes/Mautic/ContactCompanyDescription.ts b/packages/nodes-base/nodes/Mautic/CompanyContactDescription.ts similarity index 84% rename from packages/nodes-base/nodes/Mautic/ContactCompanyDescription.ts rename to packages/nodes-base/nodes/Mautic/CompanyContactDescription.ts index 6aabd5bc9..bb4f3faec 100644 --- a/packages/nodes-base/nodes/Mautic/ContactCompanyDescription.ts +++ b/packages/nodes-base/nodes/Mautic/CompanyContactDescription.ts @@ -2,7 +2,7 @@ import { INodeProperties, } from 'n8n-workflow'; -export const contactCompanyOperations = [ +export const companyContactOperations = [ { displayName: 'Operation', name: 'operation', @@ -10,7 +10,7 @@ export const contactCompanyOperations = [ displayOptions: { show: { resource: [ - 'contactCompany', + 'companyContact', ], }, }, @@ -31,10 +31,10 @@ export const contactCompanyOperations = [ }, ] as INodeProperties[]; -export const contactCompanyFields = [ +export const companyContactFields = [ /* -------------------------------------------------------------------------- */ - /* contactCompany:add */ + /* companyContact:add */ /* -------------------------------------------------------------------------- */ { displayName: 'Contact ID', @@ -43,7 +43,7 @@ export const contactCompanyFields = [ displayOptions: { show: { resource: [ - 'contactCompany', + 'companyContact', ], operation: [ 'add', @@ -61,7 +61,7 @@ export const contactCompanyFields = [ displayOptions: { show: { resource: [ - 'contactCompany', + 'companyContact', ], operation: [ 'add', diff --git a/packages/nodes-base/nodes/Mautic/ContactSegmentDescription.ts b/packages/nodes-base/nodes/Mautic/ContactSegmentDescription.ts new file mode 100644 index 000000000..302002b9d --- /dev/null +++ b/packages/nodes-base/nodes/Mautic/ContactSegmentDescription.ts @@ -0,0 +1,82 @@ +import { + INodeProperties, +} from 'n8n-workflow'; + +export const contactSegmentOperations = [ + { + displayName: 'Operation', + name: 'operation', + type: 'options', + displayOptions: { + show: { + resource: [ + 'contactSegment', + ], + }, + }, + options: [ + { + name: 'Add', + value: 'add', + description: 'Add contact to a segment', + }, + { + name: 'Remove', + value: 'remove', + description: 'Remove contact from a segment', + }, + ], + default: 'add', + description: 'The operation to perform.', + }, +] as INodeProperties[]; + +export const contactSegmentFields = [ + + /* -------------------------------------------------------------------------- */ + /* contactSegment:add */ + /* -------------------------------------------------------------------------- */ + { + displayName: 'Contact ID', + name: 'contactId', + type: 'string', + required: true, + displayOptions: { + show: { + resource: [ + 'contactSegment', + ], + operation: [ + 'add', + 'remove', + ], + }, + }, + default: '', + description: 'Contact ID', + }, + { + + displayName: 'Segment ID', + name: 'segmentId', + type: 'options', + required: true, + displayOptions: { + show: { + resource: [ + 'contactSegment', + ], + operation: [ + 'add', + 'remove', + ], + }, + }, + typeOptions: { + loadOptionsMethod: 'getSegments', + }, + default: '', + description: 'Segment ID', + + }, +] as INodeProperties[]; diff --git a/packages/nodes-base/nodes/Mautic/Mautic.node.ts b/packages/nodes-base/nodes/Mautic/Mautic.node.ts index 56d7eb8f2..629666604 100644 --- a/packages/nodes-base/nodes/Mautic/Mautic.node.ts +++ b/packages/nodes-base/nodes/Mautic/Mautic.node.ts @@ -30,9 +30,14 @@ import { } from './CompanyDescription'; import { - contactCompanyFields, - contactCompanyOperations, -} from './ContactCompanyDescription'; + companyContactFields, + companyContactOperations, +} from './CompanyContactDescription'; + +import { + contactSegmentFields, + contactSegmentOperations, +} from './ContactSegmentDescription'; import { snakeCase, @@ -42,7 +47,7 @@ export class Mautic implements INodeType { description: INodeTypeDescription = { displayName: 'Mautic', name: 'mautic', - icon: 'file:mautic.png', + icon: 'file:mautic.svg', group: ['output'], version: 1, subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}', @@ -104,15 +109,20 @@ export class Mautic implements INodeType { value: 'company', description: 'Create or modify a company', }, + { + name: 'Company Contact', + value: 'companyContact', + description: 'Add/remove contacts to/from a company', + }, { name: 'Contact', value: 'contact', description: 'Create & modify contacts', }, { - name: 'Contact <> Company', - value: 'contactCompany', - description: 'Add/ remove contacts from a company', + name: 'Contact Segment', + value: 'contactSegment', + description: 'Add/remove contacts to/from a segment', }, ], default: 'contact', @@ -122,8 +132,10 @@ export class Mautic implements INodeType { ...companyFields, ...contactOperations, ...contactFields, - ...contactCompanyOperations, - ...contactCompanyFields, + ...contactSegmentOperations, + ...contactSegmentFields, + ...companyContactOperations, + ...companyContactFields, ], }; @@ -194,6 +206,19 @@ export class Mautic implements INodeType { } return returnData; }, + // Get all the available segments to display them to user so that he can + // select them easily + async getSegments(this: ILoadOptionsFunctions): Promise { + const returnData: INodePropertyOptions[] = []; + const segments = await mauticApiRequestAllItems.call(this, 'lists', 'GET', '/segments'); + for (const segment of segments) { + returnData.push({ + name: segment.name, + value: segment.id, + }); + } + return returnData; + }, }, }; @@ -547,7 +572,22 @@ export class Mautic implements INodeType { } } - if (resource === 'contactCompany') { + if (resource === 'contactSegment') { + //https://developer.mautic.org/?php#add-contact-to-a-segment + if (operation === 'add') { + const contactId = this.getNodeParameter('contactId', i) as string; + const segmentId = this.getNodeParameter('segmentId', i) as string; + responseData = await mauticApiRequest.call(this, 'POST', `/segments/${segmentId}/contact/${contactId}/add`); + } + //https://developer.mautic.org/#remove-contact-from-a-segment + if (operation === 'remove') { + const contactId = this.getNodeParameter('contactId', i) as string; + const segmentId = this.getNodeParameter('segmentId', i) as string; + responseData = await mauticApiRequest.call(this, 'POST', `/segments/${segmentId}/contact/${contactId}/remove`); + } + } + + if (resource === 'companyContact') { //https://developer.mautic.org/#add-contact-to-a-company if (operation === 'add') { const contactId = this.getNodeParameter('contactId', i) as string; diff --git a/packages/nodes-base/nodes/Mautic/MauticTrigger.node.ts b/packages/nodes-base/nodes/Mautic/MauticTrigger.node.ts index 239350bc5..019e89b2d 100644 --- a/packages/nodes-base/nodes/Mautic/MauticTrigger.node.ts +++ b/packages/nodes-base/nodes/Mautic/MauticTrigger.node.ts @@ -24,7 +24,7 @@ export class MauticTrigger implements INodeType { description: INodeTypeDescription = { displayName: 'Mautic Trigger', name: 'mauticTrigger', - icon: 'file:mautic.png', + icon: 'file:mautic.svg', group: ['trigger'], version: 1, description: 'Handle Mautic events via webhooks', diff --git a/packages/nodes-base/nodes/Mautic/mautic.png b/packages/nodes-base/nodes/Mautic/mautic.png deleted file mode 100644 index d427cae7d..000000000 Binary files a/packages/nodes-base/nodes/Mautic/mautic.png and /dev/null differ diff --git a/packages/nodes-base/nodes/Mautic/mautic.svg b/packages/nodes-base/nodes/Mautic/mautic.svg new file mode 100644 index 000000000..0a0ac6960 --- /dev/null +++ b/packages/nodes-base/nodes/Mautic/mautic.svg @@ -0,0 +1,17 @@ + + + + + + + + + +