mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
⚡ Small improvements to Mailjet-Node
This commit is contained in:
parent
202f7ada03
commit
91e5b7fde2
|
@ -50,50 +50,15 @@ export const emailFields = [
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
placeholder: 'admin@example.com',
|
||||||
description: 'The title for the email',
|
description: 'The title for the email',
|
||||||
},
|
},
|
||||||
{
|
|
||||||
displayName: 'Is Body HTML?',
|
|
||||||
name: 'isBodyHtml',
|
|
||||||
type: 'boolean',
|
|
||||||
required: true,
|
|
||||||
default: true,
|
|
||||||
displayOptions: {
|
|
||||||
show: {
|
|
||||||
resource: [
|
|
||||||
'email',
|
|
||||||
],
|
|
||||||
operation: [
|
|
||||||
'send',
|
|
||||||
]
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
displayName: 'Body',
|
|
||||||
name: 'body',
|
|
||||||
type: 'string',
|
|
||||||
required: true,
|
|
||||||
typeOptions: {
|
|
||||||
alwaysOpenEditWindow: true,
|
|
||||||
},
|
|
||||||
default: '',
|
|
||||||
displayOptions: {
|
|
||||||
show: {
|
|
||||||
resource: [
|
|
||||||
'email',
|
|
||||||
],
|
|
||||||
operation: [
|
|
||||||
'send',
|
|
||||||
]
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
displayName: 'To Email',
|
displayName: 'To Email',
|
||||||
name: 'toEmails',
|
name: 'toEmail',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
required: true,
|
required: true,
|
||||||
|
placeholder: 'info@example.com',
|
||||||
description: 'Email address of the recipient. Multiple ones can be separated by comma.',
|
description: 'Email address of the recipient. Multiple ones can be separated by comma.',
|
||||||
displayOptions: {
|
displayOptions: {
|
||||||
show: {
|
show: {
|
||||||
|
@ -106,6 +71,54 @@ export const emailFields = [
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Subject',
|
||||||
|
name: 'subject',
|
||||||
|
type: 'string',
|
||||||
|
default: '',
|
||||||
|
placeholder: 'My subject line',
|
||||||
|
description: 'Subject line of the email.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Text',
|
||||||
|
name: 'text',
|
||||||
|
type: 'string',
|
||||||
|
typeOptions: {
|
||||||
|
alwaysOpenEditWindow: true,
|
||||||
|
},
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
resource: [
|
||||||
|
'email',
|
||||||
|
],
|
||||||
|
operation: [
|
||||||
|
'send',
|
||||||
|
]
|
||||||
|
},
|
||||||
|
},
|
||||||
|
default: '',
|
||||||
|
description: 'Plain text message of email.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'HTML',
|
||||||
|
name: 'html',
|
||||||
|
type: 'string',
|
||||||
|
typeOptions: {
|
||||||
|
alwaysOpenEditWindow: true,
|
||||||
|
},
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
resource: [
|
||||||
|
'email',
|
||||||
|
],
|
||||||
|
operation: [
|
||||||
|
'send',
|
||||||
|
]
|
||||||
|
},
|
||||||
|
},
|
||||||
|
default: '',
|
||||||
|
description: 'HTML text message of email.',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
displayName: 'Additional Fields',
|
displayName: 'Additional Fields',
|
||||||
name: 'additionalFields',
|
name: 'additionalFields',
|
||||||
|
@ -124,8 +137,8 @@ export const emailFields = [
|
||||||
},
|
},
|
||||||
options: [
|
options: [
|
||||||
{
|
{
|
||||||
displayName: 'Bcc Addresses',
|
displayName: 'Bcc Email',
|
||||||
name: 'bccAddresses',
|
name: 'bccEmail',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
description: 'Bcc Email address of the recipient. Multiple ones can be separated by comma.',
|
description: 'Bcc Email address of the recipient. Multiple ones can be separated by comma.',
|
||||||
default: '',
|
default: '',
|
||||||
|
@ -149,32 +162,60 @@ export const emailFields = [
|
||||||
type: 'number',
|
type: 'number',
|
||||||
default: 2,
|
default: 2,
|
||||||
},
|
},
|
||||||
{
|
|
||||||
displayName: 'Subject',
|
|
||||||
name: 'subject',
|
|
||||||
type: 'string',
|
|
||||||
default: '',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
displayName: 'Track Opens',
|
|
||||||
name: 'trackOpens',
|
|
||||||
type: 'string',
|
|
||||||
description: 'Enable or disable open tracking on this message.',
|
|
||||||
default: '',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
displayName: 'Track Clicks',
|
|
||||||
name: 'trackClicks',
|
|
||||||
type: 'string',
|
|
||||||
description: 'Enable or disable open tracking on this message.',
|
|
||||||
default: '',
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
displayName: 'Template Language',
|
displayName: 'Template Language',
|
||||||
name: 'templateLanguage',
|
name: 'templateLanguage',
|
||||||
type: 'boolean',
|
type: 'boolean',
|
||||||
default: true,
|
default: true,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Track Clicks',
|
||||||
|
name: 'trackClicks',
|
||||||
|
type: 'options',
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
name: 'Account Default',
|
||||||
|
value: 'account_default',
|
||||||
|
description: 'Use the values specified in the Mailjet account',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Disabled',
|
||||||
|
value: 'disabled',
|
||||||
|
description: 'Disable tracking for this message',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Enabled',
|
||||||
|
value: 'enabled',
|
||||||
|
description: 'Enable tracking for this message',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
description: 'Enable or disable open tracking on this message.',
|
||||||
|
default: 'account_default',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Track Opens',
|
||||||
|
name: 'trackOpens',
|
||||||
|
type: 'options',
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
name: 'Account Default',
|
||||||
|
value: 'account_default',
|
||||||
|
description: 'Use the values specified in the Mailjet account',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Disabled',
|
||||||
|
value: 'disabled',
|
||||||
|
description: 'Disable tracking for this message',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Enabled',
|
||||||
|
value: 'enabled',
|
||||||
|
description: 'Enable tracking for this message',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
description: 'Enable or disable open tracking on this message.',
|
||||||
|
default: 'account_default',
|
||||||
|
},
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -236,14 +277,16 @@ export const emailFields = [
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
placeholder: 'admin@example.com',
|
||||||
description: 'The title for the email',
|
description: 'The title for the email',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
displayName: 'Template',
|
displayName: 'To Email',
|
||||||
name: 'templateId',
|
name: 'toEmail',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
required: true,
|
required: true,
|
||||||
default: '',
|
placeholder: 'info@example.com',
|
||||||
|
description: 'Email address of the recipient. Multiple ones can be separated by comma.',
|
||||||
displayOptions: {
|
displayOptions: {
|
||||||
show: {
|
show: {
|
||||||
resource: [
|
resource: [
|
||||||
|
@ -256,11 +299,11 @@ export const emailFields = [
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
displayName: 'To Email',
|
displayName: 'Template',
|
||||||
name: 'toEmails',
|
name: 'templateId',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
required: true,
|
required: true,
|
||||||
description: 'Email address of the recipient. Multiple ones can be separated by comma.',
|
default: '',
|
||||||
displayOptions: {
|
displayOptions: {
|
||||||
show: {
|
show: {
|
||||||
resource: [
|
resource: [
|
||||||
|
@ -290,15 +333,15 @@ export const emailFields = [
|
||||||
},
|
},
|
||||||
options: [
|
options: [
|
||||||
{
|
{
|
||||||
displayName: 'Bcc Addresses',
|
displayName: 'Bcc Email',
|
||||||
name: 'bccAddresses',
|
name: 'bccEmail',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
description: 'Bcc Recipients of the email separated by ,.',
|
description: 'Bcc Recipients of the email separated by ,.',
|
||||||
default: '',
|
default: '',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
displayName: 'Cc Addresses',
|
displayName: 'Cc Email',
|
||||||
name: 'ccAddresses',
|
name: 'ccEmail',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
description: 'Cc recipients of the email separated by ,.',
|
description: 'Cc recipients of the email separated by ,.',
|
||||||
default: '',
|
default: '',
|
||||||
|
|
|
@ -52,7 +52,6 @@ export async function mailjetApiRequestAllItems(this: IExecuteFunctions | IHookF
|
||||||
query.Offset = 0;
|
query.Offset = 0;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
query.Offset;
|
|
||||||
responseData = await mailjetApiRequest.call(this, method, endpoint, body, query, undefined, { resolveWithFullResponse: true });
|
responseData = await mailjetApiRequest.call(this, method, endpoint, body, query, undefined, { resolveWithFullResponse: true });
|
||||||
returnData.push.apply(returnData, responseData.body);
|
returnData.push.apply(returnData, responseData.body);
|
||||||
query.Offset = query.Offset + query.Limit;
|
query.Offset = query.Offset + query.Limit;
|
||||||
|
|
|
@ -96,10 +96,10 @@ export class Mailjet implements INodeType {
|
||||||
//https://dev.mailjet.com/email/guides/send-api-v31/#send-a-basic-email
|
//https://dev.mailjet.com/email/guides/send-api-v31/#send-a-basic-email
|
||||||
if (operation === 'send') {
|
if (operation === 'send') {
|
||||||
const fromEmail = this.getNodeParameter('fromEmail', i) as string;
|
const fromEmail = this.getNodeParameter('fromEmail', i) as string;
|
||||||
const isBodyHtml = this.getNodeParameter('isBodyHtml', i) as boolean;
|
const htmlBody = this.getNodeParameter('html', i) as string;
|
||||||
const message = this.getNodeParameter('body', i) as string;
|
const textBody = this.getNodeParameter('text', i) as string;
|
||||||
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
|
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
|
||||||
const toEmails = (this.getNodeParameter('toEmails', i) as string).split(',') as string[];
|
const toEmail = (this.getNodeParameter('toEmail', i) as string).split(',') as string[];
|
||||||
const variables = (this.getNodeParameter('variablesUi', i) as IDataObject).variablesValues as IDataObject[];
|
const variables = (this.getNodeParameter('variablesUi', i) as IDataObject).variablesValues as IDataObject[];
|
||||||
|
|
||||||
const body: IDataObject = {
|
const body: IDataObject = {
|
||||||
|
@ -116,11 +116,11 @@ export class Mailjet implements INodeType {
|
||||||
],
|
],
|
||||||
//SandboxMode: true,
|
//SandboxMode: true,
|
||||||
};
|
};
|
||||||
for (const toEmail of toEmails) {
|
for (const email of toEmail) {
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
body.Messages[0].to.push({
|
body.Messages[0].to.push({
|
||||||
email: toEmail,
|
email,
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
if (variables) {
|
if (variables) {
|
||||||
for (const variable of variables) {
|
for (const variable of variables) {
|
||||||
|
@ -128,28 +128,29 @@ export class Mailjet implements INodeType {
|
||||||
body.Messages[0].Variables[variable.name] = variable.value;
|
body.Messages[0].Variables[variable.name] = variable.value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (isBodyHtml) {
|
if (htmlBody) {
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
body.Messages[0].HTMLPart = message;
|
body.Messages[0].HTMLPart = htmlBody;
|
||||||
} else {
|
|
||||||
//@ts-ignore
|
|
||||||
body.Messages[0].TextPart = message;
|
|
||||||
}
|
}
|
||||||
if (additionalFields.bccAddresses) {
|
if (textBody) {
|
||||||
const bccAddresses = (additionalFields.bccAddresses as string).split(',') as string[];
|
//@ts-ignore
|
||||||
for (const bccAddress of bccAddresses) {
|
body.Messages[0].TextPart = textBody;
|
||||||
|
}
|
||||||
|
if (additionalFields.bccEmail) {
|
||||||
|
const bccEmail = (additionalFields.bccEmail as string).split(',') as string[];
|
||||||
|
for (const email of bccEmail) {
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
body.Messages[0].Bcc.push({
|
body.Messages[0].Bcc.push({
|
||||||
email: bccAddress,
|
email,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (additionalFields.ccAddresses) {
|
if (additionalFields.ccEmail) {
|
||||||
const ccAddresses = (additionalFields.ccAddresses as string).split(',') as string[];
|
const ccEmail = (additionalFields.ccEmail as string).split(',') as string[];
|
||||||
for (const ccAddress of ccAddresses) {
|
for (const email of ccEmail) {
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
body.Messages[0].Cc.push({
|
body.Messages[0].Cc.push({
|
||||||
email: ccAddress,
|
email,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -185,9 +186,10 @@ export class Mailjet implements INodeType {
|
||||||
if (operation === 'sendTemplate') {
|
if (operation === 'sendTemplate') {
|
||||||
const fromEmail = this.getNodeParameter('fromEmail', i) as string;
|
const fromEmail = this.getNodeParameter('fromEmail', i) as string;
|
||||||
const templateId = this.getNodeParameter('templateId', i) as string;
|
const templateId = this.getNodeParameter('templateId', i) as string;
|
||||||
|
const subject = this.getNodeParameter('subject', i) as string;
|
||||||
const variables = (this.getNodeParameter('variablesUi', i) as IDataObject).variablesValues as IDataObject[];
|
const variables = (this.getNodeParameter('variablesUi', i) as IDataObject).variablesValues as IDataObject[];
|
||||||
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
|
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
|
||||||
const toEmails = (this.getNodeParameter('toEmails', i) as string).split(',') as string[];
|
const toEmail = (this.getNodeParameter('toEmail', i) as string).split(',') as string[];
|
||||||
|
|
||||||
const body: IDataObject = {
|
const body: IDataObject = {
|
||||||
Messages: [
|
Messages: [
|
||||||
|
@ -195,6 +197,7 @@ export class Mailjet implements INodeType {
|
||||||
From: {
|
From: {
|
||||||
email: fromEmail,
|
email: fromEmail,
|
||||||
},
|
},
|
||||||
|
Subject: subject,
|
||||||
to: [],
|
to: [],
|
||||||
Cc: [],
|
Cc: [],
|
||||||
Bcc: [],
|
Bcc: [],
|
||||||
|
@ -204,10 +207,10 @@ export class Mailjet implements INodeType {
|
||||||
],
|
],
|
||||||
//SandboxMode: true,
|
//SandboxMode: true,
|
||||||
};
|
};
|
||||||
for (const toEmail of toEmails) {
|
for (const email of toEmail) {
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
body.Messages[0].to.push({
|
body.Messages[0].to.push({
|
||||||
email: toEmail,
|
email,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (variables) {
|
if (variables) {
|
||||||
|
@ -216,28 +219,24 @@ export class Mailjet implements INodeType {
|
||||||
body.Messages[0].Variables[variable.name] = variable.value;
|
body.Messages[0].Variables[variable.name] = variable.value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (additionalFields.bccAddresses) {
|
if (additionalFields.bccEmail) {
|
||||||
const bccAddresses = (additionalFields.bccAddresses as string).split(',') as string[];
|
const bccEmail = (additionalFields.bccEmail as string).split(',') as string[];
|
||||||
for (const bccAddress of bccAddresses) {
|
for (const email of bccEmail) {
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
body.Messages[0].Bcc.push({
|
body.Messages[0].Bcc.push({
|
||||||
email: bccAddress,
|
email,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (additionalFields.ccAddresses) {
|
if (additionalFields.ccEmail) {
|
||||||
const ccAddresses = (additionalFields.ccAddresses as string).split(',') as string[];
|
const ccEmail = (additionalFields.ccEmail as string).split(',') as string[];
|
||||||
for (const ccAddress of ccAddresses) {
|
for (const email of ccEmail) {
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
body.Messages[0].Cc.push({
|
body.Messages[0].Cc.push({
|
||||||
email: ccAddress,
|
email,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (additionalFields.subject) {
|
|
||||||
//@ts-ignore
|
|
||||||
body.Messages[0].Subject = additionalFields.subject as string;
|
|
||||||
}
|
|
||||||
if (additionalFields.trackOpens) {
|
if (additionalFields.trackOpens) {
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
body.Messages[0].TrackOpens = additionalFields.trackOpens as string;
|
body.Messages[0].TrackOpens = additionalFields.trackOpens as string;
|
||||||
|
|
|
@ -62,14 +62,14 @@ export class MailjetTrigger implements INodeType {
|
||||||
name: 'email.open',
|
name: 'email.open',
|
||||||
value: 'open',
|
value: 'open',
|
||||||
},
|
},
|
||||||
{
|
|
||||||
name: 'email.spam',
|
|
||||||
value: 'spam',
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
name: 'email.sent',
|
name: 'email.sent',
|
||||||
value: 'sent',
|
value: 'sent',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: 'email.spam',
|
||||||
|
value: 'spam',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: 'email.unsub',
|
name: 'email.unsub',
|
||||||
value: 'unsub',
|
value: 'unsub',
|
||||||
|
@ -85,17 +85,22 @@ export class MailjetTrigger implements INodeType {
|
||||||
webhookMethods = {
|
webhookMethods = {
|
||||||
default: {
|
default: {
|
||||||
async checkExists(this: IHookFunctions): Promise<boolean> {
|
async checkExists(this: IHookFunctions): Promise<boolean> {
|
||||||
|
const endpoint = `/v3/rest/eventcallbackurl`;
|
||||||
|
const responseData = await mailjetApiRequest.call(this, 'GET', endpoint);
|
||||||
|
|
||||||
|
const event = this.getNodeParameter('event') as string;
|
||||||
|
const webhookUrl = this.getNodeWebhookUrl('default');
|
||||||
|
|
||||||
|
for (const webhook of responseData.Data) {
|
||||||
|
if (webhook.EventType === event && webhook.Url === webhookUrl) {
|
||||||
|
// Set webhook-id to be sure that it can be deleted
|
||||||
const webhookData = this.getWorkflowStaticData('node');
|
const webhookData = this.getWorkflowStaticData('node');
|
||||||
if (webhookData.webhookId === undefined) {
|
webhookData.webhookId = webhook.ID as string;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
const endpoint = `/v3/rest/eventcallbackurl/${webhookData.webhookId}`;
|
|
||||||
try {
|
|
||||||
await mailjetApiRequest.call(this, 'GET', endpoint);
|
|
||||||
} catch (e) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
},
|
},
|
||||||
async create(this: IHookFunctions): Promise<boolean> {
|
async create(this: IHookFunctions): Promise<boolean> {
|
||||||
const webhookUrl = this.getNodeWebhookUrl('default');
|
const webhookUrl = this.getNodeWebhookUrl('default');
|
||||||
|
|
Loading…
Reference in a new issue