AutomationFlowsAI & RAG › [agente-abogado]-asistente-whatsapp (lm Chat Open Ai)

[agente-abogado]-asistente-whatsapp (lm Chat Open Ai)

[Agente-Abogado]-Asistente-Whatsapp. Uses lmChatOpenAi, toolWorkflow, memoryPostgresChat, toolCalculator. Webhook trigger; 51 nodes.

Webhook trigger★★★★★ complexityAI-powered51 nodesOpenAI ChatTool WorkflowMemory Postgres ChatTool CalculatorAgentHTTP RequestOpenAIRedis
AI & RAG Trigger: Webhook Nodes: 51 Complexity: ★★★★★ AI nodes: yes Added:

This workflow follows the Agent → Chainllm 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": "[Agente-Abogado]-Asistente-Whatsapp",
  "nodes": [
    {
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini"
        },
        "options": {
          "frequencyPenalty": 0,
          "presencePenalty": 0,
          "temperature": 0.3
        }
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.2,
      "position": [
        -416,
        608
      ],
      "id": "956b4f3a-9323-4f91-bee0-68ea458a62dd",
      "name": "OpenAI Chat Model",
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "name": "AgenteEmail",
        "description": "Utiliza esta herramienta para realizar acciones en el correo electr\u00f3nico.",
        "workflowId": {
          "__rl": true,
          "value": "mTDFT7cxuL6SbSDS",
          "mode": "list",
          "cachedResultUrl": "/workflow/mTDFT7cxuL6SbSDS",
          "cachedResultName": "[Agente-Abogado]-Email"
        },
        "workflowInputs": {
          "mappingMode": "defineBelow",
          "value": {},
          "matchingColumns": [],
          "schema": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        }
      },
      "type": "@n8n/n8n-nodes-langchain.toolWorkflow",
      "typeVersion": 2,
      "position": [
        -96,
        1088
      ],
      "id": "e18c65ce-5f9d-44ad-82e0-403698632130",
      "name": "Agente de Email"
    },
    {
      "parameters": {
        "name": "AgenteCalendario",
        "description": "Utiliza esta herramienta para gestionar eventos en el calendario.",
        "workflowId": {
          "__rl": true,
          "value": "XzSO33RKmz5uq1h1",
          "mode": "list",
          "cachedResultUrl": "/workflow/XzSO33RKmz5uq1h1",
          "cachedResultName": "[Agente-Abogado]-Calendario"
        },
        "workflowInputs": {
          "mappingMode": "defineBelow",
          "value": {},
          "matchingColumns": [],
          "schema": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        }
      },
      "type": "@n8n/n8n-nodes-langchain.toolWorkflow",
      "typeVersion": 2,
      "position": [
        128,
        1072
      ],
      "id": "8fcec876-b7e0-467a-a728-a1a290a115c2",
      "name": "Agente de Calendario"
    },
    {
      "parameters": {
        "name": "AgenteContactos",
        "description": "Utiliza esta herramienta para obtener, actualizar, agregar o eliminar contactos.",
        "workflowId": {
          "__rl": true,
          "value": "epddTw7x6V6KALpz",
          "mode": "list",
          "cachedResultUrl": "/workflow/epddTw7x6V6KALpz",
          "cachedResultName": "[Agente-Abogados]-Contactos"
        },
        "workflowInputs": {
          "mappingMode": "defineBelow",
          "value": {},
          "matchingColumns": [],
          "schema": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        }
      },
      "type": "@n8n/n8n-nodes-langchain.toolWorkflow",
      "typeVersion": 2,
      "position": [
        384,
        1072
      ],
      "id": "5e1adfed-1c9d-48a3-9416-db162dde6f7e",
      "name": "AgenteContactos"
    },
    {
      "parameters": {
        "sessionIdType": "customKey",
        "sessionKey": "={{ $('Edit Fields').item.json.message.chatId }}",
        "contextWindowLength": 10
      },
      "type": "@n8n/n8n-nodes-langchain.memoryPostgresChat",
      "typeVersion": 1.3,
      "position": [
        -176,
        592
      ],
      "id": "dcc0a6cf-38db-4614-bcd4-a53368bfbfb2",
      "name": "Postgres Chat Memory",
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      },
      "disabled": true
    },
    {
      "parameters": {
        "content": "## Agente Principal",
        "height": 984,
        "width": 1492,
        "color": 4
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -464,
        -176
      ],
      "id": "83c92d4a-5082-4c20-963e-7514378b3b79",
      "name": "Sticky Note1"
    },
    {
      "parameters": {},
      "type": "@n8n/n8n-nodes-langchain.toolCalculator",
      "typeVersion": 1,
      "position": [
        880,
        608
      ],
      "id": "14be9d05-4292-4085-98fc-1604a4541659",
      "name": "Calculator"
    },
    {
      "parameters": {
        "name": "AgenteLegislacion",
        "description": "Utiliza esta herramienta para consultas legales, jur\u00eddicas, o que requieran de un abogado.",
        "workflowId": {
          "__rl": true,
          "value": "ucIZQ3jQ0F07gXuV",
          "mode": "list",
          "cachedResultUrl": "/workflow/ucIZQ3jQ0F07gXuV",
          "cachedResultName": "[Agente-Abogado]-RAG"
        },
        "workflowInputs": {
          "mappingMode": "defineBelow",
          "value": {
            "chatInput": "={{ $json.content }}"
          },
          "matchingColumns": [],
          "schema": [
            {
              "id": "chatInput",
              "displayName": "chatInput",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "canBeUsedToMatch": true,
              "type": "string"
            },
            {
              "id": "sessionId",
              "displayName": "sessionId",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "canBeUsedToMatch": true,
              "type": "string"
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        }
      },
      "type": "@n8n/n8n-nodes-langchain.toolWorkflow",
      "typeVersion": 2,
      "position": [
        624,
        1072
      ],
      "id": "6e24eaf2-b64e-4d66-ae51-4d9223648816",
      "name": "AgenteLegislacion"
    },
    {
      "parameters": {
        "content": "## SUB-AGENTES",
        "height": 296,
        "width": 1240,
        "color": 3
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -176,
        944
      ],
      "id": "c33463da-0609-409f-bccd-1e24252dab2f",
      "name": "Sticky Note3"
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "={{ $json.content  || $('Webhook').item.json.body.data.message.conversation }}",
        "options": {
          "systemMessage": "=# Descripcion General:\n\nEres el asistente personal definitivo. Tu trabajo es enviar la consulta del usuario a la herramienta correcta. Nunca debes escribir correos electr\u00f3nicos ni crear res\u00famenes, ni inventarte informaci\u00f3n. Solo debes llamar a la herramienta adecuada. Es importante que pases la consulta lo m\u00e1s detallada posible a tus herramientas para que puedan realizar la acci\u00f3n correctamente. SIEMPRE tienes que llamar a la herramienta adecuada en cualquier consulta, y NUNCA respondas sin obtener informaci\u00f3n de las siguientes herramientas:\n\n# Herramientas:\n**AgenteCalendario**: utiliza esta herramienta para gestionar eventos en el calendario.\n**AgenteEmail**: utiliza esta herramienta para realizar acciones en el correo electr\u00f3nico.\n**AgenteLegislacion**: utiliza esta herramienta para consultas relacionadas en el \u00e1mbito legal, jur\u00eddico o que requiera de un abogado. Por ejemplo: consulta sobre un art\u00edculo, una ley, una normativa, o algo parecido.\n**AgenteContactos**: utiliza esta herramienta para a\u00f1adir, eliminar, consultar, o editar un contacto.\n\n# Reglas:\nAlgunas acciones requieren que primero busques la informaci\u00f3n de contacto. Para las siguientes acciones, primero debes obtener la informaci\u00f3n de contacto y luego enviarla a la herramienta correspondiente:\n\nEnviar correos electr\u00f3nicos\nRedactar correos electr\u00f3nicos\nResponder correos electr\u00f3nicos\nCrear un borrador\nCrear eventos de calendario\n\nEn caso de que el contacto que haya aportado en la entrada no se encuentre en la base de datos de contacto, deber\u00e1 utilizar el correo que proporcione en la entrada. Si no ha proporcionado ning\u00fan correo, hay que solicitarlo.\n\nSi se pide enviar un correo a un destinatario que no se encuentra en la lista de contactos del **AgenteContactos**, preg\u00fantale si desea a\u00f1adir ese correo como nuevo contacto. Para ello, le pedir\u00e1s como informaci\u00f3n el nombre del contacto y utilizar\u00e1s al **AgenteContactos** para que agregue el nuevo contacto.\n\n## Ejemplo 1:\n\nEntrada: Env\u00eda un correo electr\u00f3nico a Jos\u00e9 Manuel pregunt\u00e1ndole a qu\u00e9 hora quiere salir.\n\nAcci\u00f3n:\n\nUsa **AgenteContactos** para obtener el correo electr\u00f3nico de Jos\u00e9 Manuel.\nUsa **AgenteEmail** para enviar el correo electr\u00f3nico. Pasar\u00e1s la consulta a la herramienta con un mensaje como:\n\"Env\u00eda un correo electr\u00f3nico a Jos\u00e9 Manuel pregunt\u00e1ndole a qu\u00e9 hora quiere salir. Aqu\u00ed est\u00e1 su correo electr\u00f3nico: [direcci\u00f3n de correo electr\u00f3nico]\"\nSalida: El correo ha sido enviado a Jos\u00e9 Manuel. \u00bfPuedo ayudarte con algo m\u00e1s?\n\n\n## Ejemplo 2:\n\nEntrada: Dame el art\u00edculo 200 del c\u00f3digo civil.\n\nAcci\u00f3n: Usa **AgenteLegislacion** para que busque en su base de conocimiento el art\u00edculo 200 del c\u00f3digo civil. Pasar\u00e1s la consulta a la herramienta con un mensaje como: \"Art\u00edculo 200 del c\u00f3digo civil\".\n\n\n\n\n- La fecha y hora actual es: **{{ $now }}**.  ",
          "maxIterations": 30
        }
      },
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 1.7,
      "position": [
        128,
        160
      ],
      "id": "e821e24d-bbab-4bb1-832b-19d0caa11daf",
      "name": "Agente Principal"
    },
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "9ba08a39-97d4-47a1-8f38-fad696e53395",
        "options": {}
      },
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        -5200,
        272
      ],
      "id": "ef3ecac0-8d01-4a28-a724-066189604939",
      "name": "Webhook"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "24c275ee-aef2-4b03-bf22-4ca69aa05e98",
              "name": "serverUrl",
              "value": "={{ $json.body.server_url }}",
              "type": "string"
            },
            {
              "id": "a15eb467-42de-4299-a389-667647ccc613",
              "name": "instanceName",
              "value": "={{ $json.body.instance }}",
              "type": "string"
            },
            {
              "id": "13f6d482-fb2d-42a2-958e-e82273d6679c",
              "name": "apiKey",
              "value": "={{ $json.body.apikey }}",
              "type": "string"
            },
            {
              "id": "557486dd-9057-4d07-8c8a-19583a79b9f9",
              "name": "message.messageId",
              "value": "={{ $json.body.data.key.id }}",
              "type": "string"
            },
            {
              "id": "79493ec9-a117-496c-88bf-65254c376d20",
              "name": "message.chatId",
              "value": "={{ $json.body.data.key.remoteJid }}",
              "type": "string"
            },
            {
              "id": "1208a065-1670-40c7-9b9d-5c8c87cedd3f",
              "name": "message.messageType",
              "value": "={{ $json.body.data.message.conversation ? 'text': '' }}{{ $json.body.data.message.extendedTextMessage ? 'text': '' }}{{ $json.body.data.message.audioMessage ? 'audio': '' }}{{ $json.body.data.message.imageMessage ? 'image': '' }}",
              "type": "string"
            },
            {
              "id": "2e0a8ca5-35b9-4d4d-9005-1e66ac828eeb",
              "name": "message.messageContent",
              "value": "={{ $json.body.data.message.extendedTextMessage?.text || '' }}{{ $json.body.data.message.imageMessage?.caption || '' }}{{ $json.body.data.message.conversation || '' }}",
              "type": "string"
            },
            {
              "id": "2f72443f-eace-44fa-8a81-5f3bf1ab5e88",
              "name": "message.messageTimeStamp",
              "value": "={{ $json.body.date_time.toDateTime().toISO() }}",
              "type": "string"
            },
            {
              "id": "a8c0f64c-2ad7-42c8-9af0-eb792f298cdd",
              "name": "userName",
              "value": "={{ $json.body.data.pushName }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -4960,
        272
      ],
      "id": "2234ed39-3431-44cd-b2e0-e604213ec93c",
      "name": "Edit Fields"
    },
    {
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 2
                },
                "conditions": [
                  {
                    "leftValue": "={{ $json.messageType }}",
                    "rightValue": "audio",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "id": "e397999f-f0d4-47db-8619-c188b5e3616b"
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "audio"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 2
                },
                "conditions": [
                  {
                    "id": "338e3688-336d-4e2a-a3a9-d81e6bbd4e11",
                    "leftValue": "={{ $json.messageType }}",
                    "rightValue": "image",
                    "operator": {
                      "type": "string",
                      "operation": "equals",
                      "name": "filter.operator.equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "image"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 2
                },
                "conditions": [
                  {
                    "id": "b8f82334-7775-4e5d-9d7c-f6402af55910",
                    "leftValue": "={{ $json.messageType }}",
                    "rightValue": "text",
                    "operator": {
                      "type": "string",
                      "operation": "equals",
                      "name": "filter.operator.equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "text"
            }
          ]
        },
        "options": {
          "fallbackOutput": "extra",
          "renameFallbackOutput": "other"
        }
      },
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3.2,
      "position": [
        -2896,
        224
      ],
      "id": "c62b3b59-5466-4df1-811a-fd42972b2bf2",
      "name": "Switch"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{ $('Edit Fields').item.json.serverUrl }}/chat/getBase64FromMediaMessage/{{ $('Edit Fields').item.json.instanceName }}",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "apikey",
              "value": "={{ $('Edit Fields').item.json.apiKey }}"
            }
          ]
        },
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "message.key.id",
              "value": "={{ $json.messageId }}"
            },
            {
              "name": "convertToMp4",
              "value": "={{ Boolean(false) }}"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        -2544,
        -16
      ],
      "id": "8092e908-c7bc-4580-8664-f073e7d34105",
      "name": "descargar audio"
    },
    {
      "parameters": {
        "operation": "toBinary",
        "sourceProperty": "base64",
        "options": {
          "mimeType": "={{ $json.mimetype }}"
        }
      },
      "type": "n8n-nodes-base.convertToFile",
      "typeVersion": 1.1,
      "position": [
        -2320,
        -16
      ],
      "id": "7cc39723-c63d-4c02-912a-db774eecca1c",
      "name": "convertir audio"
    },
    {
      "parameters": {
        "resource": "audio",
        "operation": "transcribe",
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "typeVersion": 1.8,
      "position": [
        -2096,
        -16
      ],
      "id": "1e1270b6-34f2-4220-aa1e-1433a758f17e",
      "name": "OpenAI",
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{ $('Edit Fields').item.json.serverUrl }}/chat/getBase64FromMediaMessage/{{ $('Edit Fields').item.json.instanceName }}",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "apikey",
              "value": "={{ $('Edit Fields').item.json.apiKey }}"
            }
          ]
        },
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "message.key.id",
              "value": "={{ $json.messageId }}"
            },
            {
              "name": "convertToMp4",
              "value": "={{ Boolean(false) }}"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        -2496,
        192
      ],
      "id": "eabc8bb7-ad9e-483a-a957-223f1266d82d",
      "name": "descargar imagen"
    },
    {
      "parameters": {
        "operation": "toBinary",
        "sourceProperty": "base64",
        "options": {
          "mimeType": "={{ $json.mimetype }}"
        }
      },
      "type": "n8n-nodes-base.convertToFile",
      "typeVersion": 1.1,
      "position": [
        -2288,
        192
      ],
      "id": "c2b09573-975c-46fd-9f98-9decc9d2794f",
      "name": "convertir imagen"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "a54b459d-e8df-47e1-be8c-a8a476ab93c3",
              "name": "content",
              "value": "={{ $json.text }}",
              "type": "string"
            },
            {
              "id": "1b078c6c-6824-43e2-8bff-8a56fca7a1c9",
              "name": "timestamp",
              "value": "={{ $('Json Parse').item.json.messageTimeStamp }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -1872,
        -16
      ],
      "id": "8a1d2006-a758-4cf6-af24-4bd6cbfd74b7",
      "name": "audio content"
    },
    {
      "parameters": {
        "resource": "image",
        "operation": "analyze",
        "modelId": {
          "__rl": true,
          "value": "gpt-4o-mini",
          "mode": "list",
          "cachedResultName": "GPT-4O-MINI"
        },
        "text": "Describe la imagen",
        "inputType": "base64",
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "typeVersion": 1.8,
      "position": [
        -2064,
        192
      ],
      "id": "3add1938-9f3c-4552-883c-f05b2dc0e1d3",
      "name": "describe imagen",
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "a54b459d-e8df-47e1-be8c-a8a476ab93c3",
              "name": "content",
              "value": "=<image>\n{{ $json.content }}\n</image>",
              "type": "string"
            },
            {
              "id": "29e2c943-8bb0-4199-84dd-16d098894ddd",
              "name": "timestamp",
              "value": "={{ $('Json Parse').item.json.messageTimeStamp }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -1872,
        192
      ],
      "id": "3b206c40-23d4-4222-bd0e-f8d191cb8b87",
      "name": "image content"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "bcea6c99-72fa-44d3-acc6-ecfdec887583",
              "name": "content",
              "value": "={{ $json.messageContent }}",
              "type": "string"
            },
            {
              "id": "6abb6aff-1f4a-4ab5-aece-c2bf1d27a59d",
              "name": "timestamp",
              "value": "={{ $('Json Parse').item.json.messageTimeStamp }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -1872,
        416
      ],
      "id": "5ca33b73-9356-420f-877a-b7f4c6b3aa7a",
      "name": "text content"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "d2599831-cc84-4aa6-acf7-77ed624f72ab",
              "name": "content",
              "value": "={{ $json.messages.join(\"\\n\") }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -736,
        144
      ],
      "id": "b050c08d-0aab-4eb1-b806-fce0165fc99b",
      "name": "mensaje"
    },
    {
      "parameters": {
        "operation": "push",
        "list": "={{ $('Edit Fields').item.json.message.chatId }}",
        "messageData": "={{ JSON.stringify($('Edit Fields').item.json.message) }}",
        "tail": true
      },
      "type": "n8n-nodes-base.redis",
      "typeVersion": 1,
      "position": [
        -4736,
        272
      ],
      "id": "ffc976df-de74-4370-8d7e-ac81c9640832",
      "name": "push mensaje",
      "credentials": {
        "redis": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "fieldToSplitOut": "message",
        "options": {}
      },
      "type": "n8n-nodes-base.splitOut",
      "typeVersion": 1,
      "position": [
        -3456,
        240
      ],
      "id": "e9a4ce0d-0db4-45af-8d07-c394212074b2",
      "name": "Split Out"
    },
    {
      "parameters": {
        "mode": "raw",
        "jsonOutput": "={{ JSON.parse($json.message) }}",
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -3248,
        240
      ],
      "id": "cab3fa98-a4ad-488b-93ae-4133e532d4af",
      "name": "Json Parse"
    },
    {
      "parameters": {
        "numberInputs": 3
      },
      "type": "n8n-nodes-base.merge",
      "typeVersion": 3.1,
      "position": [
        -1328,
        144
      ],
      "id": "c54b857a-5cbf-4f4f-b45e-7e73dc4429d3",
      "name": "Merge"
    },
    {
      "parameters": {
        "sortFieldsUi": {
          "sortField": [
            {
              "fieldName": "timestamp"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.sort",
      "typeVersion": 1,
      "position": [
        -1152,
        144
      ],
      "id": "ed796990-f057-45ed-aa8f-b24f8f41fc96",
      "name": "Sort"
    },
    {
      "parameters": {
        "fieldsToAggregate": {
          "fieldToAggregate": [
            {
              "fieldToAggregate": "content",
              "renameField": true,
              "outputFieldName": "messages"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.aggregate",
      "typeVersion": 1,
      "position": [
        -976,
        144
      ],
      "id": "e0b5da15-bffc-4205-95f3-bd14c474e3e7",
      "name": "Aggregate"
    },
    {
      "parameters": {
        "amount": 8
      },
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1.1,
      "position": [
        -4544,
        272
      ],
      "id": "98b2c3a3-bc13-45ff-932d-fcf65a8a9e62",
      "name": "Wait1"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "18445dcf-1967-40d1-aec2-6d2196b1364b",
              "leftValue": "={{ JSON.parse($json.message.last()).messageId }}",
              "rightValue": "={{ $('Edit Fields').item.json.message.messageId }}",
              "operator": {
                "type": "string",
                "operation": "equals",
                "name": "filter.operator.equals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        -4048,
        272
      ],
      "id": "8feda2e2-3e65-4740-b8a0-c416e8ccbe74",
      "name": "If"
    },
    {
      "parameters": {},
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        -3760,
        512
      ],
      "id": "a7f374b2-d954-4a41-94e9-87b0a4af7045",
      "name": "No Operation, do nothing"
    },
    {
      "parameters": {
        "operation": "get",
        "propertyName": "message",
        "key": "={{ $('Edit Fields').item.json.message.chatId }}",
        "options": {}
      },
      "type": "n8n-nodes-base.redis",
      "typeVersion": 1,
      "position": [
        -4304,
        272
      ],
      "id": "61010ede-086c-48fc-9b5f-d41250b38f61",
      "name": "obtener todos mensajes",
      "credentials": {
        "redis": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "delete",
        "key": "={{ $('Edit Fields').item.json.message.chatId }}"
      },
      "type": "n8n-nodes-base.redis",
      "typeVersion": 1,
      "position": [
        -3728,
        240
      ],
      "id": "d14b6249-7573-4b28-ab0d-c70d9f6de5f1",
      "name": "borrar todos mensajes",
      "credentials": {
        "redis": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "content": "# Encolamiento de Mensajes",
        "height": 1000,
        "width": 1760
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -4784,
        -192
      ],
      "id": "3be45cc4-ff36-4bbb-925f-d517c957426a",
      "name": "Sticky Note"
    },
    {
      "parameters": {
        "content": "# Procesamiento del Mensaje (Texto, Audio, Imagen)",
        "height": 1000,
        "width": 2472,
        "color": 3
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -2976,
        -192
      ],
      "id": "c176c951-4292-4bfc-bba7-ac5e08ae1be5",
      "name": "Sticky Note4"
    },
    {
      "parameters": {
        "content": "# Entrada WhatsApp",
        "height": 496,
        "width": 476,
        "color": 4
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -5296,
        80
      ],
      "id": "7f4f5456-71e1-48d3-8b92-634f38beffe9",
      "name": "Sticky Note5"
    },
    {
      "parameters": {
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.outputParserAutofixing",
      "typeVersion": 1,
      "position": [
        1376,
        416
      ],
      "id": "6c282ce8-7c3a-47cb-8eb7-28c15ec96229",
      "name": "Auto-fixing Output Parser"
    },
    {
      "parameters": {
        "jsonSchemaExample": "{\n\t\"response\": {\n      \"part_1\": \"Parte uno de la respuesta\",\n      \"part_2\": \"Parte dos de la respuesta (opcional).\",\n      \"part_3\": \"Parte tres de la respuesta (opcional).\"\n    }\n}"
      },
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "typeVersion": 1.2,
      "position": [
        1696,
        592
      ],
      "id": "2f57570d-c8b4-4cd7-b2c2-3b37125eaf2b",
      "name": "Structured Output Parser"
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "=Texto de entrada:\n{{ $json.output }}",
        "hasOutputParser": true,
        "messages": {
          "messageValues": [
            {
              "message": "=# Formatea el texto de entrada de acuerdo a las instrucciones.\n\n---------------\n\n## Instrucciones\n- Devuelve un mensaje de salida dividido en 1, 2, o 3 partes, dependiendo de la lingitud del texto de entrada.\n- El mensaje de salida debe sonar relajado y amigable.\n- Elimina estos caracteres:\n \"*\", \"\u00bf\", \"\u00a1\", \"#\"\n- Utiliza signos de interrogaci\u00f3n \"?\" **solo en el final de las frases que sean preguntas.**\n- **No** es necesario que las 3 partes contengan un mensaje.\n- Si el texto de entrada contine una lista, d\u00e9jala sola en una parte.\n- En la respuesta no se puede devolver mensajes como \"Utilizando la herramienta Conocimiento para buscar...\" o cosas similares.\n- **IMPORTANTE: No a\u00f1adas ni elimines informaci\u00f3n esencial del texto de entrada. Respeta fielmente el contenido original. Solamente ajusta la forma (ej. eliminar caracteres, dividir en partes, ajustar estilo) para cumplir las instrucciones dadas.**\n\n## **IMPORTANTE**\n- Si haces bien tu trabajo te voy a pagar un sueldo de $5,000 USD al mes.\n- **SIEMPRE debes completar al menos una parte con texto**."
            }
          ]
        }
      },
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "typeVersion": 1.6,
      "position": [
        1152,
        160
      ],
      "id": "5f85294b-99e8-42ba-b9d3-fb79ce1e5883",
      "name": "Verificador de Respuesta"
    },
    {
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini"
        },
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.2,
      "position": [
        1152,
        608
      ],
      "id": "cb6adb64-7d77-43f5-a6bb-6a070be662ab",
      "name": "4o mini Verificador",
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{ $('Edit Fields').item.json.serverUrl }}/message/sendText/{{ $('Edit Fields').item.json.instanceName }}",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "apikey",
              "value": "={{ $('Edit Fields').item.json.apiKey }}"
            }
          ]
        },
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "number",
              "value": "={{ $('Edit Fields').item.json.message.chatId }}"
            },
            {
              "name": "text",
              "value": "={{ $('Verificador de Respuesta').item.json.output.response.part_1 }}"
            },
            {
              "name": "delay",
              "value": "={{ 2000 }}"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1792,
        160
      ],
      "id": "0b54785f-e35e-4237-bb4a-120277feaf72",
      "name": "Enviar Parte1"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "4b92a1f4-d4bc-4689-87cf-1be40aa49c27",
              "leftValue": "={{ $('Verificador de Respuesta').item.json.output.response.part_2 }}",
              "rightValue": "",
              "operator": {
                "type": "string",
                "operation": "notEmpty",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        2016,
        160
      ],
      "id": "1354912f-612d-4422-afd4-1a07546d3995",
      "name": "If Parte 2"
    },
    {
      "parameters": {
        "amount": "={{ 2+$('Verificador de Respuesta').item.json.output.response.part_2.length*0.01 }}"
      },
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1.1,
      "position": [
        2256,
        48
      ],
      "id": "b87d8256-e87a-4029-9e6a-d4002160808f",
      "name": "Wait"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{ $('Edit Fields').item.json.serverUrl }}/message/sendText/{{ $('Edit Fields').item.json.instanceName }}",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "apikey",
              "value": "={{ $('Edit Fields').item.json.apiKey }}"
            }
          ]
        },
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "number",
              "value": "={{ $('Edit Fields').item.json.message.chatId }}"
            },
            {
              "name": "text",
              "value": "={{ $('Verificador de Respuesta').item.json.output.response.part_2 }}"
            },
            {
              "name": "delay",
              "value": "={{ 2000 }}"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        2448,
        48
      ],
      "id": "2e2a849f-da23-41f9-9a21-82f49cf8c84f",
      "name": "Enviar Parte2"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "4b92a1f4-d4bc-4689-87cf-1be40aa49c27",
              "leftValue": "={{ $('Verificador de Respuesta').item.json.output.response.part_3 }}",
              "rightValue": "",
              "operator": {
                "type": "string",
                "operation": "notEmpty",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        2736,
        176
      ],
      "id": "b1141a64-5b26-403e-a527-008a1a426176",
      "name": "If Parte 3"
    },
    {
      "parameters": {
        "amount": "={{ 2+$('Verificador de Respuesta').item.json.output.response.part_3.length*0.01 }}"
      },
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1.1,
      "position": [
        2960,
        48
      ],
      "id": "497f41ed-5120-4a73-8d9c-22c11cd19fe7",
      "name": "Wait2"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{ $('Edit Fields').item.json.serverUrl }}/message/sendText/{{ $('Edit Fields').item.json.instanceName }}",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "apikey",
              "value": "={{ $('Edit Fields').item.json.apiKey }}"
            }
          ]
        },
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "number",
              "value": "={{ $('Edit Fields').item.json.message.chatId }}"
            },
            {
              "name": "text",
              "value": "={{ $('Verificador de Respuesta').item.json.output.response.part_3 }}"
            },
            {
              "name": "delay",
              "value": "={{ 2000 }}"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        3200,
        48
      ],
      "id": "55bd4c43-ba57-486e-a393-4fa64c1d3026",
      "name": "Enviar Parte3"
    },
    {
      "parameters": {},
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        3440,
        192
      ],
      "id": "779d5707-dfba-4363-9251-befc6ea9194d",
      "name": "No Operation, do nothing1"
    },
    {
      "parameters": {
        "content": "# Formato de Respuesta por WhatsApp",
        "height": 980,
        "width": 2504,
        "color": 6
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        1072,
        -176
      ],
      "id": "a8efecd9-91a9-4bb3-8fae-f7d682629752",
      "name": "Sticky Note6"
    },
    {
      "parameters": {},
      "type": "@n8n/n8n-nodes-langchain.toolWorkflow",
      "typeVersion": 2.2,
      "position": [
        880,
        1056
      ],
      "id": "545d0c6c-aa1d-425f-b93c-8bfed8e939d0",
      "name": "RedaccionDocumentos",
      "disabled": true
    }
  ],
  "connections": {
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Agente Principal",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Agente de Email": {
      "ai_tool": [
        [
          {
            "node": "Agente Principal",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Agente de Calendario": {
      "ai_tool": [
        [
          {
            "node": "Agente Principal",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "AgenteContactos": {
      "ai_tool": [
        [
          {
            "node": "Agente Principal",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Postgres Chat Memory": {
      "ai_memory": [
        [
          {
            "node": "Agente Principal",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Calculator": {
      "ai_tool": [
        [
          {
            "node": "Agente Principal",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "AgenteLegislacion": {
      "ai_tool": [
        [
          {
            "node": "Agente Principal",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Agente Principal": {
      "main": [
        [
          {
            "node": "Verificador de Respuesta",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Webhook": {
      "main": [
        [
          {
            "node": "Edit Fields",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Edit Fields": {
      "main": [
        [
          {
            "node": "push mensaje",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Switch": {
      "main": [
        [
          {
            "node": "descargar audio",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "descargar imagen",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "text content",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "descargar audio": {
      "main": [
        [
          {
            "node": "convertir audio",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "convertir audio": {
      "main": [
        [
          {
            "node": "OpenAI",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI": {
      "main": [
        [
          {
            "node": "audio content",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "descargar imagen": {
      "main": [
        [
          {
            "node": "convertir imagen",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "convertir imagen": {
      "main": [
        [
          {
            "node": "describe imagen",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "audio content": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "describe imagen": {
      "main": [
        [
          {
            "node": "image content",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "image content": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "text content": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 2
          }
        ]
      ]
    },
    "push mensaje": {
      "main": [
        [
          {
            "node": "Wait1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split Out": {
      "main": [
        [
          {
            "node": "Json Parse",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Json Parse": {
      "main": [
        [
          {
            "node": "Switch",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge": {
      "main": [
        [
          {
            "node": "Sort",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Sort": {
      "main": [
        [
          {
            "node": "Aggregate",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Aggregate": {
      "main": [
        [
          {
            "node": "mensaje",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait1": {
      "main": [
        [
          {
            "node": "obtener todos mensajes",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If": {
      "main": [
        [
          {
            "node": "borrar todos mensajes",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "No Operation, do nothing",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "obtener todos mensajes": {
      "main": [
        [
          {
            "node": "If",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "borrar todos mensajes": {
      "main": [
        [
          {
            "node": "Split Out",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "mensaje": {
      "main": [
        [
          {
            "node": "Agente Principal",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Auto-fixing Output Parser": {
      "ai_outputParser": [
        [
          {
            "node": "Verificador de Respuesta",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Structured Output Parser": {
      "ai_outputParser": [
        [
          {
            "node": "Auto-fixing Output Parser",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Verificador de Respuesta": {
      "main": [
        [
          {
            "node": "Enviar Parte1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "4o mini Verificador": {
      "ai_languageModel": [
        [
          {
            "node": "Verificador de Respuesta",
            "type": "ai_languageModel",
            "index": 0
          },
          {
            "node": "Auto-fixing Output Parser",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Enviar Parte1": {
      "main": [
        [
          {
            "node": "If Parte 2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If Parte 2": {
      "main": [
        [
          {
            "node": "Wait",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "If Parte 3",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait": {
      "main": [
        [
          {
            "node": "Enviar Parte2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Enviar Parte2": {
      "main": [
        [
          {
            "node": "If Parte 3",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If Parte 3": {
      "main": [
        [
          {
            "node": "Wait2",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "No Operation, do nothing1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait2": {
      "main": [
        [
          {
            "node": "Enviar Parte3",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Enviar Parte3": {
      "main": [
        [
          {
            "node": "No Operation, do nothing1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "RedaccionDocumentos": {
      "ai_tool": [
        []
      ]
    }
  },
  "active": true,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "6d7d3deb-6e39-4d52-b21f-31929aeef25b",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "id": "zbhYdholF0S8Rw5c",
  "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

[Agente-Abogado]-Asistente-Whatsapp. Uses lmChatOpenAi, toolWorkflow, memoryPostgresChat, toolCalculator. Webhook trigger; 51 nodes.

Source: https://github.com/aiporvos/chatflow-legal/blob/main/flujos/1-[Agente-Abogado]-Asistente-Whatsapp.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

CLINICAINTEGRAL_secretary. Uses postgres, mcpClientTool, googleDriveTool, toolWorkflow. Webhook trigger; 89 nodes.

Postgres, Mcp Client Tool, Google Drive Tool +14
AI & RAG

Remi 1.1. Uses lmChatOpenAi, memoryPostgresChat, openAi, postgres. Webhook trigger; 89 nodes.

OpenAI Chat, Memory Postgres Chat, OpenAI +7
AI & RAG

my-secretary. Uses postgres, mcpClientTool, googleDriveTool, toolWorkflow. Webhook trigger; 86 nodes.

Postgres, Mcp Client Tool, Google Drive Tool +13
AI & RAG

My workflow 7. Uses openAi, redis, httpRequest, agent. Webhook trigger; 77 nodes.

OpenAI, Redis, HTTP Request +8
AI & RAG

My workflow 7. Uses openAi, redis, httpRequest, agent. Webhook trigger; 77 nodes.

OpenAI, Redis, HTTP Request +8