mirror of
https://github.com/n8n-io/n8n.git
synced 2025-02-21 02:56:40 -08:00
✨ 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 <luizeof@gmail.com>
This commit is contained in:
parent
7b752ce492
commit
7dcbaedea6
|
@ -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[];
|
|
@ -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<INodePropertyOptions[]> {
|
||||
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') {
|
||||
|
|
Loading…
Reference in a new issue