2022-08-17 08:50:24 -07:00
|
|
|
import { IExecuteFunctions } from 'n8n-core';
|
2020-09-13 02:08:43 -07:00
|
|
|
|
|
|
|
import {
|
|
|
|
IDataObject,
|
|
|
|
ILoadOptionsFunctions,
|
|
|
|
INodeExecutionData,
|
|
|
|
INodePropertyOptions,
|
|
|
|
INodeType,
|
|
|
|
INodeTypeDescription,
|
|
|
|
} from 'n8n-workflow';
|
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
import { microsoftApiRequest, microsoftApiRequestAllItems } from './GenericFunctions';
|
2020-09-13 02:08:43 -07:00
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
import { channelFields, channelOperations } from './ChannelDescription';
|
2020-09-13 02:08:43 -07:00
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
import { channelMessageFields, channelMessageOperations } from './ChannelMessageDescription';
|
2020-09-13 02:08:43 -07:00
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
import { chatMessageFields, chatMessageOperations } from './ChatMessageDescription';
|
2022-04-01 08:21:25 -07:00
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
import { taskFields, taskOperations } from './TaskDescription';
|
2021-02-07 12:39:39 -08:00
|
|
|
|
2020-09-13 02:08:43 -07:00
|
|
|
export class MicrosoftTeams implements INodeType {
|
|
|
|
description: INodeTypeDescription = {
|
|
|
|
displayName: 'Microsoft Teams',
|
|
|
|
name: 'microsoftTeams',
|
2021-02-07 12:39:39 -08:00
|
|
|
icon: 'file:teams.svg',
|
2020-09-13 02:08:43 -07:00
|
|
|
group: ['input'],
|
|
|
|
version: 1,
|
|
|
|
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
|
|
|
|
description: 'Consume Microsoft Teams API',
|
|
|
|
defaults: {
|
|
|
|
name: 'Microsoft Teams',
|
|
|
|
},
|
|
|
|
inputs: ['main'],
|
|
|
|
outputs: ['main'],
|
|
|
|
credentials: [
|
|
|
|
{
|
|
|
|
name: 'microsoftTeamsOAuth2Api',
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
properties: [
|
|
|
|
{
|
|
|
|
displayName: 'Resource',
|
|
|
|
name: 'resource',
|
|
|
|
type: 'options',
|
2022-04-25 02:22:16 -07:00
|
|
|
noDataExpression: true,
|
2020-09-13 02:08:43 -07:00
|
|
|
options: [
|
|
|
|
{
|
|
|
|
name: 'Channel',
|
|
|
|
value: 'channel',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Channel Message (Beta)',
|
|
|
|
value: 'channelMessage',
|
|
|
|
},
|
2022-04-01 08:21:25 -07:00
|
|
|
{
|
|
|
|
name: 'Chat Message',
|
|
|
|
value: 'chatMessage',
|
|
|
|
},
|
2021-02-07 12:39:39 -08:00
|
|
|
{
|
|
|
|
name: 'Task',
|
|
|
|
value: 'task',
|
|
|
|
},
|
2020-09-13 02:08:43 -07:00
|
|
|
],
|
|
|
|
default: 'channel',
|
|
|
|
},
|
|
|
|
// CHANNEL
|
|
|
|
...channelOperations,
|
|
|
|
...channelFields,
|
|
|
|
/// MESSAGE
|
|
|
|
...channelMessageOperations,
|
|
|
|
...channelMessageFields,
|
2022-04-01 08:21:25 -07:00
|
|
|
...chatMessageOperations,
|
|
|
|
...chatMessageFields,
|
2021-02-07 12:39:39 -08:00
|
|
|
///TASK
|
|
|
|
...taskOperations,
|
|
|
|
...taskFields,
|
2020-09-13 02:08:43 -07:00
|
|
|
],
|
|
|
|
};
|
|
|
|
|
|
|
|
methods = {
|
|
|
|
loadOptions: {
|
|
|
|
// Get all the team's channels to display them to user so that he can
|
|
|
|
// select them easily
|
|
|
|
async getChannels(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
|
|
|
const returnData: INodePropertyOptions[] = [];
|
|
|
|
const teamId = this.getCurrentNodeParameter('teamId') as string;
|
2022-08-17 08:50:24 -07:00
|
|
|
const { value } = await microsoftApiRequest.call(
|
|
|
|
this,
|
|
|
|
'GET',
|
|
|
|
`/v1.0/teams/${teamId}/channels`,
|
|
|
|
);
|
2020-09-13 02:08:43 -07:00
|
|
|
for (const channel of value) {
|
|
|
|
const channelName = channel.displayName;
|
|
|
|
const channelId = channel.id;
|
|
|
|
returnData.push({
|
|
|
|
name: channelName,
|
|
|
|
value: channelId,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return returnData;
|
|
|
|
},
|
|
|
|
// Get all the teams to display them to user so that he can
|
|
|
|
// select them easily
|
|
|
|
async getTeams(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
|
|
|
const returnData: INodePropertyOptions[] = [];
|
|
|
|
const { value } = await microsoftApiRequest.call(this, 'GET', '/v1.0/me/joinedTeams');
|
|
|
|
for (const team of value) {
|
|
|
|
const teamName = team.displayName;
|
|
|
|
const teamId = team.id;
|
|
|
|
returnData.push({
|
|
|
|
name: teamName,
|
|
|
|
value: teamId,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return returnData;
|
|
|
|
},
|
2021-02-07 12:39:39 -08:00
|
|
|
// Get all the groups to display them to user so that he can
|
|
|
|
// select them easily
|
|
|
|
async getGroups(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
|
|
|
const returnData: INodePropertyOptions[] = [];
|
2022-04-25 02:22:16 -07:00
|
|
|
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);
|
2021-02-07 12:39:39 -08:00
|
|
|
for (const group of value) {
|
|
|
|
returnData.push({
|
2022-04-25 02:22:16 -07:00
|
|
|
name: group.displayName || group.mail || group.id,
|
2021-02-07 12:39:39 -08:00
|
|
|
value: group.id,
|
2022-04-25 02:22:16 -07:00
|
|
|
description: group.mail,
|
2021-02-07 12:39:39 -08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
return returnData;
|
|
|
|
},
|
|
|
|
// Get all the plans to display them to user so that he can
|
|
|
|
// select them easily
|
|
|
|
async getPlans(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
|
|
|
const returnData: INodePropertyOptions[] = [];
|
2022-04-25 02:22:16 -07:00
|
|
|
let groupId = this.getCurrentNodeParameter('groupId') as string;
|
2022-12-02 03:53:59 -08:00
|
|
|
const operation = this.getNodeParameter('operation', 0);
|
2022-04-25 02:22:16 -07:00
|
|
|
if (operation === 'update' && (groupId === undefined || groupId === null)) {
|
|
|
|
// groupId not found at base, check updateFields for the groupId
|
|
|
|
groupId = this.getCurrentNodeParameter('updateFields.groupId') as string;
|
|
|
|
}
|
2022-08-17 08:50:24 -07:00
|
|
|
const { value } = await microsoftApiRequest.call(
|
|
|
|
this,
|
|
|
|
'GET',
|
|
|
|
`/v1.0/groups/${groupId}/planner/plans`,
|
|
|
|
);
|
2021-02-07 12:39:39 -08:00
|
|
|
for (const plan of value) {
|
|
|
|
returnData.push({
|
|
|
|
name: plan.title,
|
|
|
|
value: plan.id,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return returnData;
|
|
|
|
},
|
|
|
|
// Get all the plans to display them to user so that he can
|
|
|
|
// select them easily
|
|
|
|
async getBuckets(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
|
|
|
const returnData: INodePropertyOptions[] = [];
|
2022-04-25 02:22:16 -07:00
|
|
|
let planId = this.getCurrentNodeParameter('planId') as string;
|
2022-12-02 03:53:59 -08:00
|
|
|
const operation = this.getNodeParameter('operation', 0);
|
2022-04-25 02:22:16 -07:00
|
|
|
if (operation === 'update' && (planId === undefined || planId === null)) {
|
|
|
|
// planId not found at base, check updateFields for the planId
|
|
|
|
planId = this.getCurrentNodeParameter('updateFields.planId') as string;
|
|
|
|
}
|
2022-08-17 08:50:24 -07:00
|
|
|
const { value } = await microsoftApiRequest.call(
|
|
|
|
this,
|
|
|
|
'GET',
|
|
|
|
`/v1.0/planner/plans/${planId}/buckets`,
|
|
|
|
);
|
2021-02-07 12:39:39 -08:00
|
|
|
for (const bucket of value) {
|
|
|
|
returnData.push({
|
|
|
|
name: bucket.name,
|
|
|
|
value: bucket.id,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return returnData;
|
|
|
|
},
|
|
|
|
// Get all the plans to display them to user so that he can
|
|
|
|
// select them easily
|
|
|
|
async getMembers(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
|
|
|
const returnData: INodePropertyOptions[] = [];
|
2022-04-25 02:22:16 -07:00
|
|
|
let groupId = this.getCurrentNodeParameter('groupId') as string;
|
2022-12-02 03:53:59 -08:00
|
|
|
const operation = this.getNodeParameter('operation', 0);
|
2022-04-25 02:22:16 -07:00
|
|
|
if (operation === 'update' && (groupId === undefined || groupId === null)) {
|
|
|
|
// groupId not found at base, check updateFields for the groupId
|
|
|
|
groupId = this.getCurrentNodeParameter('updateFields.groupId') as string;
|
|
|
|
}
|
2022-08-17 08:50:24 -07:00
|
|
|
const { value } = await microsoftApiRequest.call(
|
|
|
|
this,
|
|
|
|
'GET',
|
|
|
|
`/v1.0/groups/${groupId}/members`,
|
|
|
|
);
|
2021-02-07 12:39:39 -08:00
|
|
|
for (const member of value) {
|
|
|
|
returnData.push({
|
|
|
|
name: member.displayName,
|
|
|
|
value: member.id,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return returnData;
|
|
|
|
},
|
|
|
|
// Get all the labels to display them to user so that he can
|
|
|
|
// select them easily
|
|
|
|
async getLabels(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
|
|
|
const returnData: INodePropertyOptions[] = [];
|
2022-04-25 02:22:16 -07:00
|
|
|
|
|
|
|
let planId = this.getCurrentNodeParameter('planId') as string;
|
2022-12-02 03:53:59 -08:00
|
|
|
const operation = this.getNodeParameter('operation', 0);
|
2022-04-25 02:22:16 -07:00
|
|
|
if (operation === 'update' && (planId === undefined || planId === null)) {
|
|
|
|
// planId not found at base, check updateFields for the planId
|
|
|
|
planId = this.getCurrentNodeParameter('updateFields.planId') as string;
|
|
|
|
}
|
2022-08-17 08:50:24 -07:00
|
|
|
const { categoryDescriptions } = await microsoftApiRequest.call(
|
|
|
|
this,
|
|
|
|
'GET',
|
|
|
|
`/v1.0/planner/plans/${planId}/details`,
|
|
|
|
);
|
2021-02-07 12:39:39 -08:00
|
|
|
for (const key of Object.keys(categoryDescriptions)) {
|
|
|
|
if (categoryDescriptions[key] !== null) {
|
|
|
|
returnData.push({
|
|
|
|
name: categoryDescriptions[key],
|
|
|
|
value: key,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return returnData;
|
|
|
|
},
|
2022-04-01 08:21:25 -07:00
|
|
|
// Get all the chats to display them to user so that they can
|
|
|
|
// select them easily
|
|
|
|
async getChats(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
|
|
|
const returnData: INodePropertyOptions[] = [];
|
|
|
|
const qs: IDataObject = {
|
|
|
|
$expand: 'members',
|
|
|
|
};
|
|
|
|
const { value } = await microsoftApiRequest.call(this, 'GET', '/v1.0/chats', {}, qs);
|
|
|
|
for (const chat of value) {
|
|
|
|
if (!chat.topic) {
|
|
|
|
chat.topic = chat.members
|
2022-08-17 08:50:24 -07:00
|
|
|
.filter((member: IDataObject) => member.displayName)
|
|
|
|
.map((member: IDataObject) => member.displayName)
|
|
|
|
.join(', ');
|
2022-04-01 08:21:25 -07:00
|
|
|
}
|
2023-01-13 09:11:56 -08:00
|
|
|
const chatName = `${chat.topic || '(no title) - ' + (chat.id as string)} (${
|
|
|
|
chat.chatType
|
|
|
|
})`;
|
2022-04-01 08:21:25 -07:00
|
|
|
const chatId = chat.id;
|
|
|
|
returnData.push({
|
|
|
|
name: chatName,
|
|
|
|
value: chatId,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return returnData;
|
|
|
|
},
|
2020-09-13 02:08:43 -07:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
|
|
|
const items = this.getInputData();
|
2022-08-30 08:55:33 -07:00
|
|
|
const returnData: INodeExecutionData[] = [];
|
2022-04-22 09:29:51 -07:00
|
|
|
const length = items.length;
|
2020-09-13 02:08:43 -07:00
|
|
|
const qs: IDataObject = {};
|
|
|
|
let responseData;
|
2022-12-02 03:53:59 -08:00
|
|
|
const resource = this.getNodeParameter('resource', 0);
|
|
|
|
const operation = this.getNodeParameter('operation', 0);
|
2020-09-13 02:08:43 -07:00
|
|
|
for (let i = 0; i < length; i++) {
|
2021-07-19 23:58:54 -07:00
|
|
|
try {
|
|
|
|
if (resource === 'channel') {
|
|
|
|
//https://docs.microsoft.com/en-us/graph/api/channel-post?view=graph-rest-beta&tabs=http
|
|
|
|
if (operation === 'create') {
|
|
|
|
const teamId = this.getNodeParameter('teamId', i) as string;
|
|
|
|
const name = this.getNodeParameter('name', i) as string;
|
2022-11-18 07:29:44 -08:00
|
|
|
const options = this.getNodeParameter('options', i);
|
2021-07-19 23:58:54 -07:00
|
|
|
const body: IDataObject = {
|
|
|
|
displayName: name,
|
|
|
|
};
|
|
|
|
if (options.description) {
|
|
|
|
body.description = options.description as string;
|
|
|
|
}
|
|
|
|
if (options.type) {
|
|
|
|
body.membershipType = options.type as string;
|
|
|
|
}
|
2022-08-17 08:50:24 -07:00
|
|
|
responseData = await microsoftApiRequest.call(
|
|
|
|
this,
|
|
|
|
'POST',
|
|
|
|
`/v1.0/teams/${teamId}/channels`,
|
|
|
|
body,
|
|
|
|
);
|
2020-09-13 02:08:43 -07:00
|
|
|
}
|
2021-07-19 23:58:54 -07:00
|
|
|
//https://docs.microsoft.com/en-us/graph/api/channel-delete?view=graph-rest-beta&tabs=http
|
|
|
|
if (operation === 'delete') {
|
|
|
|
const teamId = this.getNodeParameter('teamId', i) as string;
|
|
|
|
const channelId = this.getNodeParameter('channelId', i) as string;
|
2022-08-17 08:50:24 -07:00
|
|
|
responseData = await microsoftApiRequest.call(
|
|
|
|
this,
|
|
|
|
'DELETE',
|
|
|
|
`/v1.0/teams/${teamId}/channels/${channelId}`,
|
|
|
|
);
|
2021-07-19 23:58:54 -07:00
|
|
|
responseData = { success: true };
|
2020-09-13 02:08:43 -07:00
|
|
|
}
|
2021-07-19 23:58:54 -07:00
|
|
|
//https://docs.microsoft.com/en-us/graph/api/channel-get?view=graph-rest-beta&tabs=http
|
|
|
|
if (operation === 'get') {
|
|
|
|
const teamId = this.getNodeParameter('teamId', i) as string;
|
|
|
|
const channelId = this.getNodeParameter('channelId', i) as string;
|
2022-08-17 08:50:24 -07:00
|
|
|
responseData = await microsoftApiRequest.call(
|
|
|
|
this,
|
|
|
|
'GET',
|
|
|
|
`/v1.0/teams/${teamId}/channels/${channelId}`,
|
|
|
|
);
|
2020-09-13 02:08:43 -07:00
|
|
|
}
|
2021-07-19 23:58:54 -07:00
|
|
|
//https://docs.microsoft.com/en-us/graph/api/channel-list?view=graph-rest-beta&tabs=http
|
|
|
|
if (operation === 'getAll') {
|
|
|
|
const teamId = this.getNodeParameter('teamId', i) as string;
|
2022-11-18 05:31:38 -08:00
|
|
|
const returnAll = this.getNodeParameter('returnAll', i);
|
2021-07-19 23:58:54 -07:00
|
|
|
if (returnAll) {
|
2022-08-17 08:50:24 -07:00
|
|
|
responseData = await microsoftApiRequestAllItems.call(
|
|
|
|
this,
|
|
|
|
'value',
|
|
|
|
'GET',
|
|
|
|
`/v1.0/teams/${teamId}/channels`,
|
|
|
|
);
|
2021-07-19 23:58:54 -07:00
|
|
|
} else {
|
2022-11-18 06:26:22 -08:00
|
|
|
qs.limit = this.getNodeParameter('limit', i);
|
2022-08-17 08:50:24 -07:00
|
|
|
responseData = await microsoftApiRequestAllItems.call(
|
|
|
|
this,
|
|
|
|
'value',
|
|
|
|
'GET',
|
|
|
|
`/v1.0/teams/${teamId}/channels`,
|
|
|
|
{},
|
|
|
|
);
|
2021-07-19 23:58:54 -07:00
|
|
|
responseData = responseData.splice(0, qs.limit);
|
|
|
|
}
|
2020-09-13 02:08:43 -07:00
|
|
|
}
|
2021-07-19 23:58:54 -07:00
|
|
|
//https://docs.microsoft.com/en-us/graph/api/channel-patch?view=graph-rest-beta&tabs=http
|
|
|
|
if (operation === 'update') {
|
|
|
|
const teamId = this.getNodeParameter('teamId', i) as string;
|
|
|
|
const channelId = this.getNodeParameter('channelId', i) as string;
|
2022-11-18 07:29:44 -08:00
|
|
|
const updateFields = this.getNodeParameter('updateFields', i);
|
2021-07-19 23:58:54 -07:00
|
|
|
const body: IDataObject = {};
|
|
|
|
if (updateFields.name) {
|
|
|
|
body.displayName = updateFields.name as string;
|
|
|
|
}
|
|
|
|
if (updateFields.description) {
|
|
|
|
body.description = updateFields.description as string;
|
|
|
|
}
|
2022-08-17 08:50:24 -07:00
|
|
|
responseData = await microsoftApiRequest.call(
|
|
|
|
this,
|
|
|
|
'PATCH',
|
|
|
|
`/v1.0/teams/${teamId}/channels/${channelId}`,
|
|
|
|
body,
|
|
|
|
);
|
2021-07-19 23:58:54 -07:00
|
|
|
responseData = { success: true };
|
2020-09-13 02:08:43 -07:00
|
|
|
}
|
|
|
|
}
|
2021-07-19 23:58:54 -07:00
|
|
|
if (resource === 'channelMessage') {
|
|
|
|
//https://docs.microsoft.com/en-us/graph/api/channel-post-messages?view=graph-rest-beta&tabs=http
|
|
|
|
//https://docs.microsoft.com/en-us/graph/api/channel-post-messagereply?view=graph-rest-beta&tabs=http
|
|
|
|
if (operation === 'create') {
|
|
|
|
const teamId = this.getNodeParameter('teamId', i) as string;
|
|
|
|
const channelId = this.getNodeParameter('channelId', i) as string;
|
|
|
|
const messageType = this.getNodeParameter('messageType', i) as string;
|
|
|
|
const message = this.getNodeParameter('message', i) as string;
|
2022-11-18 07:29:44 -08:00
|
|
|
const options = this.getNodeParameter('options', i);
|
2021-02-24 14:58:35 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const body: IDataObject = {
|
|
|
|
body: {
|
|
|
|
contentType: messageType,
|
|
|
|
content: message,
|
|
|
|
},
|
|
|
|
};
|
2021-02-24 14:58:35 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (options.makeReply) {
|
|
|
|
const replyToId = options.makeReply as string;
|
2022-08-17 08:50:24 -07:00
|
|
|
responseData = await microsoftApiRequest.call(
|
|
|
|
this,
|
|
|
|
'POST',
|
|
|
|
`/beta/teams/${teamId}/channels/${channelId}/messages/${replyToId}/replies`,
|
|
|
|
body,
|
|
|
|
);
|
2021-07-19 23:58:54 -07:00
|
|
|
} else {
|
2022-08-17 08:50:24 -07:00
|
|
|
responseData = await microsoftApiRequest.call(
|
|
|
|
this,
|
|
|
|
'POST',
|
|
|
|
`/beta/teams/${teamId}/channels/${channelId}/messages`,
|
|
|
|
body,
|
|
|
|
);
|
2021-07-19 23:58:54 -07:00
|
|
|
}
|
2021-02-24 14:58:35 -08:00
|
|
|
}
|
2021-07-19 23:58:54 -07:00
|
|
|
//https://docs.microsoft.com/en-us/graph/api/channel-list-messages?view=graph-rest-beta&tabs=http
|
|
|
|
if (operation === 'getAll') {
|
|
|
|
const teamId = this.getNodeParameter('teamId', i) as string;
|
|
|
|
const channelId = this.getNodeParameter('channelId', i) as string;
|
2022-11-18 05:31:38 -08:00
|
|
|
const returnAll = this.getNodeParameter('returnAll', i);
|
2021-07-19 23:58:54 -07:00
|
|
|
if (returnAll) {
|
2022-08-17 08:50:24 -07:00
|
|
|
responseData = await microsoftApiRequestAllItems.call(
|
|
|
|
this,
|
|
|
|
'value',
|
|
|
|
'GET',
|
|
|
|
`/beta/teams/${teamId}/channels/${channelId}/messages`,
|
|
|
|
);
|
2021-07-19 23:58:54 -07:00
|
|
|
} else {
|
2022-11-18 06:26:22 -08:00
|
|
|
qs.limit = this.getNodeParameter('limit', i);
|
2022-08-17 08:50:24 -07:00
|
|
|
responseData = await microsoftApiRequestAllItems.call(
|
|
|
|
this,
|
|
|
|
'value',
|
|
|
|
'GET',
|
|
|
|
`/beta/teams/${teamId}/channels/${channelId}/messages`,
|
|
|
|
{},
|
|
|
|
);
|
2021-07-19 23:58:54 -07:00
|
|
|
responseData = responseData.splice(0, qs.limit);
|
2022-04-01 08:21:25 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (resource === 'chatMessage') {
|
|
|
|
// https://docs.microsoft.com/en-us/graph/api/channel-post-messages?view=graph-rest-1.0&tabs=http
|
|
|
|
if (operation === 'create') {
|
|
|
|
const chatId = this.getNodeParameter('chatId', i) as string;
|
|
|
|
const messageType = this.getNodeParameter('messageType', i) as string;
|
|
|
|
const message = this.getNodeParameter('message', i) as string;
|
|
|
|
const body: IDataObject = {
|
|
|
|
body: {
|
|
|
|
contentType: messageType,
|
|
|
|
content: message,
|
|
|
|
},
|
|
|
|
};
|
2022-08-17 08:50:24 -07:00
|
|
|
responseData = await microsoftApiRequest.call(
|
|
|
|
this,
|
|
|
|
'POST',
|
|
|
|
`/v1.0/chats/${chatId}/messages`,
|
|
|
|
body,
|
|
|
|
);
|
2022-04-01 08:21:25 -07:00
|
|
|
}
|
|
|
|
// https://docs.microsoft.com/en-us/graph/api/chat-list-messages?view=graph-rest-1.0&tabs=http
|
|
|
|
if (operation === 'get') {
|
|
|
|
const chatId = this.getNodeParameter('chatId', i) as string;
|
|
|
|
const messageId = this.getNodeParameter('messageId', i) as string;
|
2022-08-17 08:50:24 -07:00
|
|
|
responseData = await microsoftApiRequest.call(
|
|
|
|
this,
|
|
|
|
'GET',
|
|
|
|
`/v1.0/chats/${chatId}/messages/${messageId}`,
|
|
|
|
);
|
2022-04-01 08:21:25 -07:00
|
|
|
}
|
|
|
|
// https://docs.microsoft.com/en-us/graph/api/chat-list-messages?view=graph-rest-1.0&tabs=http
|
|
|
|
if (operation === 'getAll') {
|
|
|
|
const chatId = this.getNodeParameter('chatId', i) as string;
|
2022-11-18 05:31:38 -08:00
|
|
|
const returnAll = this.getNodeParameter('returnAll', i);
|
2022-04-01 08:21:25 -07:00
|
|
|
if (returnAll) {
|
2022-08-17 08:50:24 -07:00
|
|
|
responseData = await microsoftApiRequestAllItems.call(
|
|
|
|
this,
|
|
|
|
'value',
|
|
|
|
'GET',
|
|
|
|
`/v1.0/chats/${chatId}/messages`,
|
|
|
|
);
|
2022-04-01 08:21:25 -07:00
|
|
|
} else {
|
2022-11-18 06:26:22 -08:00
|
|
|
qs.limit = this.getNodeParameter('limit', i);
|
2022-08-17 08:50:24 -07:00
|
|
|
responseData = await microsoftApiRequestAllItems.call(
|
|
|
|
this,
|
|
|
|
'value',
|
|
|
|
'GET',
|
|
|
|
`/v1.0/chats/${chatId}/messages`,
|
|
|
|
{},
|
|
|
|
);
|
2022-04-01 08:21:25 -07:00
|
|
|
responseData = responseData.splice(0, qs.limit);
|
2021-07-19 23:58:54 -07:00
|
|
|
}
|
2020-09-13 02:08:43 -07:00
|
|
|
}
|
|
|
|
}
|
2021-07-19 23:58:54 -07:00
|
|
|
if (resource === 'task') {
|
|
|
|
//https://docs.microsoft.com/en-us/graph/api/planner-post-tasks?view=graph-rest-1.0&tabs=http
|
|
|
|
if (operation === 'create') {
|
|
|
|
const planId = this.getNodeParameter('planId', i) as string;
|
|
|
|
const bucketId = this.getNodeParameter('bucketId', i) as string;
|
|
|
|
const title = this.getNodeParameter('title', i) as string;
|
2022-11-18 07:29:44 -08:00
|
|
|
const additionalFields = this.getNodeParameter('additionalFields', i);
|
2021-07-19 23:58:54 -07:00
|
|
|
const body: IDataObject = {
|
|
|
|
planId,
|
|
|
|
bucketId,
|
|
|
|
title,
|
2021-02-07 12:39:39 -08:00
|
|
|
};
|
2021-07-19 23:58:54 -07:00
|
|
|
Object.assign(body, additionalFields);
|
2021-02-07 12:39:39 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (body.assignedTo) {
|
|
|
|
body.assignments = {
|
|
|
|
[body.assignedTo as string]: {
|
|
|
|
'@odata.type': 'microsoft.graph.plannerAssignment',
|
2022-08-17 08:50:24 -07:00
|
|
|
orderHint: ' !',
|
2021-07-19 23:58:54 -07:00
|
|
|
},
|
|
|
|
};
|
|
|
|
delete body.assignedTo;
|
|
|
|
}
|
2021-02-07 12:39:39 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (Array.isArray(body.labels)) {
|
2022-08-17 08:50:24 -07:00
|
|
|
body.appliedCategories = (body.labels as string[]).map((label) => ({
|
|
|
|
[label]: true,
|
|
|
|
}));
|
2021-07-19 23:58:54 -07:00
|
|
|
}
|
2021-02-07 12:39:39 -08:00
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
responseData = await microsoftApiRequest.call(
|
|
|
|
this,
|
|
|
|
'POST',
|
2022-12-29 03:20:43 -08:00
|
|
|
'/v1.0/planner/tasks',
|
2022-08-17 08:50:24 -07:00
|
|
|
body,
|
|
|
|
);
|
2021-02-07 12:39:39 -08:00
|
|
|
}
|
2021-07-19 23:58:54 -07:00
|
|
|
//https://docs.microsoft.com/en-us/graph/api/plannertask-delete?view=graph-rest-1.0&tabs=http
|
|
|
|
if (operation === 'delete') {
|
|
|
|
const taskId = this.getNodeParameter('taskId', i) as string;
|
2022-08-17 08:50:24 -07:00
|
|
|
const task = await microsoftApiRequest.call(
|
|
|
|
this,
|
|
|
|
'GET',
|
|
|
|
`/v1.0/planner/tasks/${taskId}`,
|
|
|
|
);
|
|
|
|
responseData = await microsoftApiRequest.call(
|
|
|
|
this,
|
|
|
|
'DELETE',
|
|
|
|
`/v1.0/planner/tasks/${taskId}`,
|
|
|
|
{},
|
|
|
|
{},
|
|
|
|
undefined,
|
|
|
|
{ 'If-Match': task['@odata.etag'] },
|
|
|
|
);
|
2021-07-19 23:58:54 -07:00
|
|
|
responseData = { success: true };
|
|
|
|
}
|
|
|
|
//https://docs.microsoft.com/en-us/graph/api/plannertask-get?view=graph-rest-1.0&tabs=http
|
|
|
|
if (operation === 'get') {
|
|
|
|
const taskId = this.getNodeParameter('taskId', i) as string;
|
2022-08-17 08:50:24 -07:00
|
|
|
responseData = await microsoftApiRequest.call(
|
|
|
|
this,
|
|
|
|
'GET',
|
|
|
|
`/v1.0/planner/tasks/${taskId}`,
|
|
|
|
);
|
2021-02-07 12:39:39 -08:00
|
|
|
}
|
2021-07-19 23:58:54 -07:00
|
|
|
if (operation === 'getAll') {
|
2022-04-25 02:22:16 -07:00
|
|
|
const tasksFor = this.getNodeParameter('tasksFor', i) as string;
|
2022-11-18 05:31:38 -08:00
|
|
|
const returnAll = this.getNodeParameter('returnAll', i);
|
2022-04-25 02:22:16 -07:00
|
|
|
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) {
|
2022-08-17 08:50:24 -07:00
|
|
|
responseData = await microsoftApiRequestAllItems.call(
|
|
|
|
this,
|
|
|
|
'value',
|
|
|
|
'GET',
|
|
|
|
`/v1.0/users/${memberId}/planner/tasks`,
|
|
|
|
);
|
2022-04-25 02:22:16 -07:00
|
|
|
} else {
|
2022-11-18 06:26:22 -08:00
|
|
|
qs.limit = this.getNodeParameter('limit', i);
|
2022-08-17 08:50:24 -07:00
|
|
|
responseData = await microsoftApiRequestAllItems.call(
|
|
|
|
this,
|
|
|
|
'value',
|
|
|
|
'GET',
|
|
|
|
`/v1.0/users/${memberId}/planner/tasks`,
|
|
|
|
{},
|
|
|
|
);
|
2022-04-25 02:22:16 -07:00
|
|
|
responseData = responseData.splice(0, qs.limit);
|
|
|
|
}
|
2021-07-19 23:58:54 -07:00
|
|
|
} else {
|
2022-04-25 02:22:16 -07:00
|
|
|
//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) {
|
2022-08-17 08:50:24 -07:00
|
|
|
responseData = await microsoftApiRequestAllItems.call(
|
|
|
|
this,
|
|
|
|
'value',
|
|
|
|
'GET',
|
|
|
|
`/v1.0/planner/plans/${planId}/tasks`,
|
|
|
|
);
|
2022-04-25 02:22:16 -07:00
|
|
|
} else {
|
2022-11-18 06:26:22 -08:00
|
|
|
qs.limit = this.getNodeParameter('limit', i);
|
2022-08-17 08:50:24 -07:00
|
|
|
responseData = await microsoftApiRequestAllItems.call(
|
|
|
|
this,
|
|
|
|
'value',
|
|
|
|
'GET',
|
|
|
|
`/v1.0/planner/plans/${planId}/tasks`,
|
|
|
|
{},
|
|
|
|
);
|
2022-04-25 02:22:16 -07:00
|
|
|
responseData = responseData.splice(0, qs.limit);
|
|
|
|
}
|
2021-07-19 23:58:54 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
//https://docs.microsoft.com/en-us/graph/api/plannertask-update?view=graph-rest-1.0&tabs=http
|
|
|
|
if (operation === 'update') {
|
|
|
|
const taskId = this.getNodeParameter('taskId', i) as string;
|
2022-11-18 07:29:44 -08:00
|
|
|
const updateFields = this.getNodeParameter('updateFields', i);
|
2021-07-19 23:58:54 -07:00
|
|
|
const body: IDataObject = {};
|
|
|
|
Object.assign(body, updateFields);
|
|
|
|
|
|
|
|
if (body.assignedTo) {
|
|
|
|
body.assignments = {
|
|
|
|
[body.assignedTo as string]: {
|
|
|
|
'@odata.type': 'microsoft.graph.plannerAssignment',
|
2022-08-17 08:50:24 -07:00
|
|
|
orderHint: ' !',
|
2021-07-19 23:58:54 -07:00
|
|
|
},
|
|
|
|
};
|
|
|
|
delete body.assignedTo;
|
|
|
|
}
|
2021-02-07 12:39:39 -08:00
|
|
|
|
2022-04-25 02:22:16 -07:00
|
|
|
if (body.groupId) {
|
|
|
|
// tasks are assigned to a plan and bucket, group is used for filtering
|
|
|
|
delete body.groupId;
|
|
|
|
}
|
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (Array.isArray(body.labels)) {
|
2022-08-17 08:50:24 -07:00
|
|
|
body.appliedCategories = (body.labels as string[]).map((label) => ({
|
|
|
|
[label]: true,
|
|
|
|
}));
|
2021-07-19 23:58:54 -07:00
|
|
|
}
|
2021-02-07 12:39:39 -08:00
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
const task = await microsoftApiRequest.call(
|
|
|
|
this,
|
|
|
|
'GET',
|
|
|
|
`/v1.0/planner/tasks/${taskId}`,
|
|
|
|
);
|
2021-02-07 12:39:39 -08:00
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
responseData = await microsoftApiRequest.call(
|
|
|
|
this,
|
|
|
|
'PATCH',
|
|
|
|
`/v1.0/planner/tasks/${taskId}`,
|
|
|
|
body,
|
|
|
|
{},
|
|
|
|
undefined,
|
|
|
|
{ 'If-Match': task['@odata.etag'] },
|
|
|
|
);
|
2021-07-19 23:58:54 -07:00
|
|
|
|
|
|
|
responseData = { success: true };
|
|
|
|
}
|
2021-02-07 12:39:39 -08:00
|
|
|
}
|
2022-08-30 08:55:33 -07:00
|
|
|
|
|
|
|
const executionData = this.helpers.constructExecutionMetaData(
|
|
|
|
this.helpers.returnJsonArray(responseData),
|
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
|
|
|
|
returnData.push(...executionData);
|
2021-07-19 23:58:54 -07:00
|
|
|
} catch (error) {
|
|
|
|
if (this.continueOnFail()) {
|
2022-08-30 08:55:33 -07:00
|
|
|
const executionErrorData = this.helpers.constructExecutionMetaData(
|
|
|
|
this.helpers.returnJsonArray({ error: error.message }),
|
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
returnData.push(...executionErrorData);
|
2021-07-19 23:58:54 -07:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
throw error;
|
2020-09-13 02:08:43 -07:00
|
|
|
}
|
|
|
|
}
|
2022-08-30 08:55:33 -07:00
|
|
|
return this.prepareOutputData(returnData);
|
2020-09-13 02:08:43 -07:00
|
|
|
}
|
|
|
|
}
|