mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +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) {
|
||||
const config = getSendAndWaitConfig(context);
|
||||
|
||||
const instanceId = context.getInstanceId();
|
||||
const attributionText = 'This message was sent automatically with ';
|
||||
const link = createUtmCampaignLink('n8n-nodes-base.discord', instanceId);
|
||||
const description = `${config.message}\n\n_${attributionText}_[n8n](${link})`;
|
||||
let description = config.message;
|
||||
if (config.appendAttribution !== false) {
|
||||
const instanceId = context.getInstanceId();
|
||||
const attributionText = 'This message was sent automatically with ';
|
||||
const link = createUtmCampaignLink('n8n-nodes-base.discord', instanceId);
|
||||
description = `${config.message}\n\n_${attributionText}_[n8n](${link})`;
|
||||
}
|
||||
|
||||
const body = {
|
||||
embeds: [
|
||||
|
||||
@@ -46,7 +46,8 @@ describe('Test EmailSendV2, email => sendAndWait', () => {
|
||||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce('my subject');
|
||||
mockExecuteFunctions.evaluateExpression.mockReturnValueOnce('http://localhost/waiting-webhook');
|
||||
mockExecuteFunctions.evaluateExpression.mockReturnValueOnce('nodeID');
|
||||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce({});
|
||||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce({}); // approvalOptions
|
||||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce({}); // options
|
||||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce('approval');
|
||||
|
||||
// configureWaitTillDate
|
||||
|
||||
@@ -8,7 +8,10 @@ import type {
|
||||
import { fromEmailProperty, toEmailProperty } from './descriptions';
|
||||
import { configureTransport } from './utils';
|
||||
import { configureWaitTillDate } from '../../../utils/sendAndWait/configureWaitTillDate.util';
|
||||
import { createEmailBody } from '../../../utils/sendAndWait/email-templates';
|
||||
import {
|
||||
createEmailBodyWithN8nAttribution,
|
||||
createEmailBodyWithoutN8nAttribution,
|
||||
} from '../../../utils/sendAndWait/email-templates';
|
||||
import {
|
||||
createButton,
|
||||
getSendAndWaitConfig,
|
||||
@@ -30,9 +33,14 @@ export async function execute(this: IExecuteFunctions): Promise<INodeExecutionDa
|
||||
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 = {
|
||||
from: fromEmail,
|
||||
|
||||
@@ -162,16 +162,19 @@ export function getPagingParameters(resource: string, operation = 'getAll') {
|
||||
export function createSendAndWaitMessageBody(context: IExecuteFunctions) {
|
||||
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(
|
||||
(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 = {
|
||||
text,
|
||||
|
||||
@@ -41,7 +41,8 @@ describe('Test GoogleChat, message => sendAndWait', () => {
|
||||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce('my subject');
|
||||
mockExecuteFunctions.evaluateExpression.mockReturnValueOnce('http://localhost/waiting-webhook');
|
||||
mockExecuteFunctions.evaluateExpression.mockReturnValueOnce('nodeID');
|
||||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce({});
|
||||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce({}); // approvalOptions
|
||||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce({}); // options
|
||||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce('approval');
|
||||
|
||||
// configureWaitTillDate
|
||||
|
||||
@@ -48,7 +48,8 @@ describe('Test MicrosoftOutlookV2, message => sendAndWait', () => {
|
||||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce('my subject');
|
||||
mockExecuteFunctions.evaluateExpression.mockReturnValueOnce('http://localhost/waiting-webhook');
|
||||
mockExecuteFunctions.evaluateExpression.mockReturnValueOnce('nodeID');
|
||||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce({});
|
||||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce({}); // approvalOptions
|
||||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce({}); // options
|
||||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce('approval');
|
||||
|
||||
// configureWaitTillDate
|
||||
|
||||
@@ -5,7 +5,10 @@ import type {
|
||||
INodeProperties,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import { createEmailBody } from '../../../../../../utils/sendAndWait/email-templates';
|
||||
import {
|
||||
createEmailBodyWithN8nAttribution,
|
||||
createEmailBodyWithoutN8nAttribution,
|
||||
} from '../../../../../../utils/sendAndWait/email-templates';
|
||||
import {
|
||||
getSendAndWaitConfig,
|
||||
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));
|
||||
}
|
||||
|
||||
const instanceId = this.getInstanceId();
|
||||
|
||||
const bodyContent = createEmailBody(config.message, buttons.join('\n'), instanceId);
|
||||
let bodyContent: string;
|
||||
if (config.appendAttribution !== false) {
|
||||
const instanceId = this.getInstanceId();
|
||||
bodyContent = createEmailBodyWithN8nAttribution(config.message, buttons.join('\n'), instanceId);
|
||||
} else {
|
||||
bodyContent = createEmailBodyWithoutN8nAttribution(config.message, buttons.join('\n'));
|
||||
}
|
||||
|
||||
const fields: IDataObject = {
|
||||
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 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(
|
||||
(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 = {
|
||||
body: {
|
||||
|
||||
@@ -12,6 +12,7 @@ import { NodeOperationError } from 'n8n-workflow';
|
||||
|
||||
import type { SendAndWaitMessageBody } from './MessageInterface';
|
||||
import { getSendAndWaitConfig } from '../../../utils/sendAndWait/utils';
|
||||
import { createUtmCampaignLink } from '../../../utils/utilities';
|
||||
|
||||
export async function slackApiRequest(
|
||||
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') {
|
||||
delete body.blocks[1].text.emoji;
|
||||
}
|
||||
|
||||
@@ -260,14 +260,17 @@ export function createSendAndWaitMessageBody(context: IExecuteFunctions) {
|
||||
const config = getSendAndWaitConfig(context);
|
||||
let text = config.message;
|
||||
|
||||
const instanceId = context.getInstanceId();
|
||||
const attributionText = 'This message was sent automatically with ';
|
||||
const link = createUtmCampaignLink('n8n-nodes-base.telegram', instanceId);
|
||||
text = `${text}\n\n_${attributionText}_[n8n](${link})`;
|
||||
if (config.appendAttribution !== false) {
|
||||
const instanceId = context.getInstanceId();
|
||||
const attributionText = 'This message was sent automatically with ';
|
||||
const link = createUtmCampaignLink('n8n-nodes-base.telegram', instanceId);
|
||||
text = `${text}\n\n_${attributionText}_[n8n](${link})`;
|
||||
}
|
||||
|
||||
const body = {
|
||||
chat_id,
|
||||
text,
|
||||
|
||||
disable_web_page_preview: true,
|
||||
parse_mode: 'Markdown',
|
||||
reply_markup: {
|
||||
|
||||
@@ -44,7 +44,8 @@ describe('Test Telegram, message => sendAndWait', () => {
|
||||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce('my subject');
|
||||
mockExecuteFunctions.evaluateExpression.mockReturnValueOnce('http://localhost/waiting-webhook');
|
||||
mockExecuteFunctions.evaluateExpression.mockReturnValueOnce('nodeID');
|
||||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce({});
|
||||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce({}); // approvalOptions
|
||||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce({}); // options
|
||||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce('approval');
|
||||
|
||||
// configureWaitTillDate
|
||||
|
||||
@@ -15,6 +15,7 @@ import type {
|
||||
WhatsAppAppWebhookSubscription,
|
||||
} from './types';
|
||||
import type { SendAndWaitConfig } from '../../utils/sendAndWait/utils';
|
||||
import { createUtmCampaignLink } from '../../utils/utilities';
|
||||
export const WHATSAPP_BASE_URL = 'https://graph.facebook.com/v13.0/';
|
||||
|
||||
async function appAccessTokenRead(
|
||||
@@ -109,11 +110,19 @@ export const createMessage = (
|
||||
sendAndWaitConfig: SendAndWaitConfig,
|
||||
phoneNumberId: string,
|
||||
recipientPhoneNumber: string,
|
||||
instanceId: string,
|
||||
): IHttpRequestOptions => {
|
||||
const buttons = sendAndWaitConfig.options.map((option) => {
|
||||
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 {
|
||||
baseURL: WHATSAPP_BASE_URL,
|
||||
method: 'POST',
|
||||
@@ -121,7 +130,7 @@ export const createMessage = (
|
||||
body: {
|
||||
messaging_product: 'whatsapp',
|
||||
text: {
|
||||
body: `${sendAndWaitConfig.message}\n\n${buttons.join('')}`,
|
||||
body: `${sendAndWaitConfig.message}\n\n${buttons.join('')}${n8nAttribution}`,
|
||||
},
|
||||
type: 'text',
|
||||
to: recipientPhoneNumber,
|
||||
|
||||
@@ -83,11 +83,12 @@ export class WhatsApp implements INodeType {
|
||||
);
|
||||
|
||||
const config = getSendAndWaitConfig(this);
|
||||
const instanceId = this.getInstanceId();
|
||||
|
||||
await this.helpers.httpRequestWithAuthentication.call(
|
||||
this,
|
||||
WHATSAPP_CREDENTIALS_TYPE,
|
||||
createMessage(config, phoneNumberId, recipientPhoneNumber),
|
||||
createMessage(config, phoneNumberId, recipientPhoneNumber, instanceId),
|
||||
);
|
||||
|
||||
const waitTill = configureWaitTillDate(this);
|
||||
|
||||
@@ -43,6 +43,7 @@ describe('createMessage', () => {
|
||||
mockSendAndWaitConfig,
|
||||
phoneID,
|
||||
recipientPhone,
|
||||
'',
|
||||
);
|
||||
|
||||
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({
|
||||
baseURL: WHATSAPP_BASE_URL,
|
||||
|
||||
@@ -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>
|
||||
`;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user