Skip to content

Commit

Permalink
feat(Microsoft Teams Node): Enhancements and cleanup (#2940)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
Goggin and michael-radency committed Apr 25, 2022
1 parent ff26a98 commit d446f9e
Show file tree
Hide file tree
Showing 5 changed files with 220 additions and 57 deletions.
12 changes: 6 additions & 6 deletions packages/nodes-base/nodes/Microsoft/Teams/ChannelDescription.ts
Expand Up @@ -7,6 +7,7 @@ export const channelOperations: INodeProperties[] = [
displayName: 'Operation',
name: 'operation',
type: 'options',
noDataExpression: true,
displayOptions: {
show: {
resource: [
Expand Down Expand Up @@ -42,7 +43,6 @@ export const channelOperations: INodeProperties[] = [
},
],
default: 'create',
description: 'The operation to perform.',
},
];

Expand Down Expand Up @@ -87,7 +87,7 @@ export const channelFields: INodeProperties[] = [
},
},
default: '',
description: 'Channel name as it will appear to the user in Microsoft Teams.',
description: 'Channel name as it will appear to the user in Microsoft Teams',
},
{
displayName: 'Options',
Expand Down Expand Up @@ -266,7 +266,7 @@ export const channelFields: INodeProperties[] = [
},
},
default: false,
description: 'If all results should be returned or only up to a given limit.',
description: 'Whether to return all results or only up to a given limit',
},
{
displayName: 'Limit',
Expand All @@ -289,8 +289,8 @@ export const channelFields: INodeProperties[] = [
minValue: 1,
maxValue: 500,
},
default: 100,
description: 'How many results to return.',
default: 50,
description: 'Max number of results to return',
},

/* -------------------------------------------------------------------------- */
Expand Down Expand Up @@ -360,7 +360,7 @@ export const channelFields: INodeProperties[] = [
name: 'name',
type: 'string',
default: '',
description: 'Channel name as it will appear to the user in Microsoft Teams.',
description: 'Channel name as it will appear to the user in Microsoft Teams',
},
{
displayName: 'Description',
Expand Down
Expand Up @@ -7,6 +7,7 @@ export const channelMessageOperations: INodeProperties[] = [
displayName: 'Operation',
name: 'operation',
type: 'options',
noDataExpression: true,
displayOptions: {
show: {
resource: [
Expand All @@ -27,7 +28,6 @@ export const channelMessageOperations: INodeProperties[] = [
},
],
default: 'create',
description: 'The operation to perform.',
},
];

Expand Down Expand Up @@ -103,7 +103,7 @@ export const channelMessageFields: INodeProperties[] = [
],
},
},
default: '',
default: 'text',
description: 'The type of the content',
},
{
Expand All @@ -125,7 +125,7 @@ export const channelMessageFields: INodeProperties[] = [
},
},
default: '',
description: 'The content of the item.',
description: 'The content of the item',
},
{
displayName: 'Options',
Expand All @@ -149,7 +149,7 @@ export const channelMessageFields: INodeProperties[] = [
name: 'makeReply',
type: 'string',
default: '',
description: 'An optional ID of the message you want to reply to.',
description: 'An optional ID of the message you want to reply to',
},
],
},
Expand Down Expand Up @@ -213,7 +213,7 @@ export const channelMessageFields: INodeProperties[] = [
},
},
default: false,
description: 'If all results should be returned or only up to a given limit.',
description: 'Whether to return all results or only up to a given limit',
},
{
displayName: 'Limit',
Expand All @@ -236,7 +236,7 @@ export const channelMessageFields: INodeProperties[] = [
minValue: 1,
maxValue: 500,
},
default: 100,
description: 'How many results to return.',
default: 50,
description: 'Max number of results to return',
},
];
Expand Up @@ -7,6 +7,7 @@ export const chatMessageOperations: INodeProperties[] = [
displayName: 'Operation',
name: 'operation',
type: 'options',
noDataExpression: true,
displayOptions: {
show: {
resource: [
Expand All @@ -32,7 +33,6 @@ export const chatMessageOperations: INodeProperties[] = [
},
],
default: 'create',
description: 'The operation to perform.',
},
];

Expand Down Expand Up @@ -87,7 +87,7 @@ export const chatMessageFields: INodeProperties[] = [
],
},
},
default: '',
default: 'text',
description: 'The type of the content',
},
{
Expand All @@ -109,7 +109,7 @@ export const chatMessageFields: INodeProperties[] = [
},
},
default: '',
description: 'The content of the item.',
description: 'The content of the item',
},

/* -------------------------------------------------------------------------- */
Expand Down Expand Up @@ -170,7 +170,7 @@ export const chatMessageFields: INodeProperties[] = [
},
},
default: false,
description: 'If all results should be returned or only up to a given limit.',
description: 'Whether to return all results or only up to a given limit',
},
{
displayName: 'Limit',
Expand All @@ -193,7 +193,7 @@ export const chatMessageFields: INodeProperties[] = [
minValue: 1,
maxValue: 500,
},
default: 100,
description: 'How many results to return.',
default: 50,
description: 'Max number of results to return',
},
];
77 changes: 62 additions & 15 deletions packages/nodes-base/nodes/Microsoft/Teams/MicrosoftTeams.node.ts
Expand Up @@ -9,6 +9,7 @@ import {
INodePropertyOptions,
INodeType,
INodeTypeDescription,
JsonObject,
} from 'n8n-workflow';

import {
Expand Down Expand Up @@ -61,6 +62,7 @@ export class MicrosoftTeams implements INodeType {
displayName: 'Resource',
name: 'resource',
type: 'options',
noDataExpression: true,
options: [
{
name: 'Channel',
Expand All @@ -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,
Expand Down Expand Up @@ -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;
Expand All @@ -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({
Expand All @@ -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({
Expand All @@ -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({
Expand All @@ -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) {
Expand Down Expand Up @@ -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
Expand All @@ -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 }));
}
Expand All @@ -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;
Expand Down

0 comments on commit d446f9e

Please sign in to comment.