import { IExecuteFunctions, INodeExecutionData, INodeType, INodeTypeDescription, } from 'n8n-workflow'; import { rettiwtApiRequest } from './GenericFunctions'; export class Rettiwt implements INodeType { description: INodeTypeDescription = { displayName: 'Rettiwt', name: 'rettiwt', icon: 'file:x_logo.svg', group: ['transform'], version: 1, subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}', description: 'Interact with the Rettiwt API', defaults: { name: 'Rettiwt', }, inputs: ['main'], outputs: ['main'], credentials: [ { name: 'rettiwtApi', required: true, }, ], properties: [ { displayName: 'Resource', name: 'resource', type: 'options', noDataExpression: true, options: [ { name: 'Tweet', value: 'tweet', }, { name: 'User', value: 'user', }, { name: 'API Key', value: 'apiKey', }, ], default: 'tweet', }, { displayName: 'Operation', name: 'operation', type: 'options', noDataExpression: true, displayOptions: { show: { resource: ['tweet'], }, }, options: [ { name: 'Create', value: 'create', description: 'Create a tweet', action: 'Create a tweet', }, { name: 'Get', value: 'get', description: 'Get a tweet', action: 'Get a tweet', }, { name: 'Like', value: 'like', description: 'Like a tweet', action: 'Like a tweet', }, { name: 'Retweet', value: 'retweet', description: 'Retweet a tweet', action: 'Retweet a tweet', }, { name: 'Search', value: 'search', description: 'Search tweets', action: 'Search tweets', }, ], default: 'create', }, { displayName: 'Operation', name: 'operation', type: 'options', noDataExpression: true, displayOptions: { show: { resource: ['user'], }, }, options: [ { name: 'Follow', value: 'follow', description: 'Follow a user', action: 'Follow a user', }, { name: 'Get', value: 'get', description: 'Get user details', action: 'Get user details', }, { name: 'Get Timeline', value: 'getTimeline', description: 'Get user timeline', action: 'Get user timeline', }, ], default: 'get', }, { displayName: 'Operation', name: 'operation', type: 'options', noDataExpression: true, displayOptions: { show: { resource: ['apiKey'], }, }, options: [ { name: 'Create', value: 'create', description: 'Create a new API key', action: 'Create a new API key', }, { name: 'Delete', value: 'delete', description: 'Delete an API key', action: 'Delete an API key', }, { name: 'Get Many', value: 'getMany', description: 'Get many API keys', action: 'Get many API keys', }, ], default: 'create', }, // ... (rest of the properties remain the same) ], }; async execute(this: IExecuteFunctions): Promise { const items = this.getInputData(); const returnData: INodeExecutionData[] = []; const resource = this.getNodeParameter('resource', 0) as string; const operation = this.getNodeParameter('operation', 0) as string; for (let i = 0; i < items.length; i++) { try { if (resource === 'tweet') { if (operation === 'create') { const tweetText = this.getNodeParameter('tweetText', i) as string; const responseData = await rettiwtApiRequest.call(this, 'POST', '/tweet/post', { text: tweetText, }); returnData.push({ json: responseData }); } else if (operation === 'get') { const tweetId = this.getNodeParameter('tweetId', i) as string; const responseData = await rettiwtApiRequest.call( this, 'GET', `/tweet/details/${tweetId}`, ); returnData.push({ json: responseData }); } else if (operation === 'like') { const tweetId = this.getNodeParameter('tweetId', i) as string; const responseData = await rettiwtApiRequest.call( this, 'POST', `/tweet/like/${tweetId}`, ); returnData.push({ json: responseData }); } else if (operation === 'retweet') { const tweetId = this.getNodeParameter('tweetId', i) as string; const responseData = await rettiwtApiRequest.call( this, 'POST', `/tweet/retweet/${tweetId}`, ); returnData.push({ json: responseData }); } else if (operation === 'search') { const searchQuery = this.getNodeParameter('searchQuery', i) as string; const responseData = await rettiwtApiRequest.call( this, 'GET', `/tweet/search?q=${encodeURIComponent(searchQuery)}`, ); returnData.push({ json: responseData }); } } else if (resource === 'user') { if (operation === 'follow') { const userId = this.getNodeParameter('userId', i) as string; const responseData = await rettiwtApiRequest.call( this, 'POST', `/user/follow/${userId}`, ); returnData.push({ json: responseData }); } else if (operation === 'get') { const userId = this.getNodeParameter('userId', i) as string; const responseData = await rettiwtApiRequest.call( this, 'GET', `/user/details/${userId}`, ); returnData.push({ json: responseData }); } else if (operation === 'getTimeline') { const userId = this.getNodeParameter('userId', i) as string; const responseData = await rettiwtApiRequest.call( this, 'GET', `/user/timeline/${userId}`, ); returnData.push({ json: responseData }); } } else if (resource === 'apiKey') { if (operation === 'create') { const responseData = await rettiwtApiRequest.call(this, 'POST', '/api/keys'); returnData.push({ json: responseData }); } else if (operation === 'delete') { const keyId = this.getNodeParameter('keyId', i) as string; const responseData = await rettiwtApiRequest.call(this, 'DELETE', `/api/keys/${keyId}`); returnData.push({ json: responseData }); } else if (operation === 'getMany') { const responseData = await rettiwtApiRequest.call(this, 'GET', '/api/keys'); returnData.push({ json: responseData }); } } } catch (error) { if (this.continueOnFail()) { returnData.push({ json: { error: error.message } }); continue; } throw error; } } return [returnData]; } }