From 7dcbaedea6c0a141f3295ff51b99362d2e95aba0 Mon Sep 17 00:00:00 2001 From: Omar Ajoue Date: Fri, 3 Sep 2021 18:30:29 +0200 Subject: [PATCH] :sparkles: Add Mautic Campaings to Node Actions (#2164) * added mautic campaings node actions * Changed campaign contact term and fixed typos Co-authored-by: Luiz Eduardo de Oliveira Fonseca --- .../Mautic/CampaignContactDescription.ts | 82 +++++++++++++++++++ .../nodes-base/nodes/Mautic/Mautic.node.ts | 40 +++++++++ 2 files changed, 122 insertions(+) create mode 100644 packages/nodes-base/nodes/Mautic/CampaignContactDescription.ts diff --git a/packages/nodes-base/nodes/Mautic/CampaignContactDescription.ts b/packages/nodes-base/nodes/Mautic/CampaignContactDescription.ts new file mode 100644 index 0000000000..55edfdbc7d --- /dev/null +++ b/packages/nodes-base/nodes/Mautic/CampaignContactDescription.ts @@ -0,0 +1,82 @@ +import { + INodeProperties, +} from 'n8n-workflow'; + +export const campaignContactOperations = [ + { + displayName: 'Operation', + name: 'operation', + type: 'options', + displayOptions: { + show: { + resource: [ + 'campaignContact', + ], + }, + }, + options: [ + { + name: 'Add', + value: 'add', + description: 'Add contact to a campaign', + }, + { + name: 'Remove', + value: 'remove', + description: 'Remove contact from a campaign', + }, + ], + default: 'add', + description: 'The operation to perform.', + }, +] as INodeProperties[]; + +export const campaignContactFields = [ + + /* -------------------------------------------------------------------------- */ + /* campaignContact:add */ + /* -------------------------------------------------------------------------- */ + { + displayName: 'Contact ID', + name: 'contactId', + type: 'string', + required: true, + displayOptions: { + show: { + resource: [ + 'campaignContact', + ], + operation: [ + 'add', + 'remove', + ], + }, + }, + default: '', + description: 'Contact ID', + }, + { + + displayName: 'Campaign ID', + name: 'campaignId', + type: 'options', + required: true, + displayOptions: { + show: { + resource: [ + 'campaignContact', + ], + operation: [ + 'add', + 'remove', + ], + }, + }, + typeOptions: { + loadOptionsMethod: 'getCampaigns', + }, + default: '', + description: 'Campaign ID', + + }, +] as INodeProperties[]; diff --git a/packages/nodes-base/nodes/Mautic/Mautic.node.ts b/packages/nodes-base/nodes/Mautic/Mautic.node.ts index e035f4205b..75a23fd1cd 100644 --- a/packages/nodes-base/nodes/Mautic/Mautic.node.ts +++ b/packages/nodes-base/nodes/Mautic/Mautic.node.ts @@ -39,6 +39,11 @@ import { contactSegmentOperations, } from './ContactSegmentDescription'; +import { + campaignContactFields, + campaignContactOperations, +} from './CampaignContactDescription'; + import { snakeCase, } from 'change-case'; @@ -104,6 +109,11 @@ export class Mautic implements INodeType { name: 'resource', type: 'options', options: [ + { + name: 'Campaign Contact', + value: 'campaignContact', + description: 'Add/remove contacts to/from a campaign', + }, { name: 'Company', value: 'company', @@ -134,6 +144,8 @@ export class Mautic implements INodeType { ...contactFields, ...contactSegmentOperations, ...contactSegmentFields, + ...campaignContactOperations, + ...campaignContactFields, ...companyContactOperations, ...companyContactFields, ], @@ -234,6 +246,19 @@ export class Mautic implements INodeType { } return returnData; }, + // Get all the available campaings to display them to user so that he can + // select them easily + async getCampaigns(this: ILoadOptionsFunctions): Promise { + const returnData: INodePropertyOptions[] = []; + const campaings = await mauticApiRequestAllItems.call(this, 'campaigns', 'GET', '/campaigns'); + for (const campaign of campaings) { + returnData.push({ + name: campaign.name, + value: campaign.id, + }); + } + return returnData; + }, }, }; @@ -774,6 +799,21 @@ export class Mautic implements INodeType { } } + if (resource === 'campaignContact') { + //https://developer.mautic.org/#add-contact-to-a-campaign + if (operation === 'add') { + const contactId = this.getNodeParameter('contactId', i) as string; + const campaignId = this.getNodeParameter('campaignId', i) as string; + responseData = await mauticApiRequest.call(this, 'POST', `/campaigns/${campaignId}/contact/${contactId}/add`); + } + //https://developer.mautic.org/#remove-contact-from-a-campaign + if (operation === 'remove') { + const contactId = this.getNodeParameter('contactId', i) as string; + const campaignId = this.getNodeParameter('campaignId', i) as string; + responseData = await mauticApiRequest.call(this, 'POST', `/campaigns/${campaignId}/contact/${contactId}/remove`); + } + } + if (resource === 'companyContact') { //https://developer.mautic.org/#add-contact-to-a-company if (operation === 'add') {