n8n/packages/nodes-base/nodes/Microsoft/Teams/v2/helpers/utils.ts
Michael Kret 2c146cca62
feat(Microsoft Teams Node): Overhaul (#7477)
Co-authored-by: Giulio Andreini <andreini@netseven.it>
2024-01-22 18:35:09 +02:00

45 lines
1.2 KiB
TypeScript

import type { IExecuteFunctions, ILoadOptionsFunctions, INodeListSearchItems } from 'n8n-workflow';
export function prepareMessage(
this: IExecuteFunctions | ILoadOptionsFunctions,
message: string,
contentType: 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 : ''}`;
contentType = 'html';
message = `${message}<br><br><em> Powered by <a href="${link}">this n8n workflow</a> </em>`;
}
return {
body: {
contentType,
content: message,
},
};
}
export function filterSortSearchListItems(items: INodeListSearchItems[], filter?: string) {
return items
.filter(
(item) =>
!filter ||
item.name.toLowerCase().includes(filter.toLowerCase()) ||
item.value.toString().toLowerCase().includes(filter.toLowerCase()),
)
.sort((a, b) => {
if (a.name.toLocaleLowerCase() < b.name.toLocaleLowerCase()) {
return -1;
}
if (a.name.toLocaleLowerCase() > b.name.toLocaleLowerCase()) {
return 1;
}
return 0;
});
}