feat(Microsoft Teams Node): Overhaul (#7477)

Co-authored-by: Giulio Andreini <andreini@netseven.it>
This commit is contained in:
Michael Kret
2024-01-22 18:35:09 +02:00
committed by GitHub
parent 44f6ef2ed7
commit 2c146cca62
68 changed files with 6284 additions and 664 deletions

View File

@@ -0,0 +1,109 @@
import type { INodeProperties, IExecuteFunctions, IDataObject } from 'n8n-workflow';
import { updateDisplayOptions } from '@utils/utilities';
import { bucketRLC, groupRLC, memberRLC, planRLC } from '../../descriptions';
import { microsoftApiRequest } from '../../transport';
import { DateTime } from 'luxon';
const properties: INodeProperties[] = [
groupRLC,
planRLC,
bucketRLC,
{
displayName: 'Title',
name: 'title',
required: true,
type: 'string',
default: '',
placeholder: 'e.g. new task',
description: 'Title of the task',
},
{
displayName: 'Options',
name: 'options',
type: 'collection',
default: {},
placeholder: 'Add Option',
options: [
{
...memberRLC,
displayName: 'Assigned To',
name: 'assignedTo',
description: 'Who the task should be assigned to',
typeOptions: {
loadOptionsDependsOn: ['groupId.balue'],
},
},
{
displayName: 'Due Date Time',
name: 'dueDateTime',
type: 'string',
validateType: 'dateTime',
default: '',
description:
'Date and time at which the task is due. The Timestamp type represents date and time information using ISO 8601 format and is always in UTC time.',
},
{
displayName: 'Percent Complete',
name: 'percentComplete',
type: 'number',
typeOptions: {
minValue: 0,
maxValue: 100,
},
default: 0,
placeholder: 'e.g. 75',
description:
'Percentage of task completion. When set to 100, the task is considered completed.',
},
],
},
];
const displayOptions = {
show: {
resource: ['task'],
operation: ['create'],
},
};
export const description = updateDisplayOptions(displayOptions, properties);
export async function execute(this: IExecuteFunctions, i: number) {
//https://docs.microsoft.com/en-us/graph/api/planner-post-tasks?view=graph-rest-1.0&tabs=http
const planId = this.getNodeParameter('planId', i, '', { extractValue: true }) as string;
const bucketId = this.getNodeParameter('bucketId', i, '', { extractValue: true }) as string;
const title = this.getNodeParameter('title', i) as string;
const options = this.getNodeParameter('options', i);
const body: IDataObject = {
planId,
bucketId,
title,
};
if (options.assignedTo) {
options.assignedTo = this.getNodeParameter('options.assignedTo', i, '', {
extractValue: true,
}) as string;
}
if (options.dueDateTime && options.dueDateTime instanceof DateTime) {
options.dueDateTime = options.dueDateTime.toISO();
}
Object.assign(body, options);
if (body.assignedTo) {
body.assignments = {
[body.assignedTo as string]: {
'@odata.type': 'microsoft.graph.plannerAssignment',
orderHint: ' !',
},
};
delete body.assignedTo;
}
return await microsoftApiRequest.call(this, 'POST', '/v1.0/planner/tasks', body);
}

View File

@@ -0,0 +1,41 @@
import type { INodeProperties, IExecuteFunctions } from 'n8n-workflow';
import { updateDisplayOptions } from '@utils/utilities';
import { microsoftApiRequest } from '../../transport';
const properties: INodeProperties[] = [
{
displayName: 'Task ID',
name: 'taskId',
required: true,
type: 'string',
placeholder: 'e.g. h3ufgLvXPkSRzYm-zO5cY5gANtBQ',
description: 'The ID of the task to delete',
default: '',
},
];
const displayOptions = {
show: {
resource: ['task'],
operation: ['deleteTask'],
},
};
export const description = updateDisplayOptions(displayOptions, properties);
export async function execute(this: IExecuteFunctions, i: number) {
//https://docs.microsoft.com/en-us/graph/api/plannertask-delete?view=graph-rest-1.0&tabs=http
const taskId = this.getNodeParameter('taskId', i) as string;
const task = await microsoftApiRequest.call(this, 'GET', `/v1.0/planner/tasks/${taskId}`);
await microsoftApiRequest.call(
this,
'DELETE',
`/v1.0/planner/tasks/${taskId}`,
{},
{},
undefined,
{ 'If-Match': task['@odata.etag'] },
);
return { success: true };
}

View File

@@ -0,0 +1,31 @@
import type { INodeProperties, IExecuteFunctions } from 'n8n-workflow';
import { updateDisplayOptions } from '@utils/utilities';
import { microsoftApiRequest } from '../../transport';
const properties: INodeProperties[] = [
{
displayName: 'Task ID',
name: 'taskId',
required: true,
type: 'string',
description: 'The ID of the task to retrieve',
placeholder: 'e.g. h3ufgLvXPkSRzYm-zO5cY5gANtBQ',
default: '',
},
];
const displayOptions = {
show: {
resource: ['task'],
operation: ['get'],
},
};
export const description = updateDisplayOptions(displayOptions, properties);
export async function execute(this: IExecuteFunctions, i: number) {
//https://docs.microsoft.com/en-us/graph/api/plannertask-get?view=graph-rest-1.0&tabs=http
const taskId = this.getNodeParameter('taskId', i) as string;
return await microsoftApiRequest.call(this, 'GET', `/v1.0/planner/tasks/${taskId}`);
}

View File

@@ -0,0 +1,97 @@
import type { INodeProperties, IExecuteFunctions } from 'n8n-workflow';
import { groupRLC, planRLC } from '../../descriptions';
import { microsoftApiRequest, microsoftApiRequestAllItems } from '../../transport';
import { updateDisplayOptions } from '@utils/utilities';
import { returnAllOrLimit } from '@utils/descriptions';
const properties: INodeProperties[] = [
{
displayName: 'Tasks For',
name: 'tasksFor',
default: 'member',
required: true,
type: 'options',
description: 'Whether to retrieve the tasks for a user or for a plan',
options: [
{
name: 'Group Member',
value: 'member',
description: 'Tasks assigned to group member',
},
{
name: 'Plan',
value: 'plan',
description: 'Tasks in group plan',
},
],
},
groupRLC,
{
...planRLC,
displayOptions: {
show: {
tasksFor: ['plan'],
},
},
},
...returnAllOrLimit,
];
const displayOptions = {
show: {
resource: ['task'],
operation: ['getAll'],
},
};
export const description = updateDisplayOptions(displayOptions, properties);
export async function execute(this: IExecuteFunctions, i: number) {
const tasksFor = this.getNodeParameter('tasksFor', i) as string;
const returnAll = this.getNodeParameter('returnAll', i);
if (tasksFor === 'member') {
//https://docs.microsoft.com/en-us/graph/api/planneruser-list-tasks?view=graph-rest-1.0&tabs=http
const memberId = ((await microsoftApiRequest.call(this, 'GET', '/v1.0/me')) as { id: string })
.id;
if (returnAll) {
return await microsoftApiRequestAllItems.call(
this,
'value',
'GET',
`/v1.0/users/${memberId}/planner/tasks`,
);
} else {
const limit = this.getNodeParameter('limit', i);
const responseData = await microsoftApiRequestAllItems.call(
this,
'value',
'GET',
`/v1.0/users/${memberId}/planner/tasks`,
{},
);
return responseData.splice(0, limit);
}
} else {
//https://docs.microsoft.com/en-us/graph/api/plannerplan-list-tasks?view=graph-rest-1.0&tabs=http
const planId = this.getNodeParameter('planId', i, '', { extractValue: true }) as string;
if (returnAll) {
return await microsoftApiRequestAllItems.call(
this,
'value',
'GET',
`/v1.0/planner/plans/${planId}/tasks`,
);
} else {
const limit = this.getNodeParameter('limit', i);
const responseData = await microsoftApiRequestAllItems.call(
this,
'value',
'GET',
`/v1.0/planner/plans/${planId}/tasks`,
{},
);
return responseData.splice(0, limit);
}
}
}

View File

@@ -0,0 +1,62 @@
import type { INodeProperties } from 'n8n-workflow';
import * as create from './create.operation';
import * as deleteTask from './deleteTask.operation';
import * as get from './get.operation';
import * as getAll from './getAll.operation';
import * as update from './update.operation';
export { create, deleteTask, get, getAll, update };
export const description: INodeProperties[] = [
{
displayName: 'Operation',
name: 'operation',
type: 'options',
noDataExpression: true,
displayOptions: {
show: {
resource: ['task'],
},
},
options: [
{
name: 'Create',
value: 'create',
description: 'Create a task',
action: 'Create task',
},
{
name: 'Delete',
value: 'deleteTask',
description: 'Delete a task',
action: 'Delete task',
},
{
name: 'Get',
value: 'get',
description: 'Get a task',
action: 'Get task',
},
{
name: 'Get Many',
value: 'getAll',
description: 'Get many tasks',
action: 'Get many tasks',
},
{
name: 'Update',
value: 'update',
description: 'Update a task',
action: 'Update task',
},
],
default: 'create',
},
...create.description,
...deleteTask.description,
...get.description,
...getAll.description,
...update.description,
];

View File

@@ -0,0 +1,155 @@
import type { INodeProperties, IExecuteFunctions, IDataObject } from 'n8n-workflow';
import { bucketRLC, groupRLC, memberRLC, planRLC } from '../../descriptions';
import { microsoftApiRequest } from '../../transport';
import { updateDisplayOptions } from '@utils/utilities';
import { DateTime } from 'luxon';
const properties: INodeProperties[] = [
{
displayName: 'Task ID',
name: 'taskId',
required: true,
type: 'string',
default: '',
placeholder: 'e.g. h3ufgLvXPkSRzYm-zO5cY5gANtBQ',
description: 'The ID of the task to update',
},
{
displayName: 'Update Fields',
name: 'updateFields',
type: 'collection',
default: {},
placeholder: 'Add Field',
options: [
{
...memberRLC,
displayName: 'Assigned To',
name: 'assignedTo',
description: 'Who the task should be assigned to',
hint: "Select 'Team' from options first",
required: false,
typeOptions: {
loadOptionsDependsOn: ['updateFields.groupId.value'],
},
},
{
...bucketRLC,
required: false,
typeOptions: {
loadOptionsDependsOn: ['updateFields.planId.value'],
},
},
{
displayName: 'Due Date Time',
name: 'dueDateTime',
type: 'string',
validateType: 'dateTime',
default: '',
description:
'Date and time at which the task is due. The Timestamp type represents date and time information using ISO 8601 format and is always in UTC time.',
},
{
...groupRLC,
required: false,
typeOptions: {
loadOptionsDependsOn: ['/groupSource'],
},
},
{
displayName: 'Percent Complete',
name: 'percentComplete',
type: 'number',
typeOptions: {
minValue: 0,
maxValue: 100,
},
default: 0,
placeholder: 'e.g. 75',
description:
'Percentage of task completion. When set to 100, the task is considered completed.',
},
{
...planRLC,
required: false,
hint: "Select 'Team' from options first",
typeOptions: {
loadOptionsDependsOn: ['updateFields.groupId.value'],
},
},
{
displayName: 'Title',
name: 'title',
type: 'string',
default: '',
placeholder: 'e.g. my task',
description: 'Title of the task',
},
],
},
];
const displayOptions = {
show: {
resource: ['task'],
operation: ['update'],
},
};
export const description = updateDisplayOptions(displayOptions, properties);
export async function execute(this: IExecuteFunctions, i: number) {
//https://docs.microsoft.com/en-us/graph/api/plannertask-update?view=graph-rest-1.0&tabs=http
const taskId = this.getNodeParameter('taskId', i, '', { extractValue: true }) as string;
const updateFields = this.getNodeParameter('updateFields', i);
for (const key of Object.keys(updateFields)) {
if (key === 'groupId') {
// tasks are assigned to a plan and bucket, group is used for filtering
delete updateFields.groupId;
continue;
}
if (key === 'assignedTo') {
const assignedTo = this.getNodeParameter('updateFields.assignedTo', i, '', {
extractValue: true,
}) as string;
updateFields.assignments = {
[assignedTo]: {
'@odata.type': 'microsoft.graph.plannerAssignment',
orderHint: ' !',
},
};
delete updateFields.assignedTo;
continue;
}
if (['bucketId', 'planId'].includes(key)) {
updateFields[key] = this.getNodeParameter(`updateFields.${key}`, i, '', {
extractValue: true,
}) as string;
}
if (key === 'dueDateTime' && updateFields.dueDateTime instanceof DateTime) {
updateFields.dueDateTime = updateFields.dueDateTime.toISO();
}
}
const body: IDataObject = {};
Object.assign(body, updateFields);
const task = await microsoftApiRequest.call(this, 'GET', `/v1.0/planner/tasks/${taskId}`);
await microsoftApiRequest.call(
this,
'PATCH',
`/v1.0/planner/tasks/${taskId}`,
body,
{},
undefined,
{ 'If-Match': task['@odata.etag'] },
);
return { success: true };
}