AutomationFlowsAI & RAG › Ai-powered Document Chat with Nextcloud Files Using Langchain and Openai

Ai-powered Document Chat with Nextcloud Files Using Langchain and Openai

Byjohappel @johappel on n8n.io

Entry point*: A public chat-trigger greets the user; every incoming chat message starts the flow. AI agent*: A LangChain agent (“AI Nextcloud”) uses the configured OpenAI model plus short-term memory to continue the dialogue in context. Purpose*: Answers questions about files…

Chat trigger trigger★★★★☆ complexityAI-powered21 nodesChat TriggerOpenAI ChatMemory Buffer WindowAgentExecute Workflow TriggerNext CloudTool WorkflowN8N Nodes Word2Text
AI & RAG Trigger: Chat trigger Nodes: 21 Complexity: ★★★★☆ AI nodes: yes Added:

This workflow corresponds to n8n.io template #4465 — we link there as the canonical source.

This workflow follows the Agent → Chat Trigger recipe pattern — see all workflows that pair these two integrations.

The workflow JSON

Copy or download the full n8n JSON below. Paste it into a new n8n workflow, add your credentials, activate. Full import guide →

Download .json
{
  "nodes": [
    {
      "id": "9745c907-14fe-49b8-9acf-b4e847bf2ebc",
      "name": "When chat message received",
      "type": "@n8n/n8n-nodes-langchain.chatTrigger",
      "position": [
        -1060,
        -200
      ],
      "parameters": {
        "public": true,
        "options": {},
        "initialMessages": "Hi there! \ud83d\udc4b\nMy name is Johan. How can I assist you today?"
      },
      "typeVersion": 1.1
    },
    {
      "id": "aa540b75-cb88-4f09-b76a-c1a66b2eb34b",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        -1000,
        40
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "qwen3-235b-a22b",
          "cachedResultName": "qwen3-235b-a22b"
        },
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "fcb5b3c9-c0d4-41b1-8f76-58c2bb1bf822",
      "name": "Simple Memory",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        -840,
        40
      ],
      "parameters": {},
      "typeVersion": 1.3
    },
    {
      "id": "da680124-9c4e-4bb7-9d70-8ae0d5515bb0",
      "name": "AI Nextcloud",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        -860,
        -200
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 1.9
    },
    {
      "id": "cce0ea8a-5bd1-48ad-9e2c-bca053755278",
      "name": "When Executed by Another Workflow",
      "type": "n8n-nodes-base.executeWorkflowTrigger",
      "position": [
        -1620,
        580
      ],
      "parameters": {
        "workflowInputs": {
          "values": [
            {
              "name": "path"
            }
          ]
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "d382c346-4f35-4772-a3e3-2104be66ffce",
      "name": "Switch",
      "type": "n8n-nodes-base.switch",
      "position": [
        -720,
        500
      ],
      "parameters": {
        "rules": {
          "values": [
            {
              "outputKey": "pdf",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "902f5ebf-b91a-48d1-a1bf-9a46c98a0853",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.contentType }}",
                    "rightValue": "application/pdf"
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "md",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "8c48e515-832a-421c-8cde-7c1123c14467",
                    "operator": {
                      "type": "string",
                      "operation": "contains"
                    },
                    "leftValue": "={{ $json.contentType }}",
                    "rightValue": "text/markdown"
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "docx",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "044f36c5-5787-4308-9b49-8b28d0288649",
                    "operator": {
                      "name": "filter.operator.equals",
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.contentType }}",
                    "rightValue": "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
                  }
                ]
              },
              "renameOutput": true
            }
          ]
        },
        "options": {}
      },
      "typeVersion": 3.2
    },
    {
      "id": "14addc84-0661-4913-bf6b-9870cce876bf",
      "name": "Aggregate",
      "type": "n8n-nodes-base.aggregate",
      "position": [
        -60,
        500
      ],
      "parameters": {
        "options": {},
        "aggregate": "aggregateAllItemData"
      },
      "typeVersion": 1
    },
    {
      "id": "e7a14c39-5853-4e2f-8549-47917eedd3ac",
      "name": "output",
      "type": "n8n-nodes-base.set",
      "position": [
        120,
        500
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "0f77cdc0-3115-4abd-91aa-069a36b1a7ac",
              "name": "output",
              "type": "string",
              "value": "={{ $json.data }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "dc6ee0ee-b2e8-433d-8acb-b182dc6e8529",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1700,
        260
      ],
      "parameters": {
        "color": 6,
        "width": 2080,
        "height": 700,
        "content": "# Subworkflow \n\n## Nextcloud\n\nList Files in a gigven path and returns Dile contents form docs\n\nRequired Community Node:\nhttps://www.npmjs.com/package/n8n-nodes-word2text\n"
      },
      "typeVersion": 1
    },
    {
      "id": "858059e4-6a66-4442-8a04-d9cd4fd6dcc0",
      "name": "If readable",
      "type": "n8n-nodes-base.if",
      "position": [
        -1120,
        580
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "or",
          "conditions": [
            {
              "id": "dcc91aaa-d9bb-4c11-88b7-c569f811ec1d",
              "operator": {
                "type": "string",
                "operation": "contains"
              },
              "leftValue": "={{ $json.contentType }}",
              "rightValue": "pdf"
            },
            {
              "id": "b7695016-8a8d-460e-977e-f415443df1f2",
              "operator": {
                "type": "string",
                "operation": "contains"
              },
              "leftValue": "={{ $json.contentType }}",
              "rightValue": "markdown"
            },
            {
              "id": "ca8021f0-a853-4a09-aee9-96494a66d131",
              "operator": {
                "name": "filter.operator.equals",
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $json.contentType }}",
              "rightValue": "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "e3341daa-f89d-4666-848a-1dbcfb7a9f74",
      "name": "Get Files",
      "type": "n8n-nodes-base.nextCloud",
      "position": [
        -1300,
        580
      ],
      "parameters": {
        "path": "={{ $json.path }}",
        "resource": "folder",
        "operation": "list"
      },
      "credentials": {
        "nextCloudApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "23d1168d-c0f1-412c-bfe2-fc229cd0567a",
      "name": "Download File",
      "type": "n8n-nodes-base.nextCloud",
      "position": [
        -900,
        500
      ],
      "parameters": {
        "path": "={{ $json.path.urlDecode() }}",
        "operation": "download"
      },
      "credentials": {
        "nextCloudApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "9aaeb43a-6156-4c72-a090-9eb07fb2a85c",
      "name": "add path 1",
      "type": "n8n-nodes-base.code",
      "position": [
        -320,
        300
      ],
      "parameters": {
        "jsCode": "for (const item of $input.all()) {\n  item.json.path = $('Switch').first().json.path;\n}\n\nreturn $input.all();"
      },
      "typeVersion": 2
    },
    {
      "id": "fe21734c-e0e5-43f3-8bb9-4fd976ab61a9",
      "name": "add path 2",
      "type": "n8n-nodes-base.code",
      "position": [
        -320,
        500
      ],
      "parameters": {
        "jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nfor (const item of $input.all()) {\n  item.json.path = $('Switch').first().json.path;\n}\n\nreturn $input.all();"
      },
      "typeVersion": 2
    },
    {
      "id": "46bb7f6b-7a0d-4761-b50b-50ed8a0fd01a",
      "name": "add path 3",
      "type": "n8n-nodes-base.code",
      "position": [
        -320,
        720
      ],
      "parameters": {
        "jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nfor (const item of $input.all()) {\n  item.json.path = $('Switch').first().json.path;\n}\n\nreturn $input.all();"
      },
      "typeVersion": 2
    },
    {
      "id": "6124f284-2846-4c88-b075-2a2fec028664",
      "name": "test data",
      "type": "n8n-nodes-base.code",
      "position": [
        -1460,
        580
      ],
      "parameters": {
        "jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nfor (const item of $input.all()) {\n  item.json.path  = item.json.path || '/test/folder';\n}\n\nreturn $input.all();"
      },
      "typeVersion": 2
    },
    {
      "id": "7b11ef64-3887-4baa-a8ca-3c76c8f4eb02",
      "name": "Nextcloud Tool",
      "type": "@n8n/n8n-nodes-langchain.toolWorkflow",
      "position": [
        -700,
        40
      ],
      "parameters": {
        "workflowId": {
          "__rl": true,
          "mode": "list",
          "value": "fni6RBWYOcTGA0tT",
          "cachedResultName": "nextcloud-folder"
        },
        "description": "Call this tool to read files from a folder (in Nextcloud). Pass the folder path as a parameter.",
        "workflowInputs": {
          "value": {
            "path": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('path', ``, 'string') }}"
          },
          "schema": [
            {
              "id": "path",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "path",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "path"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "c78d765f-b6fe-40bb-9245-3ce50cb009b4",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1700,
        -260
      ],
      "parameters": {
        "width": 1260,
        "height": 460,
        "content": "# Main Workflow\n\n## AI Agent\n\nAnswers question to  folder contents. \n\nPut the Path to the folder into your question."
      },
      "typeVersion": 1
    },
    {
      "id": "147fe75b-022f-4fb0-8259-bc91286f54ca",
      "name": "PDF",
      "type": "n8n-nodes-base.extractFromFile",
      "position": [
        -500,
        300
      ],
      "parameters": {
        "options": {},
        "operation": "pdf"
      },
      "typeVersion": 1
    },
    {
      "id": "1bd71897-738a-46a2-b7e3-700e4ad9db8f",
      "name": "Markdown",
      "type": "n8n-nodes-base.extractFromFile",
      "position": [
        -500,
        500
      ],
      "parameters": {
        "options": {},
        "operation": "text",
        "destinationKey": "text"
      },
      "typeVersion": 1
    },
    {
      "id": "9ed19c46-55aa-4109-85c7-a8b9cf068568",
      "name": "DOCX",
      "type": "n8n-nodes-word2text.word2text",
      "position": [
        -500,
        740
      ],
      "parameters": {},
      "typeVersion": 1
    }
  ],
  "connections": {
    "PDF": {
      "main": [
        [
          {
            "node": "add path 1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "DOCX": {
      "main": [
        [
          {
            "node": "add path 3",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Switch": {
      "main": [
        [
          {
            "node": "PDF",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Markdown",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "DOCX",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Markdown": {
      "main": [
        [
          {
            "node": "add path 2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Aggregate": {
      "main": [
        [
          {
            "node": "output",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Files": {
      "main": [
        [
          {
            "node": "If readable",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "test data": {
      "main": [
        [
          {
            "node": "Get Files",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "add path 1": {
      "main": [
        [
          {
            "node": "Aggregate",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "add path 2": {
      "main": [
        [
          {
            "node": "Aggregate",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "add path 3": {
      "main": [
        [
          {
            "node": "Aggregate",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If readable": {
      "main": [
        [
          {
            "node": "Download File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download File": {
      "main": [
        [
          {
            "node": "Switch",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Simple Memory": {
      "ai_memory": [
        [
          {
            "node": "AI Nextcloud",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Nextcloud Tool": {
      "ai_tool": [
        [
          {
            "node": "AI Nextcloud",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Nextcloud",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "When chat message received": {
      "main": [
        [
          {
            "node": "AI Nextcloud",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When Executed by Another Workflow": {
      "main": [
        [
          {
            "node": "test data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

Credentials you'll need

Each integration node will prompt for credentials when you import. We strip credential IDs before publishing — you'll add your own.

Pro

For the full experience including quality scoring and batch install features for each workflow upgrade to Pro

About this workflow

Entry point*: A public chat-trigger greets the user; every incoming chat message starts the flow. AI agent*: A LangChain agent (“AI Nextcloud”) uses the configured OpenAI model plus short-term memory to continue the dialogue in context. Purpose*: Answers questions about files…

Source: https://n8n.io/workflows/4465/ — original creator credit. Request a take-down →

More AI & RAG workflows → · Browse all categories →

Related workflows

Workflows that share integrations, category, or trigger type with this one. All free to copy and import.

AI & RAG

by Varritech Technologies

Chat Trigger, Agent, OpenAI Chat +8
AI & RAG

Airtable AI Agent. Uses lmChatOpenAi, agent, toolWorkflow, toolCode. Chat trigger; 42 nodes.

OpenAI Chat, Agent, Tool Workflow +6
AI & RAG

Ai Agent To Chat With Airtable And Analyze Data. Uses lmChatOpenAi, agent, stickyNote, memoryBufferWindow. Chat trigger; 41 nodes.

OpenAI Chat, Agent, Memory Buffer Window +6
AI & RAG

I prepared a detailed guide that shows the entire process of building an AI agent that integrates with Airtable data in n8n. This template covers everything from data preparation to advanced configura

OpenAI Chat, Agent, Memory Buffer Window +6
AI & RAG

Categories: AI Agents, Design Automation, Business Tools

Tool Workflow, HTTP Request Tool, Memory Buffer Window +7