first commit
Security: Sync from Public / sync-from-public (push) Has been cancelled
Test: Benchmark Nightly / build (push) Has been cancelled
Test: Benchmark Nightly / Notify Cats on failure (push) Has been cancelled
CI: Python / Checks (push) Has been cancelled
Test: Evals Python / Workflow Comparison Python (push) Has been cancelled
Util: Check Docs URLs / check-docs-urls (push) Has been cancelled
Test: Visual Storybook / Cloudflare Pages (push) Has been cancelled
Test: E2E Performance / build-and-test-performance (push) Has been cancelled
Test: Workflows Nightly / Run Workflow Tests (push) Has been cancelled
Util: Cleanup CI Docker Images / Delete stale CI images (push) Has been cancelled
Test: Benchmark Destroy Env / build (push) Has been cancelled
Util: Update Node Popularity / update-popularity (push) Has been cancelled
Test: E2E Coverage Weekly / Coverage Tests (push) Has been cancelled
Security: Sync from Public / sync-from-public (push) Has been cancelled
Test: Benchmark Nightly / build (push) Has been cancelled
Test: Benchmark Nightly / Notify Cats on failure (push) Has been cancelled
CI: Python / Checks (push) Has been cancelled
Test: Evals Python / Workflow Comparison Python (push) Has been cancelled
Util: Check Docs URLs / check-docs-urls (push) Has been cancelled
Test: Visual Storybook / Cloudflare Pages (push) Has been cancelled
Test: E2E Performance / build-and-test-performance (push) Has been cancelled
Test: Workflows Nightly / Run Workflow Tests (push) Has been cancelled
Util: Cleanup CI Docker Images / Delete stale CI images (push) Has been cancelled
Test: Benchmark Destroy Env / build (push) Has been cancelled
Util: Update Node Popularity / update-popularity (push) Has been cancelled
Test: E2E Coverage Weekly / Coverage Tests (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
import type {
|
||||
IExecuteFunctions,
|
||||
INodeType,
|
||||
INodeTypeDescription,
|
||||
INodeTypeBaseDescription,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import { router } from './actions/router';
|
||||
import { versionDescription } from './actions/versionDescription';
|
||||
import { listSearch } from './methods';
|
||||
import { sendAndWaitWebhook } from '../../../../utils/sendAndWait/utils';
|
||||
|
||||
export class MicrosoftTeamsV2 implements INodeType {
|
||||
description: INodeTypeDescription;
|
||||
|
||||
constructor(baseDescription: INodeTypeBaseDescription) {
|
||||
this.description = {
|
||||
...baseDescription,
|
||||
...versionDescription,
|
||||
usableAsTool: true,
|
||||
};
|
||||
}
|
||||
|
||||
methods = { listSearch };
|
||||
|
||||
webhook = sendAndWaitWebhook;
|
||||
|
||||
async execute(this: IExecuteFunctions) {
|
||||
return await router.call(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
import type { INodeProperties, IExecuteFunctions, IDataObject } from 'n8n-workflow';
|
||||
|
||||
import { updateDisplayOptions } from '@utils/utilities';
|
||||
|
||||
import { teamRLC } from '../../descriptions';
|
||||
import { microsoftApiRequest } from '../../transport';
|
||||
|
||||
const properties: INodeProperties[] = [
|
||||
teamRLC,
|
||||
{
|
||||
displayName: 'New Channel Name',
|
||||
name: 'name',
|
||||
required: true,
|
||||
type: 'string',
|
||||
default: '',
|
||||
placeholder: 'e.g. My New Channel',
|
||||
description: 'The name of the new channel you want to create',
|
||||
},
|
||||
{
|
||||
displayName: 'Options',
|
||||
name: 'options',
|
||||
type: 'collection',
|
||||
default: {},
|
||||
placeholder: 'Add option',
|
||||
options: [
|
||||
{
|
||||
displayName: 'Description',
|
||||
name: 'description',
|
||||
type: 'string',
|
||||
default: '',
|
||||
description: 'The description of the channel',
|
||||
typeOptions: {
|
||||
rows: 2,
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Type',
|
||||
name: 'type',
|
||||
type: 'options',
|
||||
options: [
|
||||
{
|
||||
name: 'Private',
|
||||
value: 'private',
|
||||
},
|
||||
{
|
||||
name: 'Standard',
|
||||
value: 'standard',
|
||||
},
|
||||
],
|
||||
default: 'standard',
|
||||
description:
|
||||
'Standard: Accessible to everyone on the team. Private: Accessible only to a specific group of people within the team.',
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
const displayOptions = {
|
||||
show: {
|
||||
resource: ['channel'],
|
||||
operation: ['create'],
|
||||
},
|
||||
};
|
||||
|
||||
export const description = updateDisplayOptions(displayOptions, properties);
|
||||
|
||||
export async function execute(this: IExecuteFunctions, i: number) {
|
||||
//https://docs.microsoft.com/en-us/graph/api/channel-post?view=graph-rest-beta&tabs=http
|
||||
const teamId = this.getNodeParameter('teamId', i, '', { extractValue: true }) 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;
|
||||
}
|
||||
return await microsoftApiRequest.call(this, 'POST', `/v1.0/teams/${teamId}/channels`, body);
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
import { type INodeProperties, type IExecuteFunctions, NodeOperationError } from 'n8n-workflow';
|
||||
|
||||
import { updateDisplayOptions } from '@utils/utilities';
|
||||
|
||||
import { channelRLC, teamRLC } from '../../descriptions';
|
||||
import { microsoftApiRequest } from '../../transport';
|
||||
|
||||
const properties: INodeProperties[] = [teamRLC, channelRLC];
|
||||
|
||||
const displayOptions = {
|
||||
show: {
|
||||
resource: ['channel'],
|
||||
operation: ['deleteChannel'],
|
||||
},
|
||||
};
|
||||
|
||||
export const description = updateDisplayOptions(displayOptions, properties);
|
||||
|
||||
export async function execute(this: IExecuteFunctions, i: number) {
|
||||
//https://docs.microsoft.com/en-us/graph/api/channel-delete?view=graph-rest-beta&tabs=http
|
||||
|
||||
try {
|
||||
const teamId = this.getNodeParameter('teamId', i, '', { extractValue: true }) as string;
|
||||
const channelId = this.getNodeParameter('channelId', i, '', { extractValue: true }) as string;
|
||||
|
||||
await microsoftApiRequest.call(this, 'DELETE', `/v1.0/teams/${teamId}/channels/${channelId}`);
|
||||
return { success: true };
|
||||
} catch (error) {
|
||||
throw new NodeOperationError(
|
||||
this.getNode(),
|
||||
"The channel you are trying to delete doesn't exist",
|
||||
{
|
||||
description: "Check that the 'Channel' parameter is correctly set",
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
import { type INodeProperties, type IExecuteFunctions, NodeOperationError } from 'n8n-workflow';
|
||||
|
||||
import { updateDisplayOptions } from '@utils/utilities';
|
||||
|
||||
import { channelRLC, teamRLC } from '../../descriptions';
|
||||
import { microsoftApiRequest } from '../../transport';
|
||||
|
||||
const properties: INodeProperties[] = [teamRLC, channelRLC];
|
||||
|
||||
const displayOptions = {
|
||||
show: {
|
||||
resource: ['channel'],
|
||||
operation: ['get'],
|
||||
},
|
||||
};
|
||||
|
||||
export const description = updateDisplayOptions(displayOptions, properties);
|
||||
|
||||
export async function execute(this: IExecuteFunctions, i: number) {
|
||||
//https://docs.microsoft.com/en-us/graph/api/channel-get?view=graph-rest-beta&tabs=http
|
||||
|
||||
try {
|
||||
const teamId = this.getNodeParameter('teamId', i, '', { extractValue: true }) as string;
|
||||
const channelId = this.getNodeParameter('channelId', i, '', { extractValue: true }) as string;
|
||||
|
||||
return await microsoftApiRequest.call(
|
||||
this,
|
||||
'GET',
|
||||
`/v1.0/teams/${teamId}/channels/${channelId}`,
|
||||
);
|
||||
} catch (error) {
|
||||
throw new NodeOperationError(
|
||||
this.getNode(),
|
||||
"The channel you are trying to get doesn't exist",
|
||||
{
|
||||
description: "Check that the 'Channel' parameter is correctly set",
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
import type { INodeProperties, IExecuteFunctions } from 'n8n-workflow';
|
||||
|
||||
import { returnAllOrLimit } from '@utils/descriptions';
|
||||
import { updateDisplayOptions } from '@utils/utilities';
|
||||
|
||||
import { teamRLC } from '../../descriptions';
|
||||
import { microsoftApiRequestAllItems } from '../../transport';
|
||||
|
||||
const properties: INodeProperties[] = [teamRLC, ...returnAllOrLimit];
|
||||
|
||||
const displayOptions = {
|
||||
show: {
|
||||
resource: ['channel'],
|
||||
operation: ['getAll'],
|
||||
},
|
||||
};
|
||||
|
||||
export const description = updateDisplayOptions(displayOptions, properties);
|
||||
|
||||
export async function execute(this: IExecuteFunctions, i: number) {
|
||||
//https://docs.microsoft.com/en-us/graph/api/channel-list?view=graph-rest-beta&tabs=http
|
||||
|
||||
const teamId = this.getNodeParameter('teamId', i, '', { extractValue: true }) as string;
|
||||
const returnAll = this.getNodeParameter('returnAll', i);
|
||||
if (returnAll) {
|
||||
return await microsoftApiRequestAllItems.call(
|
||||
this,
|
||||
'value',
|
||||
'GET',
|
||||
`/v1.0/teams/${teamId}/channels`,
|
||||
);
|
||||
} else {
|
||||
const limit = this.getNodeParameter('limit', i);
|
||||
const responseData = await microsoftApiRequestAllItems.call(
|
||||
this,
|
||||
'value',
|
||||
'GET',
|
||||
`/v1.0/teams/${teamId}/channels`,
|
||||
{},
|
||||
);
|
||||
return responseData.splice(0, limit);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
import type { INodeProperties } from 'n8n-workflow';
|
||||
|
||||
import * as create from './create.operation';
|
||||
import * as deleteChannel from './deleteChannel.operation';
|
||||
import * as get from './get.operation';
|
||||
import * as getAll from './getAll.operation';
|
||||
import * as update from './update.operation';
|
||||
|
||||
export { create, deleteChannel, get, getAll, update };
|
||||
|
||||
export const description: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Operation',
|
||||
name: 'operation',
|
||||
type: 'options',
|
||||
noDataExpression: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['channel'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: 'Create',
|
||||
value: 'create',
|
||||
description: 'Create a channel',
|
||||
action: 'Create channel',
|
||||
},
|
||||
{
|
||||
name: 'Delete',
|
||||
value: 'deleteChannel',
|
||||
description: 'Delete a channel',
|
||||
action: 'Delete channel',
|
||||
},
|
||||
{
|
||||
name: 'Get',
|
||||
value: 'get',
|
||||
description: 'Get a channel',
|
||||
action: 'Get channel',
|
||||
},
|
||||
{
|
||||
name: 'Get Many',
|
||||
value: 'getAll',
|
||||
description: 'Get many channels',
|
||||
action: 'Get many channels',
|
||||
},
|
||||
{
|
||||
name: 'Update',
|
||||
value: 'update',
|
||||
description: 'Update a channel',
|
||||
action: 'Update channel',
|
||||
},
|
||||
],
|
||||
default: 'create',
|
||||
},
|
||||
|
||||
...create.description,
|
||||
...deleteChannel.description,
|
||||
...get.description,
|
||||
...getAll.description,
|
||||
...update.description,
|
||||
];
|
||||
@@ -0,0 +1,71 @@
|
||||
import type { INodeProperties, IExecuteFunctions, IDataObject } from 'n8n-workflow';
|
||||
|
||||
import { updateDisplayOptions } from '@utils/utilities';
|
||||
|
||||
import { channelRLC, teamRLC } from '../../descriptions';
|
||||
import { microsoftApiRequest } from '../../transport';
|
||||
|
||||
const properties: INodeProperties[] = [
|
||||
teamRLC,
|
||||
channelRLC,
|
||||
{
|
||||
displayName: 'Name',
|
||||
name: 'name',
|
||||
type: 'string',
|
||||
default: '',
|
||||
placeholder: 'e.g. My New Channel name',
|
||||
description: 'The name of the channel',
|
||||
},
|
||||
{
|
||||
displayName: 'Options',
|
||||
name: 'options',
|
||||
type: 'collection',
|
||||
default: {},
|
||||
placeholder: 'Add option',
|
||||
options: [
|
||||
{
|
||||
displayName: 'Description',
|
||||
name: 'description',
|
||||
type: 'string',
|
||||
default: '',
|
||||
description: 'The description of the channel',
|
||||
typeOptions: {
|
||||
rows: 2,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
const displayOptions = {
|
||||
show: {
|
||||
resource: ['channel'],
|
||||
operation: ['update'],
|
||||
},
|
||||
};
|
||||
|
||||
export const description = updateDisplayOptions(displayOptions, properties);
|
||||
|
||||
export async function execute(this: IExecuteFunctions, i: number) {
|
||||
//https://docs.microsoft.com/en-us/graph/api/channel-patch?view=graph-rest-beta&tabs=http
|
||||
|
||||
const teamId = this.getNodeParameter('teamId', i, '', { extractValue: true }) as string;
|
||||
const channelId = this.getNodeParameter('channelId', i, '', { extractValue: true }) as string;
|
||||
const newName = this.getNodeParameter('name', i) as string;
|
||||
const newDescription = this.getNodeParameter('options.description', i, '') as string;
|
||||
|
||||
const body: IDataObject = {};
|
||||
if (newName) {
|
||||
body.displayName = newName;
|
||||
}
|
||||
if (newDescription) {
|
||||
body.description = newDescription;
|
||||
}
|
||||
await microsoftApiRequest.call(
|
||||
this,
|
||||
'PATCH',
|
||||
`/v1.0/teams/${teamId}/channels/${channelId}`,
|
||||
body,
|
||||
);
|
||||
return { success: true };
|
||||
}
|
||||
+122
@@ -0,0 +1,122 @@
|
||||
import type { INodeProperties, IExecuteFunctions, IDataObject } from 'n8n-workflow';
|
||||
|
||||
import { updateDisplayOptions } from '@utils/utilities';
|
||||
|
||||
import { channelRLC, teamRLC } from '../../descriptions';
|
||||
import { prepareMessage } from '../../helpers/utils';
|
||||
import { microsoftApiRequest } from '../../transport';
|
||||
|
||||
const properties: INodeProperties[] = [
|
||||
teamRLC,
|
||||
channelRLC,
|
||||
{
|
||||
displayName: 'Content Type',
|
||||
name: 'contentType',
|
||||
required: true,
|
||||
type: 'options',
|
||||
options: [
|
||||
{
|
||||
name: 'Text',
|
||||
value: 'text',
|
||||
},
|
||||
{
|
||||
name: 'HTML',
|
||||
value: 'html',
|
||||
},
|
||||
],
|
||||
default: 'text',
|
||||
description: 'Whether the message is plain text or HTML',
|
||||
},
|
||||
{
|
||||
displayName: 'Message',
|
||||
name: 'message',
|
||||
required: true,
|
||||
type: 'string',
|
||||
default: '',
|
||||
description: 'The content of the message to be sent',
|
||||
typeOptions: {
|
||||
rows: 2,
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Options',
|
||||
name: 'options',
|
||||
type: 'collection',
|
||||
placeholder: 'Add option',
|
||||
default: {},
|
||||
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: 'Reply to ID',
|
||||
name: 'makeReply',
|
||||
type: 'string',
|
||||
default: '',
|
||||
placeholder: 'e.g. 1673348720590',
|
||||
description:
|
||||
'An optional ID of the message you want to reply to. The message ID is the number before "?tenantId" in the message URL.',
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
const displayOptions = {
|
||||
show: {
|
||||
resource: ['channelMessage'],
|
||||
operation: ['create'],
|
||||
},
|
||||
};
|
||||
|
||||
export const description = updateDisplayOptions(displayOptions, properties);
|
||||
|
||||
export async function execute(
|
||||
this: IExecuteFunctions,
|
||||
i: number,
|
||||
nodeVersion: number,
|
||||
instanceId: string,
|
||||
) {
|
||||
//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
|
||||
|
||||
const teamId = this.getNodeParameter('teamId', i, '', { extractValue: true }) as string;
|
||||
const channelId = this.getNodeParameter('channelId', i, '', { extractValue: true }) as string;
|
||||
const contentType = this.getNodeParameter('contentType', 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,
|
||||
contentType,
|
||||
includeLinkToWorkflow as boolean,
|
||||
instanceId,
|
||||
);
|
||||
|
||||
if (options.makeReply) {
|
||||
const replyToId = options.makeReply as string;
|
||||
return await microsoftApiRequest.call(
|
||||
this,
|
||||
'POST',
|
||||
`/beta/teams/${teamId}/channels/${channelId}/messages/${replyToId}/replies`,
|
||||
body,
|
||||
);
|
||||
} else {
|
||||
return await microsoftApiRequest.call(
|
||||
this,
|
||||
'POST',
|
||||
`/beta/teams/${teamId}/channels/${channelId}/messages`,
|
||||
body,
|
||||
);
|
||||
}
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
import type { INodeProperties, IExecuteFunctions } from 'n8n-workflow';
|
||||
|
||||
import { returnAllOrLimit } from '@utils/descriptions';
|
||||
import { updateDisplayOptions } from '@utils/utilities';
|
||||
|
||||
import { channelRLC, teamRLC } from '../../descriptions';
|
||||
import { microsoftApiRequestAllItems } from '../../transport';
|
||||
|
||||
const properties: INodeProperties[] = [teamRLC, channelRLC, ...returnAllOrLimit];
|
||||
|
||||
const displayOptions = {
|
||||
show: {
|
||||
resource: ['channelMessage'],
|
||||
operation: ['getAll'],
|
||||
},
|
||||
};
|
||||
|
||||
export const description = updateDisplayOptions(displayOptions, properties);
|
||||
|
||||
export async function execute(this: IExecuteFunctions, i: number) {
|
||||
//https://docs.microsoft.com/en-us/graph/api/channel-list-messages?view=graph-rest-beta&tabs=http
|
||||
|
||||
const teamId = this.getNodeParameter('teamId', i, '', { extractValue: true }) as string;
|
||||
const channelId = this.getNodeParameter('channelId', i, '', { extractValue: true }) as string;
|
||||
const returnAll = this.getNodeParameter('returnAll', i);
|
||||
|
||||
if (returnAll) {
|
||||
return await microsoftApiRequestAllItems.call(
|
||||
this,
|
||||
'value',
|
||||
'GET',
|
||||
`/beta/teams/${teamId}/channels/${channelId}/messages`,
|
||||
);
|
||||
} else {
|
||||
const limit = this.getNodeParameter('limit', i);
|
||||
const responseData = await microsoftApiRequestAllItems.call(
|
||||
this,
|
||||
'value',
|
||||
'GET',
|
||||
`/beta/teams/${teamId}/channels/${channelId}/messages`,
|
||||
{},
|
||||
);
|
||||
return responseData.splice(0, limit);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
import type { INodeProperties } from 'n8n-workflow';
|
||||
|
||||
import * as create from './create.operation';
|
||||
import * as getAll from './getAll.operation';
|
||||
|
||||
export { create, getAll };
|
||||
|
||||
export const description: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Operation',
|
||||
name: 'operation',
|
||||
type: 'options',
|
||||
noDataExpression: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['channelMessage'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: 'Create',
|
||||
value: 'create',
|
||||
description: 'Create a message in a channel',
|
||||
action: 'Create message',
|
||||
},
|
||||
{
|
||||
name: 'Get Many',
|
||||
value: 'getAll',
|
||||
description: 'Get many messages from a channel',
|
||||
action: 'Get many messages',
|
||||
},
|
||||
],
|
||||
default: 'create',
|
||||
},
|
||||
|
||||
...create.description,
|
||||
...getAll.description,
|
||||
];
|
||||
@@ -0,0 +1,88 @@
|
||||
import type { INodeProperties, IExecuteFunctions, IDataObject } from 'n8n-workflow';
|
||||
|
||||
import { updateDisplayOptions } from '@utils/utilities';
|
||||
|
||||
import { chatRLC } from '../../descriptions';
|
||||
import { prepareMessage } from '../../helpers/utils';
|
||||
import { microsoftApiRequest } from '../../transport';
|
||||
|
||||
const properties: INodeProperties[] = [
|
||||
chatRLC,
|
||||
{
|
||||
displayName: 'Content Type',
|
||||
name: 'contentType',
|
||||
required: true,
|
||||
type: 'options',
|
||||
options: [
|
||||
{
|
||||
name: 'Text',
|
||||
value: 'text',
|
||||
},
|
||||
{
|
||||
name: 'HTML',
|
||||
value: 'html',
|
||||
},
|
||||
],
|
||||
default: 'text',
|
||||
description: 'Whether the message is plain text or HTML',
|
||||
},
|
||||
{
|
||||
displayName: 'Message',
|
||||
name: 'message',
|
||||
required: true,
|
||||
type: 'string',
|
||||
default: '',
|
||||
description: 'The content of the message to be sent',
|
||||
typeOptions: {
|
||||
rows: 2,
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Options',
|
||||
name: 'options',
|
||||
type: 'collection',
|
||||
default: {},
|
||||
description: 'Other options to set',
|
||||
placeholder: 'Add option',
|
||||
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.',
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
const displayOptions = {
|
||||
show: {
|
||||
resource: ['chatMessage'],
|
||||
operation: ['create'],
|
||||
},
|
||||
};
|
||||
|
||||
export const description = updateDisplayOptions(displayOptions, properties);
|
||||
|
||||
export async function execute(this: IExecuteFunctions, i: number, instanceId: string) {
|
||||
// https://docs.microsoft.com/en-us/graph/api/channel-post-messages?view=graph-rest-1.0&tabs=http
|
||||
|
||||
const chatId = this.getNodeParameter('chatId', i, '', { extractValue: true }) as string;
|
||||
const contentType = this.getNodeParameter('contentType', i) as string;
|
||||
const message = this.getNodeParameter('message', i) as string;
|
||||
const options = this.getNodeParameter('options', i, {});
|
||||
|
||||
const includeLinkToWorkflow = options.includeLinkToWorkflow !== false;
|
||||
|
||||
const body: IDataObject = prepareMessage.call(
|
||||
this,
|
||||
message,
|
||||
contentType,
|
||||
includeLinkToWorkflow,
|
||||
instanceId,
|
||||
);
|
||||
|
||||
return await microsoftApiRequest.call(this, 'POST', `/v1.0/chats/${chatId}/messages`, body);
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
import { type INodeProperties, type IExecuteFunctions, NodeOperationError } from 'n8n-workflow';
|
||||
|
||||
import { updateDisplayOptions } from '@utils/utilities';
|
||||
|
||||
import { chatRLC } from '../../descriptions';
|
||||
import { microsoftApiRequest } from '../../transport';
|
||||
|
||||
const properties: INodeProperties[] = [
|
||||
chatRLC,
|
||||
{
|
||||
displayName: 'Message ID',
|
||||
name: 'messageId',
|
||||
required: true,
|
||||
type: 'string',
|
||||
default: '',
|
||||
placeholder: 'e.g. 1673355049064',
|
||||
description: 'The ID of the message to retrieve',
|
||||
},
|
||||
];
|
||||
|
||||
const displayOptions = {
|
||||
show: {
|
||||
resource: ['chatMessage'],
|
||||
operation: ['get'],
|
||||
},
|
||||
};
|
||||
|
||||
export const description = updateDisplayOptions(displayOptions, properties);
|
||||
|
||||
export async function execute(this: IExecuteFunctions, i: number) {
|
||||
// https://docs.microsoft.com/en-us/graph/api/chat-list-messages?view=graph-rest-1.0&tabs=http
|
||||
|
||||
try {
|
||||
const chatId = this.getNodeParameter('chatId', i, '', { extractValue: true }) as string;
|
||||
const messageId = this.getNodeParameter('messageId', i) as string;
|
||||
|
||||
return await microsoftApiRequest.call(
|
||||
this,
|
||||
'GET',
|
||||
`/v1.0/chats/${chatId}/messages/${messageId}`,
|
||||
);
|
||||
} catch (error) {
|
||||
throw new NodeOperationError(
|
||||
this.getNode(),
|
||||
"The message you are trying to get doesn't exist",
|
||||
{
|
||||
description: "Check that the 'Message ID' parameter is correctly set",
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
import type { INodeProperties, IExecuteFunctions } from 'n8n-workflow';
|
||||
|
||||
import { returnAllOrLimit } from '@utils/descriptions';
|
||||
import { updateDisplayOptions } from '@utils/utilities';
|
||||
|
||||
import { chatRLC } from '../../descriptions';
|
||||
import { microsoftApiRequestAllItems } from '../../transport';
|
||||
|
||||
const properties: INodeProperties[] = [chatRLC, ...returnAllOrLimit];
|
||||
|
||||
const displayOptions = {
|
||||
show: {
|
||||
resource: ['chatMessage'],
|
||||
operation: ['getAll'],
|
||||
},
|
||||
};
|
||||
|
||||
export const description = updateDisplayOptions(displayOptions, properties);
|
||||
|
||||
export async function execute(this: IExecuteFunctions, i: number) {
|
||||
// https://docs.microsoft.com/en-us/graph/api/chat-list-messages?view=graph-rest-1.0&tabs=http
|
||||
|
||||
const chatId = this.getNodeParameter('chatId', i, '', { extractValue: true }) as string;
|
||||
const returnAll = this.getNodeParameter('returnAll', i);
|
||||
|
||||
if (returnAll) {
|
||||
return await microsoftApiRequestAllItems.call(
|
||||
this,
|
||||
'value',
|
||||
'GET',
|
||||
`/v1.0/chats/${chatId}/messages`,
|
||||
);
|
||||
} else {
|
||||
const limit = this.getNodeParameter('limit', i);
|
||||
const responseData = await microsoftApiRequestAllItems.call(
|
||||
this,
|
||||
'value',
|
||||
'GET',
|
||||
`/v1.0/chats/${chatId}/messages`,
|
||||
{},
|
||||
);
|
||||
return responseData.splice(0, limit);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
import { SEND_AND_WAIT_OPERATION, type INodeProperties } from 'n8n-workflow';
|
||||
|
||||
import * as create from './create.operation';
|
||||
import * as get from './get.operation';
|
||||
import * as getAll from './getAll.operation';
|
||||
import * as sendAndWait from './sendAndWait.operation';
|
||||
|
||||
export { create, get, getAll, sendAndWait };
|
||||
|
||||
export const description: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Operation',
|
||||
name: 'operation',
|
||||
type: 'options',
|
||||
noDataExpression: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['chatMessage'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: 'Create',
|
||||
value: 'create',
|
||||
description: 'Create a message in a chat',
|
||||
action: 'Create chat message',
|
||||
},
|
||||
{
|
||||
name: 'Get',
|
||||
value: 'get',
|
||||
description: 'Get a message from a chat',
|
||||
action: 'Get chat message',
|
||||
},
|
||||
{
|
||||
name: 'Get Many',
|
||||
value: 'getAll',
|
||||
description: 'Get many messages from a chat',
|
||||
action: 'Get many chat messages',
|
||||
},
|
||||
{
|
||||
name: 'Send and Wait for Response',
|
||||
value: SEND_AND_WAIT_OPERATION,
|
||||
description: 'Send a message and wait for response',
|
||||
action: 'Send message and wait for response',
|
||||
},
|
||||
],
|
||||
default: 'create',
|
||||
},
|
||||
|
||||
...create.description,
|
||||
...get.description,
|
||||
...getAll.description,
|
||||
...sendAndWait.description,
|
||||
];
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
import type { INodeProperties, IExecuteFunctions } from 'n8n-workflow';
|
||||
|
||||
import {
|
||||
getSendAndWaitConfig,
|
||||
getSendAndWaitProperties,
|
||||
} from '../../../../../../utils/sendAndWait/utils';
|
||||
import { createUtmCampaignLink } from '../../../../../../utils/utilities';
|
||||
import { chatRLC } from '../../descriptions';
|
||||
import { microsoftApiRequest } from '../../transport';
|
||||
|
||||
export const description: INodeProperties[] = getSendAndWaitProperties(
|
||||
[chatRLC],
|
||||
'chatMessage',
|
||||
undefined,
|
||||
{
|
||||
noButtonStyle: true,
|
||||
defaultApproveLabel: '✓ Approve',
|
||||
defaultDisapproveLabel: '✗ Decline',
|
||||
},
|
||||
).filter((p) => p.name !== 'subject');
|
||||
|
||||
export async function execute(this: IExecuteFunctions, i: number, instanceId: string) {
|
||||
const chatId = this.getNodeParameter('chatId', i, '', { extractValue: true }) as string;
|
||||
const config = getSendAndWaitConfig(this);
|
||||
|
||||
const buttons = config.options.map((option) => `<a href="${option.url}">${option.label}</a>`);
|
||||
|
||||
let content = `${config.message}<br><br>${buttons.join(' ')}`;
|
||||
|
||||
if (config.appendAttribution !== false) {
|
||||
const attributionText = 'This message was sent automatically with';
|
||||
const link = createUtmCampaignLink('n8n-nodes-base.microsoftTeams', instanceId);
|
||||
const attribution = `<em>${attributionText} <a href="${link}">n8n</a></em>`;
|
||||
content += `<br><br>${attribution}`;
|
||||
}
|
||||
|
||||
const body = {
|
||||
body: {
|
||||
contentType: 'html',
|
||||
content,
|
||||
},
|
||||
};
|
||||
|
||||
return await microsoftApiRequest.call(this, 'POST', `/v1.0/chats/${chatId}/messages`, body);
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import type { AllEntities } from 'n8n-workflow';
|
||||
|
||||
type NodeMap = {
|
||||
channel: 'create' | 'deleteChannel' | 'get' | 'getAll' | 'update';
|
||||
channelMessage: 'create' | 'getAll';
|
||||
chatMessage: 'create' | 'get' | 'getAll' | 'sendAndWait';
|
||||
task: 'create' | 'deleteTask' | 'get' | 'getAll' | 'update';
|
||||
};
|
||||
|
||||
export type MicrosoftTeamsType = AllEntities<NodeMap>;
|
||||
@@ -0,0 +1,94 @@
|
||||
import {
|
||||
type IExecuteFunctions,
|
||||
type IDataObject,
|
||||
type INodeExecutionData,
|
||||
NodeOperationError,
|
||||
SEND_AND_WAIT_OPERATION,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import * as channel from './channel';
|
||||
import * as channelMessage from './channelMessage';
|
||||
import * as chatMessage from './chatMessage';
|
||||
import type { MicrosoftTeamsType } from './node.type';
|
||||
import * as task from './task';
|
||||
import { configureWaitTillDate } from '../../../../../utils/sendAndWait/configureWaitTillDate.util';
|
||||
|
||||
export async function router(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
||||
const items = this.getInputData();
|
||||
const returnData: INodeExecutionData[] = [];
|
||||
let responseData;
|
||||
|
||||
const resource = this.getNodeParameter<MicrosoftTeamsType>('resource', 0);
|
||||
const operation = this.getNodeParameter('operation', 0);
|
||||
|
||||
const nodeVersion = this.getNode().typeVersion;
|
||||
const instanceId = this.getInstanceId();
|
||||
|
||||
const microsoftTeamsTypeData = {
|
||||
resource,
|
||||
operation,
|
||||
} as MicrosoftTeamsType;
|
||||
|
||||
if (
|
||||
microsoftTeamsTypeData.resource === 'chatMessage' &&
|
||||
microsoftTeamsTypeData.operation === SEND_AND_WAIT_OPERATION
|
||||
) {
|
||||
await chatMessage[microsoftTeamsTypeData.operation].execute.call(this, 0, instanceId);
|
||||
|
||||
const waitTill = configureWaitTillDate(this);
|
||||
|
||||
await this.putExecutionToWait(waitTill);
|
||||
return [items];
|
||||
}
|
||||
|
||||
for (let i = 0; i < items.length; i++) {
|
||||
try {
|
||||
switch (microsoftTeamsTypeData.resource) {
|
||||
case 'channel':
|
||||
responseData = await channel[microsoftTeamsTypeData.operation].execute.call(this, i);
|
||||
break;
|
||||
case 'channelMessage':
|
||||
responseData = await channelMessage[microsoftTeamsTypeData.operation].execute.call(
|
||||
this,
|
||||
i,
|
||||
nodeVersion,
|
||||
instanceId,
|
||||
);
|
||||
break;
|
||||
case 'chatMessage':
|
||||
responseData = await chatMessage[microsoftTeamsTypeData.operation].execute.call(
|
||||
this,
|
||||
i,
|
||||
instanceId,
|
||||
);
|
||||
break;
|
||||
case 'task':
|
||||
responseData = await task[microsoftTeamsTypeData.operation].execute.call(this, i);
|
||||
break;
|
||||
default:
|
||||
throw new NodeOperationError(
|
||||
this.getNode(),
|
||||
`The operation "${operation}" is not supported!`,
|
||||
);
|
||||
}
|
||||
|
||||
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];
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
import { DateTime } from 'luxon';
|
||||
import type { INodeProperties, IExecuteFunctions, IDataObject } from 'n8n-workflow';
|
||||
|
||||
import { updateDisplayOptions } from '@utils/utilities';
|
||||
|
||||
import { bucketRLC, groupRLC, memberRLC, planRLC } from '../../descriptions';
|
||||
import { microsoftApiRequest } from '../../transport';
|
||||
|
||||
const properties: INodeProperties[] = [
|
||||
groupRLC,
|
||||
planRLC,
|
||||
bucketRLC,
|
||||
{
|
||||
displayName: 'Title',
|
||||
name: 'title',
|
||||
required: true,
|
||||
type: 'string',
|
||||
default: '',
|
||||
placeholder: 'e.g. new task',
|
||||
description: 'Title of the task',
|
||||
},
|
||||
{
|
||||
displayName: 'Options',
|
||||
name: 'options',
|
||||
type: 'collection',
|
||||
default: {},
|
||||
placeholder: 'Add option',
|
||||
options: [
|
||||
{
|
||||
...memberRLC,
|
||||
displayName: 'Assigned To',
|
||||
name: 'assignedTo',
|
||||
description: 'Who the task should be assigned to',
|
||||
typeOptions: {
|
||||
loadOptionsDependsOn: ['groupId.balue'],
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Due Date Time',
|
||||
name: 'dueDateTime',
|
||||
type: 'string',
|
||||
validateType: 'dateTime',
|
||||
default: '',
|
||||
description:
|
||||
'Date and time at which the task is due. The Timestamp type represents date and time information using ISO 8601 format and is always in UTC time.',
|
||||
},
|
||||
{
|
||||
displayName: 'Percent Complete',
|
||||
name: 'percentComplete',
|
||||
type: 'number',
|
||||
typeOptions: {
|
||||
minValue: 0,
|
||||
maxValue: 100,
|
||||
},
|
||||
default: 0,
|
||||
placeholder: 'e.g. 75',
|
||||
description:
|
||||
'Percentage of task completion. When set to 100, the task is considered completed.',
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
const displayOptions = {
|
||||
show: {
|
||||
resource: ['task'],
|
||||
operation: ['create'],
|
||||
},
|
||||
};
|
||||
|
||||
export const description = updateDisplayOptions(displayOptions, properties);
|
||||
|
||||
export async function execute(this: IExecuteFunctions, i: number) {
|
||||
//https://docs.microsoft.com/en-us/graph/api/planner-post-tasks?view=graph-rest-1.0&tabs=http
|
||||
|
||||
const planId = this.getNodeParameter('planId', i, '', { extractValue: true }) as string;
|
||||
const bucketId = this.getNodeParameter('bucketId', i, '', { extractValue: true }) as string;
|
||||
|
||||
const title = this.getNodeParameter('title', i) as string;
|
||||
const options = this.getNodeParameter('options', i);
|
||||
|
||||
const body: IDataObject = {
|
||||
planId,
|
||||
bucketId,
|
||||
title,
|
||||
};
|
||||
|
||||
if (options.assignedTo) {
|
||||
options.assignedTo = this.getNodeParameter('options.assignedTo', i, '', {
|
||||
extractValue: true,
|
||||
}) as string;
|
||||
}
|
||||
|
||||
if (options.dueDateTime && options.dueDateTime instanceof DateTime) {
|
||||
options.dueDateTime = options.dueDateTime.toISO();
|
||||
}
|
||||
|
||||
Object.assign(body, options);
|
||||
|
||||
if (body.assignedTo) {
|
||||
body.assignments = {
|
||||
[body.assignedTo as string]: {
|
||||
'@odata.type': 'microsoft.graph.plannerAssignment',
|
||||
orderHint: ' !',
|
||||
},
|
||||
};
|
||||
delete body.assignedTo;
|
||||
}
|
||||
|
||||
return await microsoftApiRequest.call(this, 'POST', '/v1.0/planner/tasks', body);
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
import type { INodeProperties, IExecuteFunctions } from 'n8n-workflow';
|
||||
|
||||
import { updateDisplayOptions } from '@utils/utilities';
|
||||
|
||||
import { microsoftApiRequest } from '../../transport';
|
||||
|
||||
const properties: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Task ID',
|
||||
name: 'taskId',
|
||||
required: true,
|
||||
type: 'string',
|
||||
placeholder: 'e.g. h3ufgLvXPkSRzYm-zO5cY5gANtBQ',
|
||||
description: 'The ID of the task to delete',
|
||||
default: '',
|
||||
},
|
||||
];
|
||||
|
||||
const displayOptions = {
|
||||
show: {
|
||||
resource: ['task'],
|
||||
operation: ['deleteTask'],
|
||||
},
|
||||
};
|
||||
|
||||
export const description = updateDisplayOptions(displayOptions, properties);
|
||||
|
||||
export async function execute(this: IExecuteFunctions, i: number) {
|
||||
//https://docs.microsoft.com/en-us/graph/api/plannertask-delete?view=graph-rest-1.0&tabs=http
|
||||
|
||||
const taskId = this.getNodeParameter('taskId', i) as string;
|
||||
const task = await microsoftApiRequest.call(this, 'GET', `/v1.0/planner/tasks/${taskId}`);
|
||||
await microsoftApiRequest.call(
|
||||
this,
|
||||
'DELETE',
|
||||
`/v1.0/planner/tasks/${taskId}`,
|
||||
{},
|
||||
{},
|
||||
undefined,
|
||||
{ 'If-Match': task['@odata.etag'] },
|
||||
);
|
||||
return { success: true };
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
import type { INodeProperties, IExecuteFunctions } from 'n8n-workflow';
|
||||
|
||||
import { updateDisplayOptions } from '@utils/utilities';
|
||||
|
||||
import { microsoftApiRequest } from '../../transport';
|
||||
|
||||
const properties: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Task ID',
|
||||
name: 'taskId',
|
||||
required: true,
|
||||
type: 'string',
|
||||
description: 'The ID of the task to retrieve',
|
||||
placeholder: 'e.g. h3ufgLvXPkSRzYm-zO5cY5gANtBQ',
|
||||
default: '',
|
||||
},
|
||||
];
|
||||
|
||||
const displayOptions = {
|
||||
show: {
|
||||
resource: ['task'],
|
||||
operation: ['get'],
|
||||
},
|
||||
};
|
||||
|
||||
export const description = updateDisplayOptions(displayOptions, properties);
|
||||
|
||||
export async function execute(this: IExecuteFunctions, i: number) {
|
||||
//https://docs.microsoft.com/en-us/graph/api/plannertask-get?view=graph-rest-1.0&tabs=http
|
||||
|
||||
const taskId = this.getNodeParameter('taskId', i) as string;
|
||||
return await microsoftApiRequest.call(this, 'GET', `/v1.0/planner/tasks/${taskId}`);
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
import type { INodeProperties, IExecuteFunctions } from 'n8n-workflow';
|
||||
|
||||
import { returnAllOrLimit } from '@utils/descriptions';
|
||||
import { updateDisplayOptions } from '@utils/utilities';
|
||||
|
||||
import { groupRLC, planRLC } from '../../descriptions';
|
||||
import { microsoftApiRequest, microsoftApiRequestAllItems } from '../../transport';
|
||||
|
||||
const properties: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Tasks For',
|
||||
name: 'tasksFor',
|
||||
default: 'member',
|
||||
required: true,
|
||||
type: 'options',
|
||||
description: 'Whether to retrieve the tasks for a user or for a plan',
|
||||
options: [
|
||||
{
|
||||
name: 'Group Member',
|
||||
value: 'member',
|
||||
description: 'Tasks assigned to group member',
|
||||
},
|
||||
{
|
||||
name: 'Plan',
|
||||
value: 'plan',
|
||||
description: 'Tasks in group plan',
|
||||
},
|
||||
],
|
||||
},
|
||||
groupRLC,
|
||||
{
|
||||
...planRLC,
|
||||
displayOptions: {
|
||||
show: {
|
||||
tasksFor: ['plan'],
|
||||
},
|
||||
},
|
||||
},
|
||||
...returnAllOrLimit,
|
||||
];
|
||||
|
||||
const displayOptions = {
|
||||
show: {
|
||||
resource: ['task'],
|
||||
operation: ['getAll'],
|
||||
},
|
||||
};
|
||||
|
||||
export const description = updateDisplayOptions(displayOptions, properties);
|
||||
|
||||
export async function execute(this: IExecuteFunctions, i: number) {
|
||||
const tasksFor = this.getNodeParameter('tasksFor', i) as string;
|
||||
const returnAll = this.getNodeParameter('returnAll', i);
|
||||
|
||||
if (tasksFor === 'member') {
|
||||
//https://docs.microsoft.com/en-us/graph/api/planneruser-list-tasks?view=graph-rest-1.0&tabs=http
|
||||
const memberId = ((await microsoftApiRequest.call(this, 'GET', '/v1.0/me')) as { id: string })
|
||||
.id;
|
||||
if (returnAll) {
|
||||
return await microsoftApiRequestAllItems.call(
|
||||
this,
|
||||
'value',
|
||||
'GET',
|
||||
`/v1.0/users/${memberId}/planner/tasks`,
|
||||
);
|
||||
} else {
|
||||
const limit = this.getNodeParameter('limit', i);
|
||||
const responseData = await microsoftApiRequestAllItems.call(
|
||||
this,
|
||||
'value',
|
||||
'GET',
|
||||
`/v1.0/users/${memberId}/planner/tasks`,
|
||||
{},
|
||||
);
|
||||
return responseData.splice(0, limit);
|
||||
}
|
||||
} else {
|
||||
//https://docs.microsoft.com/en-us/graph/api/plannerplan-list-tasks?view=graph-rest-1.0&tabs=http
|
||||
const planId = this.getNodeParameter('planId', i, '', { extractValue: true }) as string;
|
||||
if (returnAll) {
|
||||
return await microsoftApiRequestAllItems.call(
|
||||
this,
|
||||
'value',
|
||||
'GET',
|
||||
`/v1.0/planner/plans/${planId}/tasks`,
|
||||
);
|
||||
} else {
|
||||
const limit = this.getNodeParameter('limit', i);
|
||||
const responseData = await microsoftApiRequestAllItems.call(
|
||||
this,
|
||||
'value',
|
||||
'GET',
|
||||
`/v1.0/planner/plans/${planId}/tasks`,
|
||||
{},
|
||||
);
|
||||
return responseData.splice(0, limit);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
import type { INodeProperties } from 'n8n-workflow';
|
||||
|
||||
import * as create from './create.operation';
|
||||
import * as deleteTask from './deleteTask.operation';
|
||||
import * as get from './get.operation';
|
||||
import * as getAll from './getAll.operation';
|
||||
import * as update from './update.operation';
|
||||
|
||||
export { create, deleteTask, get, getAll, update };
|
||||
|
||||
export const description: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Operation',
|
||||
name: 'operation',
|
||||
type: 'options',
|
||||
noDataExpression: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['task'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: 'Create',
|
||||
value: 'create',
|
||||
description: 'Create a task',
|
||||
action: 'Create task',
|
||||
},
|
||||
{
|
||||
name: 'Delete',
|
||||
value: 'deleteTask',
|
||||
description: 'Delete a task',
|
||||
action: 'Delete task',
|
||||
},
|
||||
{
|
||||
name: 'Get',
|
||||
value: 'get',
|
||||
description: 'Get a task',
|
||||
action: 'Get task',
|
||||
},
|
||||
{
|
||||
name: 'Get Many',
|
||||
value: 'getAll',
|
||||
description: 'Get many tasks',
|
||||
action: 'Get many tasks',
|
||||
},
|
||||
{
|
||||
name: 'Update',
|
||||
value: 'update',
|
||||
description: 'Update a task',
|
||||
action: 'Update task',
|
||||
},
|
||||
],
|
||||
default: 'create',
|
||||
},
|
||||
|
||||
...create.description,
|
||||
...deleteTask.description,
|
||||
...get.description,
|
||||
...getAll.description,
|
||||
...update.description,
|
||||
];
|
||||
@@ -0,0 +1,157 @@
|
||||
import { DateTime } from 'luxon';
|
||||
import type { INodeProperties, IExecuteFunctions, IDataObject } from 'n8n-workflow';
|
||||
|
||||
import { updateDisplayOptions } from '@utils/utilities';
|
||||
|
||||
import { bucketRLC, groupRLC, memberRLC, planRLC } from '../../descriptions';
|
||||
import { microsoftApiRequest } from '../../transport';
|
||||
|
||||
const properties: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Task ID',
|
||||
name: 'taskId',
|
||||
required: true,
|
||||
type: 'string',
|
||||
default: '',
|
||||
placeholder: 'e.g. h3ufgLvXPkSRzYm-zO5cY5gANtBQ',
|
||||
description: 'The ID of the task to update',
|
||||
},
|
||||
{
|
||||
displayName: 'Update Fields',
|
||||
name: 'updateFields',
|
||||
type: 'collection',
|
||||
default: {},
|
||||
placeholder: 'Add Field',
|
||||
options: [
|
||||
{
|
||||
...memberRLC,
|
||||
displayName: 'Assigned To',
|
||||
name: 'assignedTo',
|
||||
description: 'Who the task should be assigned to',
|
||||
hint: "Select 'Team' from options first",
|
||||
required: false,
|
||||
typeOptions: {
|
||||
loadOptionsDependsOn: ['updateFields.groupId.value'],
|
||||
},
|
||||
},
|
||||
{
|
||||
...bucketRLC,
|
||||
required: false,
|
||||
typeOptions: {
|
||||
loadOptionsDependsOn: ['updateFields.planId.value'],
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Due Date Time',
|
||||
name: 'dueDateTime',
|
||||
type: 'string',
|
||||
validateType: 'dateTime',
|
||||
default: '',
|
||||
description:
|
||||
'Date and time at which the task is due. The Timestamp type represents date and time information using ISO 8601 format and is always in UTC time.',
|
||||
},
|
||||
{
|
||||
...groupRLC,
|
||||
required: false,
|
||||
typeOptions: {
|
||||
loadOptionsDependsOn: ['/groupSource'],
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Percent Complete',
|
||||
name: 'percentComplete',
|
||||
type: 'number',
|
||||
typeOptions: {
|
||||
minValue: 0,
|
||||
maxValue: 100,
|
||||
},
|
||||
default: 0,
|
||||
placeholder: 'e.g. 75',
|
||||
description:
|
||||
'Percentage of task completion. When set to 100, the task is considered completed.',
|
||||
},
|
||||
{
|
||||
...planRLC,
|
||||
required: false,
|
||||
hint: "Select 'Team' from options first",
|
||||
typeOptions: {
|
||||
loadOptionsDependsOn: ['updateFields.groupId.value'],
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Title',
|
||||
name: 'title',
|
||||
type: 'string',
|
||||
default: '',
|
||||
placeholder: 'e.g. my task',
|
||||
description: 'Title of the task',
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
const displayOptions = {
|
||||
show: {
|
||||
resource: ['task'],
|
||||
operation: ['update'],
|
||||
},
|
||||
};
|
||||
|
||||
export const description = updateDisplayOptions(displayOptions, properties);
|
||||
|
||||
export async function execute(this: IExecuteFunctions, i: number) {
|
||||
//https://docs.microsoft.com/en-us/graph/api/plannertask-update?view=graph-rest-1.0&tabs=http
|
||||
|
||||
const taskId = this.getNodeParameter('taskId', i, '', { extractValue: true }) as string;
|
||||
const updateFields = this.getNodeParameter('updateFields', i);
|
||||
|
||||
for (const key of Object.keys(updateFields)) {
|
||||
if (key === 'groupId') {
|
||||
// tasks are assigned to a plan and bucket, group is used for filtering
|
||||
delete updateFields.groupId;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (key === 'assignedTo') {
|
||||
const assignedTo = this.getNodeParameter('updateFields.assignedTo', i, '', {
|
||||
extractValue: true,
|
||||
}) as string;
|
||||
|
||||
updateFields.assignments = {
|
||||
[assignedTo]: {
|
||||
'@odata.type': 'microsoft.graph.plannerAssignment',
|
||||
orderHint: ' !',
|
||||
},
|
||||
};
|
||||
delete updateFields.assignedTo;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (['bucketId', 'planId'].includes(key)) {
|
||||
updateFields[key] = this.getNodeParameter(`updateFields.${key}`, i, '', {
|
||||
extractValue: true,
|
||||
}) as string;
|
||||
}
|
||||
|
||||
if (key === 'dueDateTime' && updateFields.dueDateTime instanceof DateTime) {
|
||||
updateFields.dueDateTime = updateFields.dueDateTime.toISO();
|
||||
}
|
||||
}
|
||||
|
||||
const body: IDataObject = {};
|
||||
Object.assign(body, updateFields);
|
||||
|
||||
const task = await microsoftApiRequest.call(this, 'GET', `/v1.0/planner/tasks/${taskId}`);
|
||||
|
||||
await microsoftApiRequest.call(
|
||||
this,
|
||||
'PATCH',
|
||||
`/v1.0/planner/tasks/${taskId}`,
|
||||
body,
|
||||
{},
|
||||
undefined,
|
||||
{ 'If-Match': task['@odata.etag'] },
|
||||
);
|
||||
|
||||
return { success: true };
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
/* eslint-disable n8n-nodes-base/node-filename-against-convention */
|
||||
import { NodeConnectionTypes, type INodeTypeDescription } from 'n8n-workflow';
|
||||
|
||||
import * as channel from './channel';
|
||||
import * as channelMessage from './channelMessage';
|
||||
import * as chatMessage from './chatMessage';
|
||||
import * as task from './task';
|
||||
import { sendAndWaitWebhooksDescription } from '../../../../../utils/sendAndWait/descriptions';
|
||||
import { SEND_AND_WAIT_WAITING_TOOLTIP } from '../../../../../utils/sendAndWait/utils';
|
||||
|
||||
export const versionDescription: INodeTypeDescription = {
|
||||
displayName: 'Microsoft Teams',
|
||||
name: 'microsoftTeams',
|
||||
icon: 'file:teams.svg',
|
||||
group: ['input'],
|
||||
version: 2,
|
||||
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
|
||||
description: 'Consume Microsoft Teams API',
|
||||
defaults: {
|
||||
name: 'Microsoft Teams',
|
||||
},
|
||||
inputs: [NodeConnectionTypes.Main],
|
||||
outputs: [NodeConnectionTypes.Main],
|
||||
credentials: [
|
||||
{
|
||||
name: 'microsoftTeamsOAuth2Api',
|
||||
required: true,
|
||||
},
|
||||
],
|
||||
waitingNodeTooltip: SEND_AND_WAIT_WAITING_TOOLTIP,
|
||||
webhooks: sendAndWaitWebhooksDescription,
|
||||
properties: [
|
||||
{
|
||||
displayName: 'Resource',
|
||||
name: 'resource',
|
||||
type: 'options',
|
||||
noDataExpression: true,
|
||||
options: [
|
||||
{
|
||||
name: 'Channel',
|
||||
value: 'channel',
|
||||
},
|
||||
{
|
||||
name: 'Channel Message',
|
||||
value: 'channelMessage',
|
||||
},
|
||||
{
|
||||
name: 'Chat Message',
|
||||
value: 'chatMessage',
|
||||
},
|
||||
{
|
||||
name: 'Task',
|
||||
value: 'task',
|
||||
},
|
||||
],
|
||||
default: 'channel',
|
||||
},
|
||||
|
||||
...channel.description,
|
||||
...channelMessage.description,
|
||||
...chatMessage.description,
|
||||
...task.description,
|
||||
],
|
||||
};
|
||||
@@ -0,0 +1,22 @@
|
||||
import type { INodeProperties } from 'n8n-workflow';
|
||||
|
||||
export const groupSourceOptions: INodeProperties = {
|
||||
displayName: 'Group Source',
|
||||
name: 'groupSource',
|
||||
required: true,
|
||||
type: 'options',
|
||||
default: 'all',
|
||||
description: 'From where to select groups and teams',
|
||||
options: [
|
||||
{
|
||||
name: 'All Groups',
|
||||
value: 'all',
|
||||
description: 'From all groups',
|
||||
},
|
||||
{
|
||||
name: 'My Groups',
|
||||
value: 'mine',
|
||||
description: 'Only load groups that account is member of',
|
||||
},
|
||||
],
|
||||
};
|
||||
@@ -0,0 +1,2 @@
|
||||
export * from './rlc.description';
|
||||
export * from './common.description';
|
||||
@@ -0,0 +1,269 @@
|
||||
import type { INodeProperties } from 'n8n-workflow';
|
||||
|
||||
export const teamRLC: INodeProperties = {
|
||||
displayName: 'Team',
|
||||
name: 'teamId',
|
||||
type: 'resourceLocator',
|
||||
default: { mode: 'list', value: '' },
|
||||
required: true,
|
||||
description:
|
||||
'Select the team from the list, by URL, or by ID (the ID is the "groupId" parameter in the URL you get from "Get a link to the team")',
|
||||
modes: [
|
||||
{
|
||||
displayName: 'From List',
|
||||
name: 'list',
|
||||
type: 'list',
|
||||
placeholder: 'e.g. My Team',
|
||||
typeOptions: {
|
||||
searchListMethod: 'getTeams',
|
||||
searchable: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'From URL',
|
||||
name: 'url',
|
||||
type: 'string',
|
||||
placeholder: 'e.g. https://teams.microsoft.com/l/team/19%3AP8l9gXd6oqlgq…',
|
||||
extractValue: {
|
||||
type: 'regex',
|
||||
regex: 'groupId=([a-f0-9-]+)\\&',
|
||||
},
|
||||
validation: [
|
||||
{
|
||||
type: 'regex',
|
||||
properties: {
|
||||
regex: 'https:\\/\\/teams.microsoft.com\\/.*groupId=[a-f0-9-]+\\&.*',
|
||||
errorMessage: 'Not a valid Microsoft Teams URL',
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
displayName: 'By ID',
|
||||
name: 'id',
|
||||
type: 'string',
|
||||
placeholder: 'e.g. 61165b04-e4cc-4026-b43f-926b4e2a7182',
|
||||
validation: [
|
||||
{
|
||||
type: 'regex',
|
||||
properties: {
|
||||
regex: '^([0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12})[ \t]*',
|
||||
errorMessage: 'Not a valid Microsoft Teams Team ID',
|
||||
},
|
||||
},
|
||||
],
|
||||
extractValue: {
|
||||
type: 'regex',
|
||||
regex: '^([0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12})',
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
export const channelRLC: INodeProperties = {
|
||||
displayName: 'Channel',
|
||||
name: 'channelId',
|
||||
type: 'resourceLocator',
|
||||
default: { mode: 'list', value: '' },
|
||||
required: true,
|
||||
description:
|
||||
'Select the channel from the list, by URL, or by ID (the ID is the "threadId" in the URL)',
|
||||
typeOptions: {
|
||||
loadOptionsDependsOn: ['teamId.value'],
|
||||
},
|
||||
modes: [
|
||||
{
|
||||
displayName: 'From List',
|
||||
name: 'list',
|
||||
type: 'list',
|
||||
placeholder: 'Select a Channel...',
|
||||
typeOptions: {
|
||||
searchListMethod: 'getChannels',
|
||||
searchable: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'By ID',
|
||||
name: 'id',
|
||||
type: 'string',
|
||||
placeholder: '19:-xlxyqXNSCxpI1SDzgQ_L9ZvzSR26pgphq1BJ9y7QJE1@thread.tacv2',
|
||||
// validation missing because no documentation found how these unique ids look like.
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
export const chatRLC: INodeProperties = {
|
||||
displayName: 'Chat',
|
||||
name: 'chatId',
|
||||
type: 'resourceLocator',
|
||||
default: { mode: 'list', value: '' },
|
||||
required: true,
|
||||
description:
|
||||
'Select the chat from the list, by URL, or by ID (find the chat ID after "conversations/" in the URL)',
|
||||
modes: [
|
||||
{
|
||||
displayName: 'From List',
|
||||
name: 'list',
|
||||
type: 'list',
|
||||
placeholder: 'Select a Chat...',
|
||||
typeOptions: {
|
||||
searchListMethod: 'getChats',
|
||||
searchable: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'By ID',
|
||||
name: 'id',
|
||||
type: 'string',
|
||||
placeholder:
|
||||
'19:7e2f1174-e8ee-4859-b8b1-a8d1cc63d276_0c5cfdbb-596f-4d39-b557-5d9516c94107@unq.gbl.spaces',
|
||||
// validation missing because no documentation found how these unique chat ids look like.
|
||||
url: '=https://teams.microsoft.com/l/chat/{{encodeURIComponent($value)}}/0',
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
export const groupRLC: INodeProperties = {
|
||||
displayName: 'Team',
|
||||
name: 'groupId',
|
||||
type: 'resourceLocator',
|
||||
default: { mode: 'list', value: '' },
|
||||
required: true,
|
||||
typeOptions: {
|
||||
loadOptionsDependsOn: ['groupSource'],
|
||||
},
|
||||
modes: [
|
||||
{
|
||||
displayName: 'From List',
|
||||
name: 'list',
|
||||
type: 'list',
|
||||
placeholder: 'Select a Team...',
|
||||
typeOptions: {
|
||||
searchListMethod: 'getGroups',
|
||||
searchable: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'By ID',
|
||||
name: 'id',
|
||||
type: 'string',
|
||||
placeholder: '12f0ca7d-b77f-4c4e-93d2-5cbdb4f464c6',
|
||||
validation: [
|
||||
{
|
||||
type: 'regex',
|
||||
properties: {
|
||||
regex: '^([0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12})[ \t]*',
|
||||
errorMessage: 'Not a valid Microsoft Teams Team ID',
|
||||
},
|
||||
},
|
||||
],
|
||||
extractValue: {
|
||||
type: 'regex',
|
||||
regex: '^([0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12})',
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
export const planRLC: INodeProperties = {
|
||||
displayName: 'Plan',
|
||||
name: 'planId',
|
||||
type: 'resourceLocator',
|
||||
default: { mode: 'list', value: '' },
|
||||
required: true,
|
||||
typeOptions: {
|
||||
loadOptionsDependsOn: ['groupId.value'],
|
||||
},
|
||||
modes: [
|
||||
{
|
||||
displayName: 'From List',
|
||||
name: 'list',
|
||||
type: 'list',
|
||||
placeholder: 'Select a Plan...',
|
||||
typeOptions: {
|
||||
searchListMethod: 'getPlans',
|
||||
searchable: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'By ID',
|
||||
name: 'id',
|
||||
type: 'string',
|
||||
placeholder: 'rl1HYb0cUEiHPc7zgB_KWWUAA7Of',
|
||||
// validation missing because no documentation found how these unique ids look like.
|
||||
},
|
||||
],
|
||||
description: 'The plan for the task to belong to',
|
||||
};
|
||||
|
||||
export const bucketRLC: INodeProperties = {
|
||||
displayName: 'Bucket',
|
||||
name: 'bucketId',
|
||||
type: 'resourceLocator',
|
||||
default: { mode: 'list', value: '' },
|
||||
required: true,
|
||||
typeOptions: {
|
||||
loadOptionsDependsOn: ['planId.value'],
|
||||
},
|
||||
modes: [
|
||||
{
|
||||
displayName: 'From List',
|
||||
name: 'list',
|
||||
type: 'list',
|
||||
placeholder: 'Select a Bucket...',
|
||||
typeOptions: {
|
||||
searchListMethod: 'getBuckets',
|
||||
searchable: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'By ID',
|
||||
name: 'id',
|
||||
type: 'string',
|
||||
placeholder: 'rl1HYb0cUEiHPc7zgB_KWWUAA7Of',
|
||||
// validation missing because no documentation found how these unique ids look like.
|
||||
},
|
||||
],
|
||||
description: 'The bucket for the task to belong to',
|
||||
};
|
||||
|
||||
export const memberRLC: INodeProperties = {
|
||||
displayName: 'Member',
|
||||
name: 'memberId',
|
||||
type: 'resourceLocator',
|
||||
default: { mode: 'list', value: '' },
|
||||
typeOptions: {
|
||||
loadOptionsDependsOn: ['groupId.value'],
|
||||
},
|
||||
modes: [
|
||||
{
|
||||
displayName: 'From List',
|
||||
name: 'list',
|
||||
type: 'list',
|
||||
placeholder: 'Select a Member...',
|
||||
typeOptions: {
|
||||
searchListMethod: 'getMembers',
|
||||
searchable: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'By ID',
|
||||
name: 'id',
|
||||
type: 'string',
|
||||
placeholder: '7e2f1174-e8ee-4859-b8b1-a8d1cc63d276',
|
||||
validation: [
|
||||
{
|
||||
type: 'regex',
|
||||
properties: {
|
||||
regex: '^([0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12})[ \t]*',
|
||||
errorMessage: 'Not a valid Microsoft Teams Team ID',
|
||||
},
|
||||
},
|
||||
],
|
||||
extractValue: {
|
||||
type: 'regex',
|
||||
regex: '^([0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12})',
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
@@ -0,0 +1,29 @@
|
||||
export interface TeamResponse {
|
||||
id: string;
|
||||
displayName: string;
|
||||
}
|
||||
|
||||
export interface ChannelResponse {
|
||||
id: string;
|
||||
displayName: string;
|
||||
}
|
||||
|
||||
export interface WebhookNotification {
|
||||
subscriptionId: string;
|
||||
resource: string;
|
||||
resourceData: ResourceData;
|
||||
tenantId: string;
|
||||
subscriptionExpirationDateTime: string;
|
||||
}
|
||||
|
||||
export interface ResourceData {
|
||||
id: string;
|
||||
[key: string]: unknown;
|
||||
}
|
||||
|
||||
export interface SubscriptionResponse {
|
||||
id: string;
|
||||
expirationDateTime: string;
|
||||
notificationUrl: string;
|
||||
resource: string;
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
import type { IHookFunctions, IDataObject } from 'n8n-workflow';
|
||||
import { NodeOperationError } from 'n8n-workflow';
|
||||
|
||||
import type { TeamResponse, ChannelResponse, SubscriptionResponse } from './types';
|
||||
import { microsoftApiRequest } from '../transport';
|
||||
|
||||
export async function fetchAllTeams(this: IHookFunctions): Promise<TeamResponse[]> {
|
||||
const { value: teams } = (await microsoftApiRequest.call(
|
||||
this,
|
||||
'GET',
|
||||
'/v1.0/me/joinedTeams',
|
||||
)) as { value: TeamResponse[] };
|
||||
return teams;
|
||||
}
|
||||
|
||||
export async function fetchAllChannels(
|
||||
this: IHookFunctions,
|
||||
teamId: string,
|
||||
): Promise<ChannelResponse[]> {
|
||||
const { value: channels } = (await microsoftApiRequest.call(
|
||||
this,
|
||||
'GET',
|
||||
`/v1.0/teams/${teamId}/channels`,
|
||||
)) as { value: ChannelResponse[] };
|
||||
return channels;
|
||||
}
|
||||
|
||||
export async function createSubscription(
|
||||
this: IHookFunctions,
|
||||
webhookUrl: string,
|
||||
resourcePath: string,
|
||||
): Promise<SubscriptionResponse> {
|
||||
const expirationTime = new Date(Date.now() + 4318 * 60 * 1000).toISOString();
|
||||
const body: IDataObject = {
|
||||
changeType: 'created',
|
||||
notificationUrl: webhookUrl,
|
||||
resource: resourcePath,
|
||||
expirationDateTime: expirationTime,
|
||||
latestSupportedTlsVersion: 'v1_2',
|
||||
lifecycleNotificationUrl: webhookUrl,
|
||||
};
|
||||
|
||||
const response = (await microsoftApiRequest.call(
|
||||
this,
|
||||
'POST',
|
||||
'/v1.0/subscriptions',
|
||||
body,
|
||||
)) as SubscriptionResponse;
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
export async function getResourcePath(
|
||||
this: IHookFunctions,
|
||||
event: string,
|
||||
): Promise<string | string[]> {
|
||||
switch (event) {
|
||||
case 'newChat': {
|
||||
return '/me/chats';
|
||||
}
|
||||
|
||||
case 'newChatMessage': {
|
||||
const watchAllChats = this.getNodeParameter('watchAllChats', false, {
|
||||
extractValue: true,
|
||||
}) as boolean;
|
||||
|
||||
if (watchAllChats) {
|
||||
return '/me/chats/getAllMessages';
|
||||
} else {
|
||||
const chatId = this.getNodeParameter('chatId', undefined, { extractValue: true }) as string;
|
||||
return `/chats/${decodeURIComponent(chatId)}/messages`;
|
||||
}
|
||||
}
|
||||
|
||||
case 'newChannel': {
|
||||
const watchAllTeams = this.getNodeParameter('watchAllTeams', false, {
|
||||
extractValue: true,
|
||||
}) as boolean;
|
||||
|
||||
if (watchAllTeams) {
|
||||
const teams = await fetchAllTeams.call(this);
|
||||
return teams.map((team) => `/teams/${team.id}/channels`);
|
||||
} else {
|
||||
const teamId = this.getNodeParameter('teamId', undefined, { extractValue: true }) as string;
|
||||
return `/teams/${teamId}/channels`;
|
||||
}
|
||||
}
|
||||
|
||||
case 'newChannelMessage': {
|
||||
const watchAllTeams = this.getNodeParameter('watchAllTeams', false, {
|
||||
extractValue: true,
|
||||
}) as boolean;
|
||||
|
||||
if (watchAllTeams) {
|
||||
const teams = await fetchAllTeams.call(this);
|
||||
const teamChannels = await Promise.all(
|
||||
teams.map(async (team) => {
|
||||
const channels = await fetchAllChannels.call(this, team.id);
|
||||
return channels.map((channel) => `/teams/${team.id}/channels/${channel.id}/messages`);
|
||||
}),
|
||||
);
|
||||
return teamChannels.flat();
|
||||
} else {
|
||||
const teamId = this.getNodeParameter('teamId', undefined, { extractValue: true }) as string;
|
||||
const watchAllChannels = this.getNodeParameter('watchAllChannels', false, {
|
||||
extractValue: true,
|
||||
}) as boolean;
|
||||
|
||||
if (watchAllChannels) {
|
||||
const channels = await fetchAllChannels.call(this, teamId);
|
||||
return channels.map((channel) => `/teams/${teamId}/channels/${channel.id}/messages`);
|
||||
} else {
|
||||
const channelId = this.getNodeParameter('channelId', undefined, {
|
||||
extractValue: true,
|
||||
}) as string;
|
||||
return `/teams/${teamId}/channels/${decodeURIComponent(channelId)}/messages`;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
case 'newTeamMember': {
|
||||
const watchAllTeams = this.getNodeParameter('watchAllTeams', false, {
|
||||
extractValue: true,
|
||||
}) as boolean;
|
||||
|
||||
if (watchAllTeams) {
|
||||
const teams = await fetchAllTeams.call(this);
|
||||
return teams.map((team) => `/teams/${team.id}/members`);
|
||||
} else {
|
||||
const teamId = this.getNodeParameter('teamId', undefined, { extractValue: true }) as string;
|
||||
return `/teams/${teamId}/members`;
|
||||
}
|
||||
}
|
||||
|
||||
default: {
|
||||
throw new NodeOperationError(this.getNode(), {
|
||||
message: `Invalid event: ${event}`,
|
||||
description: `The selected event "${event}" is not recognized.`,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
import type { IExecuteFunctions, ILoadOptionsFunctions, INodeListSearchItems } from 'n8n-workflow';
|
||||
|
||||
export function prepareMessage(
|
||||
this: IExecuteFunctions | ILoadOptionsFunctions,
|
||||
message: string,
|
||||
contentType: 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 : ''}`;
|
||||
contentType = 'html';
|
||||
message = `${message}<br><br><em> Powered by <a href="${link}">this n8n workflow</a> </em>`;
|
||||
}
|
||||
|
||||
return {
|
||||
body: {
|
||||
contentType,
|
||||
content: message,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export function filterSortSearchListItems(items: INodeListSearchItems[], filter?: string) {
|
||||
return items
|
||||
.filter(
|
||||
(item) =>
|
||||
!filter ||
|
||||
item.name.toLowerCase().includes(filter.toLowerCase()) ||
|
||||
item.value.toString().toLowerCase().includes(filter.toLowerCase()),
|
||||
)
|
||||
.sort((a, b) => {
|
||||
if (a.name.toLocaleLowerCase() < b.name.toLocaleLowerCase()) {
|
||||
return -1;
|
||||
}
|
||||
if (a.name.toLocaleLowerCase() > b.name.toLocaleLowerCase()) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export * as listSearch from './listSearch';
|
||||
@@ -0,0 +1,280 @@
|
||||
import {
|
||||
NodeOperationError,
|
||||
type IDataObject,
|
||||
type ILoadOptionsFunctions,
|
||||
type INodeListSearchItems,
|
||||
type INodeListSearchResult,
|
||||
sleep,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import { filterSortSearchListItems } from '../helpers/utils';
|
||||
import { microsoftApiRequest } from '../transport';
|
||||
|
||||
export async function getChats(
|
||||
this: ILoadOptionsFunctions,
|
||||
filter?: string,
|
||||
): Promise<INodeListSearchResult> {
|
||||
const returnData: INodeListSearchItems[] = [];
|
||||
const qs: IDataObject = {
|
||||
$expand: 'members',
|
||||
};
|
||||
|
||||
let value: IDataObject[] = [];
|
||||
let attempts = 5;
|
||||
do {
|
||||
try {
|
||||
value = ((await microsoftApiRequest.call(this, 'GET', '/v1.0/chats', {}, qs)) as IDataObject)
|
||||
.value as IDataObject[];
|
||||
break;
|
||||
} catch (error) {
|
||||
if (attempts > 0) {
|
||||
await sleep(1000);
|
||||
attempts--;
|
||||
} else {
|
||||
throw new NodeOperationError(this.getNode(), error);
|
||||
}
|
||||
}
|
||||
} while (attempts > 0);
|
||||
|
||||
for (const chat of value) {
|
||||
if (!chat.topic) {
|
||||
chat.topic = (chat.members as IDataObject[])
|
||||
.filter((member: IDataObject) => member.displayName)
|
||||
.map((member: IDataObject) => member.displayName)
|
||||
.join(', ');
|
||||
}
|
||||
const chatName = `${chat.topic || '(no title) - ' + chat.id} (${chat.chatType})`;
|
||||
const chatId = chat.id;
|
||||
const url = chat.webUrl as string;
|
||||
returnData.push({
|
||||
name: chatName,
|
||||
value: chatId as string,
|
||||
url,
|
||||
});
|
||||
}
|
||||
|
||||
const results = returnData
|
||||
.filter(
|
||||
(item) =>
|
||||
!filter ||
|
||||
item.name.toLowerCase().includes(filter.toLowerCase()) ||
|
||||
item.value.toString().toLowerCase().includes(filter.toLowerCase()),
|
||||
)
|
||||
.sort((a, b) => {
|
||||
if (a.name.toLocaleLowerCase() < b.name.toLocaleLowerCase()) {
|
||||
return -1;
|
||||
}
|
||||
if (a.name.toLocaleLowerCase() > b.name.toLocaleLowerCase()) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
|
||||
return { results };
|
||||
}
|
||||
|
||||
export async function getTeams(
|
||||
this: ILoadOptionsFunctions,
|
||||
filter?: string,
|
||||
): Promise<INodeListSearchResult> {
|
||||
const returnData: INodeListSearchItems[] = [];
|
||||
const { value } = await microsoftApiRequest.call(this, 'GET', '/v1.0/me/joinedTeams');
|
||||
|
||||
for (const team of value) {
|
||||
const teamName = team.displayName;
|
||||
const teamId = team.id;
|
||||
// let channelId: string = '';
|
||||
|
||||
// try {
|
||||
// const channels = await microsoftApiRequestAllItems.call(
|
||||
// this,
|
||||
// 'value',
|
||||
// 'GET',
|
||||
// `/v1.0/teams/${teamId}/channels`,
|
||||
// {},
|
||||
// );
|
||||
|
||||
// if (channels.length > 0) {
|
||||
// channelId = channels.find((channel: IDataObject) => channel.displayName === 'General').id;
|
||||
// if (!channelId) {
|
||||
// channelId = channels[0].id;
|
||||
// }
|
||||
// }
|
||||
// } catch (error) {}
|
||||
|
||||
returnData.push({
|
||||
name: teamName,
|
||||
value: teamId,
|
||||
// url: channelId
|
||||
// ? `https://teams.microsoft.com/l/team/${channelId}/conversations?groupId=${teamId}&tenantId=${team.tenantId}`
|
||||
// : undefined,
|
||||
});
|
||||
}
|
||||
const results = filterSortSearchListItems(returnData, filter);
|
||||
|
||||
return { results };
|
||||
}
|
||||
|
||||
export async function getChannels(
|
||||
this: ILoadOptionsFunctions,
|
||||
filter?: string,
|
||||
): Promise<INodeListSearchResult> {
|
||||
const returnData: INodeListSearchItems[] = [];
|
||||
const teamId = this.getCurrentNodeParameter('teamId', { extractValue: true }) as string;
|
||||
const operation = this.getNodeParameter('operation', 0) as string;
|
||||
const resource = this.getNodeParameter('resource', 0) as string;
|
||||
|
||||
const excludeGeneralChannel = ['deleteChannel'];
|
||||
|
||||
if (resource === 'channel') excludeGeneralChannel.push('update');
|
||||
|
||||
const { value } = await microsoftApiRequest.call(this, 'GET', `/v1.0/teams/${teamId}/channels`);
|
||||
|
||||
for (const channel of value) {
|
||||
if (channel.displayName === 'General' && excludeGeneralChannel.includes(operation)) {
|
||||
continue;
|
||||
}
|
||||
const channelName = channel.displayName;
|
||||
const channelId = channel.id;
|
||||
const url = channel.webUrl;
|
||||
returnData.push({
|
||||
name: channelName,
|
||||
value: channelId,
|
||||
url,
|
||||
});
|
||||
}
|
||||
|
||||
const results = filterSortSearchListItems(returnData, filter);
|
||||
return { results };
|
||||
}
|
||||
|
||||
export async function getGroups(
|
||||
this: ILoadOptionsFunctions,
|
||||
filter?: string,
|
||||
): Promise<INodeListSearchResult> {
|
||||
const returnData: INodeListSearchItems[] = [];
|
||||
// const groupSource = this.getCurrentNodeParameter('groupSource') as string;
|
||||
const 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) {
|
||||
if (group.displayName === 'All Company') continue;
|
||||
|
||||
const name = group.displayName || group.mail;
|
||||
|
||||
if (name === undefined) continue;
|
||||
|
||||
returnData.push({
|
||||
name,
|
||||
value: group.id,
|
||||
});
|
||||
}
|
||||
|
||||
const results = filterSortSearchListItems(returnData, filter);
|
||||
return { results };
|
||||
}
|
||||
|
||||
export async function getPlans(
|
||||
this: ILoadOptionsFunctions,
|
||||
filter?: string,
|
||||
): Promise<INodeListSearchResult> {
|
||||
const returnData: INodeListSearchItems[] = [];
|
||||
|
||||
let groupId = '';
|
||||
|
||||
try {
|
||||
groupId = this.getCurrentNodeParameter('groupId', { extractValue: true }) as string;
|
||||
} catch (error) {}
|
||||
|
||||
const operation = this.getNodeParameter('operation', 0) as string;
|
||||
|
||||
if (operation === 'update' && !groupId) {
|
||||
groupId = this.getCurrentNodeParameter('updateFields.groupId', {
|
||||
extractValue: true,
|
||||
}) 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,
|
||||
});
|
||||
}
|
||||
const results = filterSortSearchListItems(returnData, filter);
|
||||
return { results };
|
||||
}
|
||||
|
||||
export async function getBuckets(
|
||||
this: ILoadOptionsFunctions,
|
||||
filter?: string,
|
||||
): Promise<INodeListSearchResult> {
|
||||
const returnData: INodeListSearchItems[] = [];
|
||||
let planId = '';
|
||||
|
||||
try {
|
||||
planId = this.getCurrentNodeParameter('planId', { extractValue: true }) as string;
|
||||
} catch (error) {}
|
||||
|
||||
const operation = this.getNodeParameter('operation', 0) as string;
|
||||
|
||||
if (operation === 'update' && !planId) {
|
||||
planId = this.getCurrentNodeParameter('updateFields.planId', {
|
||||
extractValue: true,
|
||||
}) 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,
|
||||
});
|
||||
}
|
||||
const results = filterSortSearchListItems(returnData, filter);
|
||||
return { results };
|
||||
}
|
||||
|
||||
export async function getMembers(
|
||||
this: ILoadOptionsFunctions,
|
||||
filter?: string,
|
||||
): Promise<INodeListSearchResult> {
|
||||
const returnData: INodeListSearchItems[] = [];
|
||||
let groupId = '';
|
||||
|
||||
try {
|
||||
groupId = this.getCurrentNodeParameter('groupId', { extractValue: true }) as string;
|
||||
} catch (error) {}
|
||||
|
||||
const operation = this.getNodeParameter('operation', 0) as string;
|
||||
|
||||
if (operation === 'update' && !groupId) {
|
||||
groupId = this.getCurrentNodeParameter('updateFields.groupId', {
|
||||
extractValue: true,
|
||||
}) 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,
|
||||
});
|
||||
}
|
||||
|
||||
const results = filterSortSearchListItems(returnData, filter);
|
||||
return { results };
|
||||
}
|
||||
@@ -0,0 +1,210 @@
|
||||
import { mockDeep } from 'jest-mock-extended';
|
||||
import type { IExecuteFunctions, INode } from 'n8n-workflow';
|
||||
|
||||
import { microsoftApiRequest } from '../../transport/index';
|
||||
|
||||
describe('Microsoft Teams Transport', () => {
|
||||
let mockExecuteFunctions: jest.Mocked<IExecuteFunctions>;
|
||||
let mockNode: INode;
|
||||
let mockRequestOAuth2: jest.Mock;
|
||||
|
||||
beforeEach(() => {
|
||||
mockExecuteFunctions = mockDeep<IExecuteFunctions>();
|
||||
mockRequestOAuth2 = jest.fn();
|
||||
mockExecuteFunctions.helpers.requestOAuth2 = mockRequestOAuth2;
|
||||
|
||||
mockNode = {
|
||||
id: 'test-node',
|
||||
name: 'Test Teams Node',
|
||||
type: 'n8n-nodes-base.microsoftTeams',
|
||||
typeVersion: 2,
|
||||
position: [0, 0],
|
||||
parameters: {},
|
||||
};
|
||||
mockExecuteFunctions.getNode.mockReturnValue(mockNode);
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
jest.resetAllMocks();
|
||||
});
|
||||
|
||||
describe('microsoftApiRequest', () => {
|
||||
describe('graphApiBaseUrl from credentials', () => {
|
||||
it('should use base URL from credentials', async () => {
|
||||
const mockResponse = { data: 'test' };
|
||||
mockRequestOAuth2.mockResolvedValue(mockResponse);
|
||||
mockExecuteFunctions.getCredentials.mockResolvedValue({
|
||||
oauthTokenData: {
|
||||
access_token: 'test-access-token',
|
||||
},
|
||||
graphApiBaseUrl: 'https://graph.microsoft.us',
|
||||
});
|
||||
|
||||
await microsoftApiRequest.call(mockExecuteFunctions, 'GET', '/teams');
|
||||
|
||||
expect(mockRequestOAuth2).toHaveBeenCalledWith(
|
||||
'microsoftTeamsOAuth2Api',
|
||||
expect.objectContaining({
|
||||
method: 'GET',
|
||||
uri: 'https://graph.microsoft.us/teams',
|
||||
json: true,
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it('should fall back to default when credentials.graphApiBaseUrl is empty', async () => {
|
||||
const mockResponse = { data: 'test' };
|
||||
mockRequestOAuth2.mockResolvedValue(mockResponse);
|
||||
mockExecuteFunctions.getCredentials.mockResolvedValue({
|
||||
oauthTokenData: {
|
||||
access_token: 'test-access-token',
|
||||
},
|
||||
graphApiBaseUrl: '',
|
||||
});
|
||||
|
||||
await microsoftApiRequest.call(mockExecuteFunctions, 'GET', '/teams');
|
||||
|
||||
expect(mockRequestOAuth2).toHaveBeenCalledWith(
|
||||
'microsoftTeamsOAuth2Api',
|
||||
expect.objectContaining({
|
||||
method: 'GET',
|
||||
uri: 'https://graph.microsoft.com/teams',
|
||||
json: true,
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it('should fall back to default when credentials.graphApiBaseUrl is undefined', async () => {
|
||||
const mockResponse = { data: 'test' };
|
||||
mockRequestOAuth2.mockResolvedValue(mockResponse);
|
||||
mockExecuteFunctions.getCredentials.mockResolvedValue({
|
||||
oauthTokenData: {
|
||||
access_token: 'test-access-token',
|
||||
},
|
||||
});
|
||||
|
||||
await microsoftApiRequest.call(mockExecuteFunctions, 'GET', '/teams');
|
||||
|
||||
expect(mockRequestOAuth2).toHaveBeenCalledWith(
|
||||
'microsoftTeamsOAuth2Api',
|
||||
expect.objectContaining({
|
||||
method: 'GET',
|
||||
uri: 'https://graph.microsoft.com/teams',
|
||||
json: true,
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it('should strip trailing slashes from base URL using regex', async () => {
|
||||
const mockResponse = { data: 'test' };
|
||||
mockRequestOAuth2.mockResolvedValue(mockResponse);
|
||||
mockExecuteFunctions.getCredentials.mockResolvedValue({
|
||||
oauthTokenData: {
|
||||
access_token: 'test-access-token',
|
||||
},
|
||||
graphApiBaseUrl: 'https://graph.microsoft.com/',
|
||||
});
|
||||
|
||||
await microsoftApiRequest.call(mockExecuteFunctions, 'GET', '/teams');
|
||||
|
||||
expect(mockRequestOAuth2).toHaveBeenCalledWith(
|
||||
'microsoftTeamsOAuth2Api',
|
||||
expect.objectContaining({
|
||||
method: 'GET',
|
||||
uri: 'https://graph.microsoft.com/teams',
|
||||
json: true,
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it('should strip multiple trailing slashes from base URL', async () => {
|
||||
const mockResponse = { data: 'test' };
|
||||
mockRequestOAuth2.mockResolvedValue(mockResponse);
|
||||
mockExecuteFunctions.getCredentials.mockResolvedValue({
|
||||
oauthTokenData: {
|
||||
access_token: 'test-access-token',
|
||||
},
|
||||
graphApiBaseUrl: 'https://graph.microsoft.com///',
|
||||
});
|
||||
|
||||
await microsoftApiRequest.call(mockExecuteFunctions, 'GET', '/teams');
|
||||
|
||||
expect(mockRequestOAuth2).toHaveBeenCalledWith(
|
||||
'microsoftTeamsOAuth2Api',
|
||||
expect.objectContaining({
|
||||
method: 'GET',
|
||||
uri: 'https://graph.microsoft.com/teams',
|
||||
json: true,
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it('should use US Government cloud endpoint', async () => {
|
||||
const mockResponse = { data: 'test' };
|
||||
mockRequestOAuth2.mockResolvedValue(mockResponse);
|
||||
mockExecuteFunctions.getCredentials.mockResolvedValue({
|
||||
oauthTokenData: {
|
||||
access_token: 'test-access-token',
|
||||
},
|
||||
graphApiBaseUrl: 'https://graph.microsoft.us',
|
||||
});
|
||||
|
||||
await microsoftApiRequest.call(mockExecuteFunctions, 'GET', '/teams');
|
||||
|
||||
expect(mockRequestOAuth2).toHaveBeenCalledWith(
|
||||
'microsoftTeamsOAuth2Api',
|
||||
expect.objectContaining({
|
||||
method: 'GET',
|
||||
uri: 'https://graph.microsoft.us/teams',
|
||||
json: true,
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it('should use US Government DOD cloud endpoint', async () => {
|
||||
const mockResponse = { data: 'test' };
|
||||
mockRequestOAuth2.mockResolvedValue(mockResponse);
|
||||
mockExecuteFunctions.getCredentials.mockResolvedValue({
|
||||
oauthTokenData: {
|
||||
access_token: 'test-access-token',
|
||||
},
|
||||
graphApiBaseUrl: 'https://dod-graph.microsoft.us',
|
||||
});
|
||||
|
||||
await microsoftApiRequest.call(mockExecuteFunctions, 'GET', '/teams');
|
||||
|
||||
expect(mockRequestOAuth2).toHaveBeenCalledWith(
|
||||
'microsoftTeamsOAuth2Api',
|
||||
expect.objectContaining({
|
||||
method: 'GET',
|
||||
uri: 'https://dod-graph.microsoft.us/teams',
|
||||
json: true,
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it('should use China cloud endpoint', async () => {
|
||||
const mockResponse = { data: 'test' };
|
||||
mockRequestOAuth2.mockResolvedValue(mockResponse);
|
||||
mockExecuteFunctions.getCredentials.mockResolvedValue({
|
||||
oauthTokenData: {
|
||||
access_token: 'test-access-token',
|
||||
},
|
||||
graphApiBaseUrl: 'https://microsoftgraph.chinacloudapi.cn',
|
||||
});
|
||||
|
||||
await microsoftApiRequest.call(mockExecuteFunctions, 'GET', '/teams');
|
||||
|
||||
expect(mockRequestOAuth2).toHaveBeenCalledWith(
|
||||
'microsoftTeamsOAuth2Api',
|
||||
expect.objectContaining({
|
||||
method: 'GET',
|
||||
uri: 'https://microsoftgraph.chinacloudapi.cn/teams',
|
||||
json: true,
|
||||
}),
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,108 @@
|
||||
import type {
|
||||
IExecuteFunctions,
|
||||
ILoadOptionsFunctions,
|
||||
IDataObject,
|
||||
JsonObject,
|
||||
IHttpRequestMethods,
|
||||
IRequestOptions,
|
||||
IHookFunctions,
|
||||
} from 'n8n-workflow';
|
||||
import { NodeApiError } from 'n8n-workflow';
|
||||
|
||||
import { capitalize } from '../../../../../utils/utilities';
|
||||
|
||||
export async function microsoftApiRequest(
|
||||
this: IExecuteFunctions | ILoadOptionsFunctions | IHookFunctions,
|
||||
method: IHttpRequestMethods,
|
||||
resource: string,
|
||||
body: any = {},
|
||||
qs: IDataObject = {},
|
||||
uri?: string,
|
||||
headers: IDataObject = {},
|
||||
): Promise<any> {
|
||||
const credentials = await this.getCredentials('microsoftTeamsOAuth2Api');
|
||||
const baseUrl = (
|
||||
typeof credentials.graphApiBaseUrl === 'string' && credentials.graphApiBaseUrl !== ''
|
||||
? credentials.graphApiBaseUrl
|
||||
: 'https://graph.microsoft.com'
|
||||
).replace(/\/+$/, '');
|
||||
const options: IRequestOptions = {
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
method,
|
||||
body,
|
||||
qs,
|
||||
uri: uri || `${baseUrl}${resource}`,
|
||||
json: true,
|
||||
};
|
||||
try {
|
||||
if (Object.keys(headers).length !== 0) {
|
||||
options.headers = Object.assign({}, options.headers, headers);
|
||||
}
|
||||
return await this.helpers.requestOAuth2.call(this, 'microsoftTeamsOAuth2Api', options);
|
||||
} catch (error) {
|
||||
const errorOptions: IDataObject = {};
|
||||
if (error.error?.error) {
|
||||
const httpCode = error.statusCode;
|
||||
error = error.error.error;
|
||||
error.statusCode = httpCode;
|
||||
errorOptions.message = error.message;
|
||||
|
||||
if (error.code === 'NotFound' && error.message === 'Resource not found') {
|
||||
const nodeResource = capitalize(this.getNodeParameter('resource', 0) as string);
|
||||
errorOptions.message = `${nodeResource} not found`;
|
||||
}
|
||||
}
|
||||
throw new NodeApiError(this.getNode(), error as JsonObject, errorOptions);
|
||||
}
|
||||
}
|
||||
|
||||
export async function microsoftApiRequestAllItems(
|
||||
this: IExecuteFunctions | ILoadOptionsFunctions,
|
||||
propertyName: string,
|
||||
method: IHttpRequestMethods,
|
||||
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: IHttpRequestMethods,
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user