From 4573d503dc01462fac6187ce8dc0d51929d186f6 Mon Sep 17 00:00:00 2001 From: Jan Date: Mon, 12 Oct 2020 10:05:16 +0200 Subject: [PATCH] :sparkles: Add matrix integration (#1046) * Added Matrix integration node * fix: Improve code quality and add new operation - Changed operation names to match casing (all camelCase) - Ordering operation names to be alphabetical - Creating a read all operation to fetch all messages from a room - Added node subtitle * fix: add element index so that expressions work on multiple items * feature: added possibility to upload and send media to Matrix - Also replacing Promises.all() + Array.map() For a regular for as it messes up ordering * refactor: merging upload + send Media in a single action * refactor: improved code quality and endpoints - Removed sync entirely as a better way to retrieve messages is now implemeented - Added rooms dropdown to operations - Added option to paginate or retrieve all room messages - Removed option to upload media from text contents. Only files are accepted now - Room members has bem moved from the Rooms resource to a standalone with Get All operation * :zap: Small improvements * :zap: Added filters to get messages * :zap: Minor improvements to Matrix-Integration Co-authored-by: Omar Ajoue Co-authored-by: ricardo --- .../credentials/MatrixApi.credentials.ts | 19 ++ .../nodes/Matrix/AccountDescription.ts | 27 ++ .../nodes/Matrix/EventDescription.ts | 73 +++++ .../nodes/Matrix/GenericFunctions.ts | 239 +++++++++++++++ .../nodes-base/nodes/Matrix/Matrix.node.ts | 172 +++++++++++ .../nodes/Matrix/MediaDescription.ts | 103 +++++++ .../nodes/Matrix/MessageDescription.ts | 180 ++++++++++++ .../nodes/Matrix/RoomDescription.ts | 277 ++++++++++++++++++ .../nodes/Matrix/RoomMemberDescription.ts | 145 +++++++++ packages/nodes-base/nodes/Matrix/matrix.png | Bin 0 -> 940 bytes packages/nodes-base/package.json | 2 + 11 files changed, 1237 insertions(+) create mode 100644 packages/nodes-base/credentials/MatrixApi.credentials.ts create mode 100644 packages/nodes-base/nodes/Matrix/AccountDescription.ts create mode 100644 packages/nodes-base/nodes/Matrix/EventDescription.ts create mode 100644 packages/nodes-base/nodes/Matrix/GenericFunctions.ts create mode 100644 packages/nodes-base/nodes/Matrix/Matrix.node.ts create mode 100644 packages/nodes-base/nodes/Matrix/MediaDescription.ts create mode 100644 packages/nodes-base/nodes/Matrix/MessageDescription.ts create mode 100644 packages/nodes-base/nodes/Matrix/RoomDescription.ts create mode 100644 packages/nodes-base/nodes/Matrix/RoomMemberDescription.ts create mode 100644 packages/nodes-base/nodes/Matrix/matrix.png diff --git a/packages/nodes-base/credentials/MatrixApi.credentials.ts b/packages/nodes-base/credentials/MatrixApi.credentials.ts new file mode 100644 index 000000000..b03d954d1 --- /dev/null +++ b/packages/nodes-base/credentials/MatrixApi.credentials.ts @@ -0,0 +1,19 @@ +import { + ICredentialType, + NodePropertyTypes, +} from 'n8n-workflow'; + + +export class MatrixApi implements ICredentialType { + name = 'matrixApi'; + displayName = 'Matrix API'; + documentationUrl = 'matrix'; + properties = [ + { + displayName: 'Access Token', + name: 'accessToken', + type: 'string' as NodePropertyTypes, + default: '', + }, + ]; +} diff --git a/packages/nodes-base/nodes/Matrix/AccountDescription.ts b/packages/nodes-base/nodes/Matrix/AccountDescription.ts new file mode 100644 index 000000000..893b11194 --- /dev/null +++ b/packages/nodes-base/nodes/Matrix/AccountDescription.ts @@ -0,0 +1,27 @@ +import { + INodeProperties, +} from 'n8n-workflow'; + +export const accountOperations = [ + { + displayName: 'Operation', + name: 'operation', + type: 'options', + displayOptions: { + show: { + resource: [ + 'account', + ], + }, + }, + options: [ + { + name: 'Me', + value: 'me', + description: "Get current user's account information", + }, + ], + default: 'me', + description: 'The operation to perform.', + }, +] as INodeProperties[]; diff --git a/packages/nodes-base/nodes/Matrix/EventDescription.ts b/packages/nodes-base/nodes/Matrix/EventDescription.ts new file mode 100644 index 000000000..81324a32b --- /dev/null +++ b/packages/nodes-base/nodes/Matrix/EventDescription.ts @@ -0,0 +1,73 @@ +import { + INodeProperties, +} from 'n8n-workflow'; + +export const eventOperations = [ + { + displayName: 'Operation', + name: 'operation', + type: 'options', + displayOptions: { + show: { + resource: [ + 'event', + ], + }, + }, + options: [ + { + name: 'Get', + value: 'get', + description: 'Get single event by ID', + }, + ], + default: 'get', + description: 'The operation to perform.', + }, +] as INodeProperties[]; + + +export const eventFields = [ + + /* -------------------------------------------------------------------------- */ + /* event:get */ + /* -------------------------------------------------------------------------- */ + { + displayName: 'Room ID', + name: 'roomId', + type: 'string', + default: '', + placeholder: '!123abc:matrix.org', + displayOptions: { + show: { + operation: [ + 'get', + ], + resource: [ + 'event', + ], + }, + }, + required: true, + description: 'The room related to the event', + }, + { + displayName: 'Event ID', + name: 'eventId', + type: 'string', + default: '', + placeholder: '$1234abcd:matrix.org', + displayOptions: { + show: { + operation: [ + 'get', + ], + resource: [ + 'event', + ], + }, + }, + required: true, + description: 'The room related to the event', + }, +] as INodeProperties[]; diff --git a/packages/nodes-base/nodes/Matrix/GenericFunctions.ts b/packages/nodes-base/nodes/Matrix/GenericFunctions.ts new file mode 100644 index 000000000..1539cf323 --- /dev/null +++ b/packages/nodes-base/nodes/Matrix/GenericFunctions.ts @@ -0,0 +1,239 @@ +import { + OptionsWithUri, +} from 'request'; + +import { IDataObject } from 'n8n-workflow'; + +import { + BINARY_ENCODING, + IExecuteFunctions, + IExecuteSingleFunctions, + ILoadOptionsFunctions, +} from 'n8n-core'; + +import * as _ from 'lodash'; +import * as uuid from 'uuid/v4'; + + +interface MessageResponse { + chunk: Message[]; +} + +interface Message { + content: object; + room_id: string; + sender: string; + type: string; + user_id: string; + +} + +export async function matrixApiRequest(this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, method: string, resource: string, body: string | object = {}, query: object = {}, headers: {} | undefined = undefined, option: {} = {}): Promise { // tslint:disable-line:no-any + let options: OptionsWithUri = { + method, + headers: headers || { + 'Content-Type': 'application/json; charset=utf-8' + }, + body, + qs: query, + // Override URL when working with media only. All other endpoints use client. + //@ts-ignore + uri: option.hasOwnProperty('overridePrefix') ? `https://matrix.org/_matrix/${option.overridePrefix}/r0${resource}` : `https://matrix.org/_matrix/client/r0${resource}`, + json: true, + }; + options = Object.assign({}, options, option); + if (Object.keys(body).length === 0) { + delete options.body; + } + if (Object.keys(query).length === 0) { + delete options.qs; + } + try { + + let response: any; // tslint:disable-line:no-any + + const credentials = this.getCredentials('matrixApi'); + if (credentials === undefined) { + throw new Error('No credentials got returned!'); + } + options.headers!.Authorization = `Bearer ${credentials.accessToken}`; + //@ts-ignore + response = await this.helpers.request(options); + + // When working with images, the request cannot be JSON (it's raw binary data) + // But the output is JSON so we have to parse it manually. + //@ts-ignore + return options.overridePrefix === 'media' ? JSON.parse(response) : response; + } catch (error) { + if (error.statusCode === 401) { + // Return a clear error + throw new Error('Matrix credentials are not valid!'); + } + + if (error.response && error.response.body && error.response.body.error) { + // Try to return the error prettier + throw new Error(`Matrix error response [${error.statusCode}]: ${error.response.body.error}`); + } + + // If that data does not exist for some reason return the actual error + throw error; + } +} + +export async function handleMatrixCall(this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, item: IDataObject, index: number, resource: string, operation: string): Promise { + + if (resource === 'account') { + if (operation === 'me') { + return await matrixApiRequest.call(this, 'GET', '/account/whoami'); + } + } + else if (resource === 'room') { + if (operation === 'create') { + const name = this.getNodeParameter('roomName', index) as string; + const preset = this.getNodeParameter('preset', index) as string; + const roomAlias = this.getNodeParameter('roomAlias', index) as string; + const body: IDataObject = { + name, + preset, + }; + if (roomAlias) { + body.room_alias_name = roomAlias; + } + return await matrixApiRequest.call(this, 'POST', `/createRoom`, body); + } else if (operation === 'join') { + const roomIdOrAlias = this.getNodeParameter('roomIdOrAlias', index) as string; + return await matrixApiRequest.call(this, 'POST', `/rooms/${roomIdOrAlias}/join`); + } else if (operation === 'leave') { + const roomId = this.getNodeParameter('roomId', index) as string; + return await matrixApiRequest.call(this, 'POST', `/rooms/${roomId}/leave`); + } else if (operation === 'invite') { + const roomId = this.getNodeParameter('roomId', index) as string; + const userId = this.getNodeParameter('userId', index) as string; + const body: IDataObject = { + user_id: userId + }; + return await matrixApiRequest.call(this, 'POST', `/rooms/${roomId}/invite`, body); + } else if (operation === 'kick') { + const roomId = this.getNodeParameter('roomId', index) as string; + const userId = this.getNodeParameter('userId', index) as string; + const reason = this.getNodeParameter('reason', index) as string; + const body: IDataObject = { + user_id: userId, + reason, + }; + return await matrixApiRequest.call(this, 'POST', `/rooms/${roomId}/kick`, body); + } + } else if (resource === 'message') { + if (operation === 'create') { + const roomId = this.getNodeParameter('roomId', index) as string; + const text = this.getNodeParameter('text', index) as string; + const body: IDataObject = { + msgtype: 'm.text', + body: text, + }; + const messageId = uuid(); + return await matrixApiRequest.call(this, 'PUT', `/rooms/${roomId}/send/m.room.message/${messageId}`, body); + } else if (operation === 'getAll') { + const roomId = this.getNodeParameter('roomId', index) as string; + const returnAll = this.getNodeParameter('returnAll', index) as boolean; + const otherOptions = this.getNodeParameter('otherOptions', index) as IDataObject; + const returnData: IDataObject[] = []; + + if (returnAll) { + let responseData; + let from; + do { + const qs: IDataObject = { + dir: 'b', // Get latest messages first - doesn't return anything if we use f without a previous token. + from, + }; + + if (otherOptions.filter) { + qs.filter = otherOptions.filter; + } + + responseData = await matrixApiRequest.call(this, 'GET', `/rooms/${roomId}/messages`, {}, qs); + returnData.push.apply(returnData, responseData.chunk); + from = responseData.end; + } while (responseData.chunk.length > 0); + } else { + const limit = this.getNodeParameter('limit', index) as number; + const qs: IDataObject = { + dir: 'b', // Get latest messages first - doesn't return anything if we use f without a previous token. + limit, + }; + + if (otherOptions.filter) { + qs.filter = otherOptions.filter; + } + + const responseData = await matrixApiRequest.call(this, 'GET', `/rooms/${roomId}/messages`, {}, qs); + returnData.push.apply(returnData, responseData.chunk); + } + + return returnData; + } + } else if (resource === 'event') { + if (operation === 'get') { + const roomId = this.getNodeParameter('roomId', index) as string; + const eventId = this.getNodeParameter('eventId', index) as string; + return await matrixApiRequest.call(this, 'GET', `/rooms/${roomId}/event/${eventId}`); + } + } else if (resource === 'media') { + if (operation === 'upload') { + const roomId = this.getNodeParameter('roomId', index) as string; + const mediaType = this.getNodeParameter('mediaType', index) as string; + const binaryPropertyName = this.getNodeParameter('binaryPropertyName', index) as string; + + let body; + const qs: IDataObject = {}; + const headers: IDataObject = {}; + let filename; + + if (item.binary === undefined + //@ts-ignore + || item.binary[binaryPropertyName] === undefined) { + throw new Error(`No binary data property "${binaryPropertyName}" does not exists on item!`); + } + + //@ts-ignore + qs.filename = item.binary[binaryPropertyName].fileName; + //@ts-ignore + filename = item.binary[binaryPropertyName].fileName; + + //@ts-ignore + body = Buffer.from(item.binary[binaryPropertyName].data, BINARY_ENCODING); + //@ts-ignore + headers['Content-Type'] = item.binary[binaryPropertyName].mimeType; + headers['accept'] = 'application/json,text/*;q=0.99'; + + const uploadRequestResult = await matrixApiRequest.call(this, 'POST', `/upload`, body, qs, headers, { + overridePrefix: 'media', + json: false, + }); + + body = { + msgtype: `m.${mediaType}`, + body: filename, + url: uploadRequestResult.content_uri, + }; + const messageId = uuid(); + return await matrixApiRequest.call(this, 'PUT', `/rooms/${roomId}/send/m.room.message/${messageId}`, body); + + } + } else if (resource === 'roomMember') { + if (operation === 'getAll') { + const roomId = this.getNodeParameter('roomId', index) as string; + const filters = this.getNodeParameter('filters', index) as IDataObject; + const qs: IDataObject = { + membership: filters.membership ? filters.membership : '', + not_membership: filters.notMembership ? filters.notMembership : '', + }; + const roomMembersResponse = await matrixApiRequest.call(this, 'GET', `/rooms/${roomId}/members`, {}, qs); + return roomMembersResponse.chunk; + } + } + + + throw new Error('Not implemented yet'); +} diff --git a/packages/nodes-base/nodes/Matrix/Matrix.node.ts b/packages/nodes-base/nodes/Matrix/Matrix.node.ts new file mode 100644 index 000000000..5f9a78267 --- /dev/null +++ b/packages/nodes-base/nodes/Matrix/Matrix.node.ts @@ -0,0 +1,172 @@ +import { + IExecuteFunctions, +} from 'n8n-core'; + +import { + IDataObject, + ILoadOptionsFunctions, + INodeExecutionData, + INodePropertyOptions, + INodeType, + INodeTypeDescription, +} from 'n8n-workflow'; + +import { + handleMatrixCall, + matrixApiRequest, +} from './GenericFunctions'; + +import { + accountOperations +} from './AccountDescription'; + +import { + eventFields, + eventOperations, +} from './EventDescription'; + +import { + mediaFields, + mediaOperations, +} from './MediaDescription'; + +import { + messageFields, + messageOperations, +} from './MessageDescription'; + +import { + roomFields, + roomOperations, +} from './RoomDescription'; + +import { + roomMemberFields, + roomMemberOperations, +} from './RoomMemberDescription'; + +export class Matrix implements INodeType { + description: INodeTypeDescription = { + displayName: 'Matrix', + name: 'matrix', + icon: 'file:matrix.png', + group: ['output'], + version: 1, + description: 'Consume Matrix API', + subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}', + defaults: { + name: 'Matrix', + color: '#772244', + }, + inputs: ['main'], + outputs: ['main'], + credentials: [ + { + name: 'matrixApi', + required: true, + }, + ], + properties: [ + + { + displayName: 'Resource', + name: 'resource', + type: 'options', + options: [ + { + name: 'Account', + value: 'account', + }, + { + name: 'Event', + value: 'event', + }, + { + name: 'Media', + value: 'media', + }, + { + name: 'Message', + value: 'message', + }, + { + name: 'Room', + value: 'room', + }, + { + name: 'Room Member', + value: 'roomMember', + }, + ], + default: 'message', + description: 'The resource to operate on.', + }, + ...accountOperations, + ...eventOperations, + ...eventFields, + ...mediaOperations, + ...mediaFields, + ...messageOperations, + ...messageFields, + ...roomOperations, + ...roomFields, + ...roomMemberOperations, + ...roomMemberFields, + ] + }; + + + methods = { + loadOptions: { + async getChannels(this: ILoadOptionsFunctions): Promise { + const returnData: INodePropertyOptions[] = []; + + const joinedRoomsResponse = await matrixApiRequest.call(this, 'GET', '/joined_rooms'); + + await Promise.all(joinedRoomsResponse.joined_rooms.map(async (roomId: string) => { + try { + const roomNameResponse = await matrixApiRequest.call(this, 'GET', `/rooms/${roomId}/state/m.room.name`); + returnData.push({ + name: roomNameResponse.name, + value: roomId, + }); + } catch (e) { + // TODO: Check, there is probably another way to get the name of this private-chats + returnData.push({ + name: `Unknown: ${roomId}`, + value: roomId, + }); + } + })); + + returnData.sort((a, b) => { + if (a.name < b.name) { return -1; } + if (a.name > b.name) { return 1; } + return 0; + }); + + return returnData; + }, + } + }; + + + async execute(this: IExecuteFunctions): Promise { + + const items = this.getInputData() as IDataObject[]; + const returnData: IDataObject[] = []; + const resource = this.getNodeParameter('resource', 0) as string; + const operation = this.getNodeParameter('operation', 0) as string; + + for (let i = 0; i < items.length; i++) { + const responseData = await handleMatrixCall.call(this, items[i], i, resource, operation); + if (Array.isArray(responseData)) { + returnData.push.apply(returnData, responseData as IDataObject[]); + } else { + returnData.push(responseData as IDataObject); + } + } + + return [this.helpers.returnJsonArray(returnData)]; + } +} diff --git a/packages/nodes-base/nodes/Matrix/MediaDescription.ts b/packages/nodes-base/nodes/Matrix/MediaDescription.ts new file mode 100644 index 000000000..aa236484d --- /dev/null +++ b/packages/nodes-base/nodes/Matrix/MediaDescription.ts @@ -0,0 +1,103 @@ +import { + INodeProperties, +} from 'n8n-workflow'; + +export const mediaOperations = [ + { + displayName: 'Operation', + name: 'operation', + type: 'options', + displayOptions: { + show: { + resource: [ + 'media', + ], + }, + }, + options: [ + { + name: 'Upload', + value: 'upload', + description: 'Send media to a chat room', + }, + ], + default: 'upload', + description: 'The operation to perform.', + }, +] as INodeProperties[]; + +export const mediaFields = [ + + /* -------------------------------------------------------------------------- */ + /* media:upload */ + /* -------------------------------------------------------------------------- */ + { + displayName: 'Room ID', + name: 'roomId', + type: 'options', + typeOptions: { + loadOptionsMethod: 'getChannels', + }, + default: '', + displayOptions: { + show: { + resource: [ + 'media', + ], + operation: [ + 'upload', + ], + }, + }, + description: 'Room ID to post ', + required: true, + }, + { + displayName: 'Binary Property', + name: 'binaryPropertyName', + type: 'string', + default: 'data', + required: true, + displayOptions: { + show: { + resource: [ + 'media', + ], + operation: [ + 'upload', + ], + }, + }, + }, + { + displayName: 'Media type', + name: 'mediaType', + type: 'options', + default: 'image', + displayOptions: { + show: { + resource: [ + 'media', + ], + operation: [ + 'upload', + ], + }, + }, + options: [ + { + name: 'File', + value: 'file', + description: 'General file', + }, + { + name: 'Image', + value: 'image', + description: 'Image media type', + }, + ], + description: 'Name of the uploaded file', + placeholder: 'mxc://matrix.org/uploaded-media-uri', + required: true, + }, +] as INodeProperties[]; diff --git a/packages/nodes-base/nodes/Matrix/MessageDescription.ts b/packages/nodes-base/nodes/Matrix/MessageDescription.ts new file mode 100644 index 000000000..63ab4a2bc --- /dev/null +++ b/packages/nodes-base/nodes/Matrix/MessageDescription.ts @@ -0,0 +1,180 @@ +import { + INodeProperties, +} from 'n8n-workflow'; + +export const messageOperations = [ + { + displayName: 'Operation', + name: 'operation', + type: 'options', + displayOptions: { + show: { + resource: [ + 'message', + ], + }, + }, + options: [ + { + name: 'Create', + value: 'create', + description: 'Send a message to a room', + }, + { + name: 'Get All', + value: 'getAll', + description: 'Gets all messages from a room', + }, + ], + default: 'create', + description: 'The operation to perform.', + }, +] as INodeProperties[]; + +export const messageFields = [ + + /* -------------------------------------------------------------------------- */ + /* message:create */ + /* -------------------------------------------------------------------------- */ + { + displayName: 'Room ID', + name: 'roomId', + type: 'options', + typeOptions: { + loadOptionsMethod: 'getChannels', + }, + default: '', + placeholder: '!123abc:matrix.org', + displayOptions: { + show: { + operation: [ + 'create', + ], + resource: [ + 'message', + ], + }, + }, + required: true, + description: 'The channel to send the message to.', + }, + { + displayName: 'Text', + name: 'text', + type: 'string', + typeOptions: { + alwaysOpenEditWindow: true, + }, + default: '', + placeholder: 'Hello from n8n!', + displayOptions: { + show: { + operation: [ + 'create', + ], + resource: [ + 'message', + ], + }, + }, + description: 'The text to send.', + }, + + + /* ----------------------------------------------------------------------- */ + /* message:getAll */ + /* ----------------------------------------------------------------------- */ + { + displayName: 'Room ID', + name: 'roomId', + type: 'options', + default: '', + typeOptions: { + loadOptionsMethod: 'getChannels', + }, + displayOptions: { + show: { + resource: [ + 'message', + ], + operation: [ + 'getAll', + ], + }, + }, + description: 'The token to start returning events from. This token can be obtained from a prev_batch token returned for each room by the sync API', + required: true, + }, + { + displayName: 'Return All', + name: 'returnAll', + type: 'boolean', + default: false, + displayOptions: { + show: { + resource: [ + 'message', + ], + operation: [ + 'getAll', + ], + }, + }, + description: 'If all results should be returned or only up to a given limit.', + required: true, + }, + { + displayName: 'Limit', + name: 'limit', + type: 'number', + displayOptions: { + show: { + resource: [ + 'message', + ], + operation: [ + 'getAll', + ], + returnAll: [ + false, + ], + }, + }, + typeOptions: { + minValue: 1, + maxValue: 500, + }, + default: 100, + description: 'How many results to return.', + }, + { + displayName: 'Other Options', + name: 'otherOptions', + type: 'collection', + displayOptions: { + show: { + resource: [ + 'message', + ], + operation: [ + 'getAll', + ], + }, + }, + default: {}, + description: 'Other options', + placeholder: 'Add options', + options: [ + { + displayName: 'Filter', + name: 'filter', + type: 'string', + default: '', + description: 'A JSON RoomEventFilter to filter returned events with. More information can be found on this page.', + placeholder: '{"contains_url":true,"types":["m.room.message", "m.sticker"]}', + }, + ], + }, + + +] as INodeProperties[]; diff --git a/packages/nodes-base/nodes/Matrix/RoomDescription.ts b/packages/nodes-base/nodes/Matrix/RoomDescription.ts new file mode 100644 index 000000000..8f07d4ff0 --- /dev/null +++ b/packages/nodes-base/nodes/Matrix/RoomDescription.ts @@ -0,0 +1,277 @@ +import { + INodeProperties, +} from 'n8n-workflow'; + +export const roomOperations = [ + { + displayName: 'Operation', + name: 'operation', + type: 'options', + displayOptions: { + show: { + resource: [ + 'room', + ], + }, + }, + options: [ + { + name: 'Create', + value: 'create', + description: 'New chat room with defined settings', + }, + { + name: 'Invite', + value: 'invite', + description: 'Invite a user to a room', + }, + { + name: 'Join', + value: 'join', + description: 'Join a new room', + }, + { + name: 'Kick', + value: 'kick', + description: 'Kick a user from a room', + }, + { + name: 'Leave', + value: 'leave', + description: 'Leave a room', + }, + ], + default: 'create', + description: 'The operation to perform.', + }, +] as INodeProperties[]; + + +export const roomFields = [ + /* -------------------------------------------------------------------------- */ + /* room:create */ + /* -------------------------------------------------------------------------- */ + { + displayName: 'Room Name', + name: 'roomName', + type: 'string', + displayOptions: { + show: { + resource: [ + 'room', + ], + operation: [ + 'create', + ], + }, + }, + default: '', + placeholder: 'My new room', + description: 'The operation to perform.', + required: true, + }, + { + displayName: 'Preset', + name: 'preset', + type: 'options', + displayOptions: { + show: { + resource: [ + 'room', + ], + operation: [ + 'create', + ], + }, + }, + options: [ + { + name: 'Private Chat', + value: 'private_chat', + description: 'Private chat', + }, + { + name: 'Public Chat', + value: 'public_chat', + description: 'Open and public chat', + }, + ], + default: 'public_chat', + placeholder: 'My new room', + description: 'The operation to perform.', + required: true, + }, + { + displayName: 'Room Alias', + name: 'roomAlias', + type: 'string', + displayOptions: { + show: { + resource: [ + 'room', + ], + operation: [ + 'create', + ], + }, + }, + default: '', + placeholder: 'coolest-room-around', + description: 'The operation to perform.', + }, + /* -------------------------------------------------------------------------- */ + /* room:join */ + /* -------------------------------------------------------------------------- */ + + { + displayName: 'Room ID or Alias', + name: 'roomIdOrAlias', + type: 'string', + displayOptions: { + show: { + resource: [ + 'room', + ], + operation: [ + 'join', + ], + }, + }, + default: '', + description: 'Room ID or alias', + required: true, + }, + + /* -------------------------------------------------------------------------- */ + /* room:leave */ + /* -------------------------------------------------------------------------- */ + { + displayName: 'Room ID', + name: 'roomId', + type: 'options', + typeOptions: { + loadOptionsMethod: 'getChannels', + }, + displayOptions: { + show: { + resource: [ + 'room', + ], + operation: [ + 'leave', + ], + }, + }, + default: '', + description: 'Room ID', + required: true, + }, + + /* -------------------------------------------------------------------------- */ + /* room:invite */ + /* -------------------------------------------------------------------------- */ + { + displayName: 'Room ID', + name: 'roomId', + type: 'options', + typeOptions: { + loadOptionsMethod: 'getChannels', + }, + displayOptions: { + show: { + resource: [ + 'room', + ], + operation: [ + 'invite', + ], + }, + }, + default: '', + description: 'Room ID', + required: true, + }, + + { + displayName: 'User ID', + name: 'userId', + type: 'string', + displayOptions: { + show: { + resource: [ + 'room', + ], + operation: [ + 'invite', + ], + }, + }, + default: '', + description: 'The fully qualified user ID of the invitee.', + placeholder: '@cheeky_monkey:matrix.org', + required: true, + }, + + + /* -------------------------------------------------------------------------- */ + /* room:kick */ + /* -------------------------------------------------------------------------- */ + { + displayName: 'Room ID', + name: 'roomId', + type: 'options', + typeOptions: { + loadOptionsMethod: 'getChannels', + }, + displayOptions: { + show: { + resource: [ + 'room', + ], + operation: [ + 'kick', + ], + }, + }, + default: '', + description: 'Room ID', + required: true, + }, + { + displayName: 'User ID', + name: 'userId', + type: 'string', + displayOptions: { + show: { + resource: [ + 'room', + ], + operation: [ + 'kick', + ], + }, + }, + default: '', + description: 'The fully qualified user ID.', + placeholder: '@cheeky_monkey:matrix.org', + required: true, + }, + { + displayName: 'Reason', + name: 'reason', + type: 'string', + displayOptions: { + show: { + resource: [ + 'room', + ], + operation: [ + 'kick', + ], + }, + }, + default: '', + description: 'Reason for kick', + placeholder: 'Telling unfunny jokes', + }, +] as INodeProperties[]; diff --git a/packages/nodes-base/nodes/Matrix/RoomMemberDescription.ts b/packages/nodes-base/nodes/Matrix/RoomMemberDescription.ts new file mode 100644 index 000000000..a72980e48 --- /dev/null +++ b/packages/nodes-base/nodes/Matrix/RoomMemberDescription.ts @@ -0,0 +1,145 @@ +import { + INodeProperties, +} from 'n8n-workflow'; + +export const roomMemberOperations = [ + { + displayName: 'Operation', + name: 'operation', + type: 'options', + displayOptions: { + show: { + resource: [ + 'roomMember', + ], + }, + }, + options: [ + { + name: 'Get All', + value: 'getAll', + description: 'Get all members', + }, + ], + default: 'getAll', + description: 'The operation to perform.', + }, +] as INodeProperties[]; + + +export const roomMemberFields = [ + /* -------------------------------------------------------------------------- */ + /* roomMember:getAll */ + /* -------------------------------------------------------------------------- */ + { + displayName: 'Room ID', + name: 'roomId', + type: 'options', + typeOptions: { + loadOptionsMethod: 'getChannels', + }, + displayOptions: { + show: { + resource: [ + 'roomMember', + ], + operation: [ + 'getAll', + ], + }, + }, + default: '', + description: 'Room ID', + required: true, + }, + { + displayName: 'Filters', + name: 'filters', + type: 'collection', + displayOptions: { + show: { + resource: [ + 'roomMember', + ], + operation: [ + 'getAll', + ], + }, + }, + default: {}, + description: 'Filtering options', + placeholder: 'Add filter', + options: [ + { + displayName: 'Exclude membership', + name: 'notMembership', + type: 'options', + default: '', + description: 'Excludes members whose membership is other than selected (uses OR filter with membership)', + options: [ + { + name: 'Any', + value: '', + description: 'Any user membership', + }, + { + name: 'Ban', + value: 'ban', + description: 'Users removed from the room', + }, + { + name: 'Invite', + value: 'invite', + description: 'Users invited to join', + }, + { + name: 'Join', + value: 'join', + description: 'Users currently in the room', + }, + { + name: 'Leave', + value: 'leave', + description: 'Users who left', + }, + ], + }, + { + displayName: 'Membership', + name: 'membership', + type: 'options', + default: '', + description: 'Only fetch users with selected membership status (uses OR filter with exclude membership)', + options: [ + { + name: 'Any', + value: '', + description: 'Any user membership', + }, + { + name: 'Ban', + value: 'ban', + description: 'Users removed from the room', + }, + { + name: 'Invite', + value: 'invite', + description: 'Users invited to join', + }, + { + name: 'Join', + value: 'join', + description: 'Users currently in the room', + }, + { + name: 'Leave', + value: 'leave', + description: 'Users who left', + }, + ], + }, + ], + }, + + +] as INodeProperties[]; diff --git a/packages/nodes-base/nodes/Matrix/matrix.png b/packages/nodes-base/nodes/Matrix/matrix.png new file mode 100644 index 0000000000000000000000000000000000000000..1c81067eac6633d4617e873ba9d57f1d79f769d8 GIT binary patch literal 940 zcmV;d15^BoP)Px#1ZP1_K>z@;j|==^1poj532;bRa{vGi!~g&e!~vBn4jTXf02y>eSaefwW^{L9 za%BKPWN%_+AW3auXJt}lVPtu6$z?nM00SIJL_t(&L+zTsOFCg3$3NN+vn(_MMTjT~ zDI3JaXl@Z{YjJH6x3*U4FK9{^hln6(D4GHr8XMF_9E_IMAc+b}G@tJC+(*A=ef3UG zlgH-;4?fSmpF8gD^SQgv=QtBnfFZ(6ze9sGEIQJ#=t#q&GjxVECmw-707gbepj_TQ&Ur5wOYaB@sQGA zDwPV{-Q9u1;eb>s1s4|=kj-XE?ToIFb~>G~wzl?XW|6V6G4T0(Jj$@)D(gX);cB%? zy}}rE+|H43CeGypP#aBog8MP9zcuI66AwDX(VG zuoiHtVwgrhxxT(;O4`TgVaw<9?BL*_F>Y>Nub1!h^z`(rj_u^+gwJWm;o%_*27@%x zhG8LXHk8hxi&EJ7?6gN=<1+VYcVGzytahDOF=s9|h%&d$zwWwpJ% z4SRcgu(Gm3ib^t>(^y2?Jy&`Ng%r?v~}o0}V^oNyx~Z8jTA zr_-b|_VV(==I7@dI=0ElNm5lVFE798N(7MdJAWF|t*o!F!{+8DjexHnzC>u|{QR7H zD&cVW+htKIm8fSNJu}>TCq}S%Z>F`}{QUd`yWLJB^)fMZ#xz8Vig%&Brqe!wg$27Ep=; zUM0C)E|{B}Bjq1UOG}_+TYMhsGcz-!sNf%f+T!9OEG#VW%FOV`lyX2#;M8`h