mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
✨ Add Humantic AI node (#1177)
* ✨ Add Humantic AI node * ⚡ Improvements Improvements to #1165 Co-authored-by: Tanay Pant <tanaypant@protonmail.com>
This commit is contained in:
190
packages/nodes-base/nodes/HumanticAI/HumanticAi.node.ts
Normal file
190
packages/nodes-base/nodes/HumanticAI/HumanticAi.node.ts
Normal file
@@ -0,0 +1,190 @@
|
||||
import {
|
||||
BINARY_ENCODING,
|
||||
IExecuteFunctions,
|
||||
} from 'n8n-core';
|
||||
|
||||
import {
|
||||
IBinaryData,
|
||||
IBinaryKeyData,
|
||||
IDataObject,
|
||||
INodeExecutionData,
|
||||
INodeType,
|
||||
INodeTypeDescription,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import {
|
||||
humanticAiApiRequest,
|
||||
} from './GenericFunctions';
|
||||
|
||||
import {
|
||||
profileFields,
|
||||
profileOperations,
|
||||
} from './ProfileDescription';
|
||||
|
||||
export class HumanticAi implements INodeType {
|
||||
description: INodeTypeDescription = {
|
||||
displayName: 'Humantic AI',
|
||||
name: 'humanticAi',
|
||||
icon: 'file:humanticai.png',
|
||||
group: ['output'],
|
||||
version: 1,
|
||||
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
|
||||
description: 'Consume Humantic AI API',
|
||||
defaults: {
|
||||
name: 'Humantic AI',
|
||||
color: '#f8ce59',
|
||||
},
|
||||
inputs: ['main'],
|
||||
outputs: ['main'],
|
||||
credentials: [
|
||||
{
|
||||
name: 'humanticAiApi',
|
||||
required: true,
|
||||
},
|
||||
],
|
||||
properties: [
|
||||
{
|
||||
displayName: 'Resource',
|
||||
name: 'resource',
|
||||
type: 'options',
|
||||
options: [
|
||||
{
|
||||
name: 'Profile',
|
||||
value: 'profile',
|
||||
},
|
||||
],
|
||||
default: 'profile',
|
||||
description: 'Resource to consume.',
|
||||
},
|
||||
// PROFILE
|
||||
...profileOperations,
|
||||
...profileFields,
|
||||
],
|
||||
};
|
||||
|
||||
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
||||
const items = this.getInputData();
|
||||
const returnData: IDataObject[] = [];
|
||||
const length = items.length as unknown as number;
|
||||
const qs: IDataObject = {};
|
||||
let responseData;
|
||||
const resource = this.getNodeParameter('resource', 0) as string;
|
||||
const operation = this.getNodeParameter('operation', 0) as string;
|
||||
for (let i = 0; i < length; i++) {
|
||||
if (resource === 'profile') {
|
||||
if (operation === 'create') {
|
||||
const userId = this.getNodeParameter('userId', i) as string;
|
||||
const sendResume = this.getNodeParameter('sendResume', i) as boolean;
|
||||
qs.userid = userId;
|
||||
|
||||
if (sendResume) {
|
||||
const binaryPropertyName = this.getNodeParameter('binaryPropertyName', i) as string;
|
||||
|
||||
if (items[i].binary === undefined) {
|
||||
throw new Error('No binary data exists on item!');
|
||||
}
|
||||
|
||||
const item = items[i].binary as IBinaryKeyData;
|
||||
|
||||
const binaryData = item[binaryPropertyName] as IBinaryData;
|
||||
|
||||
if (binaryData === undefined) {
|
||||
throw new Error(`No binary data property "${binaryPropertyName}" does not exists on item!`);
|
||||
}
|
||||
|
||||
responseData = await humanticAiApiRequest.call(
|
||||
this,
|
||||
'POST',
|
||||
`/user-profile/create`,
|
||||
{},
|
||||
qs,
|
||||
{
|
||||
formData: {
|
||||
resume: {
|
||||
value: Buffer.from(binaryData.data, BINARY_ENCODING),
|
||||
options: {
|
||||
filename: binaryData.fileName,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
);
|
||||
responseData = responseData.data;
|
||||
} else {
|
||||
responseData = await humanticAiApiRequest.call(this, 'GET', `/user-profile/create`, {}, qs);
|
||||
responseData = responseData.data;
|
||||
}
|
||||
}
|
||||
if (operation === 'get') {
|
||||
const userId = this.getNodeParameter('userId', i) as string;
|
||||
const options = this.getNodeParameter('options', i) as IDataObject;
|
||||
|
||||
qs.userid = userId;
|
||||
|
||||
if (options.persona) {
|
||||
qs.persona = (options.persona as string[]).join(',');
|
||||
}
|
||||
|
||||
responseData = await humanticAiApiRequest.call(this, 'GET', `/user-profile`, {}, qs);
|
||||
responseData = responseData.results;
|
||||
}
|
||||
if (operation === 'update') {
|
||||
const userId = this.getNodeParameter('userId', i) as string;
|
||||
const sendResume = this.getNodeParameter('sendResume', i) as string;
|
||||
qs.userid = userId;
|
||||
|
||||
if (sendResume) {
|
||||
const binaryPropertyName = this.getNodeParameter('binaryPropertyName', i) as string;
|
||||
|
||||
if (items[i].binary === undefined) {
|
||||
throw new Error('No binary data exists on item!');
|
||||
}
|
||||
|
||||
const item = items[i].binary as IBinaryKeyData;
|
||||
|
||||
const binaryData = item[binaryPropertyName] as IBinaryData;
|
||||
|
||||
if (binaryData === undefined) {
|
||||
throw new Error(`No binary data property "${binaryPropertyName}" does not exists on item!`);
|
||||
}
|
||||
|
||||
responseData = await humanticAiApiRequest.call(
|
||||
this,
|
||||
'POST',
|
||||
`/user-profile/create`,
|
||||
{},
|
||||
qs,
|
||||
{
|
||||
formData: {
|
||||
resume: {
|
||||
value: Buffer.from(binaryData.data, BINARY_ENCODING),
|
||||
options: {
|
||||
filename: binaryData.fileName,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
);
|
||||
responseData = responseData.data;
|
||||
} else {
|
||||
const text = this.getNodeParameter('text', i) as string;
|
||||
const body: IDataObject = {
|
||||
text,
|
||||
};
|
||||
|
||||
qs.userid = userId;
|
||||
|
||||
responseData = await humanticAiApiRequest.call(this, 'POST', `/user-profile/create`, body, qs);
|
||||
responseData = responseData.data;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (Array.isArray(responseData)) {
|
||||
returnData.push.apply(returnData, responseData as IDataObject[]);
|
||||
} else {
|
||||
returnData.push(responseData as IDataObject);
|
||||
}
|
||||
}
|
||||
return [this.helpers.returnJsonArray(returnData)];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user