mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
feat: Add appendN8nAttribution option to sendAndWait operation (#13697)
Co-authored-by: Michael Kret <michael.k@radency.com>
This commit is contained in:
@@ -392,11 +392,13 @@ export async function sendDiscordMessage(
|
|||||||
|
|
||||||
export function createSendAndWaitMessageBody(context: IExecuteFunctions) {
|
export function createSendAndWaitMessageBody(context: IExecuteFunctions) {
|
||||||
const config = getSendAndWaitConfig(context);
|
const config = getSendAndWaitConfig(context);
|
||||||
|
let description = config.message;
|
||||||
|
if (config.appendAttribution !== false) {
|
||||||
const instanceId = context.getInstanceId();
|
const instanceId = context.getInstanceId();
|
||||||
const attributionText = 'This message was sent automatically with ';
|
const attributionText = 'This message was sent automatically with ';
|
||||||
const link = createUtmCampaignLink('n8n-nodes-base.discord', instanceId);
|
const link = createUtmCampaignLink('n8n-nodes-base.discord', instanceId);
|
||||||
const description = `${config.message}\n\n_${attributionText}_[n8n](${link})`;
|
description = `${config.message}\n\n_${attributionText}_[n8n](${link})`;
|
||||||
|
}
|
||||||
|
|
||||||
const body = {
|
const body = {
|
||||||
embeds: [
|
embeds: [
|
||||||
|
|||||||
@@ -46,7 +46,8 @@ describe('Test EmailSendV2, email => sendAndWait', () => {
|
|||||||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce('my subject');
|
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce('my subject');
|
||||||
mockExecuteFunctions.evaluateExpression.mockReturnValueOnce('http://localhost/waiting-webhook');
|
mockExecuteFunctions.evaluateExpression.mockReturnValueOnce('http://localhost/waiting-webhook');
|
||||||
mockExecuteFunctions.evaluateExpression.mockReturnValueOnce('nodeID');
|
mockExecuteFunctions.evaluateExpression.mockReturnValueOnce('nodeID');
|
||||||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce({});
|
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce({}); // approvalOptions
|
||||||
|
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce({}); // options
|
||||||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce('approval');
|
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce('approval');
|
||||||
|
|
||||||
// configureWaitTillDate
|
// configureWaitTillDate
|
||||||
|
|||||||
@@ -8,7 +8,10 @@ import type {
|
|||||||
import { fromEmailProperty, toEmailProperty } from './descriptions';
|
import { fromEmailProperty, toEmailProperty } from './descriptions';
|
||||||
import { configureTransport } from './utils';
|
import { configureTransport } from './utils';
|
||||||
import { configureWaitTillDate } from '../../../utils/sendAndWait/configureWaitTillDate.util';
|
import { configureWaitTillDate } from '../../../utils/sendAndWait/configureWaitTillDate.util';
|
||||||
import { createEmailBody } from '../../../utils/sendAndWait/email-templates';
|
import {
|
||||||
|
createEmailBodyWithN8nAttribution,
|
||||||
|
createEmailBodyWithoutN8nAttribution,
|
||||||
|
} from '../../../utils/sendAndWait/email-templates';
|
||||||
import {
|
import {
|
||||||
createButton,
|
createButton,
|
||||||
getSendAndWaitConfig,
|
getSendAndWaitConfig,
|
||||||
@@ -30,9 +33,14 @@ export async function execute(this: IExecuteFunctions): Promise<INodeExecutionDa
|
|||||||
buttons.push(createButton(config.url, option.label, option.value, option.style));
|
buttons.push(createButton(config.url, option.label, option.value, option.style));
|
||||||
}
|
}
|
||||||
|
|
||||||
const instanceId = this.getInstanceId();
|
let htmlBody: string;
|
||||||
|
|
||||||
const htmlBody = createEmailBody(config.message, buttons.join('\n'), instanceId);
|
if (config.appendAttribution !== false) {
|
||||||
|
const instanceId = this.getInstanceId();
|
||||||
|
htmlBody = createEmailBodyWithN8nAttribution(config.message, buttons.join('\n'), instanceId);
|
||||||
|
} else {
|
||||||
|
htmlBody = createEmailBodyWithoutN8nAttribution(config.message, buttons.join('\n'));
|
||||||
|
}
|
||||||
|
|
||||||
const mailOptions: IDataObject = {
|
const mailOptions: IDataObject = {
|
||||||
from: fromEmail,
|
from: fromEmail,
|
||||||
|
|||||||
@@ -162,16 +162,19 @@ export function getPagingParameters(resource: string, operation = 'getAll') {
|
|||||||
export function createSendAndWaitMessageBody(context: IExecuteFunctions) {
|
export function createSendAndWaitMessageBody(context: IExecuteFunctions) {
|
||||||
const config = getSendAndWaitConfig(context);
|
const config = getSendAndWaitConfig(context);
|
||||||
|
|
||||||
const instanceId = context.getInstanceId();
|
|
||||||
const attributionText = '_This_ _message_ _was_ _sent_ _automatically_ _with_';
|
|
||||||
const link = createUtmCampaignLink('n8n-nodes-base.googleChat', instanceId);
|
|
||||||
const attribution = `${attributionText} _<${link}|n8n>_`;
|
|
||||||
|
|
||||||
const buttons: string[] = config.options.map(
|
const buttons: string[] = config.options.map(
|
||||||
(option) => `*<${`${config.url}?approved=${option.value}`}|${option.label}>*`,
|
(option) => `*<${`${config.url}?approved=${option.value}`}|${option.label}>*`,
|
||||||
);
|
);
|
||||||
|
|
||||||
const text = `${config.message}\n\n\n${buttons.join(' ')}\n\n${attribution}`;
|
let text = `${config.message}\n\n\n${buttons.join(' ')}`;
|
||||||
|
|
||||||
|
if (config.appendAttribution !== false) {
|
||||||
|
const instanceId = context.getInstanceId();
|
||||||
|
const attributionText = '_This_ _message_ _was_ _sent_ _automatically_ _with_';
|
||||||
|
const link = createUtmCampaignLink('n8n-nodes-base.googleChat', instanceId);
|
||||||
|
const attribution = `${attributionText} _<${link}|n8n>_`;
|
||||||
|
text += `\n\n${attribution}`;
|
||||||
|
}
|
||||||
|
|
||||||
const body = {
|
const body = {
|
||||||
text,
|
text,
|
||||||
|
|||||||
@@ -41,7 +41,8 @@ describe('Test GoogleChat, message => sendAndWait', () => {
|
|||||||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce('my subject');
|
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce('my subject');
|
||||||
mockExecuteFunctions.evaluateExpression.mockReturnValueOnce('http://localhost/waiting-webhook');
|
mockExecuteFunctions.evaluateExpression.mockReturnValueOnce('http://localhost/waiting-webhook');
|
||||||
mockExecuteFunctions.evaluateExpression.mockReturnValueOnce('nodeID');
|
mockExecuteFunctions.evaluateExpression.mockReturnValueOnce('nodeID');
|
||||||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce({});
|
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce({}); // approvalOptions
|
||||||
|
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce({}); // options
|
||||||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce('approval');
|
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce('approval');
|
||||||
|
|
||||||
// configureWaitTillDate
|
// configureWaitTillDate
|
||||||
|
|||||||
@@ -48,7 +48,8 @@ describe('Test MicrosoftOutlookV2, message => sendAndWait', () => {
|
|||||||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce('my subject');
|
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce('my subject');
|
||||||
mockExecuteFunctions.evaluateExpression.mockReturnValueOnce('http://localhost/waiting-webhook');
|
mockExecuteFunctions.evaluateExpression.mockReturnValueOnce('http://localhost/waiting-webhook');
|
||||||
mockExecuteFunctions.evaluateExpression.mockReturnValueOnce('nodeID');
|
mockExecuteFunctions.evaluateExpression.mockReturnValueOnce('nodeID');
|
||||||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce({});
|
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce({}); // approvalOptions
|
||||||
|
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce({}); // options
|
||||||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce('approval');
|
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce('approval');
|
||||||
|
|
||||||
// configureWaitTillDate
|
// configureWaitTillDate
|
||||||
|
|||||||
@@ -5,7 +5,10 @@ import type {
|
|||||||
INodeProperties,
|
INodeProperties,
|
||||||
} from 'n8n-workflow';
|
} from 'n8n-workflow';
|
||||||
|
|
||||||
import { createEmailBody } from '../../../../../../utils/sendAndWait/email-templates';
|
import {
|
||||||
|
createEmailBodyWithN8nAttribution,
|
||||||
|
createEmailBodyWithoutN8nAttribution,
|
||||||
|
} from '../../../../../../utils/sendAndWait/email-templates';
|
||||||
import {
|
import {
|
||||||
getSendAndWaitConfig,
|
getSendAndWaitConfig,
|
||||||
getSendAndWaitProperties,
|
getSendAndWaitProperties,
|
||||||
@@ -34,9 +37,13 @@ export async function execute(this: IExecuteFunctions, index: number, items: INo
|
|||||||
buttons.push(createButton(config.url, option.label, option.value, option.style));
|
buttons.push(createButton(config.url, option.label, option.value, option.style));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let bodyContent: string;
|
||||||
|
if (config.appendAttribution !== false) {
|
||||||
const instanceId = this.getInstanceId();
|
const instanceId = this.getInstanceId();
|
||||||
|
bodyContent = createEmailBodyWithN8nAttribution(config.message, buttons.join('\n'), instanceId);
|
||||||
const bodyContent = createEmailBody(config.message, buttons.join('\n'), instanceId);
|
} else {
|
||||||
|
bodyContent = createEmailBodyWithoutN8nAttribution(config.message, buttons.join('\n'));
|
||||||
|
}
|
||||||
|
|
||||||
const fields: IDataObject = {
|
const fields: IDataObject = {
|
||||||
subject: config.title,
|
subject: config.title,
|
||||||
|
|||||||
@@ -23,15 +23,18 @@ export async function execute(this: IExecuteFunctions, i: number, instanceId: st
|
|||||||
const chatId = this.getNodeParameter('chatId', i, '', { extractValue: true }) as string;
|
const chatId = this.getNodeParameter('chatId', i, '', { extractValue: true }) as string;
|
||||||
const config = getSendAndWaitConfig(this);
|
const config = getSendAndWaitConfig(this);
|
||||||
|
|
||||||
const attributionText = 'This message was sent automatically with';
|
|
||||||
const link = createUtmCampaignLink('n8n-nodes-base.microsoftTeams', instanceId);
|
|
||||||
const attribution = `<em>${attributionText} <a href="${link}">n8n</a></em>`;
|
|
||||||
|
|
||||||
const buttons = config.options.map(
|
const buttons = config.options.map(
|
||||||
(option) => `<a href="${config.url}?approved=${option.value}">${option.label}</a>`,
|
(option) => `<a href="${config.url}?approved=${option.value}">${option.label}</a>`,
|
||||||
);
|
);
|
||||||
|
|
||||||
const content = `${config.message}<br><br>${buttons.join(' ')}<br><br>${attribution}`;
|
let content = `${config.message}<br><br>${buttons.join(' ')}`;
|
||||||
|
|
||||||
|
if (config.appendAttribution !== false) {
|
||||||
|
const attributionText = 'This message was sent automatically with';
|
||||||
|
const link = createUtmCampaignLink('n8n-nodes-base.microsoftTeams', instanceId);
|
||||||
|
const attribution = `<em>${attributionText} <a href="${link}">n8n</a></em>`;
|
||||||
|
content += `<br><br>${attribution}`;
|
||||||
|
}
|
||||||
|
|
||||||
const body = {
|
const body = {
|
||||||
body: {
|
body: {
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import { NodeOperationError } from 'n8n-workflow';
|
|||||||
|
|
||||||
import type { SendAndWaitMessageBody } from './MessageInterface';
|
import type { SendAndWaitMessageBody } from './MessageInterface';
|
||||||
import { getSendAndWaitConfig } from '../../../utils/sendAndWait/utils';
|
import { getSendAndWaitConfig } from '../../../utils/sendAndWait/utils';
|
||||||
|
import { createUtmCampaignLink } from '../../../utils/utilities';
|
||||||
|
|
||||||
export async function slackApiRequest(
|
export async function slackApiRequest(
|
||||||
this: IExecuteFunctions | ILoadOptionsFunctions | IWebhookFunctions,
|
this: IExecuteFunctions | ILoadOptionsFunctions | IWebhookFunctions,
|
||||||
@@ -307,6 +308,19 @@ export function createSendAndWaitMessageBody(context: IExecuteFunctions) {
|
|||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (config.appendAttribution) {
|
||||||
|
const instanceId = context.getInstanceId();
|
||||||
|
const attributionText = 'This message was sent automatically with ';
|
||||||
|
const link = createUtmCampaignLink('n8n-nodes-base.slack', instanceId);
|
||||||
|
body.blocks.push({
|
||||||
|
type: 'section',
|
||||||
|
text: {
|
||||||
|
type: 'mrkdwn',
|
||||||
|
text: `${attributionText} _<${link}|n8n>_`,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if (context.getNode().typeVersion > 2.2 && body.blocks?.[1]?.type === 'section') {
|
if (context.getNode().typeVersion > 2.2 && body.blocks?.[1]?.type === 'section') {
|
||||||
delete body.blocks[1].text.emoji;
|
delete body.blocks[1].text.emoji;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -260,14 +260,17 @@ export function createSendAndWaitMessageBody(context: IExecuteFunctions) {
|
|||||||
const config = getSendAndWaitConfig(context);
|
const config = getSendAndWaitConfig(context);
|
||||||
let text = config.message;
|
let text = config.message;
|
||||||
|
|
||||||
|
if (config.appendAttribution !== false) {
|
||||||
const instanceId = context.getInstanceId();
|
const instanceId = context.getInstanceId();
|
||||||
const attributionText = 'This message was sent automatically with ';
|
const attributionText = 'This message was sent automatically with ';
|
||||||
const link = createUtmCampaignLink('n8n-nodes-base.telegram', instanceId);
|
const link = createUtmCampaignLink('n8n-nodes-base.telegram', instanceId);
|
||||||
text = `${text}\n\n_${attributionText}_[n8n](${link})`;
|
text = `${text}\n\n_${attributionText}_[n8n](${link})`;
|
||||||
|
}
|
||||||
|
|
||||||
const body = {
|
const body = {
|
||||||
chat_id,
|
chat_id,
|
||||||
text,
|
text,
|
||||||
|
|
||||||
disable_web_page_preview: true,
|
disable_web_page_preview: true,
|
||||||
parse_mode: 'Markdown',
|
parse_mode: 'Markdown',
|
||||||
reply_markup: {
|
reply_markup: {
|
||||||
|
|||||||
@@ -44,7 +44,8 @@ describe('Test Telegram, message => sendAndWait', () => {
|
|||||||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce('my subject');
|
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce('my subject');
|
||||||
mockExecuteFunctions.evaluateExpression.mockReturnValueOnce('http://localhost/waiting-webhook');
|
mockExecuteFunctions.evaluateExpression.mockReturnValueOnce('http://localhost/waiting-webhook');
|
||||||
mockExecuteFunctions.evaluateExpression.mockReturnValueOnce('nodeID');
|
mockExecuteFunctions.evaluateExpression.mockReturnValueOnce('nodeID');
|
||||||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce({});
|
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce({}); // approvalOptions
|
||||||
|
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce({}); // options
|
||||||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce('approval');
|
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce('approval');
|
||||||
|
|
||||||
// configureWaitTillDate
|
// configureWaitTillDate
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import type {
|
|||||||
WhatsAppAppWebhookSubscription,
|
WhatsAppAppWebhookSubscription,
|
||||||
} from './types';
|
} from './types';
|
||||||
import type { SendAndWaitConfig } from '../../utils/sendAndWait/utils';
|
import type { SendAndWaitConfig } from '../../utils/sendAndWait/utils';
|
||||||
|
import { createUtmCampaignLink } from '../../utils/utilities';
|
||||||
export const WHATSAPP_BASE_URL = 'https://graph.facebook.com/v13.0/';
|
export const WHATSAPP_BASE_URL = 'https://graph.facebook.com/v13.0/';
|
||||||
|
|
||||||
async function appAccessTokenRead(
|
async function appAccessTokenRead(
|
||||||
@@ -109,11 +110,19 @@ export const createMessage = (
|
|||||||
sendAndWaitConfig: SendAndWaitConfig,
|
sendAndWaitConfig: SendAndWaitConfig,
|
||||||
phoneNumberId: string,
|
phoneNumberId: string,
|
||||||
recipientPhoneNumber: string,
|
recipientPhoneNumber: string,
|
||||||
|
instanceId: string,
|
||||||
): IHttpRequestOptions => {
|
): IHttpRequestOptions => {
|
||||||
const buttons = sendAndWaitConfig.options.map((option) => {
|
const buttons = sendAndWaitConfig.options.map((option) => {
|
||||||
return `*${option.label}:*\n_${sendAndWaitConfig.url}?approved=${option.value}_\n\n`;
|
return `*${option.label}:*\n_${sendAndWaitConfig.url}?approved=${option.value}_\n\n`;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let n8nAttribution: string = '';
|
||||||
|
if (sendAndWaitConfig.appendAttribution) {
|
||||||
|
const attributionText = 'This message was sent automatically with ';
|
||||||
|
const link = createUtmCampaignLink('n8n-nodes-base.whatsapp', instanceId);
|
||||||
|
n8nAttribution = `\n\n${attributionText}${link}`;
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
baseURL: WHATSAPP_BASE_URL,
|
baseURL: WHATSAPP_BASE_URL,
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
@@ -121,7 +130,7 @@ export const createMessage = (
|
|||||||
body: {
|
body: {
|
||||||
messaging_product: 'whatsapp',
|
messaging_product: 'whatsapp',
|
||||||
text: {
|
text: {
|
||||||
body: `${sendAndWaitConfig.message}\n\n${buttons.join('')}`,
|
body: `${sendAndWaitConfig.message}\n\n${buttons.join('')}${n8nAttribution}`,
|
||||||
},
|
},
|
||||||
type: 'text',
|
type: 'text',
|
||||||
to: recipientPhoneNumber,
|
to: recipientPhoneNumber,
|
||||||
|
|||||||
@@ -83,11 +83,12 @@ export class WhatsApp implements INodeType {
|
|||||||
);
|
);
|
||||||
|
|
||||||
const config = getSendAndWaitConfig(this);
|
const config = getSendAndWaitConfig(this);
|
||||||
|
const instanceId = this.getInstanceId();
|
||||||
|
|
||||||
await this.helpers.httpRequestWithAuthentication.call(
|
await this.helpers.httpRequestWithAuthentication.call(
|
||||||
this,
|
this,
|
||||||
WHATSAPP_CREDENTIALS_TYPE,
|
WHATSAPP_CREDENTIALS_TYPE,
|
||||||
createMessage(config, phoneNumberId, recipientPhoneNumber),
|
createMessage(config, phoneNumberId, recipientPhoneNumber, instanceId),
|
||||||
);
|
);
|
||||||
|
|
||||||
const waitTill = configureWaitTillDate(this);
|
const waitTill = configureWaitTillDate(this);
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ describe('createMessage', () => {
|
|||||||
mockSendAndWaitConfig,
|
mockSendAndWaitConfig,
|
||||||
phoneID,
|
phoneID,
|
||||||
recipientPhone,
|
recipientPhone,
|
||||||
|
'',
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(request).toEqual({
|
expect(request).toEqual({
|
||||||
@@ -77,7 +78,12 @@ describe('createMessage', () => {
|
|||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
const request: IHttpRequestOptions = createMessage(singleOptionConfig, phoneID, recipientPhone);
|
const request: IHttpRequestOptions = createMessage(
|
||||||
|
singleOptionConfig,
|
||||||
|
phoneID,
|
||||||
|
recipientPhone,
|
||||||
|
'',
|
||||||
|
);
|
||||||
|
|
||||||
expect(request).toEqual({
|
expect(request).toEqual({
|
||||||
baseURL: WHATSAPP_BASE_URL,
|
baseURL: WHATSAPP_BASE_URL,
|
||||||
|
|||||||
@@ -79,7 +79,11 @@ export const ACTION_RECORDED_PAGE = `
|
|||||||
|
|
||||||
</html>`;
|
</html>`;
|
||||||
|
|
||||||
export function createEmailBody(message: string, buttons: string, instanceId?: string) {
|
export function createEmailBodyWithN8nAttribution(
|
||||||
|
message: string,
|
||||||
|
buttons: string,
|
||||||
|
instanceId?: string,
|
||||||
|
) {
|
||||||
const utm_campaign = instanceId ? `&utm_campaign=${instanceId}` : '';
|
const utm_campaign = instanceId ? `&utm_campaign=${instanceId}` : '';
|
||||||
const n8nWebsiteLink = `https://n8n.io/?utm_source=n8n-internal&utm_medium=send-and-wait${utm_campaign}`;
|
const n8nWebsiteLink = `https://n8n.io/?utm_source=n8n-internal&utm_medium=send-and-wait${utm_campaign}`;
|
||||||
return `
|
return `
|
||||||
@@ -139,3 +143,52 @@ export function createEmailBody(message: string, buttons: string, instanceId?: s
|
|||||||
</html>
|
</html>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function createEmailBodyWithoutN8nAttribution(message: string, buttons: string) {
|
||||||
|
return `
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang='en'>
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>My form</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body
|
||||||
|
style="font-family: Arial, sans-serif; font-size: 12px; background-color: #fbfcfe; margin: 0; padding: 0;">
|
||||||
|
<table width="100%" cellpadding="0" cellspacing="0"
|
||||||
|
style="background-color:#fbfcfe; border: 1px solid #dbdfe7; border-radius: 8px;">
|
||||||
|
<tr>
|
||||||
|
<td align="center" style="padding: 24px 0;">
|
||||||
|
<table width="448" cellpadding="0" cellspacing="0" border="0"
|
||||||
|
style="width: 100%; max-width: 448px; background-color: #ffffff; border: 1px solid #dbdfe7; border-radius: 8px; padding: 24px; box-shadow: 0px 4px 16px rgba(99, 77, 255, 0.06);">
|
||||||
|
<tr>
|
||||||
|
<td
|
||||||
|
style="text-align: center; padding-top: 8px; font-family: Arial, sans-serif; font-size: 14px; color: #7e8186;">
|
||||||
|
<p style="white-space: pre-line;">${message}</p>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td align="center" style="padding-top: 12px;">
|
||||||
|
${buttons}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<!-- Divider -->
|
||||||
|
<table width="100%" cellpadding="0" cellspacing="0" border="0" style="margin-bottom: 24px;">
|
||||||
|
<tr>
|
||||||
|
<td style="border-top: 0px solid #dbdfe7;"></td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|||||||
@@ -18,7 +18,8 @@ import {
|
|||||||
ACTION_RECORDED_PAGE,
|
ACTION_RECORDED_PAGE,
|
||||||
BUTTON_STYLE_PRIMARY,
|
BUTTON_STYLE_PRIMARY,
|
||||||
BUTTON_STYLE_SECONDARY,
|
BUTTON_STYLE_SECONDARY,
|
||||||
createEmailBody,
|
createEmailBodyWithN8nAttribution,
|
||||||
|
createEmailBodyWithoutN8nAttribution,
|
||||||
} from './email-templates';
|
} from './email-templates';
|
||||||
import type { IEmail } from './interfaces';
|
import type { IEmail } from './interfaces';
|
||||||
import { formFieldsProperties } from '../../nodes/Form/Form.node';
|
import { formFieldsProperties } from '../../nodes/Form/Form.node';
|
||||||
@@ -30,6 +31,7 @@ export type SendAndWaitConfig = {
|
|||||||
message: string;
|
message: string;
|
||||||
url: string;
|
url: string;
|
||||||
options: Array<{ label: string; value: string; style: string }>;
|
options: Array<{ label: string; value: string; style: string }>;
|
||||||
|
appendAttribution?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
type FormResponseTypeOptions = {
|
type FormResponseTypeOptions = {
|
||||||
@@ -57,6 +59,15 @@ const limitWaitTimeOption: INodeProperties = {
|
|||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const appendAttributionOption: INodeProperties = {
|
||||||
|
displayName: 'Append n8n Attribution',
|
||||||
|
name: 'appendAttribution',
|
||||||
|
type: 'boolean',
|
||||||
|
default: true,
|
||||||
|
description:
|
||||||
|
'Whether to include the phrase "This message was sent automatically with n8n" to the end of the message',
|
||||||
|
};
|
||||||
|
|
||||||
// Operation Properties ----------------------------------------------------------
|
// Operation Properties ----------------------------------------------------------
|
||||||
export function getSendAndWaitProperties(
|
export function getSendAndWaitProperties(
|
||||||
targetProperties: INodeProperties[],
|
targetProperties: INodeProperties[],
|
||||||
@@ -232,7 +243,7 @@ export function getSendAndWaitProperties(
|
|||||||
type: 'collection',
|
type: 'collection',
|
||||||
placeholder: 'Add option',
|
placeholder: 'Add option',
|
||||||
default: {},
|
default: {},
|
||||||
options: [limitWaitTimeOption],
|
options: [limitWaitTimeOption, appendAttributionOption],
|
||||||
displayOptions: {
|
displayOptions: {
|
||||||
show: {
|
show: {
|
||||||
responseType: ['approval'],
|
responseType: ['approval'],
|
||||||
@@ -273,6 +284,7 @@ export function getSendAndWaitProperties(
|
|||||||
default: 'Submit',
|
default: 'Submit',
|
||||||
},
|
},
|
||||||
limitWaitTimeOption,
|
limitWaitTimeOption,
|
||||||
|
appendAttributionOption,
|
||||||
],
|
],
|
||||||
displayOptions: {
|
displayOptions: {
|
||||||
show: {
|
show: {
|
||||||
@@ -456,11 +468,14 @@ export function getSendAndWaitConfig(context: IExecuteFunctions): SendAndWaitCon
|
|||||||
buttonDisapprovalStyle?: string;
|
buttonDisapprovalStyle?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const options = context.getNodeParameter('options', 0, {});
|
||||||
|
|
||||||
const config: SendAndWaitConfig = {
|
const config: SendAndWaitConfig = {
|
||||||
title: subject,
|
title: subject,
|
||||||
message,
|
message,
|
||||||
url: `${resumeUrl}/${nodeId}`,
|
url: `${resumeUrl}/${nodeId}`,
|
||||||
options: [],
|
options: [],
|
||||||
|
appendAttribution: options?.appendAttribution as boolean,
|
||||||
};
|
};
|
||||||
|
|
||||||
const responseType = context.getNodeParameter('responseType', 0, 'approval') as string;
|
const responseType = context.getNodeParameter('responseType', 0, 'approval') as string;
|
||||||
@@ -525,14 +540,19 @@ export function createEmail(context: IExecuteFunctions) {
|
|||||||
for (const option of config.options) {
|
for (const option of config.options) {
|
||||||
buttons.push(createButton(config.url, option.label, option.value, option.style));
|
buttons.push(createButton(config.url, option.label, option.value, option.style));
|
||||||
}
|
}
|
||||||
|
let emailBody: string;
|
||||||
|
if (config.appendAttribution !== false) {
|
||||||
const instanceId = context.getInstanceId();
|
const instanceId = context.getInstanceId();
|
||||||
|
emailBody = createEmailBodyWithN8nAttribution(config.message, buttons.join('\n'), instanceId);
|
||||||
|
} else {
|
||||||
|
emailBody = createEmailBodyWithoutN8nAttribution(config.message, buttons.join('\n'));
|
||||||
|
}
|
||||||
|
|
||||||
const email: IEmail = {
|
const email: IEmail = {
|
||||||
to,
|
to,
|
||||||
subject: config.title,
|
subject: config.title,
|
||||||
body: '',
|
body: '',
|
||||||
htmlBody: createEmailBody(config.message, buttons.join('\n'), instanceId),
|
htmlBody: emailBody,
|
||||||
};
|
};
|
||||||
|
|
||||||
return email;
|
return email;
|
||||||
|
|||||||
Reference in New Issue
Block a user