Files
n8n-enterprise-unlocked/packages/nodes-base/nodes/Microsoft/Teams/v2/actions/channel/update.operation.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

70 lines
1.7 KiB
TypeScript

import type { INodeProperties, IExecuteFunctions, IDataObject } from 'n8n-workflow';
import { updateDisplayOptions } from '@utils/utilities';
import { microsoftApiRequest } from '../../transport';
import { channelRLC, teamRLC } from '../../descriptions';
const properties: INodeProperties[] = [
teamRLC,
channelRLC,
{
displayName: 'Name',
name: 'name',
type: 'string',
default: '',
placeholder: 'e.g. My New Channel name',
description: 'The name of the channel',
},
{
displayName: 'Options',
name: 'options',
type: 'collection',
default: {},
placeholder: 'Add Option',
options: [
{
displayName: 'Description',
name: 'description',
type: 'string',
default: '',
description: 'The description of the channel',
typeOptions: {
rows: 2,
},
},
],
},
];
const displayOptions = {
show: {
resource: ['channel'],
operation: ['update'],
},
};
export const description = updateDisplayOptions(displayOptions, properties);
export async function execute(this: IExecuteFunctions, i: number) {
//https://docs.microsoft.com/en-us/graph/api/channel-patch?view=graph-rest-beta&tabs=http
const teamId = this.getNodeParameter('teamId', i, '', { extractValue: true }) as string;
const channelId = this.getNodeParameter('channelId', i, '', { extractValue: true }) as string;
const newName = this.getNodeParameter('name', i) as string;
const newDescription = this.getNodeParameter('options.description', i, '') as string;
const body: IDataObject = {};
if (newName) {
body.displayName = newName;
}
if (newDescription) {
body.description = newDescription;
}
await microsoftApiRequest.call(
this,
'PATCH',
`/v1.0/teams/${teamId}/channels/${channelId}`,
body,
);
return { success: true };
}