mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-18 10:31:15 +00:00
feat(Microsoft Teams Node): Enhancements and cleanup (#2940)
* Enhancements and cleanup for MS Teams node - Add option to limit groups to "member of" rather than whole directory - Defaults to "all" for compatibility - Add option to Get All tasks to pull from a plan instead of just a group member - Defaults to "member" for compatibility - Added in auto completiong for plans, buckets, labels and members in update fields for tasks - Update descriptions and normalize quotes for descriptions and display names * Bump MS Teams version number * ⚡ fixed version * 🔨 small fixes * 🔨 fixed nodelinter issues Co-authored-by: Michael Kret <michael.k@radency.com>
This commit is contained in:
@@ -9,6 +9,7 @@ import {
|
||||
INodePropertyOptions,
|
||||
INodeType,
|
||||
INodeTypeDescription,
|
||||
JsonObject,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import {
|
||||
@@ -61,6 +62,7 @@ export class MicrosoftTeams implements INodeType {
|
||||
displayName: 'Resource',
|
||||
name: 'resource',
|
||||
type: 'options',
|
||||
noDataExpression: true,
|
||||
options: [
|
||||
{
|
||||
name: 'Channel',
|
||||
@@ -80,7 +82,7 @@ export class MicrosoftTeams implements INodeType {
|
||||
},
|
||||
],
|
||||
default: 'channel',
|
||||
description: 'The resource to operate on.',
|
||||
description: 'The resource to operate on',
|
||||
},
|
||||
// CHANNEL
|
||||
...channelOperations,
|
||||
@@ -133,11 +135,17 @@ export class MicrosoftTeams implements INodeType {
|
||||
// select them easily
|
||||
async getGroups(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||
const returnData: INodePropertyOptions[] = [];
|
||||
const { value } = await microsoftApiRequest.call(this, 'GET', '/v1.0/groups');
|
||||
const groupSource = this.getCurrentNodeParameter('groupSource') as string;
|
||||
let requestUrl = '/v1.0/groups' as string;
|
||||
if (groupSource === 'mine') {
|
||||
requestUrl = '/v1.0/me/transitiveMemberOf';
|
||||
}
|
||||
const { value } = await microsoftApiRequest.call(this, 'GET', requestUrl);
|
||||
for (const group of value) {
|
||||
returnData.push({
|
||||
name: group.mail,
|
||||
name: group.displayName || group.mail || group.id,
|
||||
value: group.id,
|
||||
description: group.mail,
|
||||
});
|
||||
}
|
||||
return returnData;
|
||||
@@ -146,7 +154,12 @@ export class MicrosoftTeams implements INodeType {
|
||||
// select them easily
|
||||
async getPlans(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||
const returnData: INodePropertyOptions[] = [];
|
||||
const groupId = this.getCurrentNodeParameter('groupId') as string;
|
||||
let groupId = this.getCurrentNodeParameter('groupId') as string;
|
||||
const operation = this.getNodeParameter('operation', 0) as string;
|
||||
if (operation === 'update' && (groupId === undefined || groupId === null)) {
|
||||
// groupId not found at base, check updateFields for the groupId
|
||||
groupId = this.getCurrentNodeParameter('updateFields.groupId') as string;
|
||||
}
|
||||
const { value } = await microsoftApiRequest.call(this, 'GET', `/v1.0/groups/${groupId}/planner/plans`);
|
||||
for (const plan of value) {
|
||||
returnData.push({
|
||||
@@ -160,7 +173,12 @@ export class MicrosoftTeams implements INodeType {
|
||||
// select them easily
|
||||
async getBuckets(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||
const returnData: INodePropertyOptions[] = [];
|
||||
const planId = this.getCurrentNodeParameter('planId') as string;
|
||||
let planId = this.getCurrentNodeParameter('planId') as string;
|
||||
const operation = this.getNodeParameter('operation', 0) as string;
|
||||
if (operation === 'update' && (planId === undefined || planId === null)) {
|
||||
// planId not found at base, check updateFields for the planId
|
||||
planId = this.getCurrentNodeParameter('updateFields.planId') as string;
|
||||
}
|
||||
const { value } = await microsoftApiRequest.call(this, 'GET', `/v1.0/planner/plans/${planId}/buckets`);
|
||||
for (const bucket of value) {
|
||||
returnData.push({
|
||||
@@ -174,7 +192,12 @@ export class MicrosoftTeams implements INodeType {
|
||||
// select them easily
|
||||
async getMembers(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||
const returnData: INodePropertyOptions[] = [];
|
||||
const groupId = this.getCurrentNodeParameter('groupId') as string;
|
||||
let groupId = this.getCurrentNodeParameter('groupId') as string;
|
||||
const operation = this.getNodeParameter('operation', 0) as string;
|
||||
if (operation === 'update' && (groupId === undefined || groupId === null)) {
|
||||
// groupId not found at base, check updateFields for the groupId
|
||||
groupId = this.getCurrentNodeParameter('updateFields.groupId') as string;
|
||||
}
|
||||
const { value } = await microsoftApiRequest.call(this, 'GET', `/v1.0/groups/${groupId}/members`);
|
||||
for (const member of value) {
|
||||
returnData.push({
|
||||
@@ -188,7 +211,13 @@ export class MicrosoftTeams implements INodeType {
|
||||
// select them easily
|
||||
async getLabels(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||
const returnData: INodePropertyOptions[] = [];
|
||||
const planId = this.getCurrentNodeParameter('planId') as string;
|
||||
|
||||
let planId = this.getCurrentNodeParameter('planId') as string;
|
||||
const operation = this.getNodeParameter('operation', 0) as string;
|
||||
if (operation === 'update' && (planId === undefined || planId === null)) {
|
||||
// planId not found at base, check updateFields for the planId
|
||||
planId = this.getCurrentNodeParameter('updateFields.planId') as string;
|
||||
}
|
||||
const { categoryDescriptions } = await microsoftApiRequest.call(this, 'GET', `/v1.0/planner/plans/${planId}/details`);
|
||||
for (const key of Object.keys(categoryDescriptions)) {
|
||||
if (categoryDescriptions[key] !== null) {
|
||||
@@ -407,16 +436,29 @@ export class MicrosoftTeams implements INodeType {
|
||||
const taskId = this.getNodeParameter('taskId', i) as string;
|
||||
responseData = await microsoftApiRequest.call(this, 'GET', `/v1.0/planner/tasks/${taskId}`);
|
||||
}
|
||||
//https://docs.microsoft.com/en-us/graph/api/planneruser-list-tasks?view=graph-rest-1.0&tabs=http
|
||||
if (operation === 'getAll') {
|
||||
const memberId = this.getNodeParameter('memberId', i) as string;
|
||||
const tasksFor = this.getNodeParameter('tasksFor', i) as string;
|
||||
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
|
||||
if (returnAll) {
|
||||
responseData = await microsoftApiRequestAllItems.call(this, 'value', 'GET', `/v1.0/users/${memberId}/planner/tasks`);
|
||||
if (tasksFor === 'member') {
|
||||
//https://docs.microsoft.com/en-us/graph/api/planneruser-list-tasks?view=graph-rest-1.0&tabs=http
|
||||
const memberId = this.getNodeParameter('memberId', i) as string;
|
||||
if (returnAll) {
|
||||
responseData = await microsoftApiRequestAllItems.call(this, 'value', 'GET', `/v1.0/users/${memberId}/planner/tasks`);
|
||||
} else {
|
||||
qs.limit = this.getNodeParameter('limit', i) as number;
|
||||
responseData = await microsoftApiRequestAllItems.call(this, 'value', 'GET', `/v1.0/users/${memberId}/planner/tasks`, {});
|
||||
responseData = responseData.splice(0, qs.limit);
|
||||
}
|
||||
} else {
|
||||
qs.limit = this.getNodeParameter('limit', i) as number;
|
||||
responseData = await microsoftApiRequestAllItems.call(this, 'value', 'GET', `/v1.0/users/${memberId}/planner/tasks`, {});
|
||||
responseData = responseData.splice(0, qs.limit);
|
||||
//https://docs.microsoft.com/en-us/graph/api/plannerplan-list-tasks?view=graph-rest-1.0&tabs=http
|
||||
const planId = this.getNodeParameter('planId', i) as string;
|
||||
if (returnAll) {
|
||||
responseData = await microsoftApiRequestAllItems.call(this, 'value', 'GET', `/v1.0/planner/plans/${planId}/tasks`);
|
||||
} else {
|
||||
qs.limit = this.getNodeParameter('limit', i) as number;
|
||||
responseData = await microsoftApiRequestAllItems.call(this, 'value', 'GET', `/v1.0/planner/plans/${planId}/tasks`, {});
|
||||
responseData = responseData.splice(0, qs.limit);
|
||||
}
|
||||
}
|
||||
}
|
||||
//https://docs.microsoft.com/en-us/graph/api/plannertask-update?view=graph-rest-1.0&tabs=http
|
||||
@@ -436,6 +478,11 @@ export class MicrosoftTeams implements INodeType {
|
||||
delete body.assignedTo;
|
||||
}
|
||||
|
||||
if (body.groupId) {
|
||||
// tasks are assigned to a plan and bucket, group is used for filtering
|
||||
delete body.groupId;
|
||||
}
|
||||
|
||||
if (Array.isArray(body.labels)) {
|
||||
body.appliedCategories = (body.labels as string[]).map((label) => ({ [label]: true }));
|
||||
}
|
||||
@@ -454,7 +501,7 @@ export class MicrosoftTeams implements INodeType {
|
||||
}
|
||||
} catch (error) {
|
||||
if (this.continueOnFail()) {
|
||||
returnData.push({ error: error.message });
|
||||
returnData.push({ error: (error as JsonObject).message });
|
||||
continue;
|
||||
}
|
||||
throw error;
|
||||
|
||||
Reference in New Issue
Block a user