feat: Add appendN8nAttribution option to sendAndWait operation (#13697)

Co-authored-by: Michael Kret <michael.k@radency.com>
This commit is contained in:
Ria Scholz
2025-03-18 10:43:21 +01:00
committed by GitHub
parent 7e1036187f
commit d6d5a66f5d
16 changed files with 173 additions and 40 deletions

View File

@@ -79,7 +79,11 @@ export const ACTION_RECORDED_PAGE = `
</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 n8nWebsiteLink = `https://n8n.io/?utm_source=n8n-internal&utm_medium=send-and-wait${utm_campaign}`;
return `
@@ -139,3 +143,52 @@ export function createEmailBody(message: string, buttons: string, instanceId?: s
</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>
`;
}

View File

@@ -18,7 +18,8 @@ import {
ACTION_RECORDED_PAGE,
BUTTON_STYLE_PRIMARY,
BUTTON_STYLE_SECONDARY,
createEmailBody,
createEmailBodyWithN8nAttribution,
createEmailBodyWithoutN8nAttribution,
} from './email-templates';
import type { IEmail } from './interfaces';
import { formFieldsProperties } from '../../nodes/Form/Form.node';
@@ -30,6 +31,7 @@ export type SendAndWaitConfig = {
message: string;
url: string;
options: Array<{ label: string; value: string; style: string }>;
appendAttribution?: boolean;
};
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 ----------------------------------------------------------
export function getSendAndWaitProperties(
targetProperties: INodeProperties[],
@@ -232,7 +243,7 @@ export function getSendAndWaitProperties(
type: 'collection',
placeholder: 'Add option',
default: {},
options: [limitWaitTimeOption],
options: [limitWaitTimeOption, appendAttributionOption],
displayOptions: {
show: {
responseType: ['approval'],
@@ -273,6 +284,7 @@ export function getSendAndWaitProperties(
default: 'Submit',
},
limitWaitTimeOption,
appendAttributionOption,
],
displayOptions: {
show: {
@@ -456,11 +468,14 @@ export function getSendAndWaitConfig(context: IExecuteFunctions): SendAndWaitCon
buttonDisapprovalStyle?: string;
};
const options = context.getNodeParameter('options', 0, {});
const config: SendAndWaitConfig = {
title: subject,
message,
url: `${resumeUrl}/${nodeId}`,
options: [],
appendAttribution: options?.appendAttribution as boolean,
};
const responseType = context.getNodeParameter('responseType', 0, 'approval') as string;
@@ -525,14 +540,19 @@ export function createEmail(context: IExecuteFunctions) {
for (const option of config.options) {
buttons.push(createButton(config.url, option.label, option.value, option.style));
}
const instanceId = context.getInstanceId();
let emailBody: string;
if (config.appendAttribution !== false) {
const instanceId = context.getInstanceId();
emailBody = createEmailBodyWithN8nAttribution(config.message, buttons.join('\n'), instanceId);
} else {
emailBody = createEmailBodyWithoutN8nAttribution(config.message, buttons.join('\n'));
}
const email: IEmail = {
to,
subject: config.title,
body: '',
htmlBody: createEmailBody(config.message, buttons.join('\n'), instanceId),
htmlBody: emailBody,
};
return email;