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

This commit is contained in:
2026-03-17 16:22:57 +03:30
commit 3d5eaf9445
15349 changed files with 2847338 additions and 0 deletions
@@ -0,0 +1,73 @@
{
"node": "n8n-nodes-base.mattermost",
"nodeVersion": "1.0",
"codexVersion": "1.0",
"categories": ["Communication"],
"resources": {
"credentialDocumentation": [
{
"url": "https://docs.n8n.io/integrations/builtin/credentials/mattermost/"
}
],
"primaryDocumentation": [
{
"url": "https://docs.n8n.io/integrations/builtin/app-nodes/n8n-nodes-base.mattermost/"
}
],
"generic": [
{
"label": "How to host virtual coffee breaks with n8n",
"icon": "☕️",
"url": "https://n8n.io/blog/how-to-host-virtual-coffee-breaks-with-n8n/"
},
{
"label": "Supercharging your conference registration process with n8n",
"icon": "🎫",
"url": "https://n8n.io/blog/supercharging-your-conference-registration-process-with-n8n/"
},
{
"label": "Creating triggers for n8n workflows using polling",
"icon": "⏲",
"url": "https://n8n.io/blog/creating-triggers-for-n8n-workflows-using-polling/"
},
{
"label": "5 tasks you can automate with the new Notion API ",
"icon": "⚡️",
"url": "https://n8n.io/blog/5-tasks-you-can-automate-with-notion-api/"
},
{
"label": "15 Google apps you can combine and automate to increase productivity",
"icon": "💡",
"url": "https://n8n.io/blog/automate-google-apps-for-productivity/"
},
{
"label": "The ultimate guide to automate your video collaboration with Whereby, Mattermost, and n8n",
"icon": "📹",
"url": "https://n8n.io/blog/the-ultimate-guide-to-automate-your-video-collaboration-with-whereby-mattermost-and-n8n/"
},
{
"label": "5 workflow automations for Mattermost that we love at n8n",
"icon": "🤖",
"url": "https://n8n.io/blog/5-workflow-automations-for-mattermost-that-we-love-at-n8n/"
},
{
"label": "Creating Error Workflows in n8n",
"icon": "🌪",
"url": "https://n8n.io/blog/creating-error-workflows-in-n8n/"
},
{
"label": "How to automate every step of an incident response workflow",
"url": "https://n8n.io/blog/creating-custom-incident-response-workflows-with-n8n/"
},
{
"label": "Learn how to use webhooks with Mattermost slash commands",
"icon": "🦄",
"url": "https://n8n.io/blog/learn-how-to-use-webhooks-with-mattermost-slash-commands/"
},
{
"label": "7 no-code workflow automations for Amazon Web Services",
"url": "https://n8n.io/blog/aws-workflow-automation/"
}
]
}
}
@@ -0,0 +1,24 @@
import type { INodeTypeBaseDescription, IVersionedNodeType } from 'n8n-workflow';
import { VersionedNodeType } from 'n8n-workflow';
import { MattermostV1 } from './v1/MattermostV1.node';
export class Mattermost extends VersionedNodeType {
constructor() {
const baseDescription: INodeTypeBaseDescription = {
displayName: 'Mattermost',
name: 'mattermost',
icon: 'file:mattermost.svg',
group: ['output'],
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
description: 'Sends data to Mattermost',
defaultVersion: 1,
};
const nodeVersions: IVersionedNodeType['nodeVersions'] = {
1: new MattermostV1(baseDescription),
};
super(nodeVersions, baseDescription);
}
}
@@ -0,0 +1,84 @@
{
"type": "object",
"properties": {
"channel_id": {
"type": "string"
},
"create_at": {
"type": "integer"
},
"delete_at": {
"type": "integer"
},
"edit_at": {
"type": "integer"
},
"hashtags": {
"type": "string"
},
"id": {
"type": "string"
},
"is_pinned": {
"type": "boolean"
},
"last_reply_at": {
"type": "integer"
},
"message": {
"type": "string"
},
"metadata": {
"type": "object",
"properties": {
"embeds": {
"type": "array",
"items": {
"type": "object",
"properties": {
"type": {
"type": "string"
}
}
}
}
}
},
"original_id": {
"type": "string"
},
"participants": {
"type": "null"
},
"pending_post_id": {
"type": "string"
},
"props": {
"type": "object",
"properties": {
"from_bot": {
"type": "string"
}
}
},
"remote_id": {
"type": "string"
},
"reply_count": {
"type": "integer"
},
"root_id": {
"type": "string"
},
"type": {
"type": "string"
},
"update_at": {
"type": "integer"
},
"user_id": {
"type": "string"
}
},
"version": 1
}
File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 6.4 KiB

