first commit
Security: Sync from Public / sync-from-public (push) Has been cancelled
Test: Benchmark Nightly / build (push) Has been cancelled
Test: Benchmark Nightly / Notify Cats on failure (push) Has been cancelled
CI: Python / Checks (push) Has been cancelled
Test: Evals Python / Workflow Comparison Python (push) Has been cancelled
Util: Check Docs URLs / check-docs-urls (push) Has been cancelled
Test: Visual Storybook / Cloudflare Pages (push) Has been cancelled
Test: E2E Performance / build-and-test-performance (push) Has been cancelled
Test: Workflows Nightly / Run Workflow Tests (push) Has been cancelled
Util: Cleanup CI Docker Images / Delete stale CI images (push) Has been cancelled
Test: Benchmark Destroy Env / build (push) Has been cancelled
Util: Update Node Popularity / update-popularity (push) Has been cancelled
Test: E2E Coverage Weekly / Coverage Tests (push) Has been cancelled
Security: Sync from Public / sync-from-public (push) Has been cancelled
Test: Benchmark Nightly / build (push) Has been cancelled
Test: Benchmark Nightly / Notify Cats on failure (push) Has been cancelled
CI: Python / Checks (push) Has been cancelled
Test: Evals Python / Workflow Comparison Python (push) Has been cancelled
Util: Check Docs URLs / check-docs-urls (push) Has been cancelled
Test: Visual Storybook / Cloudflare Pages (push) Has been cancelled
Test: E2E Performance / build-and-test-performance (push) Has been cancelled
Test: Workflows Nightly / Run Workflow Tests (push) Has been cancelled
Util: Cleanup CI Docker Images / Delete stale CI images (push) Has been cancelled
Test: Benchmark Destroy Env / build (push) Has been cancelled
Util: Update Node Popularity / update-popularity (push) Has been cancelled
Test: E2E Coverage Weekly / Coverage Tests (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,532 @@
|
||||
import type {
|
||||
IExecuteSingleFunctions,
|
||||
IHttpRequestOptions,
|
||||
INodeProperties,
|
||||
JsonObject,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import { BrevoNode } from './GenericFunctions';
|
||||
|
||||
export const attributeOperations: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Operation',
|
||||
name: 'operation',
|
||||
type: 'options',
|
||||
noDataExpression: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['attribute'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: 'Create',
|
||||
value: 'create',
|
||||
routing: {
|
||||
request: {
|
||||
method: 'POST',
|
||||
url: '=/v3/contacts/attributes/{{$parameter.attributeCategory}}/{{encodeURI($parameter.attributeName)}}',
|
||||
},
|
||||
output: {
|
||||
postReceive: [
|
||||
{
|
||||
type: 'set',
|
||||
properties: {
|
||||
value: '={{ { "success": true } }}', // Also possible to use the original response data
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
send: {
|
||||
preSend: [
|
||||
async function (
|
||||
this: IExecuteSingleFunctions,
|
||||
requestOptions: IHttpRequestOptions,
|
||||
): Promise<IHttpRequestOptions> {
|
||||
const selectedCategory = this.getNodeParameter('attributeCategory') as string;
|
||||
const override = BrevoNode.INTERCEPTORS.get(selectedCategory);
|
||||
if (override) {
|
||||
override.call(this, requestOptions.body! as JsonObject);
|
||||
}
|
||||
|
||||
return requestOptions;
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
action: 'Create an attribute',
|
||||
},
|
||||
{
|
||||
name: 'Update',
|
||||
value: 'update',
|
||||
routing: {
|
||||
request: {
|
||||
method: 'PUT',
|
||||
url: '=/v3/contacts/attributes/{{$parameter.updateAttributeCategory}}/{{encodeURI($parameter.updateAttributeName)}}',
|
||||
},
|
||||
},
|
||||
action: 'Update an attribute',
|
||||
},
|
||||
{
|
||||
name: 'Delete',
|
||||
value: 'delete',
|
||||
routing: {
|
||||
request: {
|
||||
method: 'DELETE',
|
||||
url: '=/v3/contacts/attributes/{{$parameter.deleteAttributeCategory}}/{{encodeURI($parameter.deleteAttributeName)}}',
|
||||
},
|
||||
output: {
|
||||
postReceive: [
|
||||
{
|
||||
type: 'set',
|
||||
properties: {
|
||||
value: '={{ { "success": true } }}', // Also possible to use the original response data
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
action: 'Delete an attribute',
|
||||
},
|
||||
{
|
||||
name: 'Get Many',
|
||||
value: 'getAll',
|
||||
routing: {
|
||||
request: {
|
||||
method: 'GET',
|
||||
url: 'v3/contacts/attributes',
|
||||
},
|
||||
send: {
|
||||
paginate: false,
|
||||
},
|
||||
output: {
|
||||
postReceive: [
|
||||
{
|
||||
type: 'rootProperty',
|
||||
properties: {
|
||||
property: 'attributes',
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
action: 'Get many attributes',
|
||||
},
|
||||
],
|
||||
default: 'create',
|
||||
},
|
||||
];
|
||||
|
||||
const createAttributeOperations: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Category',
|
||||
name: 'attributeCategory',
|
||||
default: 'normal',
|
||||
description: 'Category of the attribute',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['attribute'],
|
||||
operation: ['create'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: 'Calculated',
|
||||
value: 'calculated',
|
||||
},
|
||||
{
|
||||
name: 'Category',
|
||||
value: 'category',
|
||||
},
|
||||
{
|
||||
name: 'Global',
|
||||
value: 'global',
|
||||
},
|
||||
{
|
||||
name: 'Normal',
|
||||
value: 'normal',
|
||||
},
|
||||
{
|
||||
name: 'Transactional',
|
||||
value: 'transactional',
|
||||
},
|
||||
],
|
||||
type: 'options',
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
displayName: 'Name',
|
||||
name: 'attributeName',
|
||||
default: '',
|
||||
description: 'Name of the attribute',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['attribute'],
|
||||
operation: ['create'],
|
||||
},
|
||||
},
|
||||
required: true,
|
||||
type: 'string',
|
||||
},
|
||||
{
|
||||
displayName: 'Type',
|
||||
name: 'attributeType',
|
||||
default: '',
|
||||
description: 'Attribute Type',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['attribute'],
|
||||
operation: ['create'],
|
||||
attributeCategory: ['normal'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: 'Boolean',
|
||||
value: 'boolean',
|
||||
},
|
||||
{
|
||||
name: 'Date',
|
||||
value: 'date',
|
||||
},
|
||||
{
|
||||
name: 'Float',
|
||||
value: 'float',
|
||||
},
|
||||
{
|
||||
name: 'Text',
|
||||
value: 'text',
|
||||
},
|
||||
],
|
||||
required: true,
|
||||
type: 'options',
|
||||
routing: {
|
||||
send: {
|
||||
type: 'body',
|
||||
property: 'type',
|
||||
value: '={{$value}}',
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Value',
|
||||
name: 'attributeValue',
|
||||
default: '',
|
||||
description: 'Value of the attribute',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['attribute'],
|
||||
operation: ['create'],
|
||||
attributeCategory: ['global', 'calculated'],
|
||||
},
|
||||
},
|
||||
type: 'string',
|
||||
placeholder: '',
|
||||
required: true,
|
||||
routing: {
|
||||
send: {
|
||||
type: 'body',
|
||||
property: 'value',
|
||||
value: '={{$value}}',
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Contact Attribute List',
|
||||
name: 'attributeCategoryList',
|
||||
type: 'collection',
|
||||
placeholder: 'Add Attributes',
|
||||
default: {},
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['attribute'],
|
||||
operation: ['create'],
|
||||
attributeCategory: ['category'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Contact Attributes',
|
||||
name: 'categoryEnumeration',
|
||||
placeholder: 'Add Attribute',
|
||||
type: 'fixedCollection',
|
||||
typeOptions: {
|
||||
multipleValues: true,
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: 'attributesValues',
|
||||
displayName: 'Attribute',
|
||||
values: [
|
||||
{
|
||||
displayName: 'Value ID',
|
||||
name: 'attributeCategoryValue',
|
||||
type: 'number',
|
||||
default: 1,
|
||||
description: 'ID of the value, must be numeric',
|
||||
routing: {
|
||||
send: {
|
||||
value: '={{$value}}',
|
||||
property: '=enumeration[{{$index}}].value',
|
||||
type: 'body',
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Label',
|
||||
name: 'attributeCategoryLabel',
|
||||
type: 'string',
|
||||
default: '',
|
||||
routing: {
|
||||
send: {
|
||||
value: '={{$value}}',
|
||||
property: '=enumeration[{{$index}}].label',
|
||||
type: 'body',
|
||||
},
|
||||
},
|
||||
description: 'Label of the value',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
default: {},
|
||||
description: 'List of values and labels that the attribute can take',
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
const updateAttributeOperations: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Category',
|
||||
name: 'updateAttributeCategory',
|
||||
default: 'calculated',
|
||||
description: 'Category of the attribute',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['attribute'],
|
||||
operation: ['update'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: 'Calculated',
|
||||
value: 'calculated',
|
||||
},
|
||||
{
|
||||
name: 'Category',
|
||||
value: 'category',
|
||||
},
|
||||
{
|
||||
name: 'Global',
|
||||
value: 'global',
|
||||
},
|
||||
],
|
||||
type: 'options',
|
||||
},
|
||||
{
|
||||
displayName: 'Name',
|
||||
name: 'updateAttributeName',
|
||||
default: '',
|
||||
description: 'Name of the existing attribute',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['attribute'],
|
||||
operation: ['update'],
|
||||
},
|
||||
},
|
||||
type: 'string',
|
||||
},
|
||||
{
|
||||
displayName: 'Value',
|
||||
name: 'updateAttributeValue',
|
||||
default: '',
|
||||
description: 'Value of the attribute to update',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['attribute'],
|
||||
operation: ['update'],
|
||||
},
|
||||
hide: {
|
||||
updateAttributeCategory: ['category'],
|
||||
},
|
||||
},
|
||||
type: 'string',
|
||||
placeholder: '',
|
||||
routing: {
|
||||
send: {
|
||||
type: 'body',
|
||||
property: 'value',
|
||||
value: '={{$value}}',
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Update Fields',
|
||||
name: 'updateAttributeCategoryList',
|
||||
default: {},
|
||||
description: 'List of the values and labels that the attribute can take',
|
||||
type: 'collection',
|
||||
placeholder: 'Add Field',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['attribute'],
|
||||
operation: ['update'],
|
||||
updateAttributeCategory: ['category'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Contact Attributes',
|
||||
name: 'updateCategoryEnumeration',
|
||||
placeholder: 'Add Attribute',
|
||||
type: 'fixedCollection',
|
||||
typeOptions: {
|
||||
multipleValues: true,
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: 'updateAttributesValues',
|
||||
displayName: 'Attribute',
|
||||
values: [
|
||||
{
|
||||
displayName: 'Value',
|
||||
name: 'attributeCategoryValue',
|
||||
type: 'number',
|
||||
default: 1,
|
||||
description: 'ID of the value, must be numeric',
|
||||
routing: {
|
||||
send: {
|
||||
value: '={{$value}}',
|
||||
property: '=enumeration[{{$index}}].value',
|
||||
type: 'body',
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Label',
|
||||
name: 'attributeCategoryLabel',
|
||||
type: 'string',
|
||||
default: '',
|
||||
routing: {
|
||||
send: {
|
||||
value: '={{$value}}',
|
||||
property: '=enumeration[{{$index}}].label',
|
||||
type: 'body',
|
||||
},
|
||||
},
|
||||
description: 'Label of the value',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
default: {},
|
||||
description: 'List of values and labels that the attribute can take',
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
const deleteAttribueOperations: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Category',
|
||||
name: 'deleteAttributeCategory',
|
||||
default: 'normal',
|
||||
description: 'Category of the attribute',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['attribute'],
|
||||
operation: ['delete'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: 'Calculated',
|
||||
value: 'calculated',
|
||||
},
|
||||
{
|
||||
name: 'Category',
|
||||
value: 'category',
|
||||
},
|
||||
{
|
||||
name: 'Global',
|
||||
value: 'global',
|
||||
},
|
||||
{
|
||||
name: 'Normal',
|
||||
value: 'normal',
|
||||
},
|
||||
{
|
||||
name: 'Transactional',
|
||||
value: 'transactional',
|
||||
},
|
||||
],
|
||||
type: 'options',
|
||||
},
|
||||
{
|
||||
displayName: 'Name',
|
||||
name: 'deleteAttributeName',
|
||||
default: '',
|
||||
description: 'Name of the attribute',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['attribute'],
|
||||
operation: ['delete'],
|
||||
},
|
||||
},
|
||||
type: 'string',
|
||||
},
|
||||
];
|
||||
|
||||
const getAllAttributeOperations: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Return All',
|
||||
name: 'returnAll',
|
||||
type: 'boolean',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['attribute'],
|
||||
operation: ['getAll'],
|
||||
},
|
||||
},
|
||||
default: false,
|
||||
description: 'Whether to return all results or only up to a given limit',
|
||||
},
|
||||
{
|
||||
displayName: 'Limit',
|
||||
name: 'limit',
|
||||
type: 'number',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['attribute'],
|
||||
operation: ['getAll'],
|
||||
returnAll: [false],
|
||||
},
|
||||
},
|
||||
typeOptions: {
|
||||
minValue: 1,
|
||||
maxValue: 1000,
|
||||
},
|
||||
routing: {
|
||||
output: {
|
||||
postReceive: [
|
||||
{
|
||||
type: 'limit',
|
||||
properties: {
|
||||
maxResults: '={{$value}}',
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
default: 50,
|
||||
description: 'Max number of results to return',
|
||||
},
|
||||
];
|
||||
|
||||
export const attributeFields: INodeProperties[] = [
|
||||
...createAttributeOperations,
|
||||
...updateAttributeOperations,
|
||||
...deleteAttribueOperations,
|
||||
...getAllAttributeOperations,
|
||||
];
|
||||
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"node": "n8n-nodes-base.brevo",
|
||||
"nodeVersion": "1.0",
|
||||
"codexVersion": "1.0",
|
||||
"categories": ["Marketing", "Communication"],
|
||||
"resources": {
|
||||
"credentialDocumentation": [
|
||||
{
|
||||
"url": "https://docs.n8n.io/integrations/builtin/credentials/brevo/"
|
||||
}
|
||||
],
|
||||
"primaryDocumentation": [
|
||||
{
|
||||
"url": "https://docs.n8n.io/integrations/builtin/app-nodes/n8n-nodes-base.brevo/"
|
||||
}
|
||||
]
|
||||
},
|
||||
"alias": ["sendinblue"]
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
/* eslint-disable n8n-nodes-base/node-filename-against-convention */
|
||||
import type { INodeType, INodeTypeDescription } from 'n8n-workflow';
|
||||
import { NodeConnectionTypes } from 'n8n-workflow';
|
||||
|
||||
import { attributeFields, attributeOperations } from './AttributeDescription';
|
||||
import { contactFields, contactOperations } from './ContactDescription';
|
||||
import { emailFields, emailOperations } from './EmailDescription';
|
||||
import { senderFields, senderOperations } from './SenderDescrition';
|
||||
|
||||
export class Brevo implements INodeType {
|
||||
description: INodeTypeDescription = {
|
||||
displayName: 'Brevo',
|
||||
// keep sendinblue name for backward compatibility
|
||||
name: 'sendInBlue',
|
||||
icon: 'file:brevo.svg',
|
||||
group: ['transform'],
|
||||
version: 1,
|
||||
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
|
||||
description: 'Consume Brevo API',
|
||||
defaults: {
|
||||
name: 'Brevo',
|
||||
},
|
||||
usableAsTool: true,
|
||||
inputs: [NodeConnectionTypes.Main],
|
||||
outputs: [NodeConnectionTypes.Main],
|
||||
credentials: [
|
||||
{
|
||||
name: 'sendInBlueApi',
|
||||
required: true,
|
||||
},
|
||||
],
|
||||
requestDefaults: {
|
||||
baseURL: 'https://api.brevo.com',
|
||||
},
|
||||
properties: [
|
||||
{
|
||||
displayName: 'Resource',
|
||||
name: 'resource',
|
||||
type: 'options',
|
||||
noDataExpression: true,
|
||||
options: [
|
||||
{
|
||||
name: 'Contact',
|
||||
value: 'contact',
|
||||
},
|
||||
{
|
||||
name: 'Contact Attribute',
|
||||
value: 'attribute',
|
||||
},
|
||||
{
|
||||
name: 'Email',
|
||||
value: 'email',
|
||||
},
|
||||
{
|
||||
name: 'Sender',
|
||||
value: 'sender',
|
||||
},
|
||||
],
|
||||
default: 'email',
|
||||
},
|
||||
|
||||
...attributeOperations,
|
||||
...attributeFields,
|
||||
...senderOperations,
|
||||
...senderFields,
|
||||
...contactOperations,
|
||||
...contactFields,
|
||||
...emailOperations,
|
||||
...emailFields,
|
||||
],
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"node": "n8n-nodes-base.brevoTrigger",
|
||||
"nodeVersion": "1.0",
|
||||
"codexVersion": "1.0",
|
||||
"categories": ["Marketing", "Communication"],
|
||||
"resources": {
|
||||
"credentialDocumentation": [
|
||||
{
|
||||
"url": "https://docs.n8n.io/integrations/builtin/credentials/brevo/"
|
||||
}
|
||||
],
|
||||
"primaryDocumentation": [
|
||||
{
|
||||
"url": "https://docs.n8n.io/integrations/builtin/trigger-nodes/n8n-nodes-base.brevotrigger/"
|
||||
}
|
||||
],
|
||||
"generic": []
|
||||
},
|
||||
"alias": ["sendinblue"]
|
||||
}
|
||||
@@ -0,0 +1,290 @@
|
||||
/* eslint-disable n8n-nodes-base/node-filename-against-convention */
|
||||
import {
|
||||
NodeConnectionTypes,
|
||||
type IHookFunctions,
|
||||
type INodeType,
|
||||
type INodeTypeDescription,
|
||||
type IWebhookFunctions,
|
||||
type IWebhookResponseData,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import { BrevoWebhookApi } from './GenericFunctions';
|
||||
|
||||
export class BrevoTrigger implements INodeType {
|
||||
description: INodeTypeDescription = {
|
||||
credentials: [
|
||||
{
|
||||
name: 'sendInBlueApi',
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {},
|
||||
},
|
||||
},
|
||||
],
|
||||
displayName: 'Brevo Trigger',
|
||||
defaults: {
|
||||
name: 'Brevo Trigger',
|
||||
},
|
||||
description: 'Starts the workflow when Brevo events occur',
|
||||
group: ['trigger'],
|
||||
icon: 'file:brevo.svg',
|
||||
inputs: [],
|
||||
// keep sendinblue name for backward compatibility
|
||||
name: 'sendInBlueTrigger',
|
||||
outputs: [NodeConnectionTypes.Main],
|
||||
version: 1,
|
||||
webhooks: [
|
||||
{
|
||||
name: 'default',
|
||||
httpMethod: 'POST',
|
||||
responseMode: 'onReceived',
|
||||
path: 'webhooks',
|
||||
},
|
||||
],
|
||||
properties: [
|
||||
{
|
||||
displayName: 'Resource',
|
||||
default: 'transactional',
|
||||
name: 'type',
|
||||
options: [
|
||||
{ name: 'Inbound', value: 'inbound' },
|
||||
{ name: 'Marketing', value: 'marketing' },
|
||||
{ name: 'Transactional', value: 'transactional' },
|
||||
],
|
||||
required: true,
|
||||
type: 'options',
|
||||
},
|
||||
{
|
||||
displayName: 'Trigger On',
|
||||
displayOptions: {
|
||||
show: {
|
||||
type: ['transactional'],
|
||||
},
|
||||
},
|
||||
name: 'events',
|
||||
placeholder: 'Add Event',
|
||||
options: [
|
||||
{
|
||||
name: 'Email Blocked',
|
||||
value: 'blocked',
|
||||
description: 'Triggers when transactional email is blocked',
|
||||
},
|
||||
{
|
||||
name: 'Email Clicked',
|
||||
value: 'click',
|
||||
description: 'Triggers when transactional email is clicked',
|
||||
},
|
||||
{
|
||||
name: 'Email Deferred',
|
||||
value: 'deferred',
|
||||
description: 'Triggers when transactional email is deferred',
|
||||
},
|
||||
{
|
||||
name: 'Email Delivered',
|
||||
value: 'delivered',
|
||||
description: 'Triggers when transactional email is delivered',
|
||||
},
|
||||
{
|
||||
name: 'Email Hard Bounce',
|
||||
value: 'hardBounce',
|
||||
description: 'Triggers when transactional email is hard bounced',
|
||||
},
|
||||
{
|
||||
name: 'Email Invalid',
|
||||
value: 'invalid',
|
||||
description: 'Triggers when transactional email is invalid',
|
||||
},
|
||||
{
|
||||
name: 'Email Marked Spam',
|
||||
value: 'spam',
|
||||
description: 'Triggers when transactional email is set to spam',
|
||||
},
|
||||
{
|
||||
name: 'Email Opened',
|
||||
value: 'opened',
|
||||
description: 'Triggers when transactional email is opened',
|
||||
},
|
||||
{
|
||||
name: 'Email Sent',
|
||||
value: 'request',
|
||||
description: 'Triggers when transactional email is sent',
|
||||
},
|
||||
{
|
||||
name: 'Email Soft-Bounce',
|
||||
value: 'softBounce',
|
||||
description: 'Triggers when transactional email is soft bounced',
|
||||
},
|
||||
{
|
||||
name: 'Email Unique Open',
|
||||
value: 'uniqueOpened',
|
||||
description: 'Triggers when transactional email is unique opened',
|
||||
},
|
||||
{
|
||||
name: 'Email Unsubscribed',
|
||||
value: 'unsubscribed',
|
||||
description: 'Triggers when transactional email is unsubscribed',
|
||||
},
|
||||
],
|
||||
default: [],
|
||||
required: true,
|
||||
type: 'multiOptions',
|
||||
},
|
||||
{
|
||||
displayName: 'Trigger On',
|
||||
displayOptions: {
|
||||
show: {
|
||||
type: ['marketing'],
|
||||
},
|
||||
},
|
||||
name: 'events',
|
||||
placeholder: 'Add Event',
|
||||
options: [
|
||||
{
|
||||
name: 'Marketing Email Clicked',
|
||||
value: 'click',
|
||||
description: 'Triggers when marketing email is clicked',
|
||||
},
|
||||
{
|
||||
name: 'Marketing Email Delivered',
|
||||
value: 'delivered',
|
||||
description: 'Triggers when marketing email is delivered',
|
||||
},
|
||||
{
|
||||
name: 'Marketing Email Hard Bounce',
|
||||
value: 'hardBounce',
|
||||
description: 'Triggers when marketing email is hard bounced',
|
||||
},
|
||||
{
|
||||
name: 'Marketing Email List Addition',
|
||||
value: 'listAddition',
|
||||
description: 'Triggers when marketing email is clicked',
|
||||
},
|
||||
{
|
||||
name: 'Marketing Email Opened',
|
||||
value: 'opened',
|
||||
description: 'Triggers when marketing email is opened',
|
||||
},
|
||||
{
|
||||
name: 'Marketing Email Soft Bounce',
|
||||
value: 'softBounce',
|
||||
description: 'Triggers when marketing email is soft bounced',
|
||||
},
|
||||
{
|
||||
name: 'Marketing Email Spam',
|
||||
value: 'spam',
|
||||
description: 'Triggers when marketing email is spam',
|
||||
},
|
||||
{
|
||||
name: 'Marketing Email Unsubscribed',
|
||||
value: 'unsubscribed',
|
||||
description: 'Triggers when marketing email is unsubscribed',
|
||||
},
|
||||
],
|
||||
default: [],
|
||||
required: true,
|
||||
type: 'multiOptions',
|
||||
},
|
||||
{
|
||||
displayName: 'Trigger On',
|
||||
displayOptions: {
|
||||
show: {
|
||||
type: ['inbound'],
|
||||
},
|
||||
},
|
||||
name: 'events',
|
||||
placeholder: 'Add Event',
|
||||
options: [
|
||||
{
|
||||
name: 'Inbound Email Processed',
|
||||
value: 'inboundEmailProcessed',
|
||||
description: 'Triggers when inbound email is processed',
|
||||
},
|
||||
],
|
||||
default: [],
|
||||
required: true,
|
||||
type: 'multiOptions',
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
webhookMethods = {
|
||||
default: {
|
||||
async checkExists(this: IHookFunctions): Promise<boolean> {
|
||||
const webhookData = this.getWorkflowStaticData('node');
|
||||
|
||||
const webhookUrl = this.getNodeWebhookUrl('default') as string;
|
||||
|
||||
const type = this.getNodeParameter('type') as string;
|
||||
|
||||
const events = this.getNodeParameter('events') as string[];
|
||||
|
||||
try {
|
||||
const { webhooks } = await BrevoWebhookApi.fetchWebhooks(this, type);
|
||||
|
||||
for (const webhook of webhooks) {
|
||||
if (
|
||||
webhook.type === type &&
|
||||
webhook.events.every((event) => events.includes(event)) &&
|
||||
webhookUrl === webhook.url
|
||||
) {
|
||||
webhookData.webhookId = webhook.id;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// If it did not error then the webhook exists
|
||||
return false;
|
||||
} catch (err) {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
async create(this: IHookFunctions): Promise<boolean> {
|
||||
const webhookData = this.getWorkflowStaticData('node');
|
||||
|
||||
const webhookUrl = this.getNodeWebhookUrl('default') as string;
|
||||
|
||||
const type = this.getNodeParameter('type') as string;
|
||||
|
||||
const events = this.getNodeParameter('events') as string[];
|
||||
|
||||
const responseData = await BrevoWebhookApi.createWebHook(this, type, events, webhookUrl);
|
||||
|
||||
if (responseData?.id === undefined) {
|
||||
// Required data is missing so was not successful
|
||||
return false;
|
||||
}
|
||||
|
||||
webhookData.webhookId = responseData.id;
|
||||
|
||||
return true;
|
||||
},
|
||||
async delete(this: IHookFunctions): Promise<boolean> {
|
||||
const webhookData = this.getWorkflowStaticData('node');
|
||||
|
||||
if (webhookData.webhookId !== undefined) {
|
||||
try {
|
||||
await BrevoWebhookApi.deleteWebhook(this, webhookData.webhookId as string);
|
||||
} catch (error) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Remove from the static workflow data so that it is clear
|
||||
// that no webhooks are registered anymore
|
||||
delete webhookData.webhookId;
|
||||
delete webhookData.webhookEvents;
|
||||
delete webhookData.hookSecret;
|
||||
}
|
||||
|
||||
return true;
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
async webhook(this: IWebhookFunctions): Promise<IWebhookResponseData> {
|
||||
// The data to return and so start the workflow with
|
||||
const bodyData = this.getBodyData();
|
||||
|
||||
return {
|
||||
workflowData: [this.helpers.returnJsonArray(bodyData)],
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,624 @@
|
||||
import type {
|
||||
GenericValue,
|
||||
IExecuteSingleFunctions,
|
||||
IHttpRequestOptions,
|
||||
INodeProperties,
|
||||
JsonObject,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
export const contactOperations: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Operation',
|
||||
name: 'operation',
|
||||
type: 'options',
|
||||
noDataExpression: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['contact'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: 'Create',
|
||||
value: 'create',
|
||||
action: 'Create a contact',
|
||||
routing: {
|
||||
request: {
|
||||
method: 'POST',
|
||||
url: '/v3/contacts',
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'Create or Update',
|
||||
value: 'upsert',
|
||||
action: 'Upsert a contact',
|
||||
routing: {
|
||||
request: {
|
||||
method: 'POST',
|
||||
url: '=/v3/contacts',
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'Delete',
|
||||
value: 'delete',
|
||||
action: 'Delete a contact',
|
||||
},
|
||||
{
|
||||
name: 'Get',
|
||||
value: 'get',
|
||||
action: 'Get a contact',
|
||||
},
|
||||
{
|
||||
name: 'Get Many',
|
||||
value: 'getAll',
|
||||
routing: {
|
||||
request: {
|
||||
method: 'GET',
|
||||
url: '/v3/contacts',
|
||||
},
|
||||
output: {
|
||||
postReceive: [
|
||||
{
|
||||
type: 'rootProperty',
|
||||
properties: {
|
||||
property: 'contacts',
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
operations: {
|
||||
pagination: {
|
||||
type: 'offset',
|
||||
properties: {
|
||||
limitParameter: 'limit',
|
||||
offsetParameter: 'offset',
|
||||
pageSize: 1000,
|
||||
type: 'query',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
action: 'Get many contacts',
|
||||
},
|
||||
{
|
||||
name: 'Update',
|
||||
value: 'update',
|
||||
routing: {
|
||||
output: {
|
||||
postReceive: [
|
||||
{
|
||||
type: 'set',
|
||||
properties: {
|
||||
value: '={{ { "success": true } }}', // Also possible to use the original response data
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
action: 'Update a contact',
|
||||
},
|
||||
],
|
||||
default: 'create',
|
||||
},
|
||||
];
|
||||
|
||||
const createOperations: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Email',
|
||||
name: 'email',
|
||||
type: 'string',
|
||||
placeholder: 'name@email.com',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['contact'],
|
||||
operation: ['create'],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
routing: {
|
||||
send: {
|
||||
type: 'body',
|
||||
property: 'email',
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Contact Attributes',
|
||||
name: 'createContactAttributes',
|
||||
default: {},
|
||||
description: 'Array of attributes to be added',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['contact'],
|
||||
operation: ['create'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: 'attributesValues',
|
||||
displayName: 'Attribute',
|
||||
values: [
|
||||
{
|
||||
displayName: 'Field Name',
|
||||
name: 'fieldName',
|
||||
type: 'options',
|
||||
typeOptions: {
|
||||
loadOptions: {
|
||||
routing: {
|
||||
request: {
|
||||
method: 'GET',
|
||||
url: '/v3/contacts/attributes',
|
||||
},
|
||||
output: {
|
||||
postReceive: [
|
||||
{
|
||||
type: 'rootProperty',
|
||||
properties: {
|
||||
property: 'attributes',
|
||||
},
|
||||
},
|
||||
{
|
||||
type: 'setKeyValue',
|
||||
properties: {
|
||||
name: '={{$responseItem.name}} - ({{$responseItem.category}})',
|
||||
value: '={{$responseItem.name}}',
|
||||
},
|
||||
},
|
||||
{
|
||||
type: 'sort',
|
||||
properties: {
|
||||
key: 'name',
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
},
|
||||
{
|
||||
displayName: 'Field Value',
|
||||
name: 'fieldValue',
|
||||
type: 'string',
|
||||
default: '',
|
||||
routing: {
|
||||
send: {
|
||||
value: '={{$value}}',
|
||||
property: '=attributes.{{$parent.fieldName}}',
|
||||
type: 'body',
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
placeholder: 'Add Attribute',
|
||||
type: 'fixedCollection',
|
||||
typeOptions: {
|
||||
multipleValues: true,
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
const getAllOperations: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Return All',
|
||||
name: 'returnAll',
|
||||
type: 'boolean',
|
||||
routing: {
|
||||
send: {
|
||||
paginate: '={{$value}}',
|
||||
},
|
||||
},
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['contact'],
|
||||
operation: ['getAll'],
|
||||
},
|
||||
},
|
||||
default: false,
|
||||
description: 'Whether to return all results or only up to a given limit',
|
||||
},
|
||||
{
|
||||
displayName: 'Limit',
|
||||
name: 'limit',
|
||||
type: 'number',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['contact'],
|
||||
operation: ['getAll'],
|
||||
returnAll: [false],
|
||||
},
|
||||
},
|
||||
routing: {
|
||||
send: {
|
||||
type: 'query',
|
||||
property: 'limit',
|
||||
},
|
||||
},
|
||||
typeOptions: {
|
||||
minValue: 1,
|
||||
maxValue: 1000,
|
||||
},
|
||||
default: 50,
|
||||
description: 'Max number of results to return',
|
||||
},
|
||||
{
|
||||
displayName: 'Options',
|
||||
name: 'options',
|
||||
type: 'collection',
|
||||
placeholder: 'Add option',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['contact'],
|
||||
operation: ['getAll'],
|
||||
},
|
||||
},
|
||||
default: {},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Sort',
|
||||
name: 'sort',
|
||||
type: 'options',
|
||||
options: [
|
||||
{ name: 'DESC', value: 'desc' },
|
||||
{ name: 'ASC', value: 'asc' },
|
||||
],
|
||||
routing: {
|
||||
send: {
|
||||
type: 'query',
|
||||
property: 'sort',
|
||||
value: '={{$value}}',
|
||||
},
|
||||
},
|
||||
default: 'desc',
|
||||
description: 'Sort the results in the ascending/descending order of record creation',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
displayName: 'Filters',
|
||||
name: 'filters',
|
||||
type: 'collection',
|
||||
placeholder: 'Add Filter',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['contact'],
|
||||
operation: ['getAll'],
|
||||
},
|
||||
},
|
||||
default: {},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Modified Since',
|
||||
name: 'modifiedSince',
|
||||
type: 'dateTime',
|
||||
routing: {
|
||||
send: {
|
||||
type: 'query',
|
||||
property: 'modifiedSince',
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
description:
|
||||
'Filter (urlencoded) the contacts modified after a given UTC date-time (YYYY-MM-DDTHH:mm:ss.SSSZ)',
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
const getOperations: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Contact Identifier',
|
||||
name: 'identifier',
|
||||
type: 'string',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['contact'],
|
||||
operation: ['get'],
|
||||
},
|
||||
},
|
||||
routing: {
|
||||
request: {
|
||||
method: 'GET',
|
||||
url: '=/v3/contacts/{{encodeURIComponent($value)}}',
|
||||
},
|
||||
},
|
||||
required: true,
|
||||
default: '',
|
||||
description: 'Email (urlencoded) OR ID of the contact OR its SMS attribute value',
|
||||
},
|
||||
];
|
||||
|
||||
const deleteOperations: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Contact Identifier',
|
||||
name: 'identifier',
|
||||
type: 'string',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['contact'],
|
||||
operation: ['delete'],
|
||||
},
|
||||
},
|
||||
routing: {
|
||||
request: {
|
||||
method: 'DELETE',
|
||||
url: '=/v3/contacts/{{encodeURIComponent($parameter.identifier)}}',
|
||||
},
|
||||
output: {
|
||||
postReceive: [
|
||||
{
|
||||
type: 'set',
|
||||
properties: {
|
||||
value: '={{ { "success": true } }}', // Also possible to use the original response data
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
description: 'Email (urlencoded) OR ID of the contact OR its SMS attribute value',
|
||||
},
|
||||
];
|
||||
|
||||
const updateOperations: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Contact Identifier',
|
||||
name: 'identifier',
|
||||
default: '',
|
||||
description: 'Email (urlencoded) OR ID of the contact OR its SMS attribute value',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['contact'],
|
||||
operation: ['update'],
|
||||
},
|
||||
},
|
||||
type: 'string',
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
displayName: 'Attributes',
|
||||
name: 'updateAttributes',
|
||||
default: {},
|
||||
description: 'Array of attributes to be updated',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['contact'],
|
||||
operation: ['update'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Attribute',
|
||||
name: 'updateAttributesValues',
|
||||
values: [
|
||||
{
|
||||
displayName: 'Field Name',
|
||||
name: 'fieldName',
|
||||
type: 'options',
|
||||
typeOptions: {
|
||||
loadOptions: {
|
||||
routing: {
|
||||
request: {
|
||||
method: 'GET',
|
||||
url: '/v3/contacts/attributes',
|
||||
},
|
||||
output: {
|
||||
postReceive: [
|
||||
{
|
||||
type: 'rootProperty',
|
||||
properties: {
|
||||
property: 'attributes',
|
||||
},
|
||||
},
|
||||
{
|
||||
type: 'setKeyValue',
|
||||
properties: {
|
||||
name: '={{$responseItem.name}} - ({{$responseItem.category}})',
|
||||
value: '={{$responseItem.name}}',
|
||||
},
|
||||
},
|
||||
{
|
||||
type: 'sort',
|
||||
properties: {
|
||||
key: 'name',
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
},
|
||||
{
|
||||
displayName: 'Field Value',
|
||||
name: 'fieldValue',
|
||||
type: 'string',
|
||||
default: '',
|
||||
routing: {
|
||||
send: {
|
||||
value: '={{$value}}',
|
||||
property: '=attributes.{{$parent.fieldName}}',
|
||||
type: 'body',
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
placeholder: 'Add Attribute',
|
||||
routing: {
|
||||
request: {
|
||||
method: 'PUT',
|
||||
url: '=/v3/contacts/{{encodeURIComponent($parameter.identifier)}}',
|
||||
},
|
||||
},
|
||||
type: 'fixedCollection',
|
||||
typeOptions: {
|
||||
multipleValues: true,
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
const upsertOperations: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Email',
|
||||
name: 'email',
|
||||
default: '',
|
||||
description: 'Email of the contact',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['contact'],
|
||||
operation: ['upsert'],
|
||||
},
|
||||
},
|
||||
type: 'string',
|
||||
placeholder: 'name@email.com',
|
||||
required: true,
|
||||
routing: {
|
||||
send: {
|
||||
value: '={{$value}}',
|
||||
property: 'email',
|
||||
type: 'body',
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Contact Attributes',
|
||||
name: 'upsertAttributes',
|
||||
default: {},
|
||||
description: 'Array of attributes to be updated',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['contact'],
|
||||
operation: ['upsert'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: 'upsertAttributesValues',
|
||||
displayName: 'Attribute',
|
||||
values: [
|
||||
{
|
||||
displayName: 'Field Name',
|
||||
name: 'fieldName',
|
||||
type: 'options',
|
||||
typeOptions: {
|
||||
loadOptions: {
|
||||
routing: {
|
||||
request: {
|
||||
method: 'GET',
|
||||
url: '/v3/contacts/attributes',
|
||||
},
|
||||
output: {
|
||||
postReceive: [
|
||||
{
|
||||
type: 'rootProperty',
|
||||
properties: {
|
||||
property: 'attributes',
|
||||
},
|
||||
},
|
||||
{
|
||||
type: 'setKeyValue',
|
||||
properties: {
|
||||
name: '={{$responseItem.name}} - ({{$responseItem.category}})',
|
||||
value: '={{$responseItem.name}}',
|
||||
},
|
||||
},
|
||||
{
|
||||
type: 'sort',
|
||||
properties: {
|
||||
key: 'name',
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
},
|
||||
{
|
||||
displayName: 'Field Value',
|
||||
name: 'fieldValue',
|
||||
type: 'string',
|
||||
default: '',
|
||||
routing: {
|
||||
send: {
|
||||
value: '={{$value}}',
|
||||
property: '=attributes.{{$parent.fieldName}}',
|
||||
type: 'body',
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
placeholder: 'Add Attribute',
|
||||
type: 'fixedCollection',
|
||||
typeOptions: {
|
||||
multipleValues: true,
|
||||
},
|
||||
routing: {
|
||||
send: {
|
||||
preSend: [
|
||||
async function (
|
||||
this: IExecuteSingleFunctions,
|
||||
requestOptions: IHttpRequestOptions,
|
||||
): Promise<IHttpRequestOptions> {
|
||||
const { body } = requestOptions as GenericValue as JsonObject;
|
||||
Object.assign(body!, { updateEnabled: true });
|
||||
return requestOptions;
|
||||
},
|
||||
],
|
||||
},
|
||||
output: {
|
||||
postReceive: [
|
||||
{
|
||||
type: 'set',
|
||||
properties: {
|
||||
value: '={{ { "success": true } }}', // Also possible to use the original response data
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
export const contactFields: INodeProperties[] = [
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* contact:create */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
...createOperations,
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* contact:getAll */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
...getAllOperations,
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* contact:get */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
...getOperations,
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* contact:delete */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
...deleteOperations,
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* contact:update */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
...updateOperations,
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* contact:update */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
...upsertOperations,
|
||||
];
|
||||
@@ -0,0 +1,452 @@
|
||||
import type { INodeProperties } from 'n8n-workflow';
|
||||
|
||||
import { BrevoNode } from './GenericFunctions';
|
||||
|
||||
export const emailOperations: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Operation',
|
||||
name: 'operation',
|
||||
type: 'options',
|
||||
noDataExpression: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['email'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: 'Send',
|
||||
value: 'send',
|
||||
action: 'Send a transactional email',
|
||||
},
|
||||
{
|
||||
name: 'Send Template',
|
||||
value: 'sendTemplate',
|
||||
action: 'Send an email with an existing Template',
|
||||
},
|
||||
],
|
||||
routing: {
|
||||
request: {
|
||||
method: 'POST',
|
||||
url: '/v3/smtp/email',
|
||||
},
|
||||
},
|
||||
default: 'send',
|
||||
},
|
||||
];
|
||||
|
||||
const sendHtmlEmailFields: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Send HTML',
|
||||
name: 'sendHTML',
|
||||
type: 'boolean',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['email'],
|
||||
operation: ['send'],
|
||||
},
|
||||
},
|
||||
default: false,
|
||||
},
|
||||
{
|
||||
displayName: 'Subject',
|
||||
name: 'subject',
|
||||
type: 'string',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['email'],
|
||||
operation: ['send'],
|
||||
},
|
||||
},
|
||||
routing: {
|
||||
send: {
|
||||
property: 'subject',
|
||||
type: 'body',
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
description: 'Subject of the email',
|
||||
},
|
||||
{
|
||||
displayName: 'Text Content',
|
||||
name: 'textContent',
|
||||
type: 'string',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['email'],
|
||||
operation: ['send'],
|
||||
sendHTML: [false],
|
||||
},
|
||||
},
|
||||
routing: {
|
||||
send: {
|
||||
property: 'textContent',
|
||||
type: 'body',
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
description: 'Text content of the message',
|
||||
},
|
||||
{
|
||||
displayName: 'HTML Content',
|
||||
name: 'htmlContent',
|
||||
type: 'string',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['email'],
|
||||
operation: ['send'],
|
||||
sendHTML: [true],
|
||||
},
|
||||
},
|
||||
routing: {
|
||||
send: {
|
||||
property: 'htmlContent',
|
||||
type: 'body',
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
description: 'HTML content of the message',
|
||||
},
|
||||
{
|
||||
displayName: 'Sender',
|
||||
name: 'sender',
|
||||
type: 'string',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['email'],
|
||||
operation: ['send'],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
required: true,
|
||||
routing: {
|
||||
send: {
|
||||
preSend: [BrevoNode.Validators.validateAndCompileSenderEmail],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Receipients',
|
||||
name: 'receipients',
|
||||
type: 'string',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['email'],
|
||||
operation: ['send'],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
required: true,
|
||||
routing: {
|
||||
send: {
|
||||
preSend: [BrevoNode.Validators.validateAndCompileReceipientEmails],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Additional Fields',
|
||||
name: 'additionalFields',
|
||||
placeholder: 'Add Field',
|
||||
description: 'Additional fields to add',
|
||||
type: 'collection',
|
||||
default: {},
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['email'],
|
||||
operation: ['send'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Attachments',
|
||||
name: 'emailAttachments',
|
||||
placeholder: 'Add Attachment',
|
||||
type: 'fixedCollection',
|
||||
default: {},
|
||||
options: [
|
||||
{
|
||||
name: 'attachment',
|
||||
displayName: 'Attachment Data',
|
||||
values: [
|
||||
{
|
||||
displayName: 'Input Data Field Name',
|
||||
default: '',
|
||||
name: 'binaryPropertyName',
|
||||
type: 'string',
|
||||
description:
|
||||
'The name of the incoming field containing the binary file data to be processed',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
routing: {
|
||||
send: {
|
||||
preSend: [BrevoNode.Validators.validateAndCompileAttachmentsData],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Receipients BCC',
|
||||
name: 'receipientsBCC',
|
||||
placeholder: 'Add BCC',
|
||||
type: 'fixedCollection',
|
||||
default: {},
|
||||
options: [
|
||||
{
|
||||
name: 'receipientBcc',
|
||||
displayName: 'Receipient',
|
||||
values: [
|
||||
{
|
||||
displayName: 'Receipient',
|
||||
name: 'bcc',
|
||||
type: 'string',
|
||||
default: '',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
routing: {
|
||||
send: {
|
||||
preSend: [BrevoNode.Validators.validateAndCompileBCCEmails],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Receipients CC',
|
||||
name: 'receipientsCC',
|
||||
placeholder: 'Add CC',
|
||||
type: 'fixedCollection',
|
||||
default: {},
|
||||
options: [
|
||||
{
|
||||
name: 'receipientCc',
|
||||
displayName: 'Receipient',
|
||||
values: [
|
||||
{
|
||||
displayName: 'Receipient',
|
||||
name: 'cc',
|
||||
type: 'string',
|
||||
default: '',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
routing: {
|
||||
send: {
|
||||
preSend: [BrevoNode.Validators.validateAndCompileCCEmails],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Email Tags',
|
||||
name: 'emailTags',
|
||||
default: {},
|
||||
description: 'Add tags to your emails to find them more easily',
|
||||
placeholder: 'Add Email Tags',
|
||||
type: 'fixedCollection',
|
||||
options: [
|
||||
{
|
||||
displayName: 'Tags',
|
||||
name: 'tags',
|
||||
values: [
|
||||
{
|
||||
displayName: 'Tag',
|
||||
default: '',
|
||||
name: 'tag',
|
||||
type: 'string',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
routing: {
|
||||
send: {
|
||||
preSend: [BrevoNode.Validators.validateAndCompileTags],
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
const sendHtmlTemplateEmailFields: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Template ID',
|
||||
name: 'templateId',
|
||||
type: 'options',
|
||||
default: '',
|
||||
typeOptions: {
|
||||
loadOptions: {
|
||||
routing: {
|
||||
request: {
|
||||
method: 'GET',
|
||||
url: '/v3/smtp/templates',
|
||||
qs: {
|
||||
templateStatus: true,
|
||||
limit: 1000,
|
||||
offset: 0,
|
||||
sort: 'desc',
|
||||
},
|
||||
},
|
||||
output: {
|
||||
postReceive: [
|
||||
{
|
||||
type: 'rootProperty',
|
||||
properties: {
|
||||
property: 'templates',
|
||||
},
|
||||
},
|
||||
{
|
||||
type: 'setKeyValue',
|
||||
properties: {
|
||||
name: '={{$responseItem.name}}',
|
||||
value: '={{$responseItem.id}}',
|
||||
},
|
||||
},
|
||||
{
|
||||
type: 'sort',
|
||||
properties: {
|
||||
key: 'name',
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['email'],
|
||||
operation: ['sendTemplate'],
|
||||
},
|
||||
},
|
||||
routing: {
|
||||
send: {
|
||||
type: 'body',
|
||||
property: 'templateId',
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Receipients',
|
||||
name: 'receipients',
|
||||
type: 'string',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['email'],
|
||||
operation: ['sendTemplate'],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
required: true,
|
||||
routing: {
|
||||
send: {
|
||||
preSend: [BrevoNode.Validators.validateAndCompileReceipientEmails],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Additional Fields',
|
||||
name: 'additionalFields',
|
||||
type: 'collection',
|
||||
description: 'Additional fields to add',
|
||||
placeholder: 'Add Field',
|
||||
default: {},
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['email'],
|
||||
operation: ['sendTemplate'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Attachments',
|
||||
name: 'emailAttachments',
|
||||
placeholder: 'Add Attachment',
|
||||
type: 'fixedCollection',
|
||||
default: {},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Attachment Data',
|
||||
name: 'attachment',
|
||||
values: [
|
||||
{
|
||||
displayName: 'Input Data Field Name',
|
||||
name: 'binaryPropertyName',
|
||||
default: '',
|
||||
type: 'string',
|
||||
description:
|
||||
'The name of the incoming field containing the binary file data to be processed',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
routing: {
|
||||
send: {
|
||||
preSend: [BrevoNode.Validators.validateAndCompileAttachmentsData],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Email Tags',
|
||||
name: 'emailTags',
|
||||
default: {},
|
||||
description: 'Add tags to your emails to find them more easily',
|
||||
placeholder: 'Add Email Tags',
|
||||
type: 'fixedCollection',
|
||||
options: [
|
||||
{
|
||||
displayName: 'Tags',
|
||||
name: 'tags',
|
||||
values: [
|
||||
{
|
||||
displayName: 'Tag',
|
||||
default: '',
|
||||
name: 'tag',
|
||||
type: 'string',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
routing: {
|
||||
send: {
|
||||
preSend: [BrevoNode.Validators.validateAndCompileTags],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Template Parameters',
|
||||
name: 'templateParameters',
|
||||
default: {},
|
||||
description: 'Pass a set of attributes to customize the template',
|
||||
placeholder: 'Add Parameter',
|
||||
type: 'fixedCollection',
|
||||
options: [
|
||||
{
|
||||
name: 'parameterValues',
|
||||
displayName: 'Parameters',
|
||||
values: [
|
||||
{
|
||||
displayName: 'Parameter',
|
||||
name: 'parameters',
|
||||
type: 'string',
|
||||
default: '',
|
||||
placeholder: 'key=value',
|
||||
description: 'Comma-separated key=value pairs',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
routing: {
|
||||
send: {
|
||||
preSend: [BrevoNode.Validators.validateAndCompileTemplateParameters],
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
export const emailFields: INodeProperties[] = [
|
||||
...sendHtmlEmailFields,
|
||||
...sendHtmlTemplateEmailFields,
|
||||
];
|
||||
@@ -0,0 +1,376 @@
|
||||
import type {
|
||||
IExecuteSingleFunctions,
|
||||
IHookFunctions,
|
||||
IHttpRequestOptions,
|
||||
IRequestOptions,
|
||||
IWebhookFunctions,
|
||||
JsonObject,
|
||||
} from 'n8n-workflow';
|
||||
import { jsonParse, NodeOperationError } from 'n8n-workflow';
|
||||
import MailComposer from 'nodemailer/lib/mail-composer';
|
||||
export namespace BrevoNode {
|
||||
type ValidEmailFields = { to: string } | { sender: string } | { cc: string } | { bcc: string };
|
||||
type Address = { address: string; name?: string };
|
||||
type Email = { email: string; name?: string };
|
||||
type ToEmail = { to: Email[] };
|
||||
type SenderEmail = { sender: Email };
|
||||
type CCEmail = { cc: Email[] };
|
||||
type BBCEmail = { bbc: Email[] };
|
||||
type ValidatedEmail = ToEmail | SenderEmail | CCEmail | BBCEmail;
|
||||
|
||||
const OVERRIDE_MAP_VALUES = {
|
||||
CATEGORY: 'category',
|
||||
NORMAL: 'boolean',
|
||||
TRANSACTIONAL: 'id',
|
||||
} as const;
|
||||
|
||||
const OVERRIDE_MAP_TYPE = {
|
||||
CATEGORY: 'category',
|
||||
NORMAL: 'normal',
|
||||
TRANSACTIONAL: 'transactional',
|
||||
} as const;
|
||||
|
||||
export const INTERCEPTORS = new Map<string, (body: JsonObject) => void>([
|
||||
[
|
||||
OVERRIDE_MAP_TYPE.CATEGORY,
|
||||
(body: JsonObject) => {
|
||||
body.type = OVERRIDE_MAP_VALUES.CATEGORY;
|
||||
},
|
||||
],
|
||||
[
|
||||
OVERRIDE_MAP_TYPE.NORMAL,
|
||||
(body: JsonObject) => {
|
||||
body.type = OVERRIDE_MAP_VALUES.NORMAL;
|
||||
},
|
||||
],
|
||||
[
|
||||
OVERRIDE_MAP_TYPE.TRANSACTIONAL,
|
||||
(body: JsonObject) => {
|
||||
body.type = OVERRIDE_MAP_VALUES.TRANSACTIONAL;
|
||||
},
|
||||
],
|
||||
]);
|
||||
export namespace Validators {
|
||||
function getFileName(
|
||||
itemIndex: number,
|
||||
mimeType: string,
|
||||
fileExt: string,
|
||||
fileName: string,
|
||||
): string {
|
||||
let ext = fileExt;
|
||||
if (fileExt === undefined) {
|
||||
ext = mimeType.split('/')[1];
|
||||
}
|
||||
|
||||
let name = `${fileName}.${ext}`;
|
||||
if (fileName === undefined) {
|
||||
name = `file-${itemIndex}.${ext}`;
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
export async function validateAndCompileAttachmentsData(
|
||||
this: IExecuteSingleFunctions,
|
||||
requestOptions: IHttpRequestOptions,
|
||||
): Promise<IHttpRequestOptions> {
|
||||
const dataPropertyList = this.getNodeParameter(
|
||||
'additionalFields.emailAttachments.attachment',
|
||||
) as JsonObject;
|
||||
const { body } = requestOptions;
|
||||
|
||||
const { attachment = [] } = body as { attachment: Array<{ content: string; name: string }> };
|
||||
|
||||
try {
|
||||
const { binaryPropertyName } = dataPropertyList;
|
||||
const dataMappingList = (binaryPropertyName as string).split(',');
|
||||
for (const attachmentDataName of dataMappingList) {
|
||||
const binaryData = this.helpers.assertBinaryData(attachmentDataName);
|
||||
const bufferFromIncomingData = await this.helpers.getBinaryDataBuffer(attachmentDataName);
|
||||
|
||||
const {
|
||||
data: content,
|
||||
mimeType,
|
||||
fileName,
|
||||
fileExtension,
|
||||
} = await this.helpers.prepareBinaryData(bufferFromIncomingData);
|
||||
|
||||
const itemIndex = this.getItemIndex();
|
||||
const name = getFileName(
|
||||
itemIndex,
|
||||
mimeType,
|
||||
fileExtension!,
|
||||
fileName ?? binaryData.fileName!,
|
||||
);
|
||||
|
||||
attachment.push({ content, name });
|
||||
}
|
||||
|
||||
Object.assign(body!, { attachment });
|
||||
|
||||
return requestOptions;
|
||||
} catch (err) {
|
||||
throw new NodeOperationError(this.getNode(), err as Error);
|
||||
}
|
||||
}
|
||||
|
||||
export async function validateAndCompileTags(
|
||||
this: IExecuteSingleFunctions,
|
||||
requestOptions: IHttpRequestOptions,
|
||||
): Promise<IHttpRequestOptions> {
|
||||
const { tag } = this.getNodeParameter('additionalFields.emailTags.tags') as JsonObject;
|
||||
const tags = (tag as string)
|
||||
.split(',')
|
||||
.map((entry) => entry.trim())
|
||||
.filter((entry) => {
|
||||
return entry !== '';
|
||||
});
|
||||
const { body } = requestOptions;
|
||||
Object.assign(body!, { tags });
|
||||
return requestOptions;
|
||||
}
|
||||
|
||||
function formatToEmailName(data: Address): Email {
|
||||
const { address: email, name } = data;
|
||||
const result = { email };
|
||||
if (name !== undefined && name !== '') {
|
||||
Object.assign(result, { name });
|
||||
}
|
||||
return { ...result };
|
||||
}
|
||||
|
||||
function validateEmailStrings(input: ValidEmailFields): ValidatedEmail {
|
||||
const composer = new MailComposer({ ...input });
|
||||
const addressFields = composer.compile().getAddresses();
|
||||
|
||||
const fieldFetcher = new Map<string, () => Email[] | Email>([
|
||||
[
|
||||
'bcc',
|
||||
() => {
|
||||
return (addressFields.bcc as unknown as Address[])?.map(formatToEmailName);
|
||||
},
|
||||
],
|
||||
[
|
||||
'cc',
|
||||
() => {
|
||||
return (addressFields.cc as unknown as Address[])?.map(formatToEmailName);
|
||||
},
|
||||
],
|
||||
[
|
||||
'from',
|
||||
() => {
|
||||
return (addressFields.from as unknown as Address[])?.map(formatToEmailName);
|
||||
},
|
||||
],
|
||||
[
|
||||
'reply-to',
|
||||
() => {
|
||||
return (addressFields['reply-to'] as unknown as Address[])?.map(formatToEmailName);
|
||||
},
|
||||
],
|
||||
[
|
||||
'sender',
|
||||
() => {
|
||||
return (addressFields.sender as unknown as Address[])?.map(formatToEmailName)[0];
|
||||
},
|
||||
],
|
||||
[
|
||||
'to',
|
||||
() => {
|
||||
return (addressFields.to as unknown as Address[])?.map(formatToEmailName);
|
||||
},
|
||||
],
|
||||
]);
|
||||
|
||||
const result: { [key in keyof ValidatedEmail]: Email[] | Email } = {} as ValidatedEmail;
|
||||
Object.keys(input).reduce((obj: { [key: string]: Email[] | Email }, key: string) => {
|
||||
const getter = fieldFetcher.get(key);
|
||||
const value = getter!();
|
||||
obj[key] = value;
|
||||
return obj;
|
||||
}, result);
|
||||
|
||||
return result as ValidatedEmail;
|
||||
}
|
||||
|
||||
export async function validateAndCompileCCEmails(
|
||||
this: IExecuteSingleFunctions,
|
||||
requestOptions: IHttpRequestOptions,
|
||||
): Promise<IHttpRequestOptions> {
|
||||
const ccData = this.getNodeParameter(
|
||||
'additionalFields.receipientsCC.receipientCc',
|
||||
) as JsonObject;
|
||||
const { cc } = ccData;
|
||||
const { body } = requestOptions;
|
||||
const data = validateEmailStrings({ cc: cc as string });
|
||||
Object.assign(body!, data);
|
||||
|
||||
return requestOptions;
|
||||
}
|
||||
|
||||
export async function validateAndCompileBCCEmails(
|
||||
this: IExecuteSingleFunctions,
|
||||
requestOptions: IHttpRequestOptions,
|
||||
): Promise<IHttpRequestOptions> {
|
||||
const bccData = this.getNodeParameter(
|
||||
'additionalFields.receipientsBCC.receipientBcc',
|
||||
) as JsonObject;
|
||||
const { bcc } = bccData;
|
||||
const { body } = requestOptions;
|
||||
const data = validateEmailStrings({ bcc: bcc as string });
|
||||
Object.assign(body!, data);
|
||||
|
||||
return requestOptions;
|
||||
}
|
||||
|
||||
export async function validateAndCompileReceipientEmails(
|
||||
this: IExecuteSingleFunctions,
|
||||
requestOptions: IHttpRequestOptions,
|
||||
): Promise<IHttpRequestOptions> {
|
||||
const to = this.getNodeParameter('receipients') as string;
|
||||
const { body } = requestOptions;
|
||||
const data = validateEmailStrings({ to });
|
||||
Object.assign(body!, data);
|
||||
|
||||
return requestOptions;
|
||||
}
|
||||
|
||||
export async function validateAndCompileSenderEmail(
|
||||
this: IExecuteSingleFunctions,
|
||||
requestOptions: IHttpRequestOptions,
|
||||
): Promise<IHttpRequestOptions> {
|
||||
const sender = this.getNodeParameter('sender') as string;
|
||||
const { body } = requestOptions;
|
||||
const data = validateEmailStrings({ sender });
|
||||
Object.assign(body!, data);
|
||||
|
||||
return requestOptions;
|
||||
}
|
||||
|
||||
export async function validateAndCompileTemplateParameters(
|
||||
this: IExecuteSingleFunctions,
|
||||
requestOptions: IHttpRequestOptions,
|
||||
): Promise<IHttpRequestOptions> {
|
||||
const parameterData = this.getNodeParameter(
|
||||
'additionalFields.templateParameters.parameterValues',
|
||||
);
|
||||
const { body } = requestOptions;
|
||||
const { parameters } = parameterData as JsonObject;
|
||||
const params = (parameters as string)
|
||||
.split(',')
|
||||
.filter((parameter) => {
|
||||
return parameter.split('=').length === 2;
|
||||
})
|
||||
.map((parameter) => {
|
||||
const [key, value] = parameter.split('=');
|
||||
return {
|
||||
[key]: value,
|
||||
};
|
||||
})
|
||||
.reduce((obj, cObj) => {
|
||||
Object.assign(obj, cObj);
|
||||
return obj;
|
||||
}, {});
|
||||
|
||||
Object.assign(body!, { params });
|
||||
return requestOptions;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export namespace BrevoWebhookApi {
|
||||
interface WebhookDetails {
|
||||
url: string;
|
||||
id: number;
|
||||
description: string;
|
||||
events: string[];
|
||||
type: string;
|
||||
createdAt: string;
|
||||
modifiedAt: string;
|
||||
}
|
||||
|
||||
interface WebhookId {
|
||||
id: string;
|
||||
}
|
||||
|
||||
interface Webhooks {
|
||||
webhooks: WebhookDetails[];
|
||||
}
|
||||
|
||||
const credentialsName = 'sendInBlueApi';
|
||||
const baseURL = 'https://api.brevo.com/v3';
|
||||
export const supportedAuthMap = new Map<string, (ref: IWebhookFunctions) => Promise<string>>([
|
||||
[
|
||||
'apiKey',
|
||||
async (ref: IWebhookFunctions): Promise<string> => {
|
||||
const credentials = await ref.getCredentials(credentialsName);
|
||||
return credentials.sharedSecret as string;
|
||||
},
|
||||
],
|
||||
]);
|
||||
|
||||
export const fetchWebhooks = async (ref: IHookFunctions, type: string): Promise<Webhooks> => {
|
||||
const endpoint = `${baseURL}/webhooks?type=${type}`;
|
||||
|
||||
const options: IRequestOptions = {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
},
|
||||
uri: endpoint,
|
||||
};
|
||||
|
||||
const webhooks = (await ref.helpers.requestWithAuthentication.call(
|
||||
ref,
|
||||
credentialsName,
|
||||
options,
|
||||
)) as string;
|
||||
|
||||
return await jsonParse(webhooks);
|
||||
};
|
||||
|
||||
export const createWebHook = async (
|
||||
ref: IHookFunctions,
|
||||
type: string,
|
||||
events: string[],
|
||||
url: string,
|
||||
): Promise<WebhookId> => {
|
||||
const endpoint = `${baseURL}/webhooks`;
|
||||
|
||||
const options: IRequestOptions = {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
},
|
||||
uri: endpoint,
|
||||
body: {
|
||||
events,
|
||||
type,
|
||||
url,
|
||||
},
|
||||
};
|
||||
|
||||
const webhookId = await ref.helpers.requestWithAuthentication.call(
|
||||
ref,
|
||||
credentialsName,
|
||||
options,
|
||||
);
|
||||
|
||||
return await jsonParse(webhookId as string);
|
||||
};
|
||||
|
||||
export const deleteWebhook = async (ref: IHookFunctions, webhookId: string) => {
|
||||
const endpoint = `${baseURL}/webhooks/${webhookId}`;
|
||||
const body = {};
|
||||
|
||||
const options: IRequestOptions = {
|
||||
method: 'DELETE',
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
},
|
||||
uri: endpoint,
|
||||
body,
|
||||
};
|
||||
|
||||
return await ref.helpers.requestWithAuthentication.call(ref, credentialsName, options);
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,195 @@
|
||||
import type { INodeProperties } from 'n8n-workflow';
|
||||
|
||||
export const senderOperations: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Operation',
|
||||
name: 'operation',
|
||||
type: 'options',
|
||||
noDataExpression: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['sender'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: 'Create',
|
||||
value: 'create',
|
||||
action: 'Create a sender',
|
||||
},
|
||||
{
|
||||
name: 'Delete',
|
||||
value: 'delete',
|
||||
routing: {
|
||||
request: {
|
||||
method: 'DELETE',
|
||||
url: '=/v3/senders/{{$parameter.id}}',
|
||||
},
|
||||
output: {
|
||||
postReceive: [
|
||||
{
|
||||
type: 'set',
|
||||
properties: {
|
||||
value: '={{ { "success": true } }}',
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
action: 'Delete a sender',
|
||||
},
|
||||
{
|
||||
name: 'Get Many',
|
||||
value: 'getAll',
|
||||
routing: {
|
||||
request: {
|
||||
method: 'GET',
|
||||
url: '/v3/senders',
|
||||
},
|
||||
send: {
|
||||
paginate: false,
|
||||
},
|
||||
output: {
|
||||
postReceive: [
|
||||
{
|
||||
type: 'rootProperty',
|
||||
properties: {
|
||||
property: 'senders',
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
action: 'Get many senders',
|
||||
},
|
||||
],
|
||||
default: 'create',
|
||||
},
|
||||
];
|
||||
|
||||
const senderCreateOperation: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Name',
|
||||
name: 'name',
|
||||
type: 'string',
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['sender'],
|
||||
operation: ['create'],
|
||||
},
|
||||
},
|
||||
routing: {
|
||||
request: {
|
||||
method: 'POST',
|
||||
url: '/v3/senders',
|
||||
},
|
||||
send: {
|
||||
property: 'name',
|
||||
type: 'body',
|
||||
},
|
||||
},
|
||||
required: true,
|
||||
description: 'Name of the sender',
|
||||
},
|
||||
{
|
||||
displayName: 'Email',
|
||||
name: 'email',
|
||||
type: 'string',
|
||||
placeholder: 'name@email.com',
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['sender'],
|
||||
operation: ['create'],
|
||||
},
|
||||
},
|
||||
routing: {
|
||||
send: {
|
||||
property: 'email',
|
||||
type: 'body',
|
||||
},
|
||||
},
|
||||
required: true,
|
||||
description: 'Email of the sender',
|
||||
},
|
||||
];
|
||||
|
||||
const senderDeleteOperation: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Sender ID',
|
||||
name: 'id',
|
||||
type: 'string',
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['sender'],
|
||||
operation: ['delete'],
|
||||
},
|
||||
},
|
||||
description: 'ID of the sender to delete',
|
||||
},
|
||||
];
|
||||
|
||||
const senderGetAllOperation: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Return All',
|
||||
name: 'returnAll',
|
||||
type: 'boolean',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['sender'],
|
||||
operation: ['getAll'],
|
||||
},
|
||||
},
|
||||
default: false,
|
||||
description: 'Whether to return all results or only up to a given limit',
|
||||
},
|
||||
{
|
||||
displayName: 'Limit',
|
||||
name: 'limit',
|
||||
type: 'number',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['sender'],
|
||||
operation: ['getAll'],
|
||||
returnAll: [false],
|
||||
},
|
||||
},
|
||||
typeOptions: {
|
||||
minValue: 1,
|
||||
maxValue: 1000,
|
||||
},
|
||||
routing: {
|
||||
output: {
|
||||
postReceive: [
|
||||
{
|
||||
type: 'limit',
|
||||
properties: {
|
||||
maxResults: '={{$value}}',
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
default: 10,
|
||||
description: 'Max number of results to return',
|
||||
},
|
||||
];
|
||||
|
||||
export const senderFields: INodeProperties[] = [
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* sender:create */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
...senderCreateOperation,
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* sender:delete */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
...senderDeleteOperation,
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* sender:getAll */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
...senderGetAllOperation,
|
||||
];
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "integer"
|
||||
}
|
||||
},
|
||||
"version": 1
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"attributes": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"FIRSTNAME": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"createdAt": {
|
||||
"type": "string"
|
||||
},
|
||||
"email": {
|
||||
"type": "string"
|
||||
},
|
||||
"emailBlacklisted": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"id": {
|
||||
"type": "integer"
|
||||
},
|
||||
"listIds": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "integer"
|
||||
}
|
||||
},
|
||||
"modifiedAt": {
|
||||
"type": "string"
|
||||
},
|
||||
"smsBlacklisted": {
|
||||
"type": "boolean"
|
||||
}
|
||||
},
|
||||
"version": 2
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"attributes": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"FIRSTNAME": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"createdAt": {
|
||||
"type": "string"
|
||||
},
|
||||
"email": {
|
||||
"type": "string"
|
||||
},
|
||||
"emailBlacklisted": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"id": {
|
||||
"type": "integer"
|
||||
},
|
||||
"listIds": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "integer"
|
||||
}
|
||||
},
|
||||
"listUnsubscribed": {
|
||||
"type": "null"
|
||||
},
|
||||
"modifiedAt": {
|
||||
"type": "string"
|
||||
},
|
||||
"smsBlacklisted": {
|
||||
"type": "boolean"
|
||||
}
|
||||
},
|
||||
"version": 3
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"success": {
|
||||
"type": "boolean"
|
||||
}
|
||||
},
|
||||
"version": 1
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"success": {
|
||||
"type": "boolean"
|
||||
}
|
||||
},
|
||||
"version": 1
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"messageId": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"version": 1
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"messageId": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"version": 1
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="48" height="48" fill="none"><circle cx="24" cy="24" r="24" fill="#0B996E"/><path fill="#fff" d="M31.504 21.81c1.483-1.454 2.179-3.133 2.179-5.175 0-4.22-3.106-7.035-7.787-7.035H14.4v30h9.27C30.718 39.6 36 35.289 36 29.57c0-3.132-1.622-5.945-4.496-7.76m-12.932-8.308h6.86c2.317 0 3.848 1.316 3.848 3.313 0 2.269-1.993 3.994-6.072 5.31-2.781.861-4.032 1.588-4.496 2.451l-.14.002zm4.727 22.196h-4.727v-4.63c0-2.042 1.762-4.039 4.219-4.81 2.179-.727 3.985-1.454 5.516-2.224 2.039 1.181 3.29 3.222 3.29 5.356 0 3.63-3.523 6.308-8.298 6.308"/></svg>
|
||||
|
After Width: | Height: | Size: 590 B |
Reference in New Issue
Block a user