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:
Michael Kret
2023-10-03 11:18:59 +03:00
committed by GitHub
parent f0a66873b9
commit 8f9fe6269b
20 changed files with 345 additions and 57 deletions

View File

@@ -120,6 +120,14 @@ export const channelMessageFields: INodeProperties[] = [
},
},
options: [
{
displayName: 'Include Link to Workflow',
name: 'includeLinkToWorkflow',
type: 'boolean',
default: true,
description:
'Whether to append a link to this workflow at the end of the message. This is helpful if you have many workflows sending messages.',
},
{
displayName: 'Make Reply',
name: 'makeReply',

View File

@@ -95,6 +95,30 @@ export const chatMessageFields: INodeProperties[] = [
default: '',
description: 'The content of the item',
},
{
displayName: 'Options',
name: 'options',
type: 'collection',
displayOptions: {
show: {
operation: ['create'],
resource: ['chatMessage'],
},
},
default: {},
description: 'Other options to set',
placeholder: 'Add options',
options: [
{
displayName: 'Include Link to Workflow',
name: 'includeLinkToWorkflow',
type: 'boolean',
default: true,
description:
'Whether to append a link to this workflow at the end of the message. This is helpful if you have many workflows sending messages.',
},
],
},
/* -------------------------------------------------------------------------- */
/* chatMessage:get */

View File

@@ -89,3 +89,27 @@ export async function microsoftApiRequestAllItemsSkip(
return returnData;
}
export function prepareMessage(
this: IExecuteFunctions | ILoadOptionsFunctions,
message: string,
messageType: string,
includeLinkToWorkflow: boolean,
instanceId?: string,
) {
if (includeLinkToWorkflow) {
const { id } = this.getWorkflow();
const link = `${this.getInstanceBaseUrl()}workflow/${id}?utm_source=n8n-internal&utm_medium=powered_by&utm_campaign=${encodeURIComponent(
'n8n-nodes-base.microsoftTeams',
)}${instanceId ? '_' + instanceId : ''}`;
messageType = 'html';
message = `${message}<br><br><em> Powered by <a href="${link}">this n8n workflow</a> </em>`;
}
return {
body: {
contentType: messageType,
content: message,
},
};
}

View File

@@ -8,7 +8,11 @@ import type {
INodeTypeDescription,
} from 'n8n-workflow';
import { microsoftApiRequest, microsoftApiRequestAllItems } from './GenericFunctions';
import {
microsoftApiRequest,
microsoftApiRequestAllItems,
prepareMessage,
} from './GenericFunctions';
import { channelFields, channelOperations } from './ChannelDescription';
@@ -24,7 +28,7 @@ export class MicrosoftTeams implements INodeType {
name: 'microsoftTeams',
icon: 'file:teams.svg',
group: ['input'],
version: 1,
version: [1, 1.1],
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
description: 'Consume Microsoft Teams API',
defaults: {
@@ -266,6 +270,9 @@ export class MicrosoftTeams implements INodeType {
let responseData;
const resource = this.getNodeParameter('resource', 0);
const operation = this.getNodeParameter('operation', 0);
const nodeVersion = this.getNode().typeVersion;
const instanceId = await this.getInstanceId();
for (let i = 0; i < length; i++) {
try {
if (resource === 'channel') {
@@ -365,12 +372,18 @@ export class MicrosoftTeams implements INodeType {
const message = this.getNodeParameter('message', i) as string;
const options = this.getNodeParameter('options', i);
const body: IDataObject = {
body: {
contentType: messageType,
content: message,
},
};
let includeLinkToWorkflow = options.includeLinkToWorkflow;
if (includeLinkToWorkflow === undefined) {
includeLinkToWorkflow = nodeVersion >= 1.1;
}
const body: IDataObject = prepareMessage.call(
this,
message,
messageType,
includeLinkToWorkflow as boolean,
instanceId,
);
if (options.makeReply) {
const replyToId = options.makeReply as string;
@@ -420,12 +433,19 @@ export class MicrosoftTeams implements INodeType {
const chatId = this.getNodeParameter('chatId', i) as string;
const messageType = this.getNodeParameter('messageType', i) as string;
const message = this.getNodeParameter('message', i) as string;
const body: IDataObject = {
body: {
contentType: messageType,
content: message,
},
};
const options = this.getNodeParameter('options', i, {});
const includeLinkToWorkflow =
options.includeLinkToWorkflow !== false && nodeVersion >= 1.1;
const body: IDataObject = prepareMessage.call(
this,
message,
messageType,
includeLinkToWorkflow,
instanceId,
);
responseData = await microsoftApiRequest.call(
this,
'POST',