@@ -0,0 +1,28 @@
import type {
IExecuteFunctions,
INodeType,
INodeTypeBaseDescription,
INodeTypeDescription,
} from 'n8n-workflow';
import { router } from './actions/router';
import { versionDescription } from './actions/versionDescription';
import { loadOptions } from './methods';
export class MattermostV1 implements INodeType {
description: INodeTypeDescription;
constructor(baseDescription: INodeTypeBaseDescription) {
this.description = {
...baseDescription,
...versionDescription,
usableAsTool: true,
};
}
methods = { loadOptions };
async execute(this: IExecuteFunctions) {
return await router.call(this);
}
}
@@ -0,0 +1,29 @@
import type { AllEntities, Entity, PropertiesOf } from 'n8n-workflow';
type MattermostMap = {
channel: 'addUser' | 'create' | 'delete' | 'members' | 'restore' | 'statistics' | 'search';
message: 'delete' | 'post' | 'postEphemeral';
reaction: 'create' | 'delete' | 'getAll';
user: 'create' | 'deactive' | 'getAll' | 'getByEmail' | 'getById' | 'invite';
};
export type Mattermost = AllEntities<MattermostMap>;
export type MattermostChannel = Entity<MattermostMap, 'channel'>;
export type MattermostMessage = Entity<MattermostMap, 'message'>;
export type MattermostReaction = Entity<MattermostMap, 'reaction'>;
export type MattermostUser = Entity<MattermostMap, 'user'>;
export type ChannelProperties = PropertiesOf<MattermostChannel>;
export type MessageProperties = PropertiesOf<MattermostMessage>;
export type ReactionProperties = PropertiesOf<MattermostReaction>;
export type UserProperties = PropertiesOf<MattermostUser>;
export interface IAttachment {
fields: {
item?: object[];
};
actions: {
item?: object[];
};
}
@@ -0,0 +1,42 @@
import type { ChannelProperties } from '../../Interfaces';
export const channelAddUserDescription: ChannelProperties = [
{
displayName: 'Channel Name or ID',
name: 'channelId',
type: 'options',
typeOptions: {
loadOptionsMethod: 'getChannels',
},
options: [],
default: '',
required: true,
displayOptions: {
show: {
operation: ['addUser'],
resource: ['channel'],
},
},
description:
'The ID of the channel to invite user to. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
},
{
displayName: 'User Name or ID',
name: 'userId',
type: 'options',
typeOptions: {
loadOptionsMethod: 'getUsers',
},
options: [],
default: '',
required: true,
displayOptions: {
show: {
operation: ['addUser'],
resource: ['channel'],
},
},
description:
'The ID of the user to invite into channel. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
},
];
@@ -0,0 +1,21 @@
import type { IExecuteFunctions, IDataObject, INodeExecutionData } from 'n8n-workflow';
import { apiRequest } from '../../../transport';
export async function addUser(
this: IExecuteFunctions,
index: number,
): Promise<INodeExecutionData[]> {
const channelId = this.getNodeParameter('channelId', index) as string;
const body = {} as IDataObject;
const qs = {} as IDataObject;
const requestMethod = 'POST';
const endpoint = `channels/${channelId}/members`;
body.user_id = this.getNodeParameter('userId', index) as string;
const responseData = await apiRequest.call(this, requestMethod, endpoint, body, qs);
return this.helpers.returnJsonArray(responseData as IDataObject[]);
}
@@ -0,0 +1,4 @@
import { channelAddUserDescription as description } from './description';
import { addUser as execute } from './execute';
export { description, execute };
@@ -0,0 +1,76 @@
import type { ChannelProperties } from '../../Interfaces';
export const channelCreateDescription: ChannelProperties = [
{
displayName: 'Team Name or ID',
name: 'teamId',
type: 'options',
typeOptions: {
loadOptionsMethod: 'getTeams',
},
options: [],
default: '',
required: true,
displayOptions: {
show: {
operation: ['create'],
resource: ['channel'],
},
},
description:
'The Mattermost Team. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
},
{
displayName: 'Display Name',
name: 'displayName',
type: 'string',
default: '',
placeholder: 'Announcements',
displayOptions: {
show: {
operation: ['create'],
resource: ['channel'],
},
},
required: true,
description: 'The non-unique UI name for the channel',
},
{
displayName: 'Name',
name: 'channel',
type: 'string',
default: '',
placeholder: 'announcements',
displayOptions: {
show: {
operation: ['create'],
resource: ['channel'],
},
},
required: true,
description: 'The unique handle for the channel, will be present in the channel URL',
},
{
displayName: 'Type',
name: 'type',
type: 'options',
displayOptions: {
show: {
operation: ['create'],
resource: ['channel'],
},
},
options: [
{
name: 'Private',
value: 'private',
},
{
name: 'Public',
value: 'public',
},
],
default: 'public',
description: 'The type of channel to create',
},
];
@@ -0,0 +1,24 @@
import type { IExecuteFunctions, IDataObject, INodeExecutionData } from 'n8n-workflow';
import { apiRequest } from '../../../transport';
export async function create(
this: IExecuteFunctions,
index: number,
): Promise<INodeExecutionData[]> {
const body = {} as IDataObject;
const qs = {} as IDataObject;
const requestMethod = 'POST';
const endpoint = 'channels';
const type = this.getNodeParameter('type', index) as string;
body.team_id = this.getNodeParameter('teamId', index) as string;
body.display_name = this.getNodeParameter('displayName', index) as string;
body.name = this.getNodeParameter('channel', index) as string;
body.type = type === 'public' ? 'O' : 'P';
const responseData = await apiRequest.call(this, requestMethod, endpoint, body, qs);
return this.helpers.returnJsonArray(responseData as IDataObject[]);
}
@@ -0,0 +1,4 @@
import { channelCreateDescription as description } from './description';
import { create as execute } from './execute';
export { description, execute };
@@ -0,0 +1,23 @@
import type { ChannelProperties } from '../../Interfaces';
export const channelDeleteDescription: ChannelProperties = [
{
displayName: 'Channel Name or ID',
name: 'channelId',
type: 'options',
typeOptions: {
loadOptionsMethod: 'getChannels',
},
options: [],
default: '',
required: true,
displayOptions: {
show: {
operation: ['delete'],
resource: ['channel'],
},
},
description:
'The ID of the channel to soft delete. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
},
];
@@ -0,0 +1,16 @@
import type { IExecuteFunctions, IDataObject, INodeExecutionData } from 'n8n-workflow';
import { apiRequest } from '../../../transport';
export async function del(this: IExecuteFunctions, index: number): Promise<INodeExecutionData[]> {
const channelId = this.getNodeParameter('channelId', index) as string;
const body = {} as IDataObject;
const qs = {} as IDataObject;
const requestMethod = 'DELETE';
const endpoint = `channels/${channelId}`;
const responseData = await apiRequest.call(this, requestMethod, endpoint, body, qs);
return this.helpers.returnJsonArray(responseData as IDataObject[]);
}
@@ -0,0 +1,4 @@
import { channelDeleteDescription as description } from './description';
import { del as execute } from './execute';
export { description, execute };
@@ -0,0 +1,77 @@
import type { INodeProperties } from 'n8n-workflow';
import * as addUser from './addUser';
import * as create from './create';
import * as del from './del';
import * as members from './members';
import * as restore from './restore';
import * as search from './search';
import * as statistics from './statistics';
export { create, del as delete, members, restore, addUser, statistics, search };
export const descriptions: INodeProperties[] = [
{
displayName: 'Operation',
name: 'operation',
type: 'options',
noDataExpression: true,
displayOptions: {
show: {
resource: ['channel'],
},
},
options: [
{
name: 'Add User',
value: 'addUser',
description: 'Add a user to a channel',
action: 'Add a user to a channel',
},
{
name: 'Create',
value: 'create',
description: 'Create a new channel',
action: 'Create a channel',
},
{
name: 'Delete',
value: 'delete',
description: 'Soft delete a channel',
action: 'Delete a channel',
},
{
name: 'Member',
value: 'members',
description: 'Get a page of members for a channel',
action: 'Get a page of members for a channel',
},
{
name: 'Restore',
value: 'restore',
description: 'Restores a soft deleted channel',
action: 'Restore a soft-deleted channel',
},
{
name: 'Search',
value: 'search',
description: 'Search for a channel',
action: 'Search for a channel',
},
{
name: 'Statistics',
value: 'statistics',
description: 'Get statistics for a channel',
action: 'Get statistics for a channel',
},
],
default: 'create',
},
...create.description,
...del.description,
...members.description,
...restore.description,
...addUser.description,
...statistics.description,
...search.description,
];
@@ -0,0 +1,89 @@
import type { ChannelProperties } from '../../Interfaces';
export const channelMembersDescription: ChannelProperties = [
{
displayName: 'Team Name or ID',
name: 'teamId',
type: 'options',
typeOptions: {
loadOptionsMethod: 'getTeams',
},
options: [],
default: '',
required: true,
displayOptions: {
show: {
operation: ['members'],
resource: ['channel'],
},
},
description:
'The Mattermost Team. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
},
{
displayName: 'Channel Name or ID',
name: 'channelId',
type: 'options',
typeOptions: {
loadOptionsMethod: 'getChannelsInTeam',
loadOptionsDependsOn: ['teamId'],
},
options: [],
default: '',
required: true,
displayOptions: {
show: {
operation: ['members'],
resource: ['channel'],
},
},
description:
'The Mattermost Team. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
},
{
displayName: 'Resolve Data',
name: 'resolveData',
type: 'boolean',
displayOptions: {
show: {
resource: ['channel'],
operation: ['members'],
},
},
default: true,
// eslint-disable-next-line n8n-nodes-base/node-param-description-boolean-without-whether
description:
'By default the response only contain the ID of the user. If this option gets activated, it will resolve the user automatically.',
},
{
displayName: 'Return All',
name: 'returnAll',
type: 'boolean',
displayOptions: {
show: {
operation: ['members'],
resource: ['channel'],
},
},
default: true,
description: 'Whether to return all results or only up to a given limit',
},
{
displayName: 'Limit',
name: 'limit',
type: 'number',
displayOptions: {
show: {
operation: ['members'],
resource: ['channel'],
returnAll: [false],
},
},
typeOptions: {
minValue: 1,
maxValue: 100,
},
default: 100,
description: 'Max number of results to return',
},
];
@@ -0,0 +1,44 @@
import type { IExecuteFunctions, IDataObject, INodeExecutionData } from 'n8n-workflow';
import { apiRequest, apiRequestAllItems } from '../../../transport';
export async function members(
this: IExecuteFunctions,
index: number,
): Promise<INodeExecutionData[]> {
const channelId = this.getNodeParameter('channelId', index) as string;
const returnAll = this.getNodeParameter('returnAll', index);
const resolveData = this.getNodeParameter('resolveData', index);
const limit = this.getNodeParameter('limit', index, 0);
const body = {} as IDataObject;
const qs = {} as IDataObject;
const requestMethod = 'GET';
const endpoint = `channels/${channelId}/members`;
if (!returnAll) {
qs.per_page = this.getNodeParameter('limit', index);
}
let responseData;
if (returnAll) {
responseData = await apiRequestAllItems.call(this, requestMethod, endpoint, body, qs);
} else {
responseData = await apiRequest.call(this, requestMethod, endpoint, body, qs);
if (limit) {
responseData = responseData.slice(0, limit);
}
if (resolveData) {
const userIds: string[] = [];
for (const data of responseData) {
userIds.push(data.user_id as string);
}
if (userIds.length > 0) {
responseData = await apiRequest.call(this, 'POST', 'users/ids', userIds, qs);
}
}
}
return this.helpers.returnJsonArray(responseData as IDataObject[]);
}
@@ -0,0 +1,4 @@
import { channelMembersDescription as description } from './description';
import { members as execute } from './execute';
export { description, execute };
@@ -0,0 +1,18 @@
import type { ChannelProperties } from '../../Interfaces';
export const channelRestoreDescription: ChannelProperties = [
{
displayName: 'Channel ID',
name: 'channelId',
type: 'string',
default: '',
required: true,
displayOptions: {
show: {
operation: ['restore'],
resource: ['channel'],
},
},
description: 'The ID of the channel to restore',
},
];
@@ -0,0 +1,19 @@
import type { IExecuteFunctions, IDataObject, INodeExecutionData } from 'n8n-workflow';
import { apiRequest } from '../../../transport';
export async function restore(
this: IExecuteFunctions,
index: number,
): Promise<INodeExecutionData[]> {
const channelId = this.getNodeParameter('channelId', index) as string;
const body = {} as IDataObject;
const qs = {} as IDataObject;
const requestMethod = 'POST';
const endpoint = `channels/${channelId}/restore`;
const responseData = await apiRequest.call(this, requestMethod, endpoint, body, qs);
return this.helpers.returnJsonArray(responseData as IDataObject[]);
}
@@ -0,0 +1,4 @@
import { channelRestoreDescription as description } from './description';
import { restore as execute } from './execute';
export { description, execute };
@@ -0,0 +1,69 @@
import type { ChannelProperties } from '../../Interfaces';
export const channelSearchDescription: ChannelProperties = [
{
displayName: 'Team Name or ID',
name: 'teamId',
type: 'options',
typeOptions: {
loadOptionsMethod: 'getTeams',
},
options: [],
default: '',
required: true,
displayOptions: {
show: {
operation: ['search'],
resource: ['channel'],
},
},
description:
'The Mattermost Team. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
},
{
displayName: 'Search Term',
name: 'term',
type: 'string',
default: '',
placeholder: 'General',
displayOptions: {
show: {
operation: ['search'],
resource: ['channel'],
},
},
required: true,
description: 'The search term for Channels in a Team',
},
{
displayName: 'Return All',
name: 'returnAll',
type: 'boolean',
default: false,
description: 'Whether to return all results or only up to a given limit',
displayOptions: {
show: {
operation: ['search'],
resource: ['channel'],
},
},
},
{
displayName: 'Limit',
name: 'limit',
type: 'number',
default: 100,
description: 'Max number of results to return',
typeOptions: {
minValue: 1,
maxValue: 100,
},
displayOptions: {
show: {
operation: ['search'],
resource: ['channel'],
returnAll: [false],
},
},
},
];
@@ -0,0 +1,26 @@
import type { IExecuteFunctions, IDataObject, INodeExecutionData } from 'n8n-workflow';
import { apiRequest } from '../../../transport';
export async function search(
this: IExecuteFunctions,
index: number,
): Promise<INodeExecutionData[]> {
const body = {} as IDataObject;
const qs = {} as IDataObject;
const requestMethod = 'POST';
const teamId = this.getNodeParameter('teamId', index);
const returnAll = this.getNodeParameter('returnAll', 0);
const endpoint = `teams/${teamId}/channels/search`;
body.term = this.getNodeParameter('term', index) as string;
let responseData = await apiRequest.call(this, requestMethod, endpoint, body, qs);
if (!returnAll) {
const limit = this.getNodeParameter('limit', 0);
responseData = responseData.slice(0, limit);
}
return this.helpers.returnJsonArray(responseData as IDataObject[]);
}
@@ -0,0 +1,4 @@
import { channelSearchDescription as description } from './description';
import { search as execute } from './execute';
export { description, execute };
@@ -0,0 +1,23 @@
import type { ChannelProperties } from '../../Interfaces';
export const channelStatisticsDescription: ChannelProperties = [
{
displayName: 'Channel Name or ID',
name: 'channelId',
type: 'options',
typeOptions: {
loadOptionsMethod: 'getChannels',
},
options: [],
default: '',
required: true,
displayOptions: {
show: {
operation: ['statistics'],
resource: ['channel'],
},
},
description:
'The ID of the channel to get the statistics from. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
},
];
@@ -0,0 +1,19 @@
import type { IExecuteFunctions, IDataObject, INodeExecutionData } from 'n8n-workflow';
import { apiRequest } from '../../../transport';
export async function statistics(
this: IExecuteFunctions,
index: number,
): Promise<INodeExecutionData[]> {
const channelId = this.getNodeParameter('channelId', index) as string;
const body = {} as IDataObject;
const qs = {} as IDataObject;
const requestMethod = 'GET';
const endpoint = `channels/${channelId}/stats`;
const responseData = await apiRequest.call(this, requestMethod, endpoint, body, qs);
return this.helpers.returnJsonArray(responseData as IDataObject[]);
}
@@ -0,0 +1,4 @@
import { channelStatisticsDescription as description } from './description';
import { statistics as execute } from './execute';
export { description, execute };
@@ -0,0 +1,18 @@
import type { MessageProperties } from '../../Interfaces';
export const messageDeleteDescription: MessageProperties = [
{
displayName: 'Post ID',
name: 'postId',
type: 'string',
required: true,
displayOptions: {
show: {
resource: ['message'],
operation: ['delete'],
},
},
default: '',
description: 'ID of the post to delete',
},
];
@@ -0,0 +1,16 @@
import type { IExecuteFunctions, IDataObject, INodeExecutionData } from 'n8n-workflow';
import { apiRequest } from '../../../transport';
export async function del(this: IExecuteFunctions, index: number): Promise<INodeExecutionData[]> {
const postId = this.getNodeParameter('postId', index) as string;
const body = {} as IDataObject;
const qs = {} as IDataObject;
const requestMethod = 'DELETE';
const endpoint = `posts/${postId}`;
const responseData = await apiRequest.call(this, requestMethod, endpoint, body, qs);
return this.helpers.returnJsonArray(responseData as IDataObject[]);
}
@@ -0,0 +1,4 @@
import { messageDeleteDescription as description } from './description';
import { del as execute } from './execute';
export { description, execute };
@@ -0,0 +1,45 @@
import type { INodeProperties } from 'n8n-workflow';
import * as del from './del';
import * as post from './post';
import * as postEphemeral from './postEphemeral';
export { del as delete, post, postEphemeral };
export const descriptions: INodeProperties[] = [
{
displayName: 'Operation',
name: 'operation',
type: 'options',
noDataExpression: true,
displayOptions: {
show: {
resource: ['message'],
},
},
options: [
{
name: 'Delete',
value: 'delete',
description: 'Soft delete a post, by marking the post as deleted in the database',
action: 'Delete a message',
},
{
name: 'Post',
value: 'post',
description: 'Post a message into a channel',
action: 'Post a message',
},
{
name: 'Post Ephemeral',
value: 'postEphemeral',
description: 'Post an ephemeral message into a channel',
action: 'Post an ephemeral message',
},
],
default: 'post',
},
...del.description,
...post.description,
...postEphemeral.description,
];
@@ -0,0 +1,382 @@
import type { MessageProperties } from '../../Interfaces';
export const messagePostDescription: MessageProperties = [
{
displayName: 'Channel Name or ID',
name: 'channelId',
type: 'options',
typeOptions: {
loadOptionsMethod: 'getChannels',
},
options: [],
default: '',
required: true,
displayOptions: {
show: {
operation: ['post'],
resource: ['message'],
},
},
description:
'The ID of the channel to post to. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
},
{
displayName: 'Message',
name: 'message',
type: 'string',
default: '',
displayOptions: {
show: {
operation: ['post'],
resource: ['message'],
},
},
description: 'The text to send',
},
{
displayName: 'Attachments',
name: 'attachments',
type: 'collection',
typeOptions: {
multipleValues: true,
multipleValueButtonText: 'Add attachment',
},
displayOptions: {
show: {
operation: ['post'],
resource: ['message'],
},
},
default: {},
description: 'The attachment to add',
placeholder: 'Add attachment item',
options: [
{
displayName: 'Actions',
name: 'actions',
placeholder: 'Add Actions',
description:
'Actions to add to message. More information can be found <a href="https://docs.mattermost.com/developer/interactive-messages.html" target="_blank">here</a>.',
type: 'fixedCollection',
typeOptions: {
multipleValues: true,
},
default: {},
options: [
{
displayName: 'Item',
name: 'item',
values: [
{
displayName: 'Type',
name: 'type',
type: 'options',
options: [
{
name: 'Button',
value: 'button',
},
{
name: 'Select',
value: 'select',
},
],
default: 'button',
description: 'The type of the action',
},
{
displayName: 'Data Source',
name: 'data_source',
type: 'options',
displayOptions: {
show: {
type: ['select'],
},
},
options: [
{
name: 'Channels',
value: 'channels',
},
{
name: 'Custom',
value: 'custom',
},
{
name: 'Users',
value: 'users',
},
],
default: 'custom',
description: 'The type of the action',
},
{
displayName: 'Options',
name: 'options',
placeholder: 'Add option',
description: 'Adds a new option to select field',
type: 'fixedCollection',
typeOptions: {
multipleValues: true,
},
displayOptions: {
show: {
data_source: ['custom'],
type: ['select'],
},
},
default: {},
options: [
{
name: 'option',
displayName: 'Option',
default: {},
values: [
{
displayName: 'Option Text',
name: 'text',
type: 'string',
default: '',
description: 'Text of the option',
},
{
displayName: 'Option Value',
name: 'value',
type: 'string',
default: '',
description: 'Value of the option',
},
],
},
],
},
{
displayName: 'Name',
name: 'name',
type: 'string',
default: '',
description: 'Name of the Action',
},
{
displayName: 'Integration',
name: 'integration',
placeholder: 'Add Integration',
description: 'Integration to add to message',
type: 'fixedCollection',
typeOptions: {
multipleValues: false,
},
default: {},
options: [
{
displayName: 'Item',
name: 'item',
default: {},
values: [
{
displayName: 'URL',
name: 'url',
type: 'string',
default: '',
description: 'URL of the Integration',
},
{
displayName: 'Context',
name: 'context',
placeholder: 'Add Context to Integration',
description: 'Adds a Context values set',
type: 'fixedCollection',
typeOptions: {
multipleValues: true,
},
default: {},
options: [
{
name: 'property',
displayName: 'Property',
default: {},
values: [
{
displayName: 'Property Name',
name: 'name',
type: 'string',
default: '',
description: 'Name of the property to set',
},
{
displayName: 'Property Value',
name: 'value',
type: 'string',
default: '',
description: 'Value of the property to set',
},
],
},
],
},
],
},
],
},
],
},
],
},
{
displayName: 'Author Icon',
name: 'author_icon',
type: 'string',
default: '',
description: 'Icon which should appear for the user',
},
{
displayName: 'Author Link',
name: 'author_link',
type: 'string',
default: '',
description: 'Link for the author',
},
{
displayName: 'Author Name',
name: 'author_name',
type: 'string',
default: '',
description: 'Name that should appear',
},
{
displayName: 'Color',
name: 'color',
type: 'color',
default: '#ff0000',
description: 'Color of the line left of text',
},
{
displayName: 'Fallback Text',
name: 'fallback',
type: 'string',
default: '',
description: 'Required plain-text summary of the attachment',
},
{
displayName: 'Fields',
name: 'fields',
placeholder: 'Add Fields',
description: 'Fields to add to message',
type: 'fixedCollection',
typeOptions: {
multipleValues: true,
},
default: {},
options: [
{
name: 'item',
displayName: 'Item',
values: [
{
displayName: 'Title',
name: 'title',
type: 'string',
default: '',
description: 'Title of the item',
},
{
displayName: 'Value',
name: 'value',
type: 'string',
default: '',
description: 'Value of the item',
},
{
displayName: 'Short',
name: 'short',
type: 'boolean',
default: true,
description: 'Whether items can be displayed next to each other',
},
],
},
],
},
{
displayName: 'Footer',
name: 'footer',
type: 'string',
default: '',
description: 'Text of footer to add',
},
{
displayName: 'Footer Icon',
name: 'footer_icon',
type: 'string',
default: '',
description: 'Icon which should appear next to footer',
},
{
displayName: 'Image URL',
name: 'image_url',
type: 'string',
default: '',
description: 'URL of image',
},
{
displayName: 'Pretext',
name: 'pretext',
type: 'string',
default: '',
description: 'Text which appears before the message block',
},
{
displayName: 'Text',
name: 'text',
type: 'string',
default: '',
description: 'Text to send',
},
{
displayName: 'Thumbnail URL',
name: 'thumb_url',
type: 'string',
default: '',
description: 'URL of thumbnail',
},
{
displayName: 'Title',
name: 'title',
type: 'string',
default: '',
description: 'Title of the message',
},
{
displayName: 'Title Link',
name: 'title_link',
type: 'string',
default: '',
description: 'Link of the title',
},
],
},
{
displayName: 'Other Options',
name: 'otherOptions',
type: 'collection',
displayOptions: {
show: {
operation: ['post'],
resource: ['message'],
},
},
default: {},
description: 'Other options to set',
placeholder: 'Add option',
options: [
{
displayName: 'Parent Post ID',
name: 'root_id',
type: 'string',
default: '',
description:
'If set, the created message will be a threaded reply to the specified parent post ID',
},
],
},
];
@@ -0,0 +1,85 @@
import type { IExecuteFunctions, IDataObject, INodeExecutionData } from 'n8n-workflow';
import { apiRequest } from '../../../transport';
import type { IAttachment } from '../../Interfaces';
export async function post(this: IExecuteFunctions, index: number): Promise<INodeExecutionData[]> {
const body = {} as IDataObject;
const qs = {} as IDataObject;
const requestMethod = 'POST';
const endpoint = 'posts';
body.channel_id = this.getNodeParameter('channelId', index) as string;
body.message = this.getNodeParameter('message', index) as string;
const attachments = this.getNodeParameter('attachments', index, []) as unknown as IAttachment[];
// The node does save the fields data differently than the API
// expects so fix the data befre we send the request
for (const attachment of attachments) {
if (attachment.fields !== undefined) {
if (attachment.fields.item !== undefined) {
// Move the field-content up
// @ts-ignore
attachment.fields = attachment.fields.item;
} else {
// If it does not have any items set remove it
// @ts-ignore
delete attachment.fields;
}
}
}
for (const attachment of attachments) {
if (attachment.actions !== undefined) {
if (attachment.actions.item !== undefined) {
// Move the field-content up
// @ts-ignore
attachment.actions = attachment.actions.item;
} else {
// If it does not have any items set remove it
// @ts-ignore
delete attachment.actions;
}
}
}
for (const attachment of attachments) {
if (Array.isArray(attachment.actions)) {
for (const attaction of attachment.actions) {
if (attaction.type === 'button') {
delete attaction.type;
}
if (attaction.data_source === 'custom') {
delete attaction.data_source;
}
if (attaction.options) {
attaction.options = attaction.options.option;
}
if (attaction.integration.item !== undefined) {
attaction.integration = attaction.integration.item;
if (Array.isArray(attaction.integration.context.property)) {
const tmpcontex = {};
for (const attactionintegprop of attaction.integration.context.property) {
Object.assign(tmpcontex, { [attactionintegprop.name]: attactionintegprop.value });
}
delete attaction.integration.context;
attaction.integration.context = tmpcontex;
}
}
}
}
}
body.props = {
attachments,
};
// Add all the other options to the request
const otherOptions = this.getNodeParameter('otherOptions', index) as IDataObject;
Object.assign(body, otherOptions);
const responseData = await apiRequest.call(this, requestMethod, endpoint, body, qs);
return this.helpers.returnJsonArray(responseData as IDataObject[]);
}
@@ -0,0 +1,4 @@
import { messagePostDescription as description } from './description';
import { post as execute } from './execute';
export { description, execute };
@@ -0,0 +1,54 @@
import type { MessageProperties } from '../../Interfaces';
export const messagePostEphemeralDescription: MessageProperties = [
{
displayName: 'User Name or ID',
name: 'userId',
type: 'options',
typeOptions: {
loadOptionsMethod: 'getUsers',
},
options: [],
default: '',
required: true,
displayOptions: {
show: {
operation: ['postEphemeral'],
resource: ['message'],
},
},
description:
'ID of the user to send the ephemeral message to. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
},
{
displayName: 'Channel Name or ID',
name: 'channelId',
type: 'options',
typeOptions: {
loadOptionsMethod: 'getChannels',
},
default: '',
required: true,
displayOptions: {
show: {
operation: ['postEphemeral'],
resource: ['message'],
},
},
description:
'ID of the channel to send the ephemeral message in. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
},
{
displayName: 'Message',
name: 'message',
type: 'string',
default: '',
displayOptions: {
show: {
operation: ['postEphemeral'],
resource: ['message'],
},
},
description: 'Text to send in the ephemeral message',
},
];
@@ -0,0 +1,24 @@
import type { IExecuteFunctions, IDataObject, INodeExecutionData } from 'n8n-workflow';
import { apiRequest } from '../../../transport';
export async function postEphemeral(
this: IExecuteFunctions,
index: number,
): Promise<INodeExecutionData[]> {
const qs = {} as IDataObject;
const requestMethod = 'POST';
const endpoint = 'posts/ephemeral';
const body = {
user_id: this.getNodeParameter('userId', index),
post: {
channel_id: this.getNodeParameter('channelId', index),
message: this.getNodeParameter('message', index),
},
} as IDataObject;
const responseData = await apiRequest.call(this, requestMethod, endpoint, body, qs);
return this.helpers.returnJsonArray(responseData as IDataObject[]);
}
@@ -0,0 +1,4 @@
import { messagePostEphemeralDescription as description } from './description';
import { postEphemeral as execute } from './execute';
export { description, execute };
@@ -0,0 +1,53 @@
import type { ReactionProperties } from '../../Interfaces';
export const reactionCreateDescription: ReactionProperties = [
{
displayName: 'User Name or ID',
name: 'userId',
type: 'options',
typeOptions: {
loadOptionsMethod: 'getUsers',
},
options: [],
default: '',
required: true,
displayOptions: {
show: {
resource: ['reaction'],
operation: ['create'],
},
},
description:
'ID of the user sending the reaction. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
},
{
displayName: 'Post ID',
name: 'postId',
type: 'string',
default: '',
placeholder: '3moacfqxmbdw38r38fjprh6zsr',
required: true,
displayOptions: {
show: {
resource: ['reaction'],
operation: ['create'],
},
},
description:
'ID of the post to react to. Obtainable from the post link: <code>https://mattermost.internal.n8n.io/[server]/pl/[postId]</code>',
},
{
displayName: 'Emoji Name',
name: 'emojiName',
type: 'string',
default: '',
required: true,
displayOptions: {
show: {
resource: ['reaction'],
operation: ['create'],
},
},
description: 'Emoji to use for this reaction',
},
];
@@ -0,0 +1,22 @@
import type { IExecuteFunctions, IDataObject, INodeExecutionData } from 'n8n-workflow';
import { apiRequest } from '../../../transport';
export async function create(
this: IExecuteFunctions,
index: number,
): Promise<INodeExecutionData[]> {
const qs = {} as IDataObject;
const requestMethod = 'POST';
const endpoint = 'reactions';
const body = {
user_id: this.getNodeParameter('userId', index),
post_id: this.getNodeParameter('postId', index),
emoji_name: (this.getNodeParameter('emojiName', index) as string).replace(/:/g, ''),
create_at: Date.now(),
} as { user_id: string; post_id: string; emoji_name: string; create_at: number };
const responseData = await apiRequest.call(this, requestMethod, endpoint, body, qs);
return this.helpers.returnJsonArray(responseData as IDataObject[]);
}
@@ -0,0 +1,4 @@
import { reactionCreateDescription as description } from './description';
import { create as execute } from './execute';
export { description, execute };
@@ -0,0 +1,53 @@
import type { ReactionProperties } from '../../Interfaces';
export const reactionDeleteDescription: ReactionProperties = [
{
displayName: 'User Name or ID',
name: 'userId',
type: 'options',
typeOptions: {
loadOptionsMethod: 'getUsers',
},
options: [],
default: '',
required: true,
displayOptions: {
show: {
resource: ['reaction'],
operation: ['delete'],
},
},
description:
'ID of the user whose reaction to delete. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
},
{
displayName: 'Post ID',
name: 'postId',
type: 'string',
default: '',
placeholder: '3moacfqxmbdw38r38fjprh6zsr',
required: true,
displayOptions: {
show: {
resource: ['reaction'],
operation: ['delete'],
},
},
description:
'ID of the post whose reaction to delete. Obtainable from the post link: <code>https://mattermost.internal.n8n.io/[server]/pl/[postId]</code>',
},
{
displayName: 'Emoji Name',
name: 'emojiName',
type: 'string',
default: '',
required: true,
displayOptions: {
show: {
resource: ['reaction'],
operation: ['delete'],
},
},
description: 'Name of the emoji to delete',
},
];
@@ -0,0 +1,18 @@
import type { IExecuteFunctions, IDataObject, INodeExecutionData } from 'n8n-workflow';
import { apiRequest } from '../../../transport';
export async function del(this: IExecuteFunctions, index: number): Promise<INodeExecutionData[]> {
const userId = this.getNodeParameter('userId', index) as string;
const postId = this.getNodeParameter('postId', index) as string;
const emojiName = (this.getNodeParameter('emojiName', index) as string).replace(/:/g, '');
const qs = {} as IDataObject;
const requestMethod = 'DELETE';
const endpoint = `users/${userId}/posts/${postId}/reactions/${emojiName}`;
const body = {} as IDataObject;
const responseData = await apiRequest.call(this, requestMethod, endpoint, body, qs);
return this.helpers.returnJsonArray(responseData as IDataObject[]);
}
@@ -0,0 +1,4 @@
import { reactionDeleteDescription as description } from './description';
import { del as execute } from './execute';
export { description, execute };
@@ -0,0 +1,49 @@
import type { ReactionProperties } from '../../Interfaces';
export const reactionGetAllDescription: ReactionProperties = [
{
displayName: 'Post ID',
name: 'postId',
type: 'string',
default: '',
required: true,
displayOptions: {
show: {
resource: ['reaction'],
operation: ['getAll'],
},
},
description: 'One or more (comma-separated) posts to retrieve reactions from',
},
{
displayName: 'Return All',
name: 'returnAll',
type: 'boolean',
displayOptions: {
show: {
operation: ['getAll'],
resource: ['reaction'],
},
},
default: true,
description: 'Whether to return all results or only up to a given limit',
},
{
displayName: 'Limit',
name: 'limit',
type: 'number',
displayOptions: {
show: {
operation: ['getAll'],
resource: ['reaction'],
returnAll: [false],
},
},
typeOptions: {
minValue: 1,
maxValue: 100,
},
default: 100,
description: 'Max number of results to return',
},
];
@@ -0,0 +1,25 @@
import type { IExecuteFunctions, IDataObject, INodeExecutionData } from 'n8n-workflow';
import { apiRequest } from '../../../transport';
export async function getAll(
this: IExecuteFunctions,
index: number,
): Promise<INodeExecutionData[]> {
const postId = this.getNodeParameter('postId', index) as string;
const limit = this.getNodeParameter('limit', 0, 0);
const qs = {} as IDataObject;
const requestMethod = 'GET';
const endpoint = `posts/${postId}/reactions`;
const body = {} as IDataObject;
let responseData = await apiRequest.call(this, requestMethod, endpoint, body, qs);
if (responseData === null) {
return [];
}
if (limit > 0) {
responseData = responseData.slice(0, limit);
}
return this.helpers.returnJsonArray(responseData as IDataObject[]);
}
@@ -0,0 +1,4 @@
import { reactionGetAllDescription as description } from './description';
import { getAll as execute } from './execute';
export { description, execute };
@@ -0,0 +1,45 @@
import type { INodeProperties } from 'n8n-workflow';
import * as create from './create';
import * as del from './del';
import * as getAll from './getAll';
export { create, del as delete, getAll };
export const descriptions: INodeProperties[] = [
{
displayName: 'Operation',
name: 'operation',
type: 'options',
noDataExpression: true,
displayOptions: {
show: {
resource: ['reaction'],
},
},
options: [
{
name: 'Create',
value: 'create',
description: 'Add a reaction to a post',
action: 'Create a reaction',
},
{
name: 'Delete',
value: 'delete',
description: 'Remove a reaction from a post',
action: 'Delete a reaction',
},
{
name: 'Get Many',
value: 'getAll',
description: 'Get many reactions to one or more posts',
action: 'Get many reactions',
},
],
default: 'create',
},
...create.description,
...del.description,
...getAll.description,
];
@@ -0,0 +1,55 @@
import type { IExecuteFunctions, IDataObject, INodeExecutionData } from 'n8n-workflow';
import * as channel from './channel';
import type { Mattermost } from './Interfaces';
import * as message from './message';
import * as reaction from './reaction';
import * as user from './user';
export async function router(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
const items = this.getInputData();
const operationResult: INodeExecutionData[] = [];
let responseData: IDataObject | IDataObject[] = [];
for (let i = 0; i < items.length; i++) {
const resource = this.getNodeParameter<Mattermost>('resource', i);
let operation = this.getNodeParameter('operation', i);
if (operation === 'del') {
operation = 'delete';
} else if (operation === 'desactive') {
operation = 'deactive';
}
const mattermost = {
resource,
operation,
} as Mattermost;
try {
if (mattermost.resource === 'channel') {
responseData = await channel[mattermost.operation].execute.call(this, i);
} else if (mattermost.resource === 'message') {
responseData = await message[mattermost.operation].execute.call(this, i);
} else if (mattermost.resource === 'reaction') {
responseData = await reaction[mattermost.operation].execute.call(this, i);
} else if (mattermost.resource === 'user') {
responseData = await user[mattermost.operation].execute.call(this, i);
}
const executionData = this.helpers.constructExecutionMetaData(
this.helpers.returnJsonArray(responseData),
{ itemData: { item: i } },
);
operationResult.push(...executionData);
} catch (err) {
if (this.continueOnFail()) {
operationResult.push({ json: this.getInputData(i)[0].json, error: err });
} else {
if (err.context) err.context.itemIndex = i;
throw err;
}
}
}
return [operationResult];
}
@@ -0,0 +1,244 @@
import type { UserProperties } from '../../Interfaces';
export const userCreateDescription: UserProperties = [
{
displayName: 'Username',
name: 'username',
type: 'string',
required: true,
displayOptions: {
show: {
resource: ['user'],
operation: ['create'],
},
},
default: '',
},
{
displayName: 'Auth Service',
name: 'authService',
type: 'options',
options: [
{
name: 'Email',
value: 'email',
},
{
name: 'Gitlab',
value: 'gitlab',
},
{
name: 'Google',
value: 'google',
},
{
name: 'LDAP',
value: 'ldap',
},
{
name: 'Office365',
value: 'office365',
},
{
name: 'SAML',
value: 'saml',
},
],
displayOptions: {
show: {
resource: ['user'],
operation: ['create'],
},
},
default: '',
},
{
displayName: 'Auth Data',
name: 'authData',
displayOptions: {
show: {
resource: ['user'],
operation: ['create'],
},
hide: {
authService: ['email'],
},
},
type: 'string',
default: '',
},
{
displayName: 'Email',
name: 'email',
type: 'string',
placeholder: 'name@email.com',
default: '',
displayOptions: {
show: {
resource: ['user'],
operation: ['create'],
authService: ['email'],
},
},
},
{
displayName: 'Password',
name: 'password',
type: 'string',
typeOptions: {
password: true,
},
displayOptions: {
show: {
resource: ['user'],
operation: ['create'],
authService: ['email'],
},
},
default: '',
description: 'The password used for email authentication',
},
{
displayName: 'Additional Fields',
name: 'additionalFields',
type: 'collection',
placeholder: 'Add Field',
displayOptions: {
show: {
operation: ['create'],
resource: ['user'],
},
},
default: {},
options: [
{
displayName: 'First Name',
name: 'first_name',
type: 'string',
default: '',
},
{
displayName: 'Last Name',
name: 'last_name',
type: 'string',
default: '',
},
{
displayName: 'Locale',
name: 'locale',
type: 'string',
default: '',
},
{
displayName: 'Nickname',
name: 'nickname',
type: 'string',
default: '',
},
{
displayName: 'Notification Settings',
name: 'notificationUi',
type: 'fixedCollection',
placeholder: 'Add Notification Setting',
default: {},
typeOptions: {
multipleValues: false,
},
options: [
{
displayName: 'Notify',
name: 'notificationValues',
values: [
{
displayName: 'Channel',
name: 'channel',
type: 'boolean',
default: true,
description:
'Whether to enable channel-wide notifications (@channel, @all, etc.), "false" to disable. Defaults to "true".',
},
{
displayName: 'Desktop',
name: 'desktop',
type: 'options',
options: [
{
name: 'All',
value: 'all',
description: 'Notifications for all activity',
},
{
name: 'Mention',
value: 'mention',
description: 'Mentions and direct messages only',
},
{
name: 'None',
value: 'none',
description: 'Mentions and direct messages only',
},
],
default: 'all',
},
{
displayName: 'Desktop Sound',
name: 'desktop_sound',
type: 'boolean',
default: true,
description:
'Whether to enable sound on desktop notifications, "false" to disable. Defaults to "true".',
},
{
displayName: 'Email',
name: 'email',
type: 'boolean',
default: false,
description:
'Whether to enable email notifications, "false" to disable. Defaults to "false".',
},
{
displayName: 'First Name',
name: 'first_name',
type: 'boolean',
default: false,
description:
'Whether to enable mentions for first name. Defaults to "true" if a first name is set, "false" otherwise.',
},
{
displayName: 'Mention Keys',
name: 'mention_keys',
type: 'string',
default: '',
description:
'A comma-separated list of words to count as mentions. Defaults to username and @username.',
},
{
displayName: 'Push',
name: 'push',
type: 'options',
options: [
{
name: 'All',
value: 'all',
description: 'Notifications for all activity',
},
{
name: 'Mention',
value: 'mention',
description: 'Mentions and direct messages only',
},
{
name: 'None',
value: 'none',
description: 'Mentions and direct messages only',
},
],
default: 'mention',
},
],
},
],
},
],
},
];
@@ -0,0 +1,37 @@
import type { IExecuteFunctions, IDataObject, INodeExecutionData } from 'n8n-workflow';
import { apiRequest } from '../../../transport';
export async function create(
this: IExecuteFunctions,
index: number,
): Promise<INodeExecutionData[]> {
const username = this.getNodeParameter('username', index) as string;
const authService = this.getNodeParameter('authService', index) as string;
const additionalFields = this.getNodeParameter('additionalFields', index);
const qs = {} as IDataObject;
const requestMethod = 'POST';
const endpoint = 'users';
const body = {} as IDataObject;
body.auth_service = authService;
body.username = username;
Object.assign(body, additionalFields);
if (body.notificationUi) {
body.notify_props = (body.notificationUi as IDataObject).notificationValues;
}
if (authService === 'email') {
body.email = this.getNodeParameter('email', index) as string;
body.password = this.getNodeParameter('password', index) as string;
} else {
body.auth_data = this.getNodeParameter('authData', index) as string;
}
const responseData = await apiRequest.call(this, requestMethod, endpoint, body, qs);
return this.helpers.returnJsonArray(responseData as IDataObject[]);
}
@@ -0,0 +1,4 @@
import { userCreateDescription as description } from './description';
import { create as execute } from './execute';
export { description, execute };
@@ -0,0 +1,18 @@
import type { UserProperties } from '../../Interfaces';
export const userDeactiveDescription: UserProperties = [
{
displayName: 'User ID',
name: 'userId',
type: 'string',
required: true,
displayOptions: {
show: {
resource: ['user'],
operation: ['deactive'],
},
},
default: '',
description: 'User GUID',
},
];
@@ -0,0 +1,18 @@
import type { IExecuteFunctions, IDataObject, INodeExecutionData } from 'n8n-workflow';
import { apiRequest } from '../../../transport';
export async function deactive(
this: IExecuteFunctions,
index: number,
): Promise<INodeExecutionData[]> {
const userId = this.getNodeParameter('userId', index) as string;
const qs = {} as IDataObject;
const requestMethod = 'DELETE';
const endpoint = `users/${userId}`;
const body = {} as IDataObject;
const responseData = await apiRequest.call(this, requestMethod, endpoint, body, qs);
return this.helpers.returnJsonArray(responseData as IDataObject[]);
}
@@ -0,0 +1,4 @@
import { userDeactiveDescription as description } from './description';
import { deactive as execute } from './execute';
export { description, execute };
@@ -0,0 +1,103 @@
import type { UserProperties } from '../../Interfaces';
export const userGetAllDescription: UserProperties = [
{
displayName: 'Return All',
name: 'returnAll',
type: 'boolean',
displayOptions: {
show: {
resource: ['user'],
operation: ['getAll'],
},
},
default: true,
description: 'Whether to return all results or only up to a given limit',
},
{
displayName: 'Limit',
name: 'limit',
type: 'number',
displayOptions: {
show: {
resource: ['user'],
operation: ['getAll'],
returnAll: [false],
},
},
typeOptions: {
minValue: 1,
maxValue: 100,
},
default: 100,
description: 'Max number of results to return',
},
{
displayName: 'Additional Fields',
name: 'additionalFields',
type: 'collection',
placeholder: 'Add Field',
displayOptions: {
show: {
resource: ['user'],
operation: ['getAll'],
},
},
default: {},
options: [
{
displayName: 'In Channel',
name: 'inChannel',
type: 'string',
default: '',
description: 'The ID of the channel to get users for',
},
{
displayName: 'In Team',
name: 'inTeam',
type: 'string',
default: '',
description: 'The ID of the team to get users for',
},
{
displayName: 'Not In Team',
name: 'notInTeam',
type: 'string',
default: '',
description: 'The ID of the team to exclude users for',
},
{
displayName: 'Not In Channel',
name: 'notInChannel',
type: 'string',
default: '',
description: 'The ID of the channel to exclude users for',
},
{
displayName: 'Sort',
name: 'sort',
type: 'options',
options: [
{
name: 'Created At',
value: 'createdAt',
},
{
name: 'Last Activity At',
value: 'lastActivityAt',
},
{
name: 'Status',
value: 'status',
},
{
name: 'Username',
value: 'username',
},
],
default: 'username',
description: 'The ID of the channel to exclude users for',
},
],
},
];
@@ -0,0 +1,111 @@
import { snakeCase } from 'change-case';
import type { IExecuteFunctions, IDataObject, INodeExecutionData } from 'n8n-workflow';
import { NodeOperationError } from 'n8n-workflow';
import { apiRequest, apiRequestAllItems } from '../../../transport';
export async function getAll(
this: IExecuteFunctions,
index: number,
): Promise<INodeExecutionData[]> {
const returnAll = this.getNodeParameter('returnAll', index);
const additionalFields = this.getNodeParameter('additionalFields', index);
const qs = {} as IDataObject;
const requestMethod = 'GET';
const endpoint = '/users';
const body = {} as IDataObject;
if (additionalFields.inTeam) {
qs.in_team = additionalFields.inTeam;
}
if (additionalFields.notInTeam) {
qs.not_in_team = additionalFields.notInTeam;
}
if (additionalFields.inChannel) {
qs.in_channel = additionalFields.inChannel;
}
if (additionalFields.notInChannel) {
qs.not_in_channel = additionalFields.notInChannel;
}
if (additionalFields.sort) {
qs.sort = snakeCase(additionalFields.sort as string);
}
const validRules = {
inTeam: ['last_activity_at', 'created_at', 'username'],
inChannel: ['status', 'username'],
};
if (additionalFields.sort) {
if (additionalFields.inTeam !== undefined || additionalFields.inChannel !== undefined) {
if (
additionalFields.inTeam !== undefined &&
!validRules.inTeam.includes(snakeCase(additionalFields.sort as string))
) {
throw new NodeOperationError(
this.getNode(),
`When In Team is set the only valid values for sorting are ${validRules.inTeam.join(
',',
)}`,
{ itemIndex: index },
);
}
if (
additionalFields.inChannel !== undefined &&
!validRules.inChannel.includes(snakeCase(additionalFields.sort as string))
) {
throw new NodeOperationError(
this.getNode(),
`When In Channel is set the only valid values for sorting are ${validRules.inChannel.join(
',',
)}`,
{ itemIndex: index },
);
}
if (additionalFields.inChannel === '' && additionalFields.sort !== 'username') {
throw new NodeOperationError(
this.getNode(),
'When sort is different than username In Channel must be set',
{ itemIndex: index },
);
}
if (additionalFields.inTeam === '' && additionalFields.sort !== 'username') {
throw new NodeOperationError(
this.getNode(),
'When sort is different than username In Team must be set',
{ itemIndex: index },
);
}
} else {
throw new NodeOperationError(
this.getNode(),
"When sort is defined either 'in team' or 'in channel' must be defined",
{ itemIndex: index },
);
}
}
if (additionalFields.sort === 'username') {
qs.sort = '';
}
if (!returnAll) {
qs.per_page = this.getNodeParameter('limit', index);
}
let responseData;
if (returnAll) {
responseData = await apiRequestAllItems.call(this, requestMethod, endpoint, body, qs);
} else {
responseData = await apiRequest.call(this, requestMethod, endpoint, body, qs);
}
return this.helpers.returnJsonArray(responseData as IDataObject[]);
}
@@ -0,0 +1,4 @@
import { userGetAllDescription as description } from './description';
import { getAll as execute } from './execute';
export { description, execute };
@@ -0,0 +1,19 @@
import type { UserProperties } from '../../Interfaces';
export const userGetByEmailDescription: UserProperties = [
{
displayName: 'Email',
name: 'email',
type: 'string',
placeholder: 'name@email.com',
required: true,
displayOptions: {
show: {
resource: ['user'],
operation: ['getByEmail'],
},
},
default: '',
description: "User's email",
},
];
@@ -0,0 +1,19 @@
import type { IExecuteFunctions, IDataObject, INodeExecutionData } from 'n8n-workflow';
import { apiRequest } from '../../../transport';
export async function getByEmail(
this: IExecuteFunctions,
index: number,
): Promise<INodeExecutionData[]> {
const email = this.getNodeParameter('email', index) as string;
const qs = {} as IDataObject;
const requestMethod = 'GET';
const endpoint = `users/email/${email}`;
const body = {} as IDataObject;
const responseData = await apiRequest.call(this, requestMethod, endpoint, body, qs);
return this.helpers.returnJsonArray(responseData as IDataObject[]);
}
@@ -0,0 +1,4 @@
import { userGetByEmailDescription as description } from './description';
import { getByEmail as execute } from './execute';
export { description, execute };
@@ -0,0 +1,41 @@
import type { UserProperties } from '../../Interfaces';
export const userGetByIdDescription: UserProperties = [
{
displayName: 'User IDs',
name: 'userIds',
type: 'string',
required: true,
displayOptions: {
show: {
resource: ['user'],
operation: ['getById'],
},
},
default: '',
description: "User's ID",
},
{
displayName: 'Additional Fields',
name: 'additionalFields',
type: 'collection',
placeholder: 'Add Field',
displayOptions: {
show: {
resource: ['user'],
operation: ['getById'],
},
},
default: {},
options: [
{
displayName: 'Since',
name: 'since',
type: 'dateTime',
default: '',
description:
'Only return users that have been modified since the given Unix timestamp (in milliseconds)',
},
],
},
];
@@ -0,0 +1,23 @@
import type { IExecuteFunctions, IDataObject, INodeExecutionData } from 'n8n-workflow';
import { apiRequest } from '../../../transport';
export async function getById(
this: IExecuteFunctions,
index: number,
): Promise<INodeExecutionData[]> {
const qs = {} as IDataObject;
const requestMethod = 'POST';
const endpoint = 'users/ids';
const userIds = (this.getNodeParameter('userIds', index) as string).split(',');
const additionalFields = this.getNodeParameter('additionalFields', index);
const body = userIds;
if (additionalFields.since) {
qs.since = new Date(additionalFields.since as string).getTime();
}
const responseData = await apiRequest.call(this, requestMethod, endpoint, body, qs);
return this.helpers.returnJsonArray(responseData as IDataObject[]);
}
@@ -0,0 +1,4 @@
import { userGetByIdDescription as description } from './description';
import { getById as execute } from './execute';
export { description, execute };
@@ -0,0 +1,70 @@
import type { INodeProperties } from 'n8n-workflow';
import * as create from './create';
import * as deactive from './deactive';
import * as getAll from './getAll';
import * as getByEmail from './getByEmail';
import * as getById from './getById';
import * as invite from './invite';
export { create, deactive, getAll, getByEmail, getById, invite };
export const descriptions: INodeProperties[] = [
{
displayName: 'Operation',
name: 'operation',
type: 'options',
noDataExpression: true,
displayOptions: {
show: {
resource: ['user'],
},
},
options: [
{
name: 'Create',
value: 'create',
description: 'Create a new user',
action: 'Create a user',
},
{
name: 'Deactive',
value: 'deactive',
description:
'Deactivates the user and revokes all its sessions by archiving its user object',
action: 'Deactivate a user',
},
{
name: 'Get By Email',
value: 'getByEmail',
description: 'Get a user by email',
action: 'Get a user by email',
},
{
name: 'Get By ID',
value: 'getById',
description: 'Get a user by ID',
action: 'Get a user by ID',
},
{
name: 'Get Many',
value: 'getAll',
description: 'Retrieve many users',
action: 'Get many users',
},
{
name: 'Invite',
value: 'invite',
description: 'Invite user to team',
action: 'Invite a user',
},
],
default: '',
},
...create.description,
...deactive.description,
...getAll.description,
...getByEmail.description,
...getById.description,
...invite.description,
];
@@ -0,0 +1,36 @@
import type { UserProperties } from '../../Interfaces';
export const userInviteDescription: UserProperties = [
{
displayName: 'Team Name or ID',
name: 'teamId',
type: 'options',
description:
'Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>',
typeOptions: {
loadOptionsMethod: 'getTeams',
},
required: true,
displayOptions: {
show: {
resource: ['user'],
operation: ['invite'],
},
},
default: '',
},
{
displayName: 'Emails',
name: 'emails',
type: 'string',
required: true,
displayOptions: {
show: {
resource: ['user'],
operation: ['invite'],
},
},
default: '',
description: "User's email. Multiple emails can be set separated by comma.",
},
];
@@ -0,0 +1,21 @@
import type { IExecuteFunctions, IDataObject, INodeExecutionData } from 'n8n-workflow';
import { apiRequest } from '../../../transport';
export async function invite(
this: IExecuteFunctions,
index: number,
): Promise<INodeExecutionData[]> {
const teamId = this.getNodeParameter('teamId', index) as string;
const emails = (this.getNodeParameter('emails', index) as string).split(',');
const qs = {} as IDataObject;
const requestMethod = 'POST';
const endpoint = `teams/${teamId}/invite/email`;
const body = emails;
const responseData = await apiRequest.call(this, requestMethod, endpoint, body, qs);
return this.helpers.returnJsonArray(responseData as IDataObject[]);
}
@@ -0,0 +1,4 @@
import { userInviteDescription as description } from './description';
import { invite as execute } from './execute';
export { description, execute };
@@ -0,0 +1,59 @@
/* eslint-disable n8n-nodes-base/node-filename-against-convention */
import { NodeConnectionTypes, type INodeTypeDescription } from 'n8n-workflow';
import * as channel from './channel';
import * as message from './message';
import * as reaction from './reaction';
import * as user from './user';
export const versionDescription: INodeTypeDescription = {
displayName: 'Mattermost',
name: 'mattermost',
icon: 'file:mattermost.svg',
group: ['output'],
version: 1,
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
description: 'Sends data to Mattermost',
defaults: {
name: 'Mattermost',
},
inputs: [NodeConnectionTypes.Main],
outputs: [NodeConnectionTypes.Main],
credentials: [
{
name: 'mattermostApi',
required: true,
},
],
properties: [
{
displayName: 'Resource',
name: 'resource',
type: 'options',
noDataExpression: true,
options: [
{
name: 'Channel',
value: 'channel',
},
{
name: 'Message',
value: 'message',
},
{
name: 'Reaction',
value: 'reaction',
},
{
name: 'User',
value: 'user',
},
],
default: 'message',
},
...channel.descriptions,
...message.descriptions,
...reaction.descriptions,
...user.descriptions,
],
};
File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 6.4 KiB

