mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
⚡ Extend Mautic node (#2839)
* re-submit for #2218 * ⚡ small fixes * ⚡ nodelinter fixes * ⚡ Improvements * ⚡ Improvements * ⚡ Add description and fix default value Co-authored-by: Luiz Eduardo de Oliveira Fonseca <luizeof@gmail.com> Co-authored-by: michael-radency <michael.k@radency.com> Co-authored-by: Jan Oberhauser <jan.oberhauser@gmail.com>
This commit is contained in:
@@ -9,6 +9,7 @@ import {
|
||||
INodePropertyOptions,
|
||||
INodeType,
|
||||
INodeTypeDescription,
|
||||
JsonObject,
|
||||
NodeApiError,
|
||||
NodeOperationError,
|
||||
} from 'n8n-workflow';
|
||||
@@ -24,6 +25,11 @@ import {
|
||||
contactOperations,
|
||||
} from './ContactDescription';
|
||||
|
||||
import {
|
||||
segmentEmailFields,
|
||||
segmentEmailOperations,
|
||||
} from './SegmentEmailDescription';
|
||||
|
||||
import {
|
||||
companyFields,
|
||||
companyOperations,
|
||||
@@ -59,6 +65,7 @@ export class Mautic implements INodeType {
|
||||
description: 'Consume Mautic API',
|
||||
defaults: {
|
||||
name: 'Mautic',
|
||||
color: '#52619b',
|
||||
},
|
||||
inputs: ['main'],
|
||||
outputs: ['main'],
|
||||
@@ -107,6 +114,7 @@ export class Mautic implements INodeType {
|
||||
displayName: 'Resource',
|
||||
name: 'resource',
|
||||
type: 'options',
|
||||
noDataExpression: true,
|
||||
options: [
|
||||
{
|
||||
name: 'Campaign Contact',
|
||||
@@ -133,9 +141,14 @@ export class Mautic implements INodeType {
|
||||
value: 'contactSegment',
|
||||
description: 'Add/remove contacts to/from a segment',
|
||||
},
|
||||
{
|
||||
name: 'Segment Email',
|
||||
value: 'segmentEmail',
|
||||
description: 'Send an email',
|
||||
},
|
||||
],
|
||||
default: 'contact',
|
||||
description: 'Resource to consume.',
|
||||
description: 'Resource to consume',
|
||||
},
|
||||
...companyOperations,
|
||||
...companyFields,
|
||||
@@ -147,6 +160,8 @@ export class Mautic implements INodeType {
|
||||
...campaignContactFields,
|
||||
...companyContactOperations,
|
||||
...companyContactFields,
|
||||
...segmentEmailOperations,
|
||||
...segmentEmailFields,
|
||||
],
|
||||
};
|
||||
|
||||
@@ -258,6 +273,49 @@ export class Mautic implements INodeType {
|
||||
}
|
||||
return returnData;
|
||||
},
|
||||
// Get all the available emails to display them to user so that he can
|
||||
// select them easily
|
||||
async getEmails(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||
const returnData: INodePropertyOptions[] = [];
|
||||
const emails = await mauticApiRequestAllItems.call(this, 'emails', 'GET', '/emails');
|
||||
for (const email of emails) {
|
||||
returnData.push({
|
||||
name: email.name,
|
||||
value: email.id,
|
||||
});
|
||||
}
|
||||
return returnData;
|
||||
},
|
||||
// Get all the available list / segment emails to display them to user so that he can
|
||||
// select them easily
|
||||
async getSegmentEmails(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||
const returnData: INodePropertyOptions[] = [];
|
||||
const emails = await mauticApiRequestAllItems.call(this, 'emails', 'GET', '/emails');
|
||||
for (const email of emails) {
|
||||
if (email.emailType === 'list') {
|
||||
returnData.push({
|
||||
name: email.name,
|
||||
value: email.id,
|
||||
});
|
||||
}
|
||||
}
|
||||
return returnData;
|
||||
},
|
||||
// Get all the available campaign / template emails to display them to user so that he can
|
||||
// select them easily
|
||||
async getCampaignEmails(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||
const returnData: INodePropertyOptions[] = [];
|
||||
const emails = await mauticApiRequestAllItems.call(this, 'emails', 'GET', '/emails');
|
||||
for (const email of emails) {
|
||||
if (email.emailType === 'template') {
|
||||
returnData.push({
|
||||
name: email.name,
|
||||
value: email.id,
|
||||
});
|
||||
}
|
||||
}
|
||||
return returnData;
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
@@ -781,6 +839,36 @@ export class Mautic implements INodeType {
|
||||
responseData = responseData.map(item => item.fields.all);
|
||||
}
|
||||
}
|
||||
//https://developer.mautic.org/#send-email-to-contact
|
||||
if (operation === 'sendEmail') {
|
||||
const contactId = this.getNodeParameter('contactId', i) as string;
|
||||
const campaignEmailId = this.getNodeParameter('campaignEmailId', i) as string;
|
||||
responseData = await mauticApiRequest.call(this, 'POST', `/emails/${campaignEmailId}/contact/${contactId}/send`);
|
||||
}
|
||||
//https://developer.mautic.org/#add-do-not-contact
|
||||
//https://developer.mautic.org/#remove-from-do-not-contact
|
||||
if (operation === 'editDoNotContactList') {
|
||||
const contactId = this.getNodeParameter('contactId', i) as string;
|
||||
const action = this.getNodeParameter('action', i) as string;
|
||||
const channel = this.getNodeParameter('channel', i) as string;
|
||||
const body: IDataObject = {};
|
||||
if (action === 'add') {
|
||||
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
|
||||
Object.assign(body, additionalFields);
|
||||
}
|
||||
responseData = await mauticApiRequest.call(this, 'POST', `/contacts/${contactId}/dnc/${channel}/${action}`, body);
|
||||
responseData = responseData.contact;
|
||||
}
|
||||
|
||||
//https://developer.mautic.org/#add-points
|
||||
//https://developer.mautic.org/#subtract-points
|
||||
if (operation === 'editContactPoint') {
|
||||
const contactId = this.getNodeParameter('contactId', i) as string;
|
||||
const action = this.getNodeParameter('action', i) as string;
|
||||
const points = this.getNodeParameter('points', i) as string;
|
||||
const path = (action === 'add') ? 'plus' : 'minus';
|
||||
responseData = await mauticApiRequest.call(this, 'POST', `/contacts/${contactId}/points/${path}/${points}`);
|
||||
}
|
||||
}
|
||||
|
||||
if (resource === 'contactSegment') {
|
||||
@@ -813,6 +901,14 @@ export class Mautic implements INodeType {
|
||||
}
|
||||
}
|
||||
|
||||
if (resource === 'segmentEmail') {
|
||||
//https://developer.mautic.org/#send-email-to-segment
|
||||
if (operation === 'send') {
|
||||
const segmentEmailId = this.getNodeParameter('segmentEmailId', i) as string;
|
||||
responseData = await mauticApiRequest.call(this, 'POST', `/emails/${segmentEmailId}/send`);
|
||||
}
|
||||
}
|
||||
|
||||
if (resource === 'companyContact') {
|
||||
//https://developer.mautic.org/#add-contact-to-a-company
|
||||
if (operation === 'add') {
|
||||
@@ -843,7 +939,7 @@ export class Mautic implements INodeType {
|
||||
}
|
||||
} catch (error) {
|
||||
if (this.continueOnFail()) {
|
||||
returnData.push({ error: error.message });
|
||||
returnData.push({ error: (error as JsonObject).message });
|
||||
continue;
|
||||
}
|
||||
throw error;
|
||||
|
||||
Reference in New Issue
Block a user