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}
Powered by this n8n workflow `;
}
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;
});
}