2023-01-27 03:22:44 -08:00
|
|
|
import type {
|
2020-11-18 14:58:41 -08:00
|
|
|
IDataObject,
|
2023-03-06 08:33:32 -08:00
|
|
|
IExecuteFunctions,
|
2020-11-18 14:58:41 -08:00
|
|
|
INodeExecutionData,
|
|
|
|
INodeType,
|
|
|
|
INodeTypeDescription,
|
|
|
|
} from 'n8n-workflow';
|
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
import { humanticAiApiRequest } from './GenericFunctions';
|
2020-11-18 14:58:41 -08:00
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
import { profileFields, profileOperations } from './ProfileDescription';
|
2020-11-18 14:58:41 -08:00
|
|
|
|
|
|
|
export class HumanticAi implements INodeType {
|
|
|
|
description: INodeTypeDescription = {
|
|
|
|
displayName: 'Humantic AI',
|
|
|
|
name: 'humanticAi',
|
2022-06-20 07:54:01 -07:00
|
|
|
// eslint-disable-next-line n8n-nodes-base/node-class-description-icon-not-svg
|
2024-06-06 04:34:30 -07:00
|
|
|
icon: 'file:humanticai.svg',
|
2020-11-18 14:58:41 -08:00
|
|
|
group: ['output'],
|
|
|
|
version: 1,
|
|
|
|
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
|
|
|
|
description: 'Consume Humantic AI API',
|
|
|
|
defaults: {
|
|
|
|
name: 'Humantic AI',
|
|
|
|
},
|
|
|
|
inputs: ['main'],
|
|
|
|
outputs: ['main'],
|
|
|
|
credentials: [
|
|
|
|
{
|
|
|
|
name: 'humanticAiApi',
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
properties: [
|
|
|
|
{
|
|
|
|
displayName: 'Resource',
|
|
|
|
name: 'resource',
|
|
|
|
type: 'options',
|
2022-05-20 14:47:24 -07:00
|
|
|
noDataExpression: true,
|
2020-11-18 14:58:41 -08:00
|
|
|
options: [
|
|
|
|
{
|
|
|
|
name: 'Profile',
|
|
|
|
value: 'profile',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
default: 'profile',
|
|
|
|
},
|
|
|
|
// PROFILE
|
|
|
|
...profileOperations,
|
|
|
|
...profileFields,
|
|
|
|
],
|
|
|
|
};
|
|
|
|
|
|
|
|
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
|
|
|
const items = this.getInputData();
|
|
|
|
const returnData: IDataObject[] = [];
|
2022-04-22 09:29:51 -07:00
|
|
|
const length = items.length;
|
2020-11-18 14:58:41 -08:00
|
|
|
const qs: IDataObject = {};
|
|
|
|
let responseData;
|
2022-12-02 03:53:59 -08:00
|
|
|
const resource = this.getNodeParameter('resource', 0);
|
|
|
|
const operation = this.getNodeParameter('operation', 0);
|
2020-11-18 14:58:41 -08:00
|
|
|
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) {
|
2023-01-06 06:09:32 -08:00
|
|
|
const binaryPropertyName = this.getNodeParameter('binaryPropertyName', i);
|
2023-03-06 08:33:32 -08:00
|
|
|
const binaryData = this.helpers.assertBinaryData(i, binaryPropertyName);
|
2021-08-20 09:08:40 -07:00
|
|
|
const binaryDataBuffer = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName);
|
2020-11-18 14:58:41 -08:00
|
|
|
|
|
|
|
responseData = await humanticAiApiRequest.call(
|
|
|
|
this,
|
|
|
|
'POST',
|
2022-12-29 03:20:43 -08:00
|
|
|
'/user-profile/create',
|
2020-11-18 14:58:41 -08:00
|
|
|
{},
|
|
|
|
qs,
|
|
|
|
{
|
|
|
|
formData: {
|
|
|
|
resume: {
|
2021-08-20 09:08:40 -07:00
|
|
|
value: binaryDataBuffer,
|
2020-11-18 14:58:41 -08:00
|
|
|
options: {
|
|
|
|
filename: binaryData.fileName,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
);
|
|
|
|
} else {
|
2022-08-17 08:50:24 -07:00
|
|
|
responseData = await humanticAiApiRequest.call(
|
|
|
|
this,
|
|
|
|
'GET',
|
2022-12-29 03:20:43 -08:00
|
|
|
'/user-profile/create',
|
2022-08-17 08:50:24 -07:00
|
|
|
{},
|
|
|
|
qs,
|
|
|
|
);
|
2020-11-18 14:59:36 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (responseData.data !== undefined) {
|
2020-11-18 14:58:41 -08:00
|
|
|
responseData = responseData.data;
|
2020-11-18 14:59:36 -08:00
|
|
|
} else {
|
|
|
|
delete responseData.usage_stats;
|
2020-11-18 14:58:41 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (operation === 'get') {
|
|
|
|
const userId = this.getNodeParameter('userId', i) as string;
|
2022-11-18 07:29:44 -08:00
|
|
|
const options = this.getNodeParameter('options', i);
|
2020-11-18 14:58:41 -08:00
|
|
|
|
|
|
|
qs.userid = userId;
|
|
|
|
|
|
|
|
if (options.persona) {
|
|
|
|
qs.persona = (options.persona as string[]).join(',');
|
|
|
|
}
|
|
|
|
|
2022-12-29 03:20:43 -08:00
|
|
|
responseData = await humanticAiApiRequest.call(this, 'GET', '/user-profile', {}, qs);
|
2020-11-18 14:58:41 -08:00
|
|
|
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) {
|
2023-01-06 06:09:32 -08:00
|
|
|
const binaryPropertyName = this.getNodeParameter('binaryPropertyName', i);
|
2023-03-06 08:33:32 -08:00
|
|
|
const binaryData = this.helpers.assertBinaryData(i, binaryPropertyName);
|
2021-08-20 09:08:40 -07:00
|
|
|
const binaryDataBuffer = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName);
|
2020-11-18 14:58:41 -08:00
|
|
|
|
|
|
|
responseData = await humanticAiApiRequest.call(
|
|
|
|
this,
|
|
|
|
'POST',
|
2022-12-29 03:20:43 -08:00
|
|
|
'/user-profile/create',
|
2020-11-18 14:58:41 -08:00
|
|
|
{},
|
|
|
|
qs,
|
|
|
|
{
|
|
|
|
formData: {
|
|
|
|
resume: {
|
2021-08-20 09:08:40 -07:00
|
|
|
value: binaryDataBuffer,
|
2020-11-18 14:58:41 -08:00
|
|
|
options: {
|
|
|
|
filename: binaryData.fileName,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
);
|
|
|
|
responseData = responseData.data;
|
|
|
|
} else {
|
|
|
|
const text = this.getNodeParameter('text', i) as string;
|
|
|
|
const body: IDataObject = {
|
|
|
|
text,
|
|
|
|
};
|
|
|
|
|
|
|
|
qs.userid = userId;
|
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
responseData = await humanticAiApiRequest.call(
|
|
|
|
this,
|
|
|
|
'POST',
|
2022-12-29 03:20:43 -08:00
|
|
|
'/user-profile/create',
|
2022-08-17 08:50:24 -07:00
|
|
|
body,
|
|
|
|
qs,
|
|
|
|
);
|
2020-11-18 14:58:41 -08:00
|
|
|
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)];
|
|
|
|
}
|
|
|
|
}
|