feat(Microsoft Teams Node): Overhaul (#7477)
Co-authored-by: Giulio Andreini <andreini@netseven.it>
This commit is contained in:
@@ -0,0 +1,327 @@
|
||||
import type { INodeProperties } from 'n8n-workflow';
|
||||
|
||||
export const channelOperations: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Operation',
|
||||
name: 'operation',
|
||||
type: 'options',
|
||||
noDataExpression: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['channel'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: 'Create',
|
||||
value: 'create',
|
||||
description: 'Create a channel',
|
||||
action: 'Create a channel',
|
||||
},
|
||||
{
|
||||
name: 'Delete',
|
||||
value: 'delete',
|
||||
description: 'Delete a channel',
|
||||
action: 'Delete a channel',
|
||||
},
|
||||
{
|
||||
name: 'Get',
|
||||
value: 'get',
|
||||
description: 'Get a channel',
|
||||
action: 'Get a channel',
|
||||
},
|
||||
{
|
||||
name: 'Get Many',
|
||||
value: 'getAll',
|
||||
description: 'Get many channels',
|
||||
action: 'Get many channels',
|
||||
},
|
||||
{
|
||||
name: 'Update',
|
||||
value: 'update',
|
||||
description: 'Update a channel',
|
||||
action: 'Update a channel',
|
||||
},
|
||||
],
|
||||
default: 'create',
|
||||
},
|
||||
];
|
||||
|
||||
export const channelFields: INodeProperties[] = [
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* channel:create */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
{
|
||||
displayName: 'Team Name or ID',
|
||||
name: 'teamId',
|
||||
required: true,
|
||||
type: 'options',
|
||||
description:
|
||||
'Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>',
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getTeams',
|
||||
},
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: ['create'],
|
||||
resource: ['channel'],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
},
|
||||
{
|
||||
displayName: 'Name',
|
||||
name: 'name',
|
||||
required: true,
|
||||
type: 'string',
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: ['create'],
|
||||
resource: ['channel'],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
description: 'Channel name as it will appear to the user in Microsoft Teams',
|
||||
},
|
||||
{
|
||||
displayName: 'Options',
|
||||
name: 'options',
|
||||
type: 'collection',
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: ['create'],
|
||||
resource: ['channel'],
|
||||
},
|
||||
},
|
||||
default: {},
|
||||
placeholder: 'Add Field',
|
||||
options: [
|
||||
{
|
||||
displayName: 'Description',
|
||||
name: 'description',
|
||||
type: 'string',
|
||||
default: '',
|
||||
description: "Channel's description",
|
||||
},
|
||||
{
|
||||
displayName: 'Type',
|
||||
name: 'type',
|
||||
type: 'options',
|
||||
options: [
|
||||
{
|
||||
name: 'Private',
|
||||
value: 'private',
|
||||
},
|
||||
{
|
||||
name: 'Standard',
|
||||
value: 'standard',
|
||||
},
|
||||
],
|
||||
default: 'standard',
|
||||
description: 'The type of the channel',
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* channel:delete */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
{
|
||||
displayName: 'Team Name or ID',
|
||||
name: 'teamId',
|
||||
required: true,
|
||||
type: 'options',
|
||||
description:
|
||||
'Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>',
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getTeams',
|
||||
},
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: ['delete'],
|
||||
resource: ['channel'],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
},
|
||||
{
|
||||
displayName: 'Channel Name or ID',
|
||||
name: 'channelId',
|
||||
type: 'options',
|
||||
description:
|
||||
'Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>',
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getChannels',
|
||||
loadOptionsDependsOn: ['teamId'],
|
||||
},
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: ['delete'],
|
||||
resource: ['channel'],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
},
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* channel:get */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
{
|
||||
displayName: 'Team Name or ID',
|
||||
name: 'teamId',
|
||||
required: true,
|
||||
type: 'options',
|
||||
description:
|
||||
'Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>',
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getTeams',
|
||||
},
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: ['get'],
|
||||
resource: ['channel'],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
},
|
||||
{
|
||||
displayName: 'Channel Name or ID',
|
||||
name: 'channelId',
|
||||
type: 'options',
|
||||
description:
|
||||
'Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>',
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getChannels',
|
||||
loadOptionsDependsOn: ['teamId'],
|
||||
},
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: ['get'],
|
||||
resource: ['channel'],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
},
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* channel:getAll */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
{
|
||||
displayName: 'Team Name or ID',
|
||||
name: 'teamId',
|
||||
required: true,
|
||||
type: 'options',
|
||||
description:
|
||||
'Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>',
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getTeams',
|
||||
},
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: ['getAll'],
|
||||
resource: ['channel'],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
},
|
||||
{
|
||||
displayName: 'Return All',
|
||||
name: 'returnAll',
|
||||
type: 'boolean',
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: ['getAll'],
|
||||
resource: ['channel'],
|
||||
},
|
||||
},
|
||||
default: false,
|
||||
description: 'Whether to return all results or only up to a given limit',
|
||||
},
|
||||
{
|
||||
displayName: 'Limit',
|
||||
name: 'limit',
|
||||
type: 'number',
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: ['getAll'],
|
||||
resource: ['channel'],
|
||||
returnAll: [false],
|
||||
},
|
||||
},
|
||||
typeOptions: {
|
||||
minValue: 1,
|
||||
maxValue: 500,
|
||||
},
|
||||
default: 50,
|
||||
description: 'Max number of results to return',
|
||||
},
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* channel:update */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
{
|
||||
displayName: 'Team Name or ID',
|
||||
name: 'teamId',
|
||||
required: true,
|
||||
type: 'options',
|
||||
description:
|
||||
'Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>',
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getTeams',
|
||||
},
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: ['update'],
|
||||
resource: ['channel'],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
},
|
||||
{
|
||||
displayName: 'Channel Name or ID',
|
||||
name: 'channelId',
|
||||
type: 'options',
|
||||
description:
|
||||
'Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>',
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getChannels',
|
||||
loadOptionsDependsOn: ['teamId'],
|
||||
},
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: ['update'],
|
||||
resource: ['channel'],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
},
|
||||
{
|
||||
displayName: 'Update Fields',
|
||||
name: 'updateFields',
|
||||
type: 'collection',
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: ['update'],
|
||||
resource: ['channel'],
|
||||
},
|
||||
},
|
||||
default: {},
|
||||
placeholder: 'Add Field',
|
||||
options: [
|
||||
{
|
||||
displayName: 'Name',
|
||||
name: 'name',
|
||||
type: 'string',
|
||||
default: '',
|
||||
description: 'Channel name as it will appear to the user in Microsoft Teams',
|
||||
},
|
||||
{
|
||||
displayName: 'Description',
|
||||
name: 'description',
|
||||
type: 'string',
|
||||
default: '',
|
||||
description: "Channel's description",
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
@@ -0,0 +1,210 @@
|
||||
import type { INodeProperties } from 'n8n-workflow';
|
||||
|
||||
export const channelMessageOperations: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Operation',
|
||||
name: 'operation',
|
||||
type: 'options',
|
||||
noDataExpression: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['channelMessage'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: 'Create',
|
||||
value: 'create',
|
||||
description: 'Create a message',
|
||||
action: 'Create a message in a channel',
|
||||
},
|
||||
{
|
||||
name: 'Get Many',
|
||||
value: 'getAll',
|
||||
description: 'Get many messages',
|
||||
action: 'Get many messages in a channel',
|
||||
},
|
||||
],
|
||||
default: 'create',
|
||||
},
|
||||
];
|
||||
|
||||
export const channelMessageFields: INodeProperties[] = [
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* channelMessage:create */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
{
|
||||
displayName: 'Team Name or ID',
|
||||
name: 'teamId',
|
||||
required: true,
|
||||
type: 'options',
|
||||
description:
|
||||
'Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>',
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getTeams',
|
||||
},
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: ['create'],
|
||||
resource: ['channelMessage'],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
},
|
||||
{
|
||||
displayName: 'Channel Name or ID',
|
||||
name: 'channelId',
|
||||
type: 'options',
|
||||
description:
|
||||
'Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>',
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getChannels',
|
||||
loadOptionsDependsOn: ['teamId'],
|
||||
},
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: ['create'],
|
||||
resource: ['channelMessage'],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
},
|
||||
{
|
||||
displayName: 'Message Type',
|
||||
name: 'messageType',
|
||||
required: true,
|
||||
type: 'options',
|
||||
options: [
|
||||
{
|
||||
name: 'Text',
|
||||
value: 'text',
|
||||
},
|
||||
{
|
||||
name: 'HTML',
|
||||
value: 'html',
|
||||
},
|
||||
],
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: ['create'],
|
||||
resource: ['channelMessage'],
|
||||
},
|
||||
},
|
||||
default: 'text',
|
||||
description: 'The type of the content',
|
||||
},
|
||||
{
|
||||
displayName: 'Message',
|
||||
name: 'message',
|
||||
required: true,
|
||||
type: 'string',
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: ['create'],
|
||||
resource: ['channelMessage'],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
description: 'The content of the item',
|
||||
},
|
||||
{
|
||||
displayName: 'Options',
|
||||
name: 'options',
|
||||
type: 'collection',
|
||||
placeholder: 'Add Field',
|
||||
default: {},
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['channelMessage'],
|
||||
operation: ['create'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Include Link to Workflow',
|
||||
name: 'includeLinkToWorkflow',
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
description:
|
||||
'Whether to append a link to this workflow at the end of the message. This is helpful if you have many workflows sending messages.',
|
||||
},
|
||||
{
|
||||
displayName: 'Make Reply',
|
||||
name: 'makeReply',
|
||||
type: 'string',
|
||||
default: '',
|
||||
description: 'An optional ID of the message you want to reply to',
|
||||
},
|
||||
],
|
||||
},
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* channelMessage:getAll */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
{
|
||||
displayName: 'Team Name or ID',
|
||||
name: 'teamId',
|
||||
required: true,
|
||||
type: 'options',
|
||||
description:
|
||||
'Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>',
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getTeams',
|
||||
},
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: ['getAll'],
|
||||
resource: ['channelMessage'],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
},
|
||||
{
|
||||
displayName: 'Channel Name or ID',
|
||||
name: 'channelId',
|
||||
type: 'options',
|
||||
description:
|
||||
'Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>',
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getChannels',
|
||||
loadOptionsDependsOn: ['teamId'],
|
||||
},
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: ['getAll'],
|
||||
resource: ['channelMessage'],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
},
|
||||
{
|
||||
displayName: 'Return All',
|
||||
name: 'returnAll',
|
||||
type: 'boolean',
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: ['getAll'],
|
||||
resource: ['channelMessage'],
|
||||
},
|
||||
},
|
||||
default: false,
|
||||
description: 'Whether to return all results or only up to a given limit',
|
||||
},
|
||||
{
|
||||
displayName: 'Limit',
|
||||
name: 'limit',
|
||||
type: 'number',
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: ['getAll'],
|
||||
resource: ['channelMessage'],
|
||||
returnAll: [false],
|
||||
},
|
||||
},
|
||||
typeOptions: {
|
||||
minValue: 1,
|
||||
maxValue: 500,
|
||||
},
|
||||
default: 50,
|
||||
description: 'Max number of results to return',
|
||||
},
|
||||
];
|
||||
@@ -0,0 +1,191 @@
|
||||
import type { INodeProperties } from 'n8n-workflow';
|
||||
|
||||
export const chatMessageOperations: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Operation',
|
||||
name: 'operation',
|
||||
type: 'options',
|
||||
noDataExpression: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['chatMessage'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: 'Create',
|
||||
value: 'create',
|
||||
description: 'Create a message',
|
||||
action: 'Create a chat message',
|
||||
},
|
||||
{
|
||||
name: 'Get',
|
||||
value: 'get',
|
||||
description: 'Get a message',
|
||||
action: 'Get a chat message',
|
||||
},
|
||||
{
|
||||
name: 'Get Many',
|
||||
value: 'getAll',
|
||||
description: 'Get many messages',
|
||||
action: 'Get many chat messages',
|
||||
},
|
||||
],
|
||||
default: 'create',
|
||||
},
|
||||
];
|
||||
|
||||
export const chatMessageFields: INodeProperties[] = [
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* chatMessage:create */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
{
|
||||
displayName: 'Chat Name or ID',
|
||||
name: 'chatId',
|
||||
required: true,
|
||||
type: 'options',
|
||||
description:
|
||||
'Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>',
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getChats',
|
||||
},
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: ['create', 'get'],
|
||||
resource: ['chatMessage'],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
},
|
||||
{
|
||||
displayName: 'Message Type',
|
||||
name: 'messageType',
|
||||
required: true,
|
||||
type: 'options',
|
||||
options: [
|
||||
{
|
||||
name: 'Text',
|
||||
value: 'text',
|
||||
},
|
||||
{
|
||||
name: 'HTML',
|
||||
value: 'html',
|
||||
},
|
||||
],
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: ['create'],
|
||||
resource: ['chatMessage'],
|
||||
},
|
||||
},
|
||||
default: 'text',
|
||||
description: 'The type of the content',
|
||||
},
|
||||
{
|
||||
displayName: 'Message',
|
||||
name: 'message',
|
||||
required: true,
|
||||
type: 'string',
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: ['create'],
|
||||
resource: ['chatMessage'],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
description: 'The content of the item',
|
||||
},
|
||||
{
|
||||
displayName: 'Options',
|
||||
name: 'options',
|
||||
type: 'collection',
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: ['create'],
|
||||
resource: ['chatMessage'],
|
||||
},
|
||||
},
|
||||
default: {},
|
||||
description: 'Other options to set',
|
||||
placeholder: 'Add options',
|
||||
options: [
|
||||
{
|
||||
displayName: 'Include Link to Workflow',
|
||||
name: 'includeLinkToWorkflow',
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
description:
|
||||
'Whether to append a link to this workflow at the end of the message. This is helpful if you have many workflows sending messages.',
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* chatMessage:get */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
{
|
||||
displayName: 'Message ID',
|
||||
name: 'messageId',
|
||||
required: true,
|
||||
type: 'string',
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: ['get'],
|
||||
resource: ['chatMessage'],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
},
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* chatMessage:getAll */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
{
|
||||
displayName: 'Chat Name or ID',
|
||||
name: 'chatId',
|
||||
required: true,
|
||||
type: 'options',
|
||||
description:
|
||||
'Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>',
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getChats',
|
||||
},
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: ['getAll'],
|
||||
resource: ['chatMessage'],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
},
|
||||
{
|
||||
displayName: 'Return All',
|
||||
name: 'returnAll',
|
||||
type: 'boolean',
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: ['getAll'],
|
||||
resource: ['chatMessage'],
|
||||
},
|
||||
},
|
||||
default: false,
|
||||
description: 'Whether to return all results or only up to a given limit',
|
||||
},
|
||||
{
|
||||
displayName: 'Limit',
|
||||
name: 'limit',
|
||||
type: 'number',
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: ['getAll'],
|
||||
resource: ['chatMessage'],
|
||||
returnAll: [false],
|
||||
},
|
||||
},
|
||||
typeOptions: {
|
||||
minValue: 1,
|
||||
maxValue: 500,
|
||||
},
|
||||
default: 50,
|
||||
description: 'Max number of results to return',
|
||||
},
|
||||
];
|
||||
115
packages/nodes-base/nodes/Microsoft/Teams/v1/GenericFunctions.ts
Normal file
115
packages/nodes-base/nodes/Microsoft/Teams/v1/GenericFunctions.ts
Normal file
@@ -0,0 +1,115 @@
|
||||
import type { OptionsWithUri } from 'request';
|
||||
|
||||
import type {
|
||||
IExecuteFunctions,
|
||||
ILoadOptionsFunctions,
|
||||
IDataObject,
|
||||
JsonObject,
|
||||
} from 'n8n-workflow';
|
||||
import { NodeApiError } from 'n8n-workflow';
|
||||
|
||||
export async function microsoftApiRequest(
|
||||
this: IExecuteFunctions | ILoadOptionsFunctions,
|
||||
method: string,
|
||||
resource: string,
|
||||
|
||||
body: any = {},
|
||||
qs: IDataObject = {},
|
||||
uri?: string,
|
||||
headers: IDataObject = {},
|
||||
): Promise<any> {
|
||||
const options: OptionsWithUri = {
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
method,
|
||||
body,
|
||||
qs,
|
||||
uri: uri || `https://graph.microsoft.com${resource}`,
|
||||
json: true,
|
||||
};
|
||||
try {
|
||||
if (Object.keys(headers).length !== 0) {
|
||||
options.headers = Object.assign({}, options.headers, headers);
|
||||
}
|
||||
//@ts-ignore
|
||||
return await this.helpers.requestOAuth2.call(this, 'microsoftTeamsOAuth2Api', options);
|
||||
} catch (error) {
|
||||
throw new NodeApiError(this.getNode(), error as JsonObject);
|
||||
}
|
||||
}
|
||||
|
||||
export async function microsoftApiRequestAllItems(
|
||||
this: IExecuteFunctions | ILoadOptionsFunctions,
|
||||
propertyName: string,
|
||||
method: string,
|
||||
endpoint: string,
|
||||
|
||||
body: any = {},
|
||||
query: IDataObject = {},
|
||||
): Promise<any> {
|
||||
const returnData: IDataObject[] = [];
|
||||
|
||||
let responseData;
|
||||
let uri: string | undefined;
|
||||
|
||||
do {
|
||||
responseData = await microsoftApiRequest.call(this, method, endpoint, body, query, uri);
|
||||
uri = responseData['@odata.nextLink'];
|
||||
returnData.push.apply(returnData, responseData[propertyName] as IDataObject[]);
|
||||
const limit = query.limit as number | undefined;
|
||||
if (limit && limit <= returnData.length) {
|
||||
return returnData;
|
||||
}
|
||||
} while (responseData['@odata.nextLink'] !== undefined);
|
||||
|
||||
return returnData;
|
||||
}
|
||||
|
||||
export async function microsoftApiRequestAllItemsSkip(
|
||||
this: IExecuteFunctions | ILoadOptionsFunctions,
|
||||
propertyName: string,
|
||||
method: string,
|
||||
endpoint: string,
|
||||
|
||||
body: any = {},
|
||||
query: IDataObject = {},
|
||||
): Promise<any> {
|
||||
const returnData: IDataObject[] = [];
|
||||
|
||||
let responseData;
|
||||
query.$top = 100;
|
||||
query.$skip = 0;
|
||||
|
||||
do {
|
||||
responseData = await microsoftApiRequest.call(this, method, endpoint, body, query);
|
||||
query.$skip += query.$top;
|
||||
returnData.push.apply(returnData, responseData[propertyName] as IDataObject[]);
|
||||
} while (responseData.value.length !== 0);
|
||||
|
||||
return returnData;
|
||||
}
|
||||
|
||||
export function prepareMessage(
|
||||
this: IExecuteFunctions | ILoadOptionsFunctions,
|
||||
message: string,
|
||||
messageType: string,
|
||||
includeLinkToWorkflow: boolean,
|
||||
instanceId?: string,
|
||||
) {
|
||||
if (includeLinkToWorkflow) {
|
||||
const { id } = this.getWorkflow();
|
||||
const link = `${this.getInstanceBaseUrl()}workflow/${id}?utm_source=n8n-internal&utm_medium=powered_by&utm_campaign=${encodeURIComponent(
|
||||
'n8n-nodes-base.microsoftTeams',
|
||||
)}${instanceId ? '_' + instanceId : ''}`;
|
||||
messageType = 'html';
|
||||
message = `${message}<br><br><em> Powered by <a href="${link}">this n8n workflow</a> </em>`;
|
||||
}
|
||||
|
||||
return {
|
||||
body: {
|
||||
contentType: messageType,
|
||||
content: message,
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,683 @@
|
||||
/* eslint-disable n8n-nodes-base/node-filename-against-convention */
|
||||
import type {
|
||||
IExecuteFunctions,
|
||||
IDataObject,
|
||||
ILoadOptionsFunctions,
|
||||
INodeExecutionData,
|
||||
INodePropertyOptions,
|
||||
INodeType,
|
||||
INodeTypeDescription,
|
||||
INodeTypeBaseDescription,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import {
|
||||
microsoftApiRequest,
|
||||
microsoftApiRequestAllItems,
|
||||
prepareMessage,
|
||||
} from './GenericFunctions';
|
||||
|
||||
import { channelFields, channelOperations } from './ChannelDescription';
|
||||
|
||||
import { channelMessageFields, channelMessageOperations } from './ChannelMessageDescription';
|
||||
|
||||
import { chatMessageFields, chatMessageOperations } from './ChatMessageDescription';
|
||||
|
||||
import { taskFields, taskOperations } from './TaskDescription';
|
||||
import { oldVersionNotice } from '../../../../utils/descriptions';
|
||||
|
||||
const versionDescription: INodeTypeDescription = {
|
||||
displayName: 'Microsoft Teams',
|
||||
name: 'microsoftTeams',
|
||||
icon: 'file:teams.svg',
|
||||
group: ['input'],
|
||||
version: [1, 1.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: [
|
||||
oldVersionNotice,
|
||||
{
|
||||
displayName: 'Resource',
|
||||
name: 'resource',
|
||||
type: 'options',
|
||||
noDataExpression: true,
|
||||
options: [
|
||||
{
|
||||
name: 'Channel',
|
||||
value: 'channel',
|
||||
},
|
||||
{
|
||||
name: 'Channel Message (Beta)',
|
||||
value: 'channelMessage',
|
||||
},
|
||||
{
|
||||
name: 'Chat Message',
|
||||
value: 'chatMessage',
|
||||
},
|
||||
{
|
||||
name: 'Task',
|
||||
value: 'task',
|
||||
},
|
||||
],
|
||||
default: 'channel',
|
||||
},
|
||||
// CHANNEL
|
||||
...channelOperations,
|
||||
...channelFields,
|
||||
/// MESSAGE
|
||||
...channelMessageOperations,
|
||||
...channelMessageFields,
|
||||
...chatMessageOperations,
|
||||
...chatMessageFields,
|
||||
///TASK
|
||||
...taskOperations,
|
||||
...taskFields,
|
||||
],
|
||||
};
|
||||
|
||||
export class MicrosoftTeamsV1 implements INodeType {
|
||||
description: INodeTypeDescription;
|
||||
|
||||
constructor(baseDescription: INodeTypeBaseDescription) {
|
||||
this.description = {
|
||||
...baseDescription,
|
||||
...versionDescription,
|
||||
};
|
||||
}
|
||||
|
||||
methods = {
|
||||
loadOptions: {
|
||||
// Get all the team's channels to display them to user so that they can
|
||||
// select them easily
|
||||
async getChannels(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||
const returnData: INodePropertyOptions[] = [];
|
||||
const teamId = this.getCurrentNodeParameter('teamId') as string;
|
||||
const { value } = await microsoftApiRequest.call(
|
||||
this,
|
||||
'GET',
|
||||
`/v1.0/teams/${teamId}/channels`,
|
||||
);
|
||||
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 they 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;
|
||||
},
|
||||
// Get all the groups to display them to user so that they can
|
||||
// select them easily
|
||||
async getGroups(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||
const returnData: INodePropertyOptions[] = [];
|
||||
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.displayName || group.mail || group.id,
|
||||
value: group.id,
|
||||
description: group.mail,
|
||||
});
|
||||
}
|
||||
return returnData;
|
||||
},
|
||||
// Get all the plans to display them to user so that they can
|
||||
// select them easily
|
||||
async getPlans(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||
const returnData: INodePropertyOptions[] = [];
|
||||
let groupId = this.getCurrentNodeParameter('groupId') as string;
|
||||
const operation = this.getNodeParameter('operation', 0);
|
||||
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({
|
||||
name: plan.title,
|
||||
value: plan.id,
|
||||
});
|
||||
}
|
||||
return returnData;
|
||||
},
|
||||
// Get all the plans to display them to user so that they can
|
||||
// select them easily
|
||||
async getBuckets(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||
const returnData: INodePropertyOptions[] = [];
|
||||
let planId = this.getCurrentNodeParameter('planId') as string;
|
||||
const operation = this.getNodeParameter('operation', 0);
|
||||
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({
|
||||
name: bucket.name,
|
||||
value: bucket.id,
|
||||
});
|
||||
}
|
||||
return returnData;
|
||||
},
|
||||
// Get all the plans to display them to user so that they can
|
||||
// select them easily
|
||||
async getMembers(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||
const returnData: INodePropertyOptions[] = [];
|
||||
let groupId = this.getCurrentNodeParameter('groupId') as string;
|
||||
const operation = this.getNodeParameter('operation', 0);
|
||||
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({
|
||||
name: member.displayName,
|
||||
value: member.id,
|
||||
});
|
||||
}
|
||||
return returnData;
|
||||
},
|
||||
// Get all the labels to display them to user so that they can
|
||||
// select them easily
|
||||
async getLabels(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||
const returnData: INodePropertyOptions[] = [];
|
||||
|
||||
let planId = this.getCurrentNodeParameter('planId') as string;
|
||||
const operation = this.getNodeParameter('operation', 0);
|
||||
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 as IDataObject)) {
|
||||
if (categoryDescriptions[key] !== null) {
|
||||
returnData.push({
|
||||
name: categoryDescriptions[key],
|
||||
value: key,
|
||||
});
|
||||
}
|
||||
}
|
||||
return returnData;
|
||||
},
|
||||
// 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
|
||||
.filter((member: IDataObject) => member.displayName)
|
||||
.map((member: IDataObject) => member.displayName)
|
||||
.join(', ');
|
||||
}
|
||||
const chatName = `${chat.topic || '(no title) - ' + (chat.id as string)} (${
|
||||
chat.chatType
|
||||
})`;
|
||||
const chatId = chat.id;
|
||||
returnData.push({
|
||||
name: chatName,
|
||||
value: chatId,
|
||||
});
|
||||
}
|
||||
return returnData;
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
||||
const items = this.getInputData();
|
||||
const returnData: INodeExecutionData[] = [];
|
||||
const length = items.length;
|
||||
const qs: IDataObject = {};
|
||||
let responseData;
|
||||
const resource = this.getNodeParameter('resource', 0);
|
||||
const operation = this.getNodeParameter('operation', 0);
|
||||
const nodeVersion = this.getNode().typeVersion;
|
||||
const instanceId = this.getInstanceId();
|
||||
|
||||
for (let i = 0; i < length; i++) {
|
||||
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;
|
||||
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;
|
||||
}
|
||||
responseData = await microsoftApiRequest.call(
|
||||
this,
|
||||
'POST',
|
||||
`/v1.0/teams/${teamId}/channels`,
|
||||
body,
|
||||
);
|
||||
}
|
||||
//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;
|
||||
responseData = await microsoftApiRequest.call(
|
||||
this,
|
||||
'DELETE',
|
||||
`/v1.0/teams/${teamId}/channels/${channelId}`,
|
||||
);
|
||||
responseData = { success: true };
|
||||
}
|
||||
//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;
|
||||
responseData = await microsoftApiRequest.call(
|
||||
this,
|
||||
'GET',
|
||||
`/v1.0/teams/${teamId}/channels/${channelId}`,
|
||||
);
|
||||
}
|
||||
//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;
|
||||
const returnAll = this.getNodeParameter('returnAll', i);
|
||||
if (returnAll) {
|
||||
responseData = await microsoftApiRequestAllItems.call(
|
||||
this,
|
||||
'value',
|
||||
'GET',
|
||||
`/v1.0/teams/${teamId}/channels`,
|
||||
);
|
||||
} else {
|
||||
qs.limit = this.getNodeParameter('limit', i);
|
||||
responseData = await microsoftApiRequestAllItems.call(
|
||||
this,
|
||||
'value',
|
||||
'GET',
|
||||
`/v1.0/teams/${teamId}/channels`,
|
||||
{},
|
||||
);
|
||||
responseData = responseData.splice(0, qs.limit);
|
||||
}
|
||||
}
|
||||
//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;
|
||||
const updateFields = this.getNodeParameter('updateFields', i);
|
||||
const body: IDataObject = {};
|
||||
if (updateFields.name) {
|
||||
body.displayName = updateFields.name as string;
|
||||
}
|
||||
if (updateFields.description) {
|
||||
body.description = updateFields.description as string;
|
||||
}
|
||||
responseData = await microsoftApiRequest.call(
|
||||
this,
|
||||
'PATCH',
|
||||
`/v1.0/teams/${teamId}/channels/${channelId}`,
|
||||
body,
|
||||
);
|
||||
responseData = { success: true };
|
||||
}
|
||||
}
|
||||
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;
|
||||
const options = this.getNodeParameter('options', i);
|
||||
|
||||
let includeLinkToWorkflow = options.includeLinkToWorkflow;
|
||||
if (includeLinkToWorkflow === undefined) {
|
||||
includeLinkToWorkflow = nodeVersion >= 1.1;
|
||||
}
|
||||
|
||||
const body: IDataObject = prepareMessage.call(
|
||||
this,
|
||||
message,
|
||||
messageType,
|
||||
includeLinkToWorkflow as boolean,
|
||||
instanceId,
|
||||
);
|
||||
|
||||
if (options.makeReply) {
|
||||
const replyToId = options.makeReply as string;
|
||||
responseData = await microsoftApiRequest.call(
|
||||
this,
|
||||
'POST',
|
||||
`/beta/teams/${teamId}/channels/${channelId}/messages/${replyToId}/replies`,
|
||||
body,
|
||||
);
|
||||
} else {
|
||||
responseData = await microsoftApiRequest.call(
|
||||
this,
|
||||
'POST',
|
||||
`/beta/teams/${teamId}/channels/${channelId}/messages`,
|
||||
body,
|
||||
);
|
||||
}
|
||||
}
|
||||
//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;
|
||||
const returnAll = this.getNodeParameter('returnAll', i);
|
||||
if (returnAll) {
|
||||
responseData = await microsoftApiRequestAllItems.call(
|
||||
this,
|
||||
'value',
|
||||
'GET',
|
||||
`/beta/teams/${teamId}/channels/${channelId}/messages`,
|
||||
);
|
||||
} else {
|
||||
qs.limit = this.getNodeParameter('limit', i);
|
||||
responseData = await microsoftApiRequestAllItems.call(
|
||||
this,
|
||||
'value',
|
||||
'GET',
|
||||
`/beta/teams/${teamId}/channels/${channelId}/messages`,
|
||||
{},
|
||||
);
|
||||
responseData = responseData.splice(0, qs.limit);
|
||||
}
|
||||
}
|
||||
}
|
||||
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 options = this.getNodeParameter('options', i, {});
|
||||
|
||||
const includeLinkToWorkflow =
|
||||
options.includeLinkToWorkflow !== false && nodeVersion >= 1.1;
|
||||
|
||||
const body: IDataObject = prepareMessage.call(
|
||||
this,
|
||||
message,
|
||||
messageType,
|
||||
includeLinkToWorkflow,
|
||||
instanceId,
|
||||
);
|
||||
|
||||
responseData = await microsoftApiRequest.call(
|
||||
this,
|
||||
'POST',
|
||||
`/v1.0/chats/${chatId}/messages`,
|
||||
body,
|
||||
);
|
||||
}
|
||||
// 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;
|
||||
responseData = await microsoftApiRequest.call(
|
||||
this,
|
||||
'GET',
|
||||
`/v1.0/chats/${chatId}/messages/${messageId}`,
|
||||
);
|
||||
}
|
||||
// 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;
|
||||
const returnAll = this.getNodeParameter('returnAll', i);
|
||||
if (returnAll) {
|
||||
responseData = await microsoftApiRequestAllItems.call(
|
||||
this,
|
||||
'value',
|
||||
'GET',
|
||||
`/v1.0/chats/${chatId}/messages`,
|
||||
);
|
||||
} else {
|
||||
qs.limit = this.getNodeParameter('limit', i);
|
||||
responseData = await microsoftApiRequestAllItems.call(
|
||||
this,
|
||||
'value',
|
||||
'GET',
|
||||
`/v1.0/chats/${chatId}/messages`,
|
||||
{},
|
||||
);
|
||||
responseData = responseData.splice(0, qs.limit);
|
||||
}
|
||||
}
|
||||
}
|
||||
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;
|
||||
const additionalFields = this.getNodeParameter('additionalFields', i);
|
||||
const body: IDataObject = {
|
||||
planId,
|
||||
bucketId,
|
||||
title,
|
||||
};
|
||||
Object.assign(body, additionalFields);
|
||||
|
||||
if (body.assignedTo) {
|
||||
body.assignments = {
|
||||
[body.assignedTo as string]: {
|
||||
'@odata.type': 'microsoft.graph.plannerAssignment',
|
||||
orderHint: ' !',
|
||||
},
|
||||
};
|
||||
delete body.assignedTo;
|
||||
}
|
||||
|
||||
if (Array.isArray(body.labels)) {
|
||||
body.appliedCategories = (body.labels as string[]).map((label) => ({
|
||||
[label]: true,
|
||||
}));
|
||||
}
|
||||
|
||||
responseData = await microsoftApiRequest.call(
|
||||
this,
|
||||
'POST',
|
||||
'/v1.0/planner/tasks',
|
||||
body,
|
||||
);
|
||||
}
|
||||
//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;
|
||||
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'] },
|
||||
);
|
||||
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;
|
||||
responseData = await microsoftApiRequest.call(
|
||||
this,
|
||||
'GET',
|
||||
`/v1.0/planner/tasks/${taskId}`,
|
||||
);
|
||||
}
|
||||
if (operation === 'getAll') {
|
||||
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 = 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);
|
||||
responseData = await microsoftApiRequestAllItems.call(
|
||||
this,
|
||||
'value',
|
||||
'GET',
|
||||
`/v1.0/users/${memberId}/planner/tasks`,
|
||||
{},
|
||||
);
|
||||
responseData = responseData.splice(0, qs.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) as string;
|
||||
if (returnAll) {
|
||||
responseData = await microsoftApiRequestAllItems.call(
|
||||
this,
|
||||
'value',
|
||||
'GET',
|
||||
`/v1.0/planner/plans/${planId}/tasks`,
|
||||
);
|
||||
} else {
|
||||
qs.limit = this.getNodeParameter('limit', i);
|
||||
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
|
||||
if (operation === 'update') {
|
||||
const taskId = this.getNodeParameter('taskId', i) as string;
|
||||
const updateFields = this.getNodeParameter('updateFields', i);
|
||||
const body: IDataObject = {};
|
||||
Object.assign(body, updateFields);
|
||||
|
||||
if (body.assignedTo) {
|
||||
body.assignments = {
|
||||
[body.assignedTo as string]: {
|
||||
'@odata.type': 'microsoft.graph.plannerAssignment',
|
||||
orderHint: ' !',
|
||||
},
|
||||
};
|
||||
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,
|
||||
}));
|
||||
}
|
||||
|
||||
const task = await microsoftApiRequest.call(
|
||||
this,
|
||||
'GET',
|
||||
`/v1.0/planner/tasks/${taskId}`,
|
||||
);
|
||||
|
||||
responseData = await microsoftApiRequest.call(
|
||||
this,
|
||||
'PATCH',
|
||||
`/v1.0/planner/tasks/${taskId}`,
|
||||
body,
|
||||
{},
|
||||
undefined,
|
||||
{ 'If-Match': task['@odata.etag'] },
|
||||
);
|
||||
|
||||
responseData = { success: true };
|
||||
}
|
||||
}
|
||||
|
||||
const executionData = this.helpers.constructExecutionMetaData(
|
||||
this.helpers.returnJsonArray(responseData as IDataObject),
|
||||
{ itemData: { item: i } },
|
||||
);
|
||||
|
||||
returnData.push(...executionData);
|
||||
} catch (error) {
|
||||
if (this.continueOnFail()) {
|
||||
const executionErrorData = this.helpers.constructExecutionMetaData(
|
||||
this.helpers.returnJsonArray({ error: error.message }),
|
||||
{ itemData: { item: i } },
|
||||
);
|
||||
returnData.push(...executionErrorData);
|
||||
continue;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
return [returnData];
|
||||
}
|
||||
}
|
||||
483
packages/nodes-base/nodes/Microsoft/Teams/v1/TaskDescription.ts
Normal file
483
packages/nodes-base/nodes/Microsoft/Teams/v1/TaskDescription.ts
Normal file
@@ -0,0 +1,483 @@
|
||||
import type { INodeProperties } from 'n8n-workflow';
|
||||
|
||||
export const taskOperations: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Operation',
|
||||
name: 'operation',
|
||||
type: 'options',
|
||||
noDataExpression: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['task'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: 'Create',
|
||||
value: 'create',
|
||||
description: 'Create a task',
|
||||
action: 'Create a task',
|
||||
},
|
||||
{
|
||||
name: 'Delete',
|
||||
value: 'delete',
|
||||
description: 'Delete a task',
|
||||
action: 'Delete a task',
|
||||
},
|
||||
{
|
||||
name: 'Get',
|
||||
value: 'get',
|
||||
description: 'Get a task',
|
||||
action: 'Get a task',
|
||||
},
|
||||
{
|
||||
name: 'Get Many',
|
||||
value: 'getAll',
|
||||
description: 'Get many tasks',
|
||||
action: 'Get many tasks',
|
||||
},
|
||||
{
|
||||
name: 'Update',
|
||||
value: 'update',
|
||||
description: 'Update a task',
|
||||
action: 'Update a task',
|
||||
},
|
||||
],
|
||||
default: 'create',
|
||||
},
|
||||
];
|
||||
|
||||
export const taskFields: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Group Source',
|
||||
name: 'groupSource',
|
||||
required: true,
|
||||
type: 'options',
|
||||
default: 'all',
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: ['getAll', 'create', 'update'],
|
||||
resource: ['task'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: 'All Groups',
|
||||
value: 'all',
|
||||
description: 'From all groups',
|
||||
},
|
||||
{
|
||||
name: 'My Groups',
|
||||
value: 'mine',
|
||||
description: 'Only load groups that account is member of',
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* task:create */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
{
|
||||
displayName: 'Group Name or ID',
|
||||
name: 'groupId',
|
||||
required: true,
|
||||
type: 'options',
|
||||
description:
|
||||
'Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>',
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getGroups',
|
||||
loadOptionsDependsOn: ['groupSource'],
|
||||
},
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: ['create'],
|
||||
resource: ['task'],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
},
|
||||
{
|
||||
displayName: 'Plan Name or ID',
|
||||
name: 'planId',
|
||||
required: true,
|
||||
type: 'options',
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getPlans',
|
||||
loadOptionsDependsOn: ['groupId'],
|
||||
},
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: ['create'],
|
||||
resource: ['task'],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
description:
|
||||
'The plan for the task to belong to. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.',
|
||||
},
|
||||
{
|
||||
displayName: 'Bucket Name or ID',
|
||||
name: 'bucketId',
|
||||
required: true,
|
||||
type: 'options',
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getBuckets',
|
||||
loadOptionsDependsOn: ['planId'],
|
||||
},
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: ['create'],
|
||||
resource: ['task'],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
description:
|
||||
'The bucket for the task to belong to. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.',
|
||||
},
|
||||
{
|
||||
displayName: 'Title',
|
||||
name: 'title',
|
||||
required: true,
|
||||
type: 'string',
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: ['create'],
|
||||
resource: ['task'],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
description: 'Title of the task',
|
||||
},
|
||||
{
|
||||
displayName: 'Additional Fields',
|
||||
name: 'additionalFields',
|
||||
type: 'collection',
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: ['create'],
|
||||
resource: ['task'],
|
||||
},
|
||||
},
|
||||
default: {},
|
||||
placeholder: 'Add Field',
|
||||
options: [
|
||||
{
|
||||
displayName: 'Assigned To Name or ID',
|
||||
name: 'assignedTo',
|
||||
type: 'options',
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getMembers',
|
||||
loadOptionsDependsOn: ['groupId'],
|
||||
},
|
||||
default: '',
|
||||
description:
|
||||
'Who the task should be assigned to. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.',
|
||||
},
|
||||
{
|
||||
displayName: 'Due Date Time',
|
||||
name: 'dueDateTime',
|
||||
type: '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: 'Label Names or IDs',
|
||||
name: 'labels',
|
||||
type: 'multiOptions',
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getLabels',
|
||||
loadOptionsDependsOn: ['planId'],
|
||||
},
|
||||
default: [],
|
||||
description:
|
||||
'Labels to assign to the task. Choose from the list, or specify IDs using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.',
|
||||
},
|
||||
{
|
||||
displayName: 'Percent Complete',
|
||||
name: 'percentComplete',
|
||||
type: 'number',
|
||||
typeOptions: {
|
||||
minValue: 0,
|
||||
maxValue: 100,
|
||||
},
|
||||
default: 0,
|
||||
description:
|
||||
'Percentage of task completion. When set to 100, the task is considered completed.',
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* task:delete */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
{
|
||||
displayName: 'Task ID',
|
||||
name: 'taskId',
|
||||
required: true,
|
||||
type: 'string',
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: ['delete'],
|
||||
resource: ['task'],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
},
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* task:get */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
{
|
||||
displayName: 'Task ID',
|
||||
name: 'taskId',
|
||||
required: true,
|
||||
type: 'string',
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: ['get'],
|
||||
resource: ['task'],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
},
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* task:getAll */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
{
|
||||
displayName: 'Tasks For',
|
||||
name: 'tasksFor',
|
||||
default: 'member',
|
||||
required: true,
|
||||
type: 'options',
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: ['getAll'],
|
||||
resource: ['task'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: 'Group Member',
|
||||
value: 'member',
|
||||
description: 'Tasks assigned to group member',
|
||||
},
|
||||
{
|
||||
name: 'Plan',
|
||||
value: 'plan',
|
||||
description: 'Tasks in group plan',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
displayName: 'Group Name or ID',
|
||||
name: 'groupId',
|
||||
required: true,
|
||||
type: 'options',
|
||||
description:
|
||||
'Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>',
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getGroups',
|
||||
loadOptionsDependsOn: ['groupSource'],
|
||||
},
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: ['getAll'],
|
||||
resource: ['task'],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
},
|
||||
{
|
||||
displayName: 'Member Name or ID',
|
||||
name: 'memberId',
|
||||
type: 'options',
|
||||
description:
|
||||
'Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>',
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getMembers',
|
||||
loadOptionsDependsOn: ['groupId'],
|
||||
},
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: ['getAll'],
|
||||
resource: ['task'],
|
||||
tasksFor: ['member'],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
},
|
||||
{
|
||||
displayName: 'Plan Name or ID',
|
||||
name: 'planId',
|
||||
type: 'options',
|
||||
description:
|
||||
'Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>',
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getPlans',
|
||||
loadOptionsDependsOn: ['groupId'],
|
||||
},
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: ['getAll'],
|
||||
resource: ['task'],
|
||||
tasksFor: ['plan'],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
},
|
||||
{
|
||||
displayName: 'Return All',
|
||||
name: 'returnAll',
|
||||
type: 'boolean',
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: ['getAll'],
|
||||
resource: ['task'],
|
||||
},
|
||||
},
|
||||
default: false,
|
||||
description: 'Whether to return all results or only up to a given limit',
|
||||
},
|
||||
{
|
||||
displayName: 'Limit',
|
||||
name: 'limit',
|
||||
type: 'number',
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: ['getAll'],
|
||||
resource: ['task'],
|
||||
returnAll: [false],
|
||||
},
|
||||
},
|
||||
typeOptions: {
|
||||
minValue: 1,
|
||||
maxValue: 500,
|
||||
},
|
||||
default: 50,
|
||||
description: 'Max number of results to return',
|
||||
},
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* task:update */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
{
|
||||
displayName: 'Task ID',
|
||||
name: 'taskId',
|
||||
required: true,
|
||||
type: 'string',
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: ['update'],
|
||||
resource: ['task'],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
description: 'The ID of the Task',
|
||||
},
|
||||
{
|
||||
displayName: 'Update Fields',
|
||||
name: 'updateFields',
|
||||
type: 'collection',
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: ['update'],
|
||||
resource: ['task'],
|
||||
},
|
||||
},
|
||||
default: {},
|
||||
placeholder: 'Add Field',
|
||||
options: [
|
||||
{
|
||||
displayName: 'Assigned To Name or ID',
|
||||
name: 'assignedTo',
|
||||
type: 'options',
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getMembers',
|
||||
loadOptionsDependsOn: ['groupId'],
|
||||
},
|
||||
default: '',
|
||||
description:
|
||||
'Who the task should be assigned to. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.',
|
||||
},
|
||||
{
|
||||
displayName: 'Bucket Name or ID',
|
||||
name: 'bucketId',
|
||||
type: 'options',
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getBuckets',
|
||||
loadOptionsDependsOn: ['updateFields.planId'],
|
||||
},
|
||||
default: '',
|
||||
description:
|
||||
'The bucket for the task to belong to. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.',
|
||||
},
|
||||
{
|
||||
displayName: 'Due Date Time',
|
||||
name: 'dueDateTime',
|
||||
type: '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: 'Group Name or ID',
|
||||
name: 'groupId',
|
||||
type: 'options',
|
||||
description:
|
||||
'Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>',
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getGroups',
|
||||
loadOptionsDependsOn: ['groupSource'],
|
||||
},
|
||||
default: '',
|
||||
},
|
||||
{
|
||||
displayName: 'Label Names or IDs',
|
||||
name: 'labels',
|
||||
type: 'multiOptions',
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getLabels',
|
||||
loadOptionsDependsOn: ['updateFields.planId'],
|
||||
},
|
||||
default: [],
|
||||
description:
|
||||
'Labels to assign to the task. Choose from the list, or specify IDs using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.',
|
||||
},
|
||||
{
|
||||
displayName: 'Percent Complete',
|
||||
name: 'percentComplete',
|
||||
type: 'number',
|
||||
typeOptions: {
|
||||
minValue: 0,
|
||||
maxValue: 100,
|
||||
},
|
||||
default: 0,
|
||||
description:
|
||||
'Percentage of task completion. When set to 100, the task is considered completed.',
|
||||
},
|
||||
{
|
||||
displayName: 'Plan Name or ID',
|
||||
name: 'planId',
|
||||
type: 'options',
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getPlans',
|
||||
loadOptionsDependsOn: ['groupId'],
|
||||
},
|
||||
default: '',
|
||||
description:
|
||||
'The plan for the task to belong to. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.',
|
||||
},
|
||||
{
|
||||
displayName: 'Title',
|
||||
name: 'title',
|
||||
type: 'string',
|
||||
default: '',
|
||||
description: 'Title of the task',
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
Reference in New Issue
Block a user