feat(Microsoft Teams Node): Overhaul (#7477)
Co-authored-by: Giulio Andreini <andreini@netseven.it>
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
import type { INodeProperties, IExecuteFunctions, IDataObject } from 'n8n-workflow';
|
||||
import { updateDisplayOptions } from '@utils/utilities';
|
||||
import { microsoftApiRequest } from '../../transport';
|
||||
import { teamRLC } from '../../descriptions';
|
||||
|
||||
const properties: INodeProperties[] = [
|
||||
teamRLC,
|
||||
{
|
||||
displayName: 'New Channel Name',
|
||||
name: 'name',
|
||||
required: true,
|
||||
type: 'string',
|
||||
default: '',
|
||||
placeholder: 'e.g. My New Channel',
|
||||
description: 'The name of the new channel you want to create',
|
||||
},
|
||||
{
|
||||
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,
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Type',
|
||||
name: 'type',
|
||||
type: 'options',
|
||||
options: [
|
||||
{
|
||||
name: 'Private',
|
||||
value: 'private',
|
||||
},
|
||||
{
|
||||
name: 'Standard',
|
||||
value: 'standard',
|
||||
},
|
||||
],
|
||||
default: 'standard',
|
||||
description:
|
||||
'Standard: Accessible to everyone on the team. Private: Accessible only to a specific group of people within the team.',
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
const displayOptions = {
|
||||
show: {
|
||||
resource: ['channel'],
|
||||
operation: ['create'],
|
||||
},
|
||||
};
|
||||
|
||||
export const description = updateDisplayOptions(displayOptions, properties);
|
||||
|
||||
export async function execute(this: IExecuteFunctions, i: number) {
|
||||
//https://docs.microsoft.com/en-us/graph/api/channel-post?view=graph-rest-beta&tabs=http
|
||||
const teamId = this.getNodeParameter('teamId', i, '', { extractValue: true }) as string;
|
||||
const name = this.getNodeParameter('name', i) as string;
|
||||
const options = this.getNodeParameter('options', i);
|
||||
|
||||
const body: IDataObject = {
|
||||
displayName: name,
|
||||
};
|
||||
if (options.description) {
|
||||
body.description = options.description as string;
|
||||
}
|
||||
if (options.type) {
|
||||
body.membershipType = options.type as string;
|
||||
}
|
||||
return await microsoftApiRequest.call(this, 'POST', `/v1.0/teams/${teamId}/channels`, body);
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
import { type INodeProperties, type IExecuteFunctions, NodeOperationError } from 'n8n-workflow';
|
||||
import { updateDisplayOptions } from '@utils/utilities';
|
||||
import { microsoftApiRequest } from '../../transport';
|
||||
import { channelRLC, teamRLC } from '../../descriptions';
|
||||
|
||||
const properties: INodeProperties[] = [teamRLC, channelRLC];
|
||||
|
||||
const displayOptions = {
|
||||
show: {
|
||||
resource: ['channel'],
|
||||
operation: ['deleteChannel'],
|
||||
},
|
||||
};
|
||||
|
||||
export const description = updateDisplayOptions(displayOptions, properties);
|
||||
|
||||
export async function execute(this: IExecuteFunctions, i: number) {
|
||||
//https://docs.microsoft.com/en-us/graph/api/channel-delete?view=graph-rest-beta&tabs=http
|
||||
|
||||
try {
|
||||
const teamId = this.getNodeParameter('teamId', i, '', { extractValue: true }) as string;
|
||||
const channelId = this.getNodeParameter('channelId', i, '', { extractValue: true }) as string;
|
||||
|
||||
await microsoftApiRequest.call(this, 'DELETE', `/v1.0/teams/${teamId}/channels/${channelId}`);
|
||||
return { success: true };
|
||||
} catch (error) {
|
||||
throw new NodeOperationError(
|
||||
this.getNode(),
|
||||
"The channel you are trying to delete doesn't exist",
|
||||
{
|
||||
description: "Check that the 'Channel' parameter is correctly set",
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
import { type INodeProperties, type IExecuteFunctions, NodeOperationError } from 'n8n-workflow';
|
||||
import { updateDisplayOptions } from '@utils/utilities';
|
||||
import { microsoftApiRequest } from '../../transport';
|
||||
import { channelRLC, teamRLC } from '../../descriptions';
|
||||
|
||||
const properties: INodeProperties[] = [teamRLC, channelRLC];
|
||||
|
||||
const displayOptions = {
|
||||
show: {
|
||||
resource: ['channel'],
|
||||
operation: ['get'],
|
||||
},
|
||||
};
|
||||
|
||||
export const description = updateDisplayOptions(displayOptions, properties);
|
||||
|
||||
export async function execute(this: IExecuteFunctions, i: number) {
|
||||
//https://docs.microsoft.com/en-us/graph/api/channel-get?view=graph-rest-beta&tabs=http
|
||||
|
||||
try {
|
||||
const teamId = this.getNodeParameter('teamId', i, '', { extractValue: true }) as string;
|
||||
const channelId = this.getNodeParameter('channelId', i, '', { extractValue: true }) as string;
|
||||
|
||||
return await microsoftApiRequest.call(
|
||||
this,
|
||||
'GET',
|
||||
`/v1.0/teams/${teamId}/channels/${channelId}`,
|
||||
);
|
||||
} catch (error) {
|
||||
throw new NodeOperationError(
|
||||
this.getNode(),
|
||||
"The channel you are trying to get doesn't exist",
|
||||
{
|
||||
description: "Check that the 'Channel' parameter is correctly set",
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
import type { INodeProperties, IExecuteFunctions } from 'n8n-workflow';
|
||||
import { updateDisplayOptions } from '@utils/utilities';
|
||||
import { returnAllOrLimit } from '@utils/descriptions';
|
||||
import { microsoftApiRequestAllItems } from '../../transport';
|
||||
import { teamRLC } from '../../descriptions';
|
||||
|
||||
const properties: INodeProperties[] = [teamRLC, ...returnAllOrLimit];
|
||||
|
||||
const displayOptions = {
|
||||
show: {
|
||||
resource: ['channel'],
|
||||
operation: ['getAll'],
|
||||
},
|
||||
};
|
||||
|
||||
export const description = updateDisplayOptions(displayOptions, properties);
|
||||
|
||||
export async function execute(this: IExecuteFunctions, i: number) {
|
||||
//https://docs.microsoft.com/en-us/graph/api/channel-list?view=graph-rest-beta&tabs=http
|
||||
|
||||
const teamId = this.getNodeParameter('teamId', i, '', { extractValue: true }) as string;
|
||||
const returnAll = this.getNodeParameter('returnAll', i);
|
||||
if (returnAll) {
|
||||
return await microsoftApiRequestAllItems.call(
|
||||
this,
|
||||
'value',
|
||||
'GET',
|
||||
`/v1.0/teams/${teamId}/channels`,
|
||||
);
|
||||
} else {
|
||||
const limit = this.getNodeParameter('limit', i);
|
||||
const responseData = await microsoftApiRequestAllItems.call(
|
||||
this,
|
||||
'value',
|
||||
'GET',
|
||||
`/v1.0/teams/${teamId}/channels`,
|
||||
{},
|
||||
);
|
||||
return responseData.splice(0, limit);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
import type { INodeProperties } from 'n8n-workflow';
|
||||
|
||||
import * as create from './create.operation';
|
||||
import * as deleteChannel from './deleteChannel.operation';
|
||||
import * as get from './get.operation';
|
||||
import * as getAll from './getAll.operation';
|
||||
import * as update from './update.operation';
|
||||
|
||||
export { create, deleteChannel, get, getAll, update };
|
||||
|
||||
export const description: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Operation',
|
||||
name: 'operation',
|
||||
type: 'options',
|
||||
noDataExpression: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['channel'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: 'Create',
|
||||
value: 'create',
|
||||
description: 'Create a channel',
|
||||
action: 'Create channel',
|
||||
},
|
||||
{
|
||||
name: 'Delete',
|
||||
value: 'deleteChannel',
|
||||
description: 'Delete a channel',
|
||||
action: 'Delete channel',
|
||||
},
|
||||
{
|
||||
name: 'Get',
|
||||
value: 'get',
|
||||
description: 'Get a channel',
|
||||
action: 'Get channel',
|
||||
},
|
||||
{
|
||||
name: 'Get Many',
|
||||
value: 'getAll',
|
||||
description: 'Get many channels',
|
||||
action: 'Get many channels',
|
||||
},
|
||||
{
|
||||
name: 'Update',
|
||||
value: 'update',
|
||||
description: 'Update a channel',
|
||||
action: 'Update channel',
|
||||
},
|
||||
],
|
||||
default: 'create',
|
||||
},
|
||||
|
||||
...create.description,
|
||||
...deleteChannel.description,
|
||||
...get.description,
|
||||
...getAll.description,
|
||||
...update.description,
|
||||
];
|
||||
@@ -0,0 +1,69 @@
|
||||
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 };
|
||||
}
|
||||
Reference in New Issue
Block a user