mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-30 06:59:41 -08:00
409a9ea357
* PairedItem for N8n training * Add paired item to ftp node * Add paired item to rocketChat * Add pairedItem to pushOver * Add paired item to Matrix * Add pairedItem to theHive * Add paired item to Snowflake * Add paired item to PhilipsHue * Add pairedItem to supabase * Add paired item to Odoo * fix odoo & add paired item to grist * add pairedItem to Linkedin * add pairedItem Zulip * add pairedItem PhatomBuster * add pairedItem to TodoistV2 * Add pairedItem HomeAssistant * Add pairedItem to DropContact * Add pairedItem to Aws SES * Add pairedItem to microsoftOutlook * Add pairedItem to AwsS3 * Add pairedItem to Aws DynamoDB * 🐛 fix Dropcontact enrich operation paired item support * 🐛 fix Dropcontact insert/update operation paired items * 🐛 fix Supabase paired item support * 🐛 fix Supabase paired item support * 🐛 fix N8nTrainingCustomerDatastore paired item support * 🎨 remove unused imports * 🐛 fix MicrosoftOutlook paired item support * 🐛 fix AwsS3 paired item support --------- Co-authored-by: Marcus <marcus@n8n.io>
168 lines
4 KiB
TypeScript
168 lines
4 KiB
TypeScript
import type { IExecuteFunctions } from 'n8n-core';
|
|
|
|
import type {
|
|
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',
|
|
// eslint-disable-next-line n8n-nodes-base/node-class-description-icon-not-svg
|
|
icon: 'file:matrix.png',
|
|
group: ['output'],
|
|
version: 1,
|
|
description: 'Consume Matrix API',
|
|
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
|
|
defaults: {
|
|
name: 'Matrix',
|
|
},
|
|
inputs: ['main'],
|
|
outputs: ['main'],
|
|
credentials: [
|
|
{
|
|
name: 'matrixApi',
|
|
required: true,
|
|
},
|
|
],
|
|
properties: [
|
|
{
|
|
displayName: 'Resource',
|
|
name: 'resource',
|
|
type: 'options',
|
|
noDataExpression: true,
|
|
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',
|
|
},
|
|
...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 (error) {
|
|
// 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: INodeExecutionData[] = [];
|
|
const resource = this.getNodeParameter('resource', 0);
|
|
const operation = this.getNodeParameter('operation', 0);
|
|
|
|
for (let i = 0; i < items.length; i++) {
|
|
try {
|
|
const responseData = await handleMatrixCall.call(this, items[i], i, resource, operation);
|
|
const executionData = this.helpers.constructExecutionMetaData(
|
|
this.helpers.returnJsonArray(responseData),
|
|
{ itemData: { item: i } },
|
|
);
|
|
returnData.push(...executionData);
|
|
} catch (error) {
|
|
if (this.continueOnFail()) {
|
|
const executionData = this.helpers.constructExecutionMetaData(
|
|
this.helpers.returnJsonArray({ error: error.message }),
|
|
{ itemData: { item: i } },
|
|
);
|
|
returnData.push(...executionData);
|
|
continue;
|
|
}
|
|
throw error;
|
|
}
|
|
}
|
|
return this.prepareOutputData(returnData);
|
|
}
|
|
}
|