This workflow follows the Agent → HTTP Request 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 →
{
"name": "botws13",
"nodes": [
{
"parameters": {
"httpMethod": "POST",
"path": "whatsapp"
},
"type": "n8n-nodes-base.webhook",
"typeVersion": 2,
"position": [
0,
0
],
"id": "ec1f5c66-09f3-4d91-89fd-43680809e7ac",
"name": "Webhook"
},
{
"parameters": {
"jsCode": "// Validaci\u00f3n y sanitizaci\u00f3n de entrada\nconst input = $input.first().json.body;\n\n// Validar campos requeridos\nif (!input || !input.from || !input.message) {\n return [{\n json: {\n error: 'Campos requeridos faltantes',\n status: 400\n }\n }];\n}\n\n// Sanitizar y validar n\u00famero de tel\u00e9fono\nconst cleanPhone = input.from.replace(/\\D/g, '');\n\n// Detectar intenci\u00f3n del mensaje\nconst intents = {\n pregunta: /\\?$/,\n saludo: /^(hola|buenos d\u00edas|buenas tardes|buenas noches)/i,\n despedida: /(adi\u00f3s|chao|hasta luego|nos vemos)/i,\n emergencia: /(urgente|emergencia|ayuda|socorro)/i\n};\n\nconst intent = Object.entries(intents).find(([_, regex]) => \n regex.test(input.message)\n)?.[0] || 'conversacion';\n\n// Timestamp en formato ISO\nconst timestamp = new Date().toISOString();\n\nreturn [{\n json: {\n sender: cleanPhone,\n mensaje: input.message.trim(), // Cambiado de message a mensaje\n intent,\n timestamp,\n priority: intent === 'emergencia' ? 'high' : 'normal'\n }\n}];"
},
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
180,
-20
],
"id": "047ce904-6f8e-403b-af0c-523cddc10dac",
"name": "Input Validation"
},
{
"parameters": {
"model": "mistral:latest",
"temperature": 0.7,
"maxTokens": 2000,
"topP": 0.95,
"frequencyPenalty": 0.5,
"presencePenalty": 0.5
},
"type": "@n8n/n8n-nodes-langchain.lmChatOllama",
"typeVersion": 1,
"position": [
700,
260
],
"id": "eecb615d-bc19-46bc-bb32-f0740669059b",
"name": "Ollama Chat Model",
"credentials": {
"ollamaApi": {
"name": "<your credential>"
}
}
},
{
"parameters": {
"sessionIdType": "customKey",
"sessionKey": "={{ $json.sender }}",
"tableName": "interacciones",
"contextWindowLength": 5,
"summarizeAfter": 15,
"columnNames": {
"sessionId": "numero_telefono",
"userInput": "mensaje",
"botResponse": "respuesta",
"timestamp": "fecha_creacion"
}
},
"type": "@n8n/n8n-nodes-langchain.memoryPostgresChat",
"typeVersion": 1.3,
"position": [
520,
200
],
"id": "67846270-0ce4-4a8d-be2f-8f91432cc0e5",
"name": "Postgres Chat Memory",
"credentials": {
"postgres": {
"name": "<your credential>"
}
}
},
{
"parameters": {
"promptType": "define",
"text": "Eres un asistente emp\u00e1tico y profesional. Analiza el siguiente contexto:\n\nUsuario: {{$json.sender}}\nIntenci\u00f3n detectada: {{$json.intent}}\nPrioridad: {{$json.priority}}\nHistorial reciente: {{$('Postgres Chat Memory').item.json.chatHistory}}\n\nMensaje actual: {{$json.mensaje}}\n\nResponde de manera emp\u00e1tica, profesional y concisa, manteniendo el contexto de la conversaci\u00f3n.",
"options": {
"temperature": 0.7,
"maxTokens": 500
}
},
"type": "@n8n/n8n-nodes-langchain.agent",
"typeVersion": 1.9,
"position": [
700,
60
],
"id": "ai-response-generator",
"name": "AI Response Generator"
},
{
"parameters": {
"jsCode": "// Procesamiento de respuesta\nconst response = $input.first().json;\n\n// Validaci\u00f3n de respuesta\nif (!response || !response.output) {\n return [{\n json: {\n error: 'Respuesta inv\u00e1lida del modelo',\n status: 500\n }\n }];\n}\n\n// Formateo y limpieza\nlet mensaje = response.output\n .replace(/[\\n\\r\\t]/g, ' ')\n .replace(/\\s{2,}/g, ' ')\n .trim();\n\n// Logging y m\u00e9tricas\nconst metrics = {\n responseTime: Date.now() - new Date($json.timestamp).getTime(),\n messageLength: mensaje.length,\n intent: $json.intent,\n priority: $json.priority\n};\n\nreturn [{\n json: {\n mensaje,\n metrics,\n sender: $json.sender,\n timestamp: new Date().toISOString()\n }\n}];"
},
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
840,
60
],
"id": "response-processor",
"name": "Response Processor"
},
{
"parameters": {
"method": "POST",
"url": "http://host.docker.internal:3080/api/n8n-webhook",
"sendHeaders": true,
"headerParameters": {
"parameters": [
{
"name": "x-webhook-token",
"value": "portIvan2015"
},
{
"name": "Content-Type",
"value": "application/json"
}
]
},
"sendBody": true,
"specifyBody": "json",
"jsonBody": "={\n \"action\": \"send_message\",\n \"data\": {\n \"phone\": \"{{ $json.sender }}\",\n \"message\": \"{{ $json.mensaje }}\"\n },\n \"metadata\": {\n \"intent\": \"{{ $json.metrics.intent }}\",\n \"priority\": \"{{ $json.metrics.priority }}\",\n \"responseTime\": {{ $json.metrics.responseTime }}\n }\n}"
},
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": [
1120,
60
],
"id": "message-sender",
"name": "Message Sender"
}
],
"connections": {
"Webhook": {
"main": [
[
"Input Validation"
]
]
},
"Input Validation": {
"main": [
[
"Postgres Chat Memory"
]
]
},
"Postgres Chat Memory": {
"main": [
[
"AI Response Generator"
]
],
"ai_memory": [
[
"AI Response Generator"
]
]
},
"Ollama Chat Model": {
"ai_languageModel": [
[
"AI Response Generator"
]
]
},
"AI Response Generator": {
"main": [
[
"Response Processor"
]
]
},
"Response Processor": {
"main": [
[
"Message Sender"
]
]
}
},
"settings": {
"executionOrder": "v1"
},
"tags": [
"chatbot",
"production"
]
}
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.
ollamaApipostgres
For the full experience including quality scoring and batch install features for each workflow upgrade to Pro
About this workflow
botws13. Uses lmChatOllama, memoryPostgresChat, agent, httpRequest. Webhook trigger; 7 nodes.
Source: https://github.com/oscivan84/apoyoEmocional/blob/a4728b9fc8fd0bdeb073d23a2e1420721e190c29/n8nv2.json — original creator credit. Request a take-down →
Related workflows
Workflows that share integrations, category, or trigger type with this one. All free to copy and import.
CLINICAINTEGRAL_secretary. Uses postgres, mcpClientTool, googleDriveTool, toolWorkflow. Webhook trigger; 89 nodes.
Remi 1.1. Uses lmChatOpenAi, memoryPostgresChat, openAi, postgres. Webhook trigger; 89 nodes.
my-secretary. Uses postgres, mcpClientTool, googleDriveTool, toolWorkflow. Webhook trigger; 86 nodes.
secretaria. Uses postgres, n8n-nodes-evolution-api, openAi, httpRequest. Webhook trigger; 71 nodes.
🧪 LABR - nuevo asistente (REPARADO). Uses httpRequest, postgres, postgresTool, toolCalculator. Webhook trigger; 63 nodes.