From abc2f2a51596d962915d898cbc5c6d3ce92afa18 Mon Sep 17 00:00:00 2001 From: Ricardo Espinoza Date: Thu, 8 Jul 2021 04:12:19 -0400 Subject: [PATCH] :zap: Add resource contact segment and company contact to Mautic node (#1975) * Add contact To Segment operation * :zap: Improvements to #1973 * :zap: Rename resource Co-authored-by: Rodrigo Correia Co-authored-by: Jan Oberhauser --- ...iption.ts => CompanyContactDescription.ts} | 12 +-- .../nodes/Mautic/ContactSegmentDescription.ts | 82 ++++++++++++++++++ .../nodes-base/nodes/Mautic/Mautic.node.ts | 60 ++++++++++--- .../nodes/Mautic/MauticTrigger.node.ts | 2 +- packages/nodes-base/nodes/Mautic/mautic.png | Bin 2092 -> 0 bytes packages/nodes-base/nodes/Mautic/mautic.svg | 17 ++++ 6 files changed, 156 insertions(+), 17 deletions(-) rename packages/nodes-base/nodes/Mautic/{ContactCompanyDescription.ts => CompanyContactDescription.ts} (84%) create mode 100644 packages/nodes-base/nodes/Mautic/ContactSegmentDescription.ts delete mode 100644 packages/nodes-base/nodes/Mautic/mautic.png create mode 100644 packages/nodes-base/nodes/Mautic/mautic.svg 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 6aabd5bc93..bb4f3faece 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 0000000000..302002b9dc --- /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 56d7eb8f2b..6296666049 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 239350bc50..019e89b2df 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 d427cae7dc0791b34849edb5b5669863180e5888..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2092 zcmYL~dpy(oAIG<**c_aO+@&#*`>-Urw-A&2S;a^bg_M&zhjh{s4Kan5$fcG`6!oyp zZF24Amd$0-au;EvD7NpJ^!uI16hJw(w1%bfUM_j!RibAY^fxCacfaWCVgkl5o0J@ogZYnYnZ+chUeG#uW>i<#* z6cM=L^8}2I8f-xRPcMT1O!%{1qzLG!Uj_JlEPkVSGqpJxp#91UXr>}vNH_cGH^%-S zHpl+23x)O12k7Ra(9J(jSZlh`$k^!JTxN6gb%yaKY%U;TVXcW9K3~8bx9*{2r zfMM<#OcjBs%pL#0n^1Zrs0e5>_c-wo=-BHUS_v>rfqFBakaD064YZAI_3@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E_Q_$nGJ;#iwixHJB7$F2k=}R#^$@~gx%%y>)hyw@0c$#Doxp!aykt->Cj2f03A2guD9{)7W<>E zo;9|XywS)uoOc?ZQJI`;h%j+Jffm{~g1fJoi?|a9*W?;L$%h98*G|W5S*}31i18dS0=E2|;pIv0i!;!(;wJmB+ov VD>}ghY0;+zaz2Q4tgsJE_!rj32VVdH diff --git a/packages/nodes-base/nodes/Mautic/mautic.svg b/packages/nodes-base/nodes/Mautic/mautic.svg new file mode 100644 index 0000000000..0a0ac69608 --- /dev/null +++ b/packages/nodes-base/nodes/Mautic/mautic.svg @@ -0,0 +1,17 @@ + + + + + + + + + +