@@ -0,0 +1 @@
export * as loadOptions from './loadOptions';
@@ -0,0 +1,159 @@
import type { IDataObject, ILoadOptionsFunctions, INodePropertyOptions } from 'n8n-workflow';
import { NodeOperationError } from 'n8n-workflow';
import { apiRequestAllItems } from '../transport';
// Get all the available channels
export async function getChannels(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
const endpoint = 'channels';
const responseData = await apiRequestAllItems.call(this, 'GET', endpoint, {});
if (responseData === undefined) {
throw new NodeOperationError(this.getNode(), 'No data got returned');
}
const returnData: INodePropertyOptions[] = [];
let name: string;
for (const data of responseData) {
if (data.delete_at !== 0 || !data.display_name || !data.name) {
continue;
}
name = `${data.team_display_name} - ${data.display_name || data.name} (${
data.type === 'O' ? 'public' : 'private'
})`;
returnData.push({
name,
value: data.id as string,
});
}
returnData.sort((a, b) => {
if (a.name < b.name) {
return -1;
}
if (a.name > b.name) {
return 1;
}
return 0;
});
return returnData;
}
// Get all the channels in a team
export async function getChannelsInTeam(
this: ILoadOptionsFunctions,
): Promise<INodePropertyOptions[]> {
const teamId = this.getCurrentNodeParameter('teamId');
const endpoint = `users/me/teams/${teamId}/channels`;
const responseData = await apiRequestAllItems.call(this, 'GET', endpoint, {});
if (responseData === undefined) {
throw new NodeOperationError(this.getNode(), 'No data got returned');
}
const returnData: INodePropertyOptions[] = [];
let name: string;
for (const data of responseData) {
if (data.delete_at !== 0 || !data.display_name || !data.name) {
continue;
}
const channelTypes: IDataObject = {
D: 'direct',
G: 'group',
O: 'public',
P: 'private',
};
name = `${data.display_name} (${channelTypes[data.type as string]})`;
returnData.push({
name,
value: data.id as string,
});
}
returnData.sort((a, b) => {
if (a.name < b.name) {
return -1;
}
if (a.name > b.name) {
return 1;
}
return 0;
});
return returnData;
}
export async function getTeams(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
const endpoint = 'users/me/teams';
const responseData = await apiRequestAllItems.call(this, 'GET', endpoint, {});
if (responseData === undefined) {
throw new NodeOperationError(this.getNode(), 'No data got returned');
}
const returnData: INodePropertyOptions[] = [];
let name: string;
for (const data of responseData) {
if (data.delete_at !== 0) {
continue;
}
name = `${data.display_name} (${data.type === 'O' ? 'public' : 'private'})`;
returnData.push({
name,
value: data.id as string,
});
}
returnData.sort((a, b) => {
if (a.name < b.name) {
return -1;
}
if (a.name > b.name) {
return 1;
}
return 0;
});
return returnData;
}
export async function getUsers(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
const endpoint = 'users';
const responseData = await apiRequestAllItems.call(this, 'GET', endpoint, {});
if (responseData === undefined) {
throw new NodeOperationError(this.getNode(), 'No data got returned');
}
const returnData: INodePropertyOptions[] = [];
for (const data of responseData) {
if (data.delete_at !== 0) {
continue;
}
returnData.push({
name: data.username as string,
value: data.id as string,
});
}
returnData.sort((a, b) => {
if (a.name < b.name) {
return -1;
}
if (a.name > b.name) {
return 1;
}
return 0;
});
return returnData;
}
@@ -0,0 +1,58 @@
import type {
IExecuteFunctions,
IHookFunctions,
ILoadOptionsFunctions,
GenericValue,
IDataObject,
IHttpRequestMethods,
IHttpRequestOptions,
} from 'n8n-workflow';
/**
* Make an API request to Mattermost
*/
export async function apiRequest(
this: IHookFunctions | IExecuteFunctions | ILoadOptionsFunctions,
method: IHttpRequestMethods,
endpoint: string,
body: IDataObject | GenericValue | GenericValue[] = {},
query: IDataObject = {},
) {
const credentials = await this.getCredentials('mattermostApi');
const baseUrl = (credentials.baseUrl as string).replace(/\/$/, '');
const options: IHttpRequestOptions = {
method,
body,
qs: query,
url: `${baseUrl}/api/v4/${endpoint}`,
headers: {
'content-type': 'application/json; charset=utf-8',
},
skipSslCertificateValidation: credentials.allowUnauthorizedCerts as boolean,
};
return await this.helpers.httpRequestWithAuthentication.call(this, 'mattermostApi', options);
}
export async function apiRequestAllItems(
this: IExecuteFunctions | ILoadOptionsFunctions,
method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'HEAD',
endpoint: string,
body: IDataObject = {},
query: IDataObject = {},
) {
const returnData: IDataObject[] = [];
let responseData;
query.page = 0;
query.per_page = 100;
do {
responseData = await apiRequest.call(this, method, endpoint, body, query);
query.page++;
returnData.push.apply(returnData, responseData as IDataObject[]);
} while (responseData.length !== 0);
return returnData;
}