mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 01:56:46 +00:00
feat(core): Add "Sent by n8n" attribution (#7183)
Github issue / Community forum post (link here to close automatically): --------- Co-authored-by: Giulio Andreini <g.andreini@gmail.com>
This commit is contained in:
@@ -64,12 +64,51 @@ export interface IMarkupReplyKeyboardRemove {
|
||||
* @param {IDataObject} body The body object to add fields to
|
||||
* @param {number} index The index of the item
|
||||
*/
|
||||
export function addAdditionalFields(this: IExecuteFunctions, body: IDataObject, index: number) {
|
||||
export function addAdditionalFields(
|
||||
this: IExecuteFunctions,
|
||||
body: IDataObject,
|
||||
index: number,
|
||||
nodeVersion?: number,
|
||||
instanceId?: string,
|
||||
) {
|
||||
const operation = this.getNodeParameter('operation', index);
|
||||
|
||||
// Add the additional fields
|
||||
const additionalFields = this.getNodeParameter('additionalFields', index);
|
||||
Object.assign(body, additionalFields);
|
||||
|
||||
const operation = this.getNodeParameter('operation', index);
|
||||
if (operation === 'sendMessage') {
|
||||
const attributionText = 'This message was sent automatically with ';
|
||||
const link = `https://n8n.io/?utm_source=n8n-internal&utm_medium=powered_by&utm_campaign=${encodeURIComponent(
|
||||
'n8n-nodes-base.telegram',
|
||||
)}${instanceId ? '_' + instanceId : ''}`;
|
||||
|
||||
if (nodeVersion && nodeVersion >= 1.1 && additionalFields.appendAttribution === undefined) {
|
||||
additionalFields.appendAttribution = true;
|
||||
}
|
||||
|
||||
if (!additionalFields.parse_mode) {
|
||||
additionalFields.parse_mode = 'Markdown';
|
||||
}
|
||||
|
||||
const regex = /(https?|ftp|file):\/\/\S+|www\.\S+|\S+\.\S+/;
|
||||
const containsUrl = regex.test(body.text as string);
|
||||
|
||||
if (!containsUrl) {
|
||||
body.disable_web_page_preview = true;
|
||||
}
|
||||
|
||||
if (additionalFields.appendAttribution) {
|
||||
if (additionalFields.parse_mode === 'Markdown') {
|
||||
body.text = `${body.text}\n\n_${attributionText}_[n8n](${link})`;
|
||||
} else if (additionalFields.parse_mode === 'HTML') {
|
||||
body.text = `${body.text}\n\n<em>${attributionText}</em><a href="${link}" target="_blank">n8n</a>`;
|
||||
}
|
||||
}
|
||||
|
||||
delete additionalFields.appendAttribution;
|
||||
}
|
||||
|
||||
Object.assign(body, additionalFields);
|
||||
|
||||
// Add the reply markup
|
||||
let replyMarkupOption = '';
|
||||
|
||||
Reference in New Issue
Block a user