mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-09 22:24:05 -08:00
✨ 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 * ⚡ Small improvements * ⚡ Added filters to get messages * ⚡ Minor improvements to Matrix-Integration Co-authored-by: Omar Ajoue <krynble@gmail.com> Co-authored-by: ricardo <ricardoespinoza105@gmail.com>
This commit is contained in:
parent
0f998d52b8
commit
4573d503dc
19
packages/nodes-base/credentials/MatrixApi.credentials.ts
Normal file
19
packages/nodes-base/credentials/MatrixApi.credentials.ts
Normal file
|
@ -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: '',
|
||||
},
|
||||
];
|
||||
}
|
27
packages/nodes-base/nodes/Matrix/AccountDescription.ts
Normal file
27
packages/nodes-base/nodes/Matrix/AccountDescription.ts
Normal file
|
@ -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[];
|
73
packages/nodes-base/nodes/Matrix/EventDescription.ts
Normal file
73
packages/nodes-base/nodes/Matrix/EventDescription.ts
Normal file
|
@ -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[];
|
239
packages/nodes-base/nodes/Matrix/GenericFunctions.ts
Normal file
239
packages/nodes-base/nodes/Matrix/GenericFunctions.ts
Normal file
|
@ -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<any> { // 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<any> {
|
||||
|
||||
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');
|
||||
}
|
172
packages/nodes-base/nodes/Matrix/Matrix.node.ts
Normal file
172
packages/nodes-base/nodes/Matrix/Matrix.node.ts
Normal file
|
@ -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<INodePropertyOptions[]> {
|
||||
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<INodeExecutionData[][]> {
|
||||
|
||||
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)];
|
||||
}
|
||||
}
|
103
packages/nodes-base/nodes/Matrix/MediaDescription.ts
Normal file
103
packages/nodes-base/nodes/Matrix/MediaDescription.ts
Normal file
|
@ -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[];
|
180
packages/nodes-base/nodes/Matrix/MessageDescription.ts
Normal file
180
packages/nodes-base/nodes/Matrix/MessageDescription.ts
Normal file
|
@ -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 <a href="https://matrix.org/docs/spec/client_server/r0.6.0" target="_blank">page</a>.',
|
||||
placeholder: '{"contains_url":true,"types":["m.room.message", "m.sticker"]}',
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
|
||||
] as INodeProperties[];
|
277
packages/nodes-base/nodes/Matrix/RoomDescription.ts
Normal file
277
packages/nodes-base/nodes/Matrix/RoomDescription.ts
Normal file
|
@ -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[];
|
145
packages/nodes-base/nodes/Matrix/RoomMemberDescription.ts
Normal file
145
packages/nodes-base/nodes/Matrix/RoomMemberDescription.ts
Normal file
|
@ -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[];
|
BIN
packages/nodes-base/nodes/Matrix/matrix.png
Normal file
BIN
packages/nodes-base/nodes/Matrix/matrix.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 940 B |
|
@ -107,6 +107,7 @@
|
|||
"dist/credentials/MailjetEmailApi.credentials.js",
|
||||
"dist/credentials/MailjetSmsApi.credentials.js",
|
||||
"dist/credentials/MandrillApi.credentials.js",
|
||||
"dist/credentials/MatrixApi.credentials.js",
|
||||
"dist/credentials/MattermostApi.credentials.js",
|
||||
"dist/credentials/MauticApi.credentials.js",
|
||||
"dist/credentials/MauticOAuth2Api.credentials.js",
|
||||
|
@ -295,6 +296,7 @@
|
|||
"dist/nodes/Mailjet/Mailjet.node.js",
|
||||
"dist/nodes/Mailjet/MailjetTrigger.node.js",
|
||||
"dist/nodes/Mandrill/Mandrill.node.js",
|
||||
"dist/nodes/Matrix/Matrix.node.js",
|
||||
"dist/nodes/Mattermost/Mattermost.node.js",
|
||||
"dist/nodes/Mautic/Mautic.node.js",
|
||||
"dist/nodes/Mautic/MauticTrigger.node.js",
|
||||
|
|
Loading…
Reference in a new issue