1
1
mirror of https://github.com/n8n-io/n8n.git synced 2024-09-22 02:29:40 +03:00

Small improvements to Mailjet-Node

This commit is contained in:
Jan Oberhauser 2020-02-14 16:56:22 -08:00
parent 202f7ada03
commit 91e5b7fde2
4 changed files with 165 additions and 119 deletions

View File

@ -50,50 +50,15 @@ export const emailFields = [
]
},
},
placeholder: 'admin@example.com',
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',
name: 'toEmails',
name: 'toEmail',
type: 'string',
required: true,
placeholder: 'info@example.com',
description: 'Email address of the recipient. Multiple ones can be separated by comma.',
displayOptions: {
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',
name: 'additionalFields',
@ -124,8 +137,8 @@ export const emailFields = [
},
options: [
{
displayName: 'Bcc Addresses',
name: 'bccAddresses',
displayName: 'Bcc Email',
name: 'bccEmail',
type: 'string',
description: 'Bcc Email address of the recipient. Multiple ones can be separated by comma.',
default: '',
@ -149,32 +162,60 @@ export const emailFields = [
type: 'number',
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',
name: 'templateLanguage',
type: 'boolean',
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',
},
{
displayName: 'Template',
name: 'templateId',
displayName: 'To Email',
name: 'toEmail',
type: 'string',
required: true,
default: '',
placeholder: 'info@example.com',
description: 'Email address of the recipient. Multiple ones can be separated by comma.',
displayOptions: {
show: {
resource: [
@ -256,11 +299,11 @@ export const emailFields = [
},
},
{
displayName: 'To Email',
name: 'toEmails',
displayName: 'Template',
name: 'templateId',
type: 'string',
required: true,
description: 'Email address of the recipient. Multiple ones can be separated by comma.',
default: '',
displayOptions: {
show: {
resource: [
@ -290,15 +333,15 @@ export const emailFields = [
},
options: [
{
displayName: 'Bcc Addresses',
name: 'bccAddresses',
displayName: 'Bcc Email',
name: 'bccEmail',
type: 'string',
description: 'Bcc Recipients of the email separated by ,.',
default: '',
},
{
displayName: 'Cc Addresses',
name: 'ccAddresses',
displayName: 'Cc Email',
name: 'ccEmail',
type: 'string',
description: 'Cc recipients of the email separated by ,.',
default: '',

View File

@ -52,7 +52,6 @@ export async function mailjetApiRequestAllItems(this: IExecuteFunctions | IHookF
query.Offset = 0;
do {
query.Offset;
responseData = await mailjetApiRequest.call(this, method, endpoint, body, query, undefined, { resolveWithFullResponse: true });
returnData.push.apply(returnData, responseData.body);
query.Offset = query.Offset + query.Limit;

View File

@ -96,10 +96,10 @@ export class Mailjet implements INodeType {
//https://dev.mailjet.com/email/guides/send-api-v31/#send-a-basic-email
if (operation === 'send') {
const fromEmail = this.getNodeParameter('fromEmail', i) as string;
const isBodyHtml = this.getNodeParameter('isBodyHtml', i) as boolean;
const message = this.getNodeParameter('body', i) as string;
const htmlBody = this.getNodeParameter('html', i) as string;
const textBody = this.getNodeParameter('text', i) as string;
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 body: IDataObject = {
@ -116,11 +116,11 @@ export class Mailjet implements INodeType {
],
//SandboxMode: true,
};
for (const toEmail of toEmails) {
for (const email of toEmail) {
//@ts-ignore
body.Messages[0].to.push({
email: toEmail,
})
email,
});
}
if (variables) {
for (const variable of variables) {
@ -128,28 +128,29 @@ export class Mailjet implements INodeType {
body.Messages[0].Variables[variable.name] = variable.value;
}
}
if (isBodyHtml) {
if (htmlBody) {
//@ts-ignore
body.Messages[0].HTMLPart = message;
} else {
//@ts-ignore
body.Messages[0].TextPart = message;
body.Messages[0].HTMLPart = htmlBody;
}
if (additionalFields.bccAddresses) {
const bccAddresses = (additionalFields.bccAddresses as string).split(',') as string[];
for (const bccAddress of bccAddresses) {
if (textBody) {
//@ts-ignore
body.Messages[0].TextPart = textBody;
}
if (additionalFields.bccEmail) {
const bccEmail = (additionalFields.bccEmail as string).split(',') as string[];
for (const email of bccEmail) {
//@ts-ignore
body.Messages[0].Bcc.push({
email: bccAddress,
email,
});
}
}
if (additionalFields.ccAddresses) {
const ccAddresses = (additionalFields.ccAddresses as string).split(',') as string[];
for (const ccAddress of ccAddresses) {
if (additionalFields.ccEmail) {
const ccEmail = (additionalFields.ccEmail as string).split(',') as string[];
for (const email of ccEmail) {
//@ts-ignore
body.Messages[0].Cc.push({
email: ccAddress,
email,
});
}
}
@ -185,9 +186,10 @@ export class Mailjet implements INodeType {
if (operation === 'sendTemplate') {
const fromEmail = this.getNodeParameter('fromEmail', 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 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 = {
Messages: [
@ -195,6 +197,7 @@ export class Mailjet implements INodeType {
From: {
email: fromEmail,
},
Subject: subject,
to: [],
Cc: [],
Bcc: [],
@ -204,10 +207,10 @@ export class Mailjet implements INodeType {
],
//SandboxMode: true,
};
for (const toEmail of toEmails) {
for (const email of toEmail) {
//@ts-ignore
body.Messages[0].to.push({
email: toEmail,
email,
});
}
if (variables) {
@ -216,28 +219,24 @@ export class Mailjet implements INodeType {
body.Messages[0].Variables[variable.name] = variable.value;
}
}
if (additionalFields.bccAddresses) {
const bccAddresses = (additionalFields.bccAddresses as string).split(',') as string[];
for (const bccAddress of bccAddresses) {
if (additionalFields.bccEmail) {
const bccEmail = (additionalFields.bccEmail as string).split(',') as string[];
for (const email of bccEmail) {
//@ts-ignore
body.Messages[0].Bcc.push({
email: bccAddress,
email,
});
}
}
if (additionalFields.ccAddresses) {
const ccAddresses = (additionalFields.ccAddresses as string).split(',') as string[];
for (const ccAddress of ccAddresses) {
if (additionalFields.ccEmail) {
const ccEmail = (additionalFields.ccEmail as string).split(',') as string[];
for (const email of ccEmail) {
//@ts-ignore
body.Messages[0].Cc.push({
email: ccAddress,
email,
});
}
}
if (additionalFields.subject) {
//@ts-ignore
body.Messages[0].Subject = additionalFields.subject as string;
}
if (additionalFields.trackOpens) {
//@ts-ignore
body.Messages[0].TrackOpens = additionalFields.trackOpens as string;

View File

@ -62,14 +62,14 @@ export class MailjetTrigger implements INodeType {
name: 'email.open',
value: 'open',
},
{
name: 'email.spam',
value: 'spam',
},
{
name: 'email.sent',
value: 'sent',
},
{
name: 'email.spam',
value: 'spam',
},
{
name: 'email.unsub',
value: 'unsub',
@ -85,17 +85,22 @@ export class MailjetTrigger implements INodeType {
webhookMethods = {
default: {
async checkExists(this: IHookFunctions): Promise<boolean> {
const webhookData = this.getWorkflowStaticData('node');
if (webhookData.webhookId === undefined) {
return false;
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');
webhookData.webhookId = webhook.ID as string;
return true;
}
}
const endpoint = `/v3/rest/eventcallbackurl/${webhookData.webhookId}`;
try {
await mailjetApiRequest.call(this, 'GET', endpoint);
} catch (e) {
return false;
}
return true;
return false;
},
async create(this: IHookFunctions): Promise<boolean> {
const webhookUrl = this.getNodeWebhookUrl('default');