UNPKG

n8n-nodes-agentic-hub

Version:

n8n community node for Agentic Hub API integration - Unified node with all resources (projects, workflows, agents, content, conversations, messages, files)

1,658 lines 72 kB
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.AgenticHub = void 0;
const n8n_workflow_1 = require("n8n-workflow");
class AgenticHub {
    constructor() {
        this.description = {
            displayName: 'Agentic Hub',
            name: 'agenticHub',
            icon: 'file:agentic-hub.svg',
            group: ['transform'],
            version: 1,
            description: 'Complete Agentic Hub API integration - Manage projects, workflows, agents, content, conversations, messages, and files',
            defaults: {
                name: 'Agentic Hub',
            },
            subtitle: '={{$parameter["resource"]}} / {{$parameter["operation"]}}',
            inputs: ["main"],
            outputs: ["main"],
            usableAsTool: true,
            credentials: [
                {
                    name: 'agenticHubApi',
                    required: true,
                },
            ],
            properties: [
                {
                    displayName: 'Resource',
                    name: 'resource',
                    type: 'options',
                    noDataExpression: true,
                    options: [
                        {
                            name: 'Agent',
                            value: 'agent',
                            description: 'Manage AI agents',
                        },
                        {
                            name: 'Content',
                            value: 'content',
                            description: 'Manage content (text and FAQ)',
                        },
                        {
                            name: 'Conversation',
                            value: 'conversation',
                            description: 'Manage conversations',
                        },
                        {
                            name: 'File',
                            value: 'file',
                            description: 'Manage files',
                        },
                        {
                            name: 'Message',
                            value: 'message',
                            description: 'Manage messages',
                        },
                        {
                            name: 'Project',
                            value: 'project',
                            description: 'Manage projects',
                        },
                        {
                            name: 'Workflow',
                            value: 'workflow',
                            description: 'Manage workflows',
                        },
                    ],
                    default: 'project',
                },
                {
                    displayName: 'Operation',
                    name: 'operation',
                    type: 'options',
                    noDataExpression: true,
                    displayOptions: {
                        show: {
                            resource: ['project'],
                        },
                    },
                    options: [
                        {
                            name: 'Create',
                            value: 'create',
                            description: 'Create a new project',
                            action: 'Create a project',
                        },
                        {
                            name: 'Delete',
                            value: 'delete',
                            description: 'Delete a project',
                            action: 'Delete a project',
                        },
                        {
                            name: 'Get by ID',
                            value: 'get',
                            description: 'Get a specific project by ID',
                            action: 'Get a project',
                        },
                        {
                            name: 'Get Many',
                            value: 'getAll',
                            description: 'Get many projects for the authenticated company',
                            action: 'Get many projects',
                        },
                        {
                            name: 'Update',
                            value: 'update',
                            description: 'Update a project',
                            action: 'Update a project',
                        },
                    ],
                    default: 'getAll',
                },
                {
                    displayName: 'Project ID',
                    name: 'projectId',
                    type: 'string',
                    default: '',
                    required: true,
                    placeholder: 'Enter Project ID',
                    description: 'The unique identifier of the project',
                    displayOptions: {
                        show: {
                            resource: ['project'],
                            operation: ['get', 'update', 'delete'],
                        },
                    },
                },
                {
                    displayName: 'Name',
                    name: 'name',
                    type: 'string',
                    default: '',
                    required: true,
                    placeholder: 'Enter project name',
                    description: 'Project name. Must be unique within the company.',
                    displayOptions: {
                        show: {
                            resource: ['project'],
                            operation: ['create'],
                        },
                    },
                },
                {
                    displayName: 'Description',
                    name: 'description',
                    type: 'string',
                    default: '',
                    placeholder: 'Enter project description',
                    description: 'Detailed description of the project',
                    displayOptions: {
                        show: {
                            resource: ['project'],
                            operation: ['create', 'update'],
                        },
                    },
                },
                {
                    displayName: 'Status',
                    name: 'status',
                    type: 'options',
                    default: 'active',
                    options: [
                        {
                            name: 'Active',
                            value: 'active',
                        },
                        {
                            name: 'Inactive',
                            value: 'inactive',
                        },
                    ],
                    description: 'Project status',
                    displayOptions: {
                        show: {
                            resource: ['project'],
                            operation: ['create', 'update'],
                        },
                    },
                },
                {
                    displayName: 'Name',
                    name: 'updateName',
                    type: 'string',
                    default: '',
                    placeholder: 'Enter project name',
                    description: 'New name for the project',
                    displayOptions: {
                        show: {
                            resource: ['project'],
                            operation: ['update'],
                        },
                    },
                },
                {
                    displayName: 'Operation',
                    name: 'operation',
                    type: 'options',
                    noDataExpression: true,
                    displayOptions: {
                        show: {
                            resource: ['workflow'],
                        },
                    },
                    options: [
                        {
                            name: 'Create',
                            value: 'create',
                            description: 'Create a new workflow',
                            action: 'Create a workflow',
                        },
                        {
                            name: 'Delete',
                            value: 'delete',
                            description: 'Delete a workflow',
                            action: 'Delete a workflow',
                        },
                        {
                            name: 'Get by ID',
                            value: 'get',
                            description: 'Get a specific workflow by ID',
                            action: 'Get a workflow',
                        },
                        {
                            name: 'Get Many',
                            value: 'getAll',
                            description: 'Get many workflows for the authenticated company',
                            action: 'Get many workflows',
                        },
                        {
                            name: 'Update',
                            value: 'update',
                            description: 'Update a workflow',
                            action: 'Update a workflow',
                        },
                    ],
                    default: 'getAll',
                },
                {
                    displayName: 'Workflow ID',
                    name: 'workflowId',
                    type: 'string',
                    default: '',
                    required: true,
                    placeholder: 'Enter Workflow ID',
                    description: 'The unique identifier of the workflow',
                    displayOptions: {
                        show: {
                            resource: ['workflow'],
                            operation: ['get', 'update', 'delete'],
                        },
                    },
                },
                {
                    displayName: 'Name',
                    name: 'workflowName',
                    type: 'string',
                    default: '',
                    required: true,
                    placeholder: 'Enter workflow name',
                    description: 'Workflow name. Must be unique within the project.',
                    displayOptions: {
                        show: {
                            resource: ['workflow'],
                            operation: ['create'],
                        },
                    },
                },
                {
                    displayName: 'Project ID',
                    name: 'workflowProjectId',
                    type: 'string',
                    default: '',
                    required: true,
                    placeholder: 'Enter Project ID',
                    description: 'ID of the project to which the workflow belongs',
                    displayOptions: {
                        show: {
                            resource: ['workflow'],
                            operation: ['create'],
                        },
                    },
                },
                {
                    displayName: 'Description',
                    name: 'workflowDescription',
                    type: 'string',
                    default: '',
                    placeholder: 'Enter workflow description',
                    description: 'Detailed description of the workflow and its purpose',
                    displayOptions: {
                        show: {
                            resource: ['workflow'],
                            operation: ['create', 'update'],
                        },
                    },
                },
                {
                    displayName: 'Status',
                    name: 'workflowStatus',
                    type: 'options',
                    default: 'active',
                    options: [
                        {
                            name: 'Active',
                            value: 'active',
                        },
                        {
                            name: 'Inactive',
                            value: 'inactive',
                        },
                    ],
                    description: 'Workflow status',
                    displayOptions: {
                        show: {
                            resource: ['workflow'],
                            operation: ['create', 'update'],
                        },
                    },
                },
                {
                    displayName: 'Name',
                    name: 'workflowUpdateName',
                    type: 'string',
                    default: '',
                    placeholder: 'Enter workflow name',
                    description: 'New name for the workflow',
                    displayOptions: {
                        show: {
                            resource: ['workflow'],
                            operation: ['update'],
                        },
                    },
                },
                {
                    displayName: 'Operation',
                    name: 'operation',
                    type: 'options',
                    noDataExpression: true,
                    displayOptions: {
                        show: {
                            resource: ['agent'],
                        },
                    },
                    options: [
                        {
                            name: 'Create',
                            value: 'create',
                            description: 'Create a new agent',
                            action: 'Create an agent',
                        },
                        {
                            name: 'Delete',
                            value: 'delete',
                            description: 'Delete an agent',
                            action: 'Delete an agent',
                        },
                        {
                            name: 'Get by ID',
                            value: 'get',
                            description: 'Get a specific agent by ID',
                            action: 'Get an agent',
                        },
                        {
                            name: 'Get Many',
                            value: 'getAll',
                            description: 'Get many agents for the authenticated company',
                            action: 'Get many agents',
                        },
                        {
                            name: 'Update',
                            value: 'update',
                            description: 'Update an agent',
                            action: 'Update an agent',
                        },
                    ],
                    default: 'getAll',
                },
                {
                    displayName: 'Agent ID',
                    name: 'agentId',
                    type: 'string',
                    default: '',
                    required: true,
                    placeholder: 'Enter Agent ID',
                    description: 'The unique identifier of the agent',
                    displayOptions: {
                        show: {
                            resource: ['agent'],
                            operation: ['get', 'update', 'delete'],
                        },
                    },
                },
                {
                    displayName: 'Name',
                    name: 'agentName',
                    type: 'string',
                    default: '',
                    required: true,
                    placeholder: 'Enter agent name',
                    description: 'Agent name. Must be unique within the workflow.',
                    displayOptions: {
                        show: {
                            resource: ['agent'],
                            operation: ['create'],
                        },
                    },
                },
                {
                    displayName: 'Workflow ID',
                    name: 'agentWorkflowId',
                    type: 'string',
                    default: '',
                    required: true,
                    placeholder: 'Enter Workflow ID',
                    description: 'ID of the workflow to which the agent belongs',
                    displayOptions: {
                        show: {
                            resource: ['agent'],
                            operation: ['create'],
                        },
                    },
                },
                {
                    displayName: 'Main Prompt',
                    name: 'mainPrompt',
                    type: 'string',
                    typeOptions: {
                        rows: 4,
                    },
                    default: '',
                    required: true,
                    placeholder: 'Enter main prompt',
                    description: "Main prompt that defines the agent's behavior",
                    displayOptions: {
                        show: {
                            resource: ['agent'],
                            operation: ['create'],
                        },
                    },
                },
                {
                    displayName: 'Dynamic Fields',
                    name: 'dynamicFields',
                    type: 'json',
                    default: '[]',
                    placeholder: '[]',
                    description: 'Additional dynamic fields for configuring the agent (JSON array)',
                    displayOptions: {
                        show: {
                            resource: ['agent'],
                            operation: ['create', 'update'],
                        },
                    },
                },
                {
                    displayName: 'Is Active',
                    name: 'isActive',
                    type: 'boolean',
                    default: true,
                    description: 'Whether the agent is active',
                    displayOptions: {
                        show: {
                            resource: ['agent'],
                            operation: ['create', 'update'],
                        },
                    },
                },
                {
                    displayName: 'Name',
                    name: 'agentUpdateName',
                    type: 'string',
                    default: '',
                    placeholder: 'Enter agent name',
                    description: 'New name for the agent',
                    displayOptions: {
                        show: {
                            resource: ['agent'],
                            operation: ['update'],
                        },
                    },
                },
                {
                    displayName: 'Main Prompt',
                    name: 'updateMainPrompt',
                    type: 'string',
                    typeOptions: {
                        rows: 4,
                    },
                    default: '',
                    placeholder: 'Enter main prompt',
                    description: "Updated prompt that defines the agent's behavior",
                    displayOptions: {
                        show: {
                            resource: ['agent'],
                            operation: ['update'],
                        },
                    },
                },
                {
                    displayName: 'Operation',
                    name: 'operation',
                    type: 'options',
                    noDataExpression: true,
                    displayOptions: {
                        show: {
                            resource: ['content'],
                        },
                    },
                    options: [
                        {
                            name: 'Create',
                            value: 'create',
                            description: 'Create new content',
                            action: 'Create content',
                        },
                        {
                            name: 'Delete',
                            value: 'delete',
                            description: 'Delete content',
                            action: 'Delete content',
                        },
                        {
                            name: 'Get by ID',
                            value: 'get',
                            description: 'Get a specific content by ID',
                            action: 'Get content',
                        },
                        {
                            name: 'Get Many',
                            value: 'getAll',
                            description: 'Get many content for the authenticated company',
                            action: 'Get many content',
                        },
                        {
                            name: 'Update',
                            value: 'update',
                            description: 'Update content',
                            action: 'Update content',
                        },
                    ],
                    default: 'getAll',
                },
                {
                    displayName: 'Content ID',
                    name: 'contentId',
                    type: 'string',
                    default: '',
                    required: true,
                    placeholder: 'Enter Content ID',
                    description: 'The unique identifier of the content',
                    displayOptions: {
                        show: {
                            resource: ['content'],
                            operation: ['get', 'update', 'delete'],
                        },
                    },
                },
                {
                    displayName: 'Workflow ID',
                    name: 'contentWorkflowId',
                    type: 'string',
                    default: '',
                    required: true,
                    placeholder: 'Enter Workflow ID',
                    description: 'ID of the workflow to which the content belongs',
                    displayOptions: {
                        show: {
                            resource: ['content'],
                            operation: ['create'],
                        },
                    },
                },
                {
                    displayName: 'Title',
                    name: 'contentTitle',
                    type: 'string',
                    default: '',
                    required: true,
                    placeholder: 'Enter content title',
                    description: 'Content title',
                    displayOptions: {
                        show: {
                            resource: ['content'],
                            operation: ['create'],
                        },
                    },
                },
                {
                    displayName: 'Type',
                    name: 'contentType',
                    type: 'options',
                    default: 'text',
                    required: true,
                    options: [
                        {
                            name: 'Text',
                            value: 'text',
                        },
                        {
                            name: 'FAQ',
                            value: 'faq',
                        },
                    ],
                    description: 'Content type',
                    displayOptions: {
                        show: {
                            resource: ['content'],
                            operation: ['create'],
                        },
                    },
                },
                {
                    displayName: 'Content',
                    name: 'contentText',
                    type: 'string',
                    typeOptions: {
                        rows: 4,
                    },
                    default: '',
                    required: true,
                    placeholder: 'Enter content text',
                    description: 'The content itself (for text type)',
                    displayOptions: {
                        show: {
                            resource: ['content'],
                            operation: ['create'],
                            contentType: ['text'],
                        },
                    },
                },
                {
                    displayName: 'FAQ Items',
                    name: 'faqItems',
                    type: 'json',
                    default: '[]',
                    required: true,
                    placeholder: '[{"ID": "faq1", "question": "Question?", "answer": "Answer"}]',
                    description: 'Array of FAQ items. Each item must have ID (string), question (string), and answer (string).',
                    displayOptions: {
                        show: {
                            resource: ['content'],
                            operation: ['create'],
                            contentType: ['faq'],
                        },
                    },
                },
                {
                    displayName: 'Title',
                    name: 'contentUpdateTitle',
                    type: 'string',
                    default: '',
                    placeholder: 'Enter content title',
                    description: 'Updated title',
                    displayOptions: {
                        show: {
                            resource: ['content'],
                            operation: ['update'],
                        },
                    },
                },
                {
                    displayName: 'Content',
                    name: 'contentUpdateText',
                    type: 'string',
                    typeOptions: {
                        rows: 4,
                    },
                    default: '',
                    placeholder: 'Enter content text',
                    description: 'Updated content (for text type)',
                    displayOptions: {
                        show: {
                            resource: ['content'],
                            operation: ['update'],
                        },
                    },
                },
                {
                    displayName: 'FAQ Items',
                    name: 'updateFaqItems',
                    type: 'json',
                    default: '',
                    placeholder: '[{"ID": "faq1", "question": "Question?", "answer": "Answer"}]',
                    description: 'Updated array of questions and answers (for faq type)',
                    displayOptions: {
                        show: {
                            resource: ['content'],
                            operation: ['update'],
                        },
                    },
                },
                {
                    displayName: 'Operation',
                    name: 'operation',
                    type: 'options',
                    noDataExpression: true,
                    displayOptions: {
                        show: {
                            resource: ['conversation'],
                        },
                    },
                    options: [
                        {
                            name: 'Get Many',
                            value: 'getAll',
                            description: 'Get many conversations for the authenticated company',
                            action: 'Get many conversations',
                        },
                        {
                            name: 'Create or Update',
                            value: 'create',
                            description: 'Create or update a conversation',
                            action: 'Create or update a conversation',
                        },
                        {
                            name: 'Get by ID',
                            value: 'get',
                            description: 'Get a specific conversation by ID',
                            action: 'Get a conversation',
                        },
                        {
                            name: 'Update',
                            value: 'update',
                            description: 'Update a conversation',
                            action: 'Update a conversation',
                        },
                    ],
                    default: 'getAll',
                },
                {
                    displayName: 'Conversation ID',
                    name: 'conversationId',
                    type: 'string',
                    default: '',
                    required: true,
                    placeholder: 'Enter Conversation ID',
                    description: 'The unique identifier of the conversation',
                    displayOptions: {
                        show: {
                            resource: ['conversation'],
                            operation: ['get', 'update'],
                        },
                    },
                },
                {
                    displayName: 'Session ID',
                    name: 'sessionId',
                    type: 'string',
                    default: '',
                    required: true,
                    placeholder: 'Enter Session ID',
                    description: 'Unique session identifier. Identifies the specific conversation.',
                    displayOptions: {
                        show: {
                            resource: ['conversation'],
                            operation: ['create'],
                        },
                    },
                },
                {
                    displayName: 'Workflow ID',
                    name: 'conversationWorkflowId',
                    type: 'string',
                    default: '',
                    required: true,
                    placeholder: 'Enter Workflow ID',
                    description: 'ID of the workflow to which the conversation belongs',
                    displayOptions: {
                        show: {
                            resource: ['conversation'],
                            operation: ['create'],
                        },
                    },
                },
                {
                    displayName: 'IP Address',
                    name: 'ipAddress',
                    type: 'string',
                    default: '',
                    placeholder: 'Enter IP address',
                    description: "User's IP address. Used for tracking and security.",
                    displayOptions: {
                        show: {
                            resource: ['conversation'],
                            operation: ['create'],
                        },
                    },
                },
                {
                    displayName: 'Phone Number',
                    name: 'phoneNumber',
                    type: 'string',
                    default: '',
                    placeholder: 'Enter phone number',
                    description: "User's phone number (if relevant)",
                    displayOptions: {
                        show: {
                            resource: ['conversation'],
                            operation: ['create'],
                        },
                    },
                },
                {
                    displayName: 'Status',
                    name: 'conversationStatus',
                    type: 'number',
                    default: 1,
                    description: 'Conversation status. Number representing the conversation state.',
                    displayOptions: {
                        show: {
                            resource: ['conversation'],
                            operation: ['update'],
                        },
                    },
                },
                {
                    displayName: 'Requires Human Attention',
                    name: 'requiresHumanAttention',
                    type: 'boolean',
                    default: false,
                    description: 'Whether the conversation requires human attention',
                    displayOptions: {
                        show: {
                            resource: ['conversation'],
                            operation: ['update'],
                        },
                    },
                },
                {
                    displayName: 'Is Handled By Human',
                    name: 'isHandledByHuman',
                    type: 'boolean',
                    default: false,
                    description: 'Whether the conversation is handled by a human',
                    displayOptions: {
                        show: {
                            resource: ['conversation'],
                            operation: ['update'],
                        },
                    },
                },
                {
                    displayName: 'Last Context',
                    name: 'lastContext',
                    type: 'string',
                    typeOptions: {
                        rows: 2,
                    },
                    default: '',
                    placeholder: 'Enter last context',
                    description: 'Last context in the conversation. Additional information about the conversation state.',
                    displayOptions: {
                        show: {
                            resource: ['conversation'],
                            operation: ['update'],
                        },
                    },
                },
                {
                    displayName: 'Operation',
                    name: 'operation',
                    type: 'options',
                    noDataExpression: true,
                    displayOptions: {
                        show: {
                            resource: ['message'],
                        },
                    },
                    options: [
                        {
                            name: 'Get Many',
                            value: 'getAll',
                            description: 'Get many messages for a conversation',
                            action: 'Get many messages',
                        },
                        {
                            name: 'Create',
                            value: 'create',
                            description: 'Create a new message (with optional conversation auto-creation)',
                            action: 'Create a message',
                        },
                        {
                            name: 'Get by ID',
                            value: 'get',
                            description: 'Get a specific message by ID',
                            action: 'Get a message',
                        },
                    ],
                    default: 'getAll',
                },
                {
                    displayName: 'Conversation ID',
                    name: 'messageConversationId',
                    type: 'string',
                    default: '',
                    required: true,
                    placeholder: 'Enter Conversation ID',
                    description: 'ID of the conversation (query parameter for Get Many, required for legacy mode Create)',
                    displayOptions: {
                        show: {
                            resource: ['message'],
                            operation: ['getAll'],
                        },
                    },
                },
                {
                    displayName: 'Message ID',
                    name: 'messageId',
                    type: 'string',
                    default: '',
                    required: true,
                    placeholder: 'Enter Message ID',
                    description: 'The unique identifier of the message',
                    displayOptions: {
                        show: {
                            resource: ['message'],
                            operation: ['get'],
                        },
                    },
                },
                {
                    displayName: 'Mode',
                    name: 'mode',
                    type: 'options',
                    default: 'unified',
                    options: [
                        {
                            name: 'Unified (Auto-Create Conversation)',
                            value: 'unified',
                            description: 'Automatically create or update conversation based on sessionId',
                        },
                        {
                            name: 'Legacy (Use conversationId)',
                            value: 'legacy',
                            description: 'Use existing conversationId (backward compatibility)',
                        },
                    ],
                    description: 'Message creation mode',
                    displayOptions: {
                        show: {
                            resource: ['message'],
                            operation: ['create'],
                        },
                    },
                },
                {
                    displayName: 'Session ID',
                    name: 'messageSessionId',
                    type: 'string',
                    default: '',
                    required: true,
                    placeholder: 'Enter Session ID',
                    description: 'Unique session identifier. Required if unified mode.',
                    displayOptions: {
                        show: {
                            resource: ['message'],
                            operation: ['create'],
                            mode: ['unified'],
                        },
                    },
                },
                {
                    displayName: 'Workflow ID',
                    name: 'messageWorkflowId',
                    type: 'string',
                    default: '',
                    required: true,
                    placeholder: 'Enter Workflow ID',
                    description: 'ID of the workflow to which the conversation belongs. Required if unified mode.',
                    displayOptions: {
                        show: {
                            resource: ['message'],
                            operation: ['create'],
                            mode: ['unified'],
                        },
                    },
                },
                {
                    displayName: 'Conversation ID',
                    name: 'legacyConversationId',
                    type: 'string',
                    default: '',
                    required: true,
                    placeholder: 'Enter Conversation ID',
                    description: 'ID of the conversation to which the message belongs. Required if legacy mode.',
                    displayOptions: {
                        show: {
                            resource: ['message'],
                            operation: ['create'],
                            mode: ['legacy'],
                        },
                    },
                },
                {
                    displayName: 'Content',
                    name: 'messageContent',
                    type: 'string',
                    typeOptions: {
                        rows: 4,
                    },
                    default: '',
                    required: true,
                    placeholder: 'Enter message content',
                    description: 'Message content. The text of the message.',
                    displayOptions: {
                        show: {
                            resource: ['message'],
                            operation: ['create'],
                        },
                    },
                },
                {
                    displayName: 'Direction',
                    name: 'direction',
                    type: 'options',
                    default: 0,
                    required: true,
                    options: [
                        {
                            name: 'From User to Agent',
                            value: 0,
                        },
                        {
                            name: 'From Agent to User',
                            value: 1,
                        },
                    ],
                    description: 'Message direction: 0 (from user to agent) or 1 (from agent to user)',
                    displayOptions: {
                        show: {
                            resource: ['message'],
                            operation: ['create'],
                        },
                    },
                },
                {
                    displayName: 'Phone Number',
                    name: 'messagePhoneNumber',
                    type: 'string',
                    default: '',
                    placeholder: 'Enter phone number',
                    description: "User's phone number (if relevant)",
                    displayOptions: {
                        show: {
                            resource: ['message'],
                            operation: ['create'],
                            mode: ['unified'],
                        },
                    },
                },
                {
                    displayName: 'Conversation Status',
                    name: 'messageConversationStatus',
                    type: 'number',
                    default: 1,
                    description: 'Conversation status. Number representing the conversation state.',
                    displayOptions: {
                        show: {
                            resource: ['message'],
                            operation: ['create'],
                            mode: ['unified'],
                        },
                    },
                },
                {
                    displayName: 'Overall Sentiment',
                    name: 'overallSentiment',
                    type: 'number',
                    default: 100,
                    description: 'Overall sentiment score for the conversation',
                    typeOptions: {
                        minValue: 0,
                        maxValue: 100,
                    },
                    displayOptions: {
                        show: {
                            resource: ['message'],
                            operation: ['create'],
                            mode: ['unified'],
                        },
                    },
                },
                {
                    displayName: 'Requires Human Attention',
                    name: 'messageRequiresHumanAttention',
                    type: 'boolean',
                    default: false,
                    description: 'Whether conversation requires human intervention',
                    displayOptions: {
                        show: {
                            resource: ['message'],
                            operation: ['create'],
                            mode: ['unified'],
                        },
                    },
                },
                {
                    displayName: 'Is Handled By Human',
                    name: 'messageIsHandledByHuman',
                    type: 'boolean',
                    default: false,
                    description: 'Whether the conversation is handled by a human',
                    displayOptions: {
                        show: {
                            resource: ['message'],
                            operation: ['create'],
                            mode: ['unified'],
                        },
                    },
                },
                {
                    displayName: 'Session ID',
                    name: 'legacySessionId',
                    type: 'string',
                    default: '',
                    placeholder: 'Enter Session ID',
                    description: 'Session identifier. Used when conversation object is not provided.',
                    displayOptions: {
                        show: {
                            resource: ['message'],
                            operation: ['create'],
                            mode: ['legacy'],
                        },
                    },
                },
                {
                    displayName: 'Message SID',
                    name: 'messageSid',
                    type: 'string',
                    default: '',
                    placeholder: 'Enter Message SID',
                    description: 'External message identifier (e.g., WhatsApp message ID)',
                    displayOptions: {
                        show: {
                            resource: ['message'],
                            operation: ['create'],
                        },
                    },
                },
                {
                    displayName: 'Sentiment Score',
                    name: 'sentimentScore',
                    type: 'number',
                    default: 100,
                    description: 'Sentiment score for this specific message',
                    typeOptions: {
                        minValue: 0,
                        maxValue: 100,
                    },
                    displayOptions: {
                        show: {
                            resource: ['message'],
                            operation: ['create'],
                        },
                    },
                },
                {
                    displayName: 'Status',
                    name: 'messageStatus',
                    type: 'number',
                    default: 0,
                    description: 'Message status',
                    displayOptions: {
                        show: {
                            resource: ['message'],
                            operation: ['create'],
                        },
                    },
                },
                {
                    displayName: 'Template ID',
                    name: 'templateId',
                    type: 'string',
                    default: '',
                    placeholder: 'Enter Template ID',
                    description: 'ID of the template used for this message (if applicable)',
                    displayOptions: {
                        show: {
                            resource: ['message'],
                            operation: ['create'],
                        },
                    },
                },
                {
                    displayName: 'Error Message',
                    name: 'errorMessage',
                    type: 'string',
                    default: '',
                    placeholder: 'Enter error message',
                    description: 'Error message if message creation failed',
                    displayOptions: {
                        show: {
                            resource: ['message'],
                            operation: ['create'],
                        },
                    },
                },
                {
                    displayName: 'Operation',
                    name: 'operation',
                    type: 'options',
                    noDataExpression: true,
                    displayOptions: {
                        show: {
                            resource: ['file'],
                        },
                    },
                    options: [
                        {
                            name: 'Get Many',
                            value: 'getAll',
                            description: 'Get many files for the authenticated company',
                            action: 'Get many files',
                        },
                        {
                            name: 'Get by ID',
                            value: 'get',
                            description: 'Get a specific file by ID',
                            action: 'Get a file',
                        },
                        {
                            name: 'Delete',
                            value: 'delete',
                            description: 'Delete a file',
                            action: 'Delete a file',
                        },
                    ],
                    default: 'getAll',
                },
                {
                    displayName: 'File ID',
                    name: 'fileId',
                    type: 'string',
                    default: '',
                    required: true,
                    placeholder: 'Enter File ID',
                    description: 'The unique identifier of the file',
                    displayOptions: {
                        show: {
                            resource: ['file'],
                            operation: ['get', 'delete'],
                        },
                    },
                },
            ],
        };
    }
    async execute() {
        const items = this.getInputData();
        const returnData = [];
        const baseUrl = 'https://app.agentic-hub.ai/api/v1';
        for (let itemIndex = 0; itemIndex < items.length; itemIndex++) {
            try {
                const credentials = await this.getCredentials('agenticHubApi');
                const resource = this.getNodeParameter('resource', itemIndex);
                const operation = this.getNodeParameter('operation', itemIndex);
                let response;
                const options = {
                    url: '',
                    headers: {
                        'x-api-key': credentials.apiKey,
                        'x-company-id': credentials.companyId,
                    },
                    json: true,
                };
                if (resource === 'project') {
                    if (operation === 'getAll') {
                        options.method = 'GET';
                        options.url = `${baseUrl}/projects`;
                    }
                    else if (operation === 'create') {
                        const name = this.getNodeParameter('name', itemIndex);
                        const description = this.getNodeParameter('description', itemIndex, '');
                        const status = this.getNodeParameter('status', itemIndex, 'active');
                        options.method = 'POST';
                        options.url = `${baseUrl}/projects`;
                        options.body = {
                            name,
                            ...(description && { description }),
                            ...(status && { status }),
                        };
                    }
                    else if (operation === 'get') {
                        const projectId = this.getNodeParameter('projectId', itemIndex);
                        options.method = 'GET';
                        options.url = `${baseUrl}/projects/${projectId}`;
                    }
                    else if (operation === 'update') {
                        const projectId = this.getNodeParameter('projectId', itemIndex);
                        const name = this.getNodeParameter('updateName', itemIndex, '');
                        const description = this.getNodeParameter('description', itemIndex, '');
                        const status = this.getNodeParameter('status', itemIndex, '');
                        options.method = 'PUT';
                        options.url = `${baseUrl}/projects/${projectId}`;
                        const body = {};
                        if (name)
                            body.name = name;
                        if (description)
                            body.description = description;
                        if (status)
                            body.status = status;
                        options.body = body;
                    }
                    else if (operation === 'delete') {
                        const projectId = this.getNodeParameter('projectId', itemIndex);
                        options.method = 'DELETE';
                        options.url = `${baseUrl}/projects/${projectId}`;
                    }
                }
                else if (resource === 'workflow') {
                    if (operation === 'getAll') {
                        options.method = 'GET';
                        options.url = `${baseUrl}/workflows`;
                    }
                    else if (operation === 'create') {
                        const name = this.getNodeParameter('workflowName', itemIndex);
                        const projectId = this.getNodeParameter('workflowProjectId', itemIndex);
                        const description = this.getNodeParameter('workflowDescription', itemIndex, '');
                        const status = this.getNodeParameter('workflowStatus', itemIndex, 'active');
                        options.method = 'POST';
                        options.url = `${baseUrl}/workflows`;
                        options.body = {
                            name,
                            projectId,
                            ...(description && { description }),
                            ...(status && { status }),
                        };
                    }
                    else if (operation === 'get') {
                        const workflowId = this.getNodeParameter('workflowId', itemIndex);
                        options.method = 'GET';
                        options.url = `${baseUrl}/workflows/${workflowId}`;
                    }
                    else if (operation === 'update') {
                        const workflowId = this.getNodeParameter('workflowId', itemIndex);
                        const name = this.getNodeParameter('workflowUpdateName', itemIndex, '');
                        const description = this.getNodeParameter('workflowDescription', itemIndex, '');
                        const status = this.getNodeParameter('workflowStatus', itemIndex, '');
                        options.method = 'PUT';
                        options.url = `${baseUrl}/workflows/${workflowId}`;
                        const body = {};
                        if (name)
                            body.name = name;
                        if (description)
                            body.description = description;
                        if (status)
                            body.status = status;
                        options.body = body;
                    }
                    else if (operation === 'delete') {
                        const workflowId = this.getNodeParameter('workflowId', itemIndex);
                        options.method = 'DELETE';
                        options.url = `${baseUrl}/workflows/${workflowId}`;
                    }
                }
                else if (resource === 'agent') {
                    if (operation === 'getAll') {
                        options.method = 'GET';
                        options.url = `${baseUrl}/agents`;
                    }
                    else if (operation === 'create') {
                        const name = this.getNodeParameter('agentName', itemIndex);
                        const workflowId = this.getNodeParameter('agentWorkflowId', itemIndex);
                        const mainPrompt = this.getNodeParameter('mainPrompt', itemIndex);
                        const dynamicFieldsStr = this.getNodeParameter('dynamicFields', itemIndex, '[]');
                        const isActive = this.getNodeParameter('isActive', itemIndex, true);
                        let dynamicFields = [];
                        try {
                            dynamicFields = JSON.parse(dynamicFieldsStr);
                        }
                        catch (e) {
                            dynamicFields = [];
                        }
                        options.method = 'POST';
                        options.url = `${baseUrl}/agents`;
                        options.body = {
                            name,
                            workflowId,
                            mainPrompt,
                            ...(dynamicFields.length > 0 && { dynamicFields }),
                            isActive,
                        };
                    }
                    else if (operation === 'get') {
                        const agentId = this.getNodeParameter('agentId', itemIndex);
                        options.method = 'GET';
                        options.url = `${baseUrl}/agents/${agentId}`;
                    }
                    else if (operation === 'update') {
                        const agentId = this.getNodeParameter('agentId', itemIndex);
                        const name = this.getNodeParameter('agentUpdateName', itemIndex, '');
                        const mainPrompt = this.getNodeParameter('updateMainPrompt', itemIndex, '');
                        const dynamicFieldsStr = this.getNodeParameter('dynamicFields', itemIndex, '');
                        const isActive = this.getNodeParameter('isActive', itemIndex, undefined);
                        options.method = 'PUT';
                        options.url = `${baseUrl}/agents/${agentId}`;
                        const body = {};
                        if (name)
                            body.name = name;
                        if (mainPrompt)
                            body.mainPrompt = mainPrompt;
                        if (dynamicFieldsStr) {
                            try {
                                body.dynamicFields = JSON.parse(dynamicFieldsStr);
                            }
                            catch (e) {
                            }
                        }
                        if (isActive !== undefined)
                            body.isActive = isActive;
                        options.body = body;
                    }
                    else if (operation === 'delete') {
                        const agentId = this.getNodeParameter('agentId', itemIndex);
                        options.method = 'DELETE';
                        options.url = `${baseUrl}/agents/${agentId}`;
                    }
                }
                else if (resource === 'content') {
                    if (operation === 'getAll') {
                        options.method = 'GET';
                        options.url = `${baseUrl}/content`;
                    }
                    else if (operation === 'create') {
                        const workflowId = this.getNodeParameter('contentWorkflowId', itemIndex);
                        const title = this.getNodeParameter('contentTitle', itemIndex);
                        const type = this.getNodeParameter('contentType', itemIndex);
                        options.method = 'POST';
                        options.url = `${baseUrl}/content`;
                        const body = {
                            workflowId,
                            title,
                            type,
                        };
                        if (type === 'text') {
                            const content = this.getNodeParameter('contentText', itemIndex);
                            body.content = content;
                        }
                        else if (type === 'faq') {
                            const faqItemsStr = this.getNodeParameter('faqItems', itemIndex);
                            try {
                                body.faqItems = JSON.parse(faqItemsStr);
                            }
                            catch (e) {
                                throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Invalid FAQ items JSON format', {
                                    itemIndex,
                                });
                            }
                        }
                        options.body = body;
                    }
                    else if (operation === 'get') {
                        const contentId = this.getNodeParameter('contentId', itemIndex);
                        options.method = 'GET';
                        options.url = `${baseUrl}/content/${contentId}`;
                    }
                    else if (operation === 'update') {
                        const contentId = this.getNodeParameter('contentId', itemIndex);
                        const title = this.getNodeParameter('contentUpdateTitle', itemIndex, '');
                        const content = this.getNodeParameter('contentUpdateText', itemIndex, '');
                        const faqItemsStr = this.getNodeParameter('updateFaqItems', itemIndex, '');
                        options.method = 'PUT';
                        options.url = `${baseUrl}/content/${contentId}`;
                        const body = {};
                        if (title)
                            body.title = title;
                        if (content)
                            body.content = content;
                        if (faqItemsStr) {
                            try {
                                body.faqItems = JSON.parse(faqItemsStr);
                            }
                            catch (e) {
                                throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Invalid FAQ items JSON format', {
                                    itemIndex,
                                });
                            }
                        }
                        options.body = body;
                    }
                    else if (operation === 'delete') {
                        const contentId = this.getNodeParameter('contentId', itemIndex);
                        options.method = 'DELETE';
                        options.url = `${baseUrl}/content/${contentId}`;
                    }
                }
                else if (resource === 'conversation') {
                    if (operation === 'getAll') {
                        options.method = 'GET';
                        options.url = `${baseUrl}/conversations`;
                    }
                    else if (operation === 'create') {
                        const sessionId = this.getNodeParameter('sessionId', itemIndex);
                        const workflowId = this.getNodeParameter('conversationWorkflowId', itemIndex);
                        const ipAddress = this.getNodeParameter('ipAddress', itemIndex, '');
                        const phoneNumber = this.getNodeParameter('phoneNumber', itemIndex, '');
                        options.method = 'POST';
                        options.url = `${baseUrl}/conversations`;
                        options.body = {
                            sessionId,
                            workflowId,
                            ...(ipAddress && { ipAddress }),
                            ...(phoneNumber && { phoneNumber }),
                        };
                    }
                    else if (operation === 'get') {
                        const conversationId = this.getNodeParameter('conversationId', itemIndex);
                        options.method = 'GET';
                        options.url = `${baseUrl}/conversations/${conversationId}`;
                    }
                    else if (operation === 'update') {
                        const conversationId = this.getNodeParameter('conversationId', itemIndex);
                        const status = this.getNodeParameter('conversationStatus', itemIndex, undefined);
                        const requiresHumanAttention = this.getNodeParameter('requiresHumanAttention', itemIndex, undefined);
                        const isHandledByHuman = this.getNodeParameter('isHandledByHuman', itemIndex, undefined);
                        const lastContext = this.getNodeParameter('lastContext', itemIndex, '');
                        options.method = 'PUT';
                        options.url = `${baseUrl}/conversations/${conversationId}`;
                        const body = {};
                        if (status !== undefined)
                            body.status = status;
                        if (requiresHumanAttention !== undefined)
                            body.requiresHumanAttention = requiresHumanAttention;
                        if (isHandledByHuman !== undefined)
                            body.isHandledByHuman = isHandledByHuman;
                        if (lastContext)
                            body.lastContext = lastContext;
                        options.body = body;
                    }
                }
                else if (resource === 'message') {
                    if (operation === 'getAll') {
                        const conversationId = this.getNodeParameter('messageConversationId', itemIndex);
                        options.method = 'GET';
                        options.url = `${baseUrl}/messages?conversationId=${conversationId}`;
                    }
                    else if (operation === 'create') {
                        const mode = this.getNodeParameter('mode', itemIndex, 'unified');
                        const content = this.getNodeParameter('messageContent', itemIndex);
                        const direction = this.getNodeParameter('direction', itemIndex);
                        const messageSid = this.getNodeParameter('messageSid', itemIndex, '');
                        const sentimentScore = this.getNodeParameter('sentimentScore', itemIndex, undefined);
                        const status = this.getNodeParameter('messageStatus', itemIndex, undefined);
                        const templateId = this.getNodeParameter('templateId', itemIndex, '');
                        const errorMessage = this.getNodeParameter('errorMessage', itemIndex, '');
                        options.method = 'POST';
                        options.url = `${baseUrl}/messages`;
                        const messageBody = {
                            content,
                            direction,
                        };
                        if (messageSid)
                            messageBody.messageSid = messageSid;
                        if (sentimentScore !== undefined)
                            messageBody.sentimentScore = sentimentScore;
                        if (status !== undefined)
                            messageBody.status = status;
                        if (templateId)
                            messageBody.templateId = templateId;
                        if (errorMessage)
                            messageBody.errorMessage = errorMessage;
                        if (mode === 'unified') {
                            const sessionId = this.getNodeParameter('messageSessionId', itemIndex);
                            const workflowId = this.getNodeParameter('messageWorkflowId', itemIndex);
                            const phoneNumber = this.getNodeParameter('messagePhoneNumber', itemIndex, '');
                            const conversationStatus = this.getNodeParameter('messageConversationStatus', itemIndex, undefined);
                            const overallSentiment = this.getNodeParameter('overallSentiment', itemIndex, undefined);
                            const requiresHumanAttention = this.getNodeParameter('messageRequiresHumanAttention', itemIndex, undefined);
                            const isHandledByHuman = this.getNodeParameter('messageIsHandledByHuman', itemIndex, undefined);
                            const conversation = {
                                sessionId,
                                workflowId,
                            };
                            if (phoneNumber && phoneNumber.trim() !== '') {
                                conversation.phoneNumber = phoneNumber;
                            }
                            if (conversationStatus !== undefined && conversationStatus !== null) {
                                conversation.status = conversationStatus;
                            }
                            if (overallSentiment !== undefined && overallSentiment !== null) {
                                conversation.overallSentiment = overallSentiment;
                            }
                            if (requiresHumanAttention !== undefined && requiresHumanAttention !== null) {
                                conversation.requiresHumanAttention = requiresHumanAttention;
                            }
                            if (isHandledByHuman !== undefined && isHandledByHuman !== null) {
                                conversation.isHandledByHuman = isHandledByHuman;
                            }
                            messageBody.conversation = conversation;
                        }
                        else {
                            const conversationId = this.getNodeParameter('legacyConversationId', itemIndex);
                            const sessionId = this.getNodeParameter('legacySessionId', itemIndex, '');
                            messageBody.conversationId = conversationId;
                            if (sessionId)
                                messageBody.sessionId = sessionId;
                        }
                        options.body = messageBody;
                    }
                    else if (operation === 'get') {
                        const messageId = this.getNodeParameter('messageId', itemIndex);
                        options.method = 'GET';
                        options.url = `${baseUrl}/messages/${messageId}`;
                    }
                }
                else if (resource === 'file') {
                    if (operation === 'getAll') {
                        options.method = 'GET';
                        options.url = `${baseUrl}/files`;
                    }
                    else if (operation === 'get') {
                        const fileId = this.getNodeParameter('fileId', itemIndex);
                        options.method = 'GET';
                        options.url = `${baseUrl}/files/${fileId}`;
                    }
                    else if (operation === 'delete') {
                        const fileId = this.getNodeParameter('fileId', itemIndex);
                        options.method = 'DELETE';
                        options.url = `${baseUrl}/files/${fileId}`;
                    }
                }
                response = await this.helpers.httpRequest(options);
                returnData.push({
                    json: response,
                    pairedItem: itemIndex,
                });
            }
            catch (error) {
                if (this.continueOnFail()) {
                    returnData.push({
                        json: {
                            success: false,
                            error: error.message,
                            timestamp: new Date().toISOString(),
                        },
                        error,
                        pairedItem: itemIndex,
                    });
                }
                else {
                    if (error.context) {
                        error.context.itemIndex = itemIndex;
                        throw error;
                    }
                    throw new n8n_workflow_1.NodeOperationError(this.getNode(), error, {
                        itemIndex,
                    });
                }
            }
        }
        return [returnData];
    }
}
exports.AgenticHub = AgenticHub;
//# sourceMappingURL=AgenticHub.node.js.map