AutomationFlowsAI & RAG › AI Document Generator from Webhook

AI Document Generator from Webhook

Original n8n title: [frontend]-generatedocument

6-[Frontend]-GenerateDocument. Uses lmChatOpenAi, googleDrive. Webhook trigger; 11 nodes.

Webhook trigger★★★★☆ complexityAI-powered11 nodesOpenAI ChatGoogle Drive
AI & RAG Trigger: Webhook Nodes: 11 Complexity: ★★★★☆ AI nodes: yes Added:

This workflow follows the Google Drive → OpenAI Chat 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
{
  "name": "6-[Frontend]-GenerateDocument",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "legal-ai/generate-document",
        "options": {}
      },
      "id": "nodeWebHook",
      "name": "Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        -1020,
        220
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "name": "type",
              "value": "={{ $json.body.type || 'generic' }}",
              "type": "string"
            },
            {
              "name": "documentType",
              "value": "={{ $json.body.documentType || '' }}",
              "type": "string"
            },
            {
              "name": "description",
              "value": "={{ $json.body.description || '' }}",
              "type": "string"
            },
            {
              "name": "templateKey",
              "value": "={{ $json.body.templateKey || '' }}",
              "type": "string"
            },
            {
              "name": "notes",
              "value": "={{ $json.body.notes || '' }}",
              "type": "string"
            }
          ]
        }
      },
      "id": "nodeParseRequest",
      "name": "Parse Request",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -780,
        220
      ]
    },
    {
      "parameters": {
        "conditions": {
          "conditions": [
            {
              "leftValue": "={{ $json.type }}",
              "rightValue": "template",
              "operator": {
                "type": "string",
                "operation": "equals"
              }
            }
          ]
        }
      },
      "id": "nodeIsTemplate",
      "name": "Is Template?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.1,
      "position": [
        -540,
        220
      ]
    },
    {
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini"
        },
        "options": {
          "temperature": 0.2,
          "frequencyPenalty": 0,
          "presencePenalty": 0,
          "responseFormat": "json"
        },
        "messages": {
          "messageValues": [
            {
              "message": "Eres un asistente legal que redacta documentos en espa\u00f1ol profesional. Tipo: {{ $json.documentType || 'Documento Legal' }}. Descripci\u00f3n: {{ $json.description }}. Devuelve JSON con {\\\"title\\\", \\\"summary\\\", \\\"content\\\" (HTML)}."
            }
          ]
        }
      },
      "id": "nodeGenerateGeneric",
      "name": "Generar Borrador",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.2,
      "position": [
        -240,
        40
      ],
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "name": "status",
              "value": "success",
              "type": "string"
            },
            {
              "name": "mode",
              "value": "generic",
              "type": "string"
            },
            {
              "name": "title",
              "value": "={{ $json.output.title || `${$json.documentType} - ${new Date().toLocaleDateString('es-AR')}` }}",
              "type": "string"
            },
            {
              "name": "summary",
              "value": "={{ $json.output.summary || '' }}",
              "type": "string"
            },
            {
              "name": "content",
              "value": "={{ $json.output.content || '' }}",
              "type": "string"
            },
            {
              "name": "message",
              "value": "Borrador generado correctamente. Puedes copiar el contenido o pegarlo en un documento nuevo.",
              "type": "string"
            }
          ]
        }
      },
      "id": "nodePrepareGenericResponse",
      "name": "Preparar Respuesta Gen\u00e9rica",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        0,
        40
      ]
    },
    {
      "parameters": {
        "options": {}
      },
      "id": "nodeRespondGeneric",
      "name": "Responder Gen\u00e9rico",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.1,
      "position": [
        240,
        40
      ]
    },
    {
      "parameters": {
        "functionCode": "const templates = {\n  intimacion: { fileId: 'REEMPLAZA_CON_ID_INTIMACION', titlePrefix: 'Redacci\u00f3n Intimaci\u00f3n' },\n  carta_documento: { fileId: 'REEMPLAZA_CON_ID_CARTA_DOCUMENTO', titlePrefix: 'Carta Documento' },\n  demanda: { fileId: 'REEMPLAZA_CON_ID_DEMANDA', titlePrefix: 'Demanda' },\n  contrato: { fileId: 'REEMPLAZA_CON_ID_CONTRATO', titlePrefix: 'Contrato' },\n  poder: { fileId: 'REEMPLAZA_CON_ID_PODER', titlePrefix: 'Poder' }\n};\nconst key = (item.templateKey || '').toLowerCase();\nif (!templates[key]) {\n  throw new Error(`Plantilla no configurada para la clave: ${item.templateKey}`);\n}\nreturn {\n  ...item,\n  templateConfig: templates[key],\n  destinationFolderId: 'REEMPLAZA_CON_ID_CARPETA_REDACCIONES'\n};"
      },
      "id": "nodeSelectTemplate",
      "name": "Seleccionar Plantilla",
      "type": "n8n-nodes-base.function",
      "typeVersion": 2,
      "position": [
        -300,
        360
      ]
    },
    {
      "parameters": {
        "operation": "copy",
        "fileId": "={{ $json.templateConfig.fileId }}",
        "options": {
          "parentId": "={{ $json.destinationFolderId }}",
          "name": "={{ `${$json.templateConfig.titlePrefix} - ${(new Date()).toISOString().split('T')[0]}` }}"
        }
      },
      "id": "nodeCopyTemplate",
      "name": "Duplicar Plantilla",
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 3,
      "position": [
        -40,
        360
      ],
      "credentials": {
        "googleDriveOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "name": "status",
              "value": "success",
              "type": "string"
            },
            {
              "name": "mode",
              "value": "template",
              "type": "string"
            },
            {
              "name": "driveUrl",
              "value": "={{ $json.webViewLink || '' }}",
              "type": "string"
            },
            {
              "name": "fileId",
              "value": "={{ $json.id || '' }}",
              "type": "string"
            },
            {
              "name": "message",
              "value": "Documento duplicado correctamente en la carpeta de redacciones. Completa los campos variables y revisa antes de compartir.",
              "type": "string"
            }
          ]
        }
      },
      "id": "nodePrepareTemplateResponse",
      "name": "Preparar Respuesta Plantilla",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        200,
        360
      ]
    },
    {
      "parameters": {
        "options": {}
      },
      "id": "nodeRespondTemplate",
      "name": "Responder Plantilla",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.1,
      "position": [
        440,
        360
      ]
    },
    {
      "parameters": {
        "content": "## Flujo de generaci\u00f3n de documentos\n\n- Webhook: POST /legal-ai/generate-document\n- type=generic -> devuelve title/summary/content (HTML).\n- type=template -> duplica la plantilla en Google Drive.\n\n\u26a0\ufe0f Reemplaza los IDs de plantillas y la carpeta destino en el nodo \"Seleccionar Plantilla\".",
        "height": 360,
        "width": 720,
        "color": 4
      },
      "id": "nodeNote",
      "name": "Notas",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -600,
        -80
      ]
    }
  ],
  "connections": {
    "Webhook": {
      "main": [
        [
          {
            "node": "Parse Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse Request": {
      "main": [
        [
          {
            "node": "Is Template?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Is Template?": {
      "main": [
        [
          {
            "node": "Generar Borrador",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Seleccionar Plantilla",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generar Borrador": {
      "main": [
        [
          {
            "node": "Preparar Respuesta Gen\u00e9rica",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Preparar Respuesta Gen\u00e9rica": {
      "main": [
        [
          {
            "node": "Responder Gen\u00e9rico",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Seleccionar Plantilla": {
      "main": [
        [
          {
            "node": "Duplicar Plantilla",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Duplicar Plantilla": {
      "main": [
        [
          {
            "node": "Preparar Respuesta Plantilla",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Preparar Respuesta Plantilla": {
      "main": [
        [
          {
            "node": "Responder Plantilla",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": true,
  "settings": {
    "executionOrder": "v1"
  },
  "id": "generate-document-frontend",
  "tags": []
}

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

6-[Frontend]-GenerateDocument. Uses lmChatOpenAi, googleDrive. Webhook trigger; 11 nodes.

Source: https://github.com/aiporvos/chatflow-legal/blob/4550e8fdbfea03a0d42723e14d17f8c62351e8d1/flujos/6-[Frontend]-GenerateDocument.json — 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

z-Api. Uses httpRequest, openAi, redis, postgres. Webhook trigger; 61 nodes.

HTTP Request, OpenAI, Redis +4
AI & RAG

This template automates the extraction of structured data from Thai government letters received via LINE or uploaded to Google Drive. It uses Mistral AI for OCR and OpenAI for information extraction,

HTTP Request, Google Drive Trigger, Google Drive +4
AI & RAG

I made this little workflow with care for people like you who are part of busy WhatsApp groups and want a simple way to keep track of everything.

Google Drive, Google Sheets, OpenAI Chat +2
AI & RAG

proposal-assistant-openai. Uses lmChatOpenAi, googleDrive, slack. Webhook trigger; 5 nodes.

OpenAI Chat, Google Drive, Slack
AI & RAG

The Ultimate Scraper for n8n uses Selenium and AI to retrieve any information displayed on a webpage. You can also use session cookies to log in to the targeted webpage for more advanced scraping need

OpenAI Chat, HTTP Request, Information Extractor +1