{
  "name": "InnoIT: Whatsapp Receive + DEMO",
  "nodes": [
    {
      "parameters": {
        "method": "POST",
        "url": "https://web.gw.fotocasa.es/v1/search/ads",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "accept",
              "value": "application/json, text/plain, */*"
            },
            {
              "name": "accept-language",
              "value": "en-GB,en-US;q=0.9,en;q=0.8"
            },
            {
              "name": "origin",
              "value": "https://www.fotocasa.es"
            },
            {
              "name": "priority",
              "value": "u=1, i"
            },
            {
              "name": "referer",
              "value": "https://www.fotocasa.es/"
            },
            {
              "name": "sec-ch-ua",
              "value": "\"Chromium\";v=\"136\", \"Google Chrome\";v=\"136\", \"Not.A/Brand\";v=\"99\""
            },
            {
              "name": "sec-ch-ua-mobile",
              "value": "?0"
            },
            {
              "name": "sec-ch-ua-platform",
              "value": "\"macOS\""
            },
            {
              "name": "sec-fetch-dest",
              "value": "empty"
            },
            {
              "name": "sec-fetch-mode",
              "value": "cors"
            },
            {
              "name": "sec-fetch-site",
              "value": "same-site"
            },
            {
              "name": "user-agent",
              "value": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "{\n  \"combinedLocations\": [\n    \"724,9,8,232,376,8019,0,0,0\"\n  ],\n  \"includePurchaseTypeFacets\": true,\n  \"isMap\": false,\n  \"latitude\": 41.3854,\n  \"longitude\": 2.17754,\n  \"pageNumber\": 1,\n  \"propertyType\": 2,\n  \"sortOrderDesc\": true,\n  \"sortType\": \"scoring\",\n  \"transactionType\": 1,\n  \"userId\": null,\n  \"size\": 30\n}",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        -96,
        -16
      ],
      "id": "907e2509-b643-46d4-8c0a-c0c51fcc2c88",
      "name": "HTTP Request"
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={\n  \"myField\": \n {{ $json.totalItems }}}",
        "options": {}
      },
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.3,
      "position": [
        160,
        32
      ],
      "id": "1005ef6d-ddb6-488a-9e4c-44de62290545",
      "name": "Respond to Webhook"
    },
    {
      "parameters": {
        "operation": "send",
        "phoneNumberId": "701373393048251",
        "recipientPhoneNumber": "={{ $('whatsapp').item.json.contacts[0].wa_id }}",
        "textBody": "={{ $json.output }}",
        "additionalFields": {}
      },
      "type": "n8n-nodes-base.whatsApp",
      "typeVersion": 1,
      "position": [
        224,
        -240
      ],
      "id": "8a8da1f6-50c7-439f-b8d2-5e9fce0c1e93",
      "name": "WhatsApp Business Cloud",
      "webhookId": "3b50de04-a134-4338-b8e4-126f289f947f",
      "credentials": {
        "whatsAppApi": {
          "id": "jnKhnE6KOiaDF1qB",
          "name": "WhatsApp account"
        }
      }
    },
    {
      "parameters": {
        "model": {
          "__rl": true,
          "value": "gpt-4.1",
          "mode": "list",
          "cachedResultName": "gpt-4.1"
        },
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.2,
      "position": [
        -560,
        -80
      ],
      "id": "133ec97e-3758-4a00-8e8d-84ecd1b61bf1",
      "name": "OpenAI Chat Model",
      "credentials": {
        "openAiApi": {
          "id": "r5FEJ6lXc0AaNF6n",
          "name": "OpenAi account"
        }
      }
    },
    {
      "parameters": {
        "sessionIdType": "customKey",
        "sessionKey": "={{ $('whatsapp').item.json.metadata.phone_number_id }}"
      },
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "typeVersion": 1.3,
      "position": [
        -224,
        -144
      ],
      "id": "3bfe149d-4895-433f-ba2b-6136b890476a",
      "name": "Simple Memory"
    },
    {
      "parameters": {
        "preBuiltAgentsCalloutHttpRequest": "",
        "httpVariantWarning": "",
        "curlImport": "",
        "method": "POST",
        "": "",
        "url": "https://api.datadoghq.eu/api/intake/llm-obs/v1/trace/spans",
        "authentication": "none",
        "provideSslCertificates": false,
        "sendQuery": false,
        "sendHeaders": true,
        "specifyHeaders": "keypair",
        "headerParameters": {
          "parameters": [
            {
              "name": "Accept",
              "value": "application/json"
            },
            {
              "name": "DD-API-KEY",
              "value": "xxx"
            }
          ]
        },
        "sendBody": true,
        "contentType": "json",
        "specifyBody": "json",
        "jsonBody": "=\n {\n  \"data\": {\n    \"type\": \"span\",\n    \"attributes\": {\n      \"ml_app\": \"weather-bot\",\n      \"session_id\": \"1\",\n      \"tags\": [\n        \"service:weather-bot\",\n        \"env:staging\",\n        \"user_handle:example-user@example.com\",\n        \"user_id:1234\"\n      ],\n      \"spans\": [\n        {\n          \"parent_id\": \"undefined\",\n          \"trace_id\": \"111\",\n          \"span_id\": \"{{$json.id}}\",\n          \"name\": \"health_coach_agent\",\n          \"meta\": {\n            \"kind\": \"agent\",\n            \"input\": {\n              \"value\": \"{{ $json.input }}\"\n            },\n            \"output\": {\n              \"value\": \"{{$json.output}}\"\n            }\n          },\n          \"start_ns\": {{$json.init_date }},\n          \"duration\": {{$json.end_date- $json.init_date}}\n        }\n      ]\n    }\n  }\n} \n",
        "options": {},
        "infoMessage": ""
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        512,
        -544
      ],
      "id": "7fc374a7-5335-4db8-87de-2f477f537866",
      "name": "Datadog HTTP Request",
      "extendsCredential": "datadogApi",
      "credentials": {
        "datadogApi": {
          "id": "a982MzsuTxNFMoU2",
          "name": "Datadog account"
        }
      },
      "onError": "continueErrorOutput"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "8804c58c-beb5-4a68-99f7-8a88ad7dae5f",
              "name": "input",
              "value": "={{ $('whatsapp').item.json.messages[0].text.body }}",
              "type": "string"
            },
            {
              "id": "b6fb45cd-c192-4497-a224-83576706bbb5",
              "name": "output",
              "value": "={{ $('AI Agent').item.json.output }}",
              "type": "string"
            },
            {
              "id": "9ba62e3d-161d-4865-a072-4f1d32621123",
              "name": "id",
              "value": "={{$execution.id }}",
              "type": "string"
            },
            {
              "id": "acbe54f6-d4a7-438b-96ba-c37988f55ef8",
              "name": "init_date",
              "value": "={{ $('InitDate').item.json.date * 1_000_000 }}",
              "type": "number"
            },
            {
              "id": "3ee62ea4-3c05-4553-b0db-ac912d4467c7",
              "name": "end_date",
              "value": "={{ $('EndDate').item.json.date  * 1_000_000}}",
              "type": "number"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        304,
        -544
      ],
      "id": "24a15f25-1a2e-4c01-99c7-501cc6c77895",
      "name": "Edit Fields"
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "={{$('whatsapp').item.json.messages[0].text.body}}",
        "options": {
          "systemMessage": "You are a helpful assistantContestale en funcion de si es su primer mensaje o no. Si es su primer mensaje, le dices hola buenos diass, si es el segundo o mas le diremos en que te puedo ayudar. si no sabemos ayudarle le diremos que en breve se pondran en contacto el\n\n",
          "returnIntermediateSteps": true
        }
      },
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 2,
      "position": [
        -336,
        -448
      ],
      "id": "ab38a946-34f5-439f-aea2-0a337d95999d",
      "name": "AI Agent",
      "notesInFlow": true,
      "alwaysOutputData": false,
      "executeOnce": false
    },
    {
      "parameters": {
        "operation": "formatDate",
        "date": "={{ $now }}",
        "format": "x",
        "outputFieldName": "date",
        "options": {}
      },
      "type": "n8n-nodes-base.dateTime",
      "typeVersion": 2,
      "position": [
        -576,
        -448
      ],
      "id": "639553d2-7a0f-4aff-b74d-96669f34be3d",
      "name": "InitDate"
    },
    {
      "parameters": {
        "operation": "formatDate",
        "date": "={{ $now }}",
        "format": "x",
        "outputFieldName": "date",
        "options": {}
      },
      "type": "n8n-nodes-base.dateTime",
      "typeVersion": 2,
      "position": [
        80,
        -544
      ],
      "id": "8c7e1007-b2db-4ac6-8fb2-5d4e85f3dec0",
      "name": "EndDate"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "d28cbb76-f64c-48cf-a3b3-f3b0cb2a0803",
              "leftValue": "={{ $json.messages }}",
              "rightValue": "",
              "operator": {
                "type": "array",
                "operation": "exists",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        -848,
        -416
      ],
      "id": "47d8fa34-2d50-4346-9e40-e73bcb8903e4",
      "name": "If"
    },
    {
      "parameters": {
        "descriptionType": "manual",
        "toolDescription": "Consultar disponibilidad para una fecha",
        "resource": "calendar",
        "calendar": {
          "__rl": true,
          "value": "marc@marcbenito.com",
          "mode": "list",
          "cachedResultName": "marc@marcbenito.com"
        },
        "timeMin": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Start_Time', ``, 'string') }}",
        "timeMax": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('End_Time', ``, 'string') }}",
        "options": {}
      },
      "type": "n8n-nodes-base.googleCalendarTool",
      "typeVersion": 1.3,
      "position": [
        656,
        -1856
      ],
      "id": "f0beade1-11ee-44e3-a186-6f467dacf3ec",
      "name": "Get availability in a calendar in Google Calendar",
      "credentials": {
        "googleCalendarOAuth2Api": {
          "id": "ePJ7h2fC8n17plWD",
          "name": "Google Calendar account"
        }
      }
    },
    {
      "parameters": {
        "descriptionType": "manual",
        "toolDescription": "Crear una cita",
        "calendar": {
          "__rl": true,
          "value": "marc@marcbenito.com",
          "mode": "list",
          "cachedResultName": "marc@marcbenito.com"
        },
        "start": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Start', ``, 'string') }}",
        "end": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('End', ``, 'string') }}",
        "additionalFields": {
          "description": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Description', ``, 'string') }}",
          "showMeAs": "opaque",
          "summary": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Summary', ``, 'string') }}"
        }
      },
      "type": "n8n-nodes-base.googleCalendarTool",
      "typeVersion": 1.3,
      "position": [
        160,
        -1856
      ],
      "id": "a2477967-641f-4850-9796-3b067ccf7ad7",
      "name": "Create an event in Google Calendar",
      "credentials": {
        "googleCalendarOAuth2Api": {
          "id": "ePJ7h2fC8n17plWD",
          "name": "Google Calendar account"
        }
      }
    },
    {
      "parameters": {
        "formTitle": "Upload your data to test RAG",
        "formFields": {
          "values": [
            {
              "fieldLabel": "Upload your file(s)",
              "fieldType": "file",
              "acceptFileTypes": ".pdf, .csv",
              "requiredField": true
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.formTrigger",
      "typeVersion": 2.2,
      "position": [
        -848,
        -1840
      ],
      "id": "79d60c73-7564-4bfb-b347-aa2166f9e365",
      "name": "Upload your file here",
      "webhookId": "82848bc4-5ea2-4e5a-8bb6-3c09b94a8c5d"
    },
    {
      "parameters": {
        "dataType": "binary",
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.documentDefaultDataLoader",
      "typeVersion": 1.1,
      "position": [
        -368,
        -1584
      ],
      "id": "0db708bf-7de8-4b71-99ff-05a79728d93a",
      "name": "Default Data Loader"
    },
    {
      "parameters": {},
      "type": "@n8n/n8n-nodes-langchain.embeddingsGoogleGemini",
      "typeVersion": 1,
      "position": [
        32,
        -1440
      ],
      "id": "0dc57e16-cdaf-452d-97f4-a5997160a1cd",
      "name": "Embeddings Google Gemini",
      "credentials": {
        "googlePalmApi": {
          "id": "6P1f4AtQwxrrUvJM",
          "name": "Google Gemini(PaLM) Api account"
        }
      }
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "={{ $('whatsapp').item.json.messages[0].text.body }}",
        "options": {
          "systemMessage": "=Eres un  asistente de una tienda de informatica. \nTienes las siguientes funcionalidades funcionalidades principales: \n- Informar al usuario de nuestros productos fisicos ( catalogo de productos)\n- Informar de nuestros servicios (catalogo de servicios)\n- Reservar citas para que un especialista le atienda.\n\nContesta siempre en castellano. \nPrimero pidele el nombre. \n\n# Para informar de los servicios\nConsulta la tool \"Catalogo de Servicios de la empresa\" para obtener detalle de los servicios\nDispones de una tool llamada: \"Catalogo de Servicios de la empresa\". Cuando el usuario hable de servicios consultala siempre. Consultala para obtener información de los servicios. Si no tenemos el servicio que solicita, informale amablemente que no disponemos de ese servicio.\n\n# Para reservar cita\nEl usuario te facilitará una fecha de reserva con una hora, un nombre de contacto,  un telefono y motivo de la cita.\n\nDispones de una tool llamada \"Catalogo de Servicios de la empresa\" para saber si tenemos el servicio . Si no tenemos el servicio que solicita, informale amablemente que no disponemos de ese servicio y no reserves cita. Antes de reservar una cita asegurate que tienes el servicio\n\n\nDebes consultar la tool de calendar y si hay cita en el horario previsto, asignarla llamando a la otra tool.\nEl nombre del evento será Cita con Señora XXX y en las notas pondremos el telefono.\nSI nos falta algun dato, le pediremos al usuario los datos que faltan\nNo nos pueden pedir fechas anteriores a hoy. hoy es: {{ $now}} }}\n\nCuando reserves una cita. llama también a la tool guardar contacto guarda los datos del usuario y en la descripcion toda la informacion de la cita.\nLas citas se pueden reservar de 9 de la mañana a 14:00 y de 16:00 a 19:00. Solo puedes reservar las 4 próximas semanas a la fecha actual. \nLos fines de semana y festivos de españa no se trabaja.\n\n# para informar de productos\nCuando te pregunten por productos llama a la  tool llamada get_products.\nCuando des información detallada de productos, añade tambien el precio: Ej:\nTeclado Mecanico RGB - Iluminacion xxx - 33 € + IVA\nNo utilices la información previa de la conversacion para obtener productos.\n\n# contexto extra\n\nSe amable con el usuario, si te facilita los datos parcialmente, solicitale los datos faltantes, y si te da el nombre, dirigete a el por el nombre. Revisa la conversación para ver si te ha dado ya el nombre. Aunque sepas el nombre preguntale si la cita es para el o para otra persona. Lo mismo con el telefono\n\n\nSi te hace preguntas que no están relacionadas sobre la tienda de informatica y la reserva de citas, desvia la conversacion , sin responder su pregunta, hacia la reserva de citas\n\n# Formateo de negrita\nPara marcar texto en negrita es con el \"*\" pero solo uno, Ej: *Teclado Mecanico RGB* - Iluminacion xxx - 33 € + IVA\n",
          "enableStreaming": true
        }
      },
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 2.2,
      "position": [
        64,
        -2096
      ],
      "id": "ec37e2e9-a79e-415d-bee6-96a41f7255fb",
      "name": "AI Agent1"
    },
    {
      "parameters": {
        "updates": [
          "messages"
        ],
        "options": {}
      },
      "type": "n8n-nodes-base.whatsAppTrigger",
      "typeVersion": 1,
      "position": [
        -1040,
        -2128
      ],
      "id": "01cb9431-a401-40af-9b56-b8fa5476f1ba",
      "name": "whatsapp",
      "webhookId": "59a1ed97-41fa-442a-90e3-0904c39ddf31",
      "credentials": {
        "whatsAppTriggerApi": {
          "id": "YWZG9yrY07KRFTQ3",
          "name": "WhatsApp OAuth account"
        }
      }
    },
    {
      "parameters": {
        "operation": "send",
        "phoneNumberId": "701373393048251",
        "recipientPhoneNumber": "={{ $('whatsapp').item.json.contacts[0].wa_id }}",
        "textBody": "={{ $json.output }}",
        "additionalFields": {}
      },
      "type": "n8n-nodes-base.whatsApp",
      "typeVersion": 1,
      "position": [
        1248,
        -2112
      ],
      "id": "45301af4-0cef-448d-808d-9f9d5f9d60e6",
      "name": "WhatsApp Business Cloud1",
      "webhookId": "3b50de04-a134-4338-b8e4-126f289f947f",
      "credentials": {
        "whatsAppApi": {
          "id": "jnKhnE6KOiaDF1qB",
          "name": "WhatsApp account"
        }
      }
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "d28cbb76-f64c-48cf-a3b3-f3b0cb2a0803",
              "leftValue": "={{ $('whatsapp').item.json.messages }}",
              "rightValue": "",
              "operator": {
                "type": "array",
                "operation": "exists",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        -528,
        -2128
      ],
      "id": "b3614e3e-7912-44ee-8377-03e739b887f8",
      "name": "If1"
    },
    {
      "parameters": {
        "model": {
          "__rl": true,
          "value": "gpt-5-chat-latest",
          "mode": "list",
          "cachedResultName": "gpt-5-chat-latest"
        },
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.2,
      "position": [
        -128,
        -1856
      ],
      "id": "60a69b0e-c603-476d-8a82-69e929e6364e",
      "name": "OpenAI Chat Model1",
      "credentials": {
        "openAiApi": {
          "id": "r5FEJ6lXc0AaNF6n",
          "name": "OpenAi account"
        }
      }
    },
    {
      "parameters": {
        "sessionIdType": "customKey",
        "sessionKey": "={{ $('whatsapp').item.json.contacts[0].wa_id }}v2"
      },
      "type": "@n8n/n8n-nodes-langchain.memoryPostgresChat",
      "typeVersion": 1.3,
      "position": [
        16,
        -1872
      ],
      "id": "25a2abb1-947c-4805-8e0d-5286d2a86924",
      "name": "Postgres Chat Memory",
      "credentials": {
        "postgres": {
          "id": "Eyxd0viKUq8WdCzU",
          "name": "Postgres account"
        }
      }
    },
    {
      "parameters": {
        "inputText": "={{ $('whatsapp').item.json.messages[0].text.body }}",
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.sentimentAnalysis",
      "typeVersion": 1.1,
      "position": [
        -256,
        -2304
      ],
      "id": "c834976f-83c2-4ecc-9a33-aef8fac9d09a",
      "name": "Sentiment Analysis"
    },
    {
      "parameters": {
        "operation": "send",
        "phoneNumberId": "701373393048251",
        "recipientPhoneNumber": "={{ $('whatsapp').item.json.contacts[0].wa_id }}",
        "textBody": "=Gracias por tu consulta, un especialista te contactará ",
        "additionalFields": {}
      },
      "type": "n8n-nodes-base.whatsApp",
      "typeVersion": 1,
      "position": [
        480,
        -2496
      ],
      "id": "0fc25fd2-0854-4e15-9f29-68ed07fdb100",
      "name": "WhatsApp Business Cloud2",
      "webhookId": "3b50de04-a134-4338-b8e4-126f289f947f",
      "credentials": {
        "whatsAppApi": {
          "id": "jnKhnE6KOiaDF1qB",
          "name": "WhatsApp account"
        }
      }
    },
    {
      "parameters": {
        "model": {
          "__rl": true,
          "value": "gpt-4.1-mini",
          "mode": "list",
          "cachedResultName": "gpt-4.1-mini"
        },
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.2,
      "position": [
        -288,
        -2096
      ],
      "id": "76df8ee2-054e-4dce-bb02-bb1213944551",
      "name": "OpenAI Chat Model2",
      "credentials": {
        "openAiApi": {
          "id": "r5FEJ6lXc0AaNF6n",
          "name": "OpenAi account"
        }
      }
    },
    {
      "parameters": {
        "descriptionType": "manual",
        "toolDescription": "Guardar referencia de contacto y motivo",
        "operation": "append",
        "documentId": {
          "__rl": true,
          "value": "1scKI4fPudIptEazQLNdUFMMJq3fEYGhJv73KgUMWvVs",
          "mode": "list",
          "cachedResultName": "InnoIT contacts",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1scKI4fPudIptEazQLNdUFMMJq3fEYGhJv73KgUMWvVs/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": "gid=0",
          "mode": "list",
          "cachedResultName": "Sheet1",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1scKI4fPudIptEazQLNdUFMMJq3fEYGhJv73KgUMWvVs/edit#gid=0"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "Date": "={{$now }}",
            "Email": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Email', ``, 'string') }}",
            "Message": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Message', ``, 'string') }}"
          },
          "matchingColumns": [],
          "schema": [
            {
              "id": "Date",
              "displayName": "Date",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "Email",
              "displayName": "Email",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "Message",
              "displayName": "Message",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleSheetsTool",
      "typeVersion": 4.7,
      "position": [
        320,
        -1872
      ],
      "id": "1876a416-f6e7-4f7a-adec-2db453de9574",
      "name": "guardar_contacto",
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "frSqKV3eztk8uUPR",
          "name": "Google Sheets marc@marcbenito.com"
        }
      }
    },
    {
      "parameters": {
        "descriptionType": "manual",
        "toolDescription": "Listado de perifericos disponibles con precio. En la DESCRIPCION está el nombre del producto",
        "documentId": {
          "__rl": true,
          "value": "1Ll_eBExamlcnGhkEFDySNI7vHX-fubUgUZCpYgKjM3c",
          "mode": "list",
          "cachedResultName": "InnoIt productos",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1Ll_eBExamlcnGhkEFDySNI7vHX-fubUgUZCpYgKjM3c/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": "gid=0",
          "mode": "list",
          "cachedResultName": "Sheet1",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1Ll_eBExamlcnGhkEFDySNI7vHX-fubUgUZCpYgKjM3c/edit#gid=0"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleSheetsTool",
      "typeVersion": 4.7,
      "position": [
        496,
        -1872
      ],
      "id": "3c7af5a0-05e6-4f25-aaf4-77f5f2647203",
      "name": "get_products",
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "frSqKV3eztk8uUPR",
          "name": "Google Sheets marc@marcbenito.com"
        }
      }
    },
    {
      "parameters": {
        "mode": "insert",
        "tableName": "n8n_vectors_store",
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.vectorStorePGVector",
      "typeVersion": 1.3,
      "position": [
        -480,
        -1840
      ],
      "id": "be36855d-7e57-4815-a948-e329bc2c57d2",
      "name": "Postgres PGVector Store",
      "credentials": {
        "postgres": {
          "id": "i56FLw9l38fzyt2z",
          "name": "PreparaULM Vector"
        }
      }
    },
    {
      "parameters": {
        "mode": "retrieve-as-tool",
        "toolDescription": "Catalogo de Servicios de la empresa. consulta los servicios disponibles.\nServicios de la empresa",
        "tableName": "n8n_vectors_store",
        "topK": 30,
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.vectorStorePGVector",
      "typeVersion": 1.3,
      "position": [
        976,
        -1840
      ],
      "id": "0109697c-52f0-426d-a0cd-dae402d2dbd0",
      "name": "Postgres PGVector Store1",
      "credentials": {
        "postgres": {
          "id": "i56FLw9l38fzyt2z",
          "name": "PreparaULM Vector"
        }
      }
    },
    {
      "parameters": {
        "operation": "formatDate",
        "date": "={{ Date.now()}}",
        "format": "x",
        "outputFieldName": "date",
        "options": {}
      },
      "type": "n8n-nodes-base.dateTime",
      "typeVersion": 2,
      "position": [
        -768,
        -2144
      ],
      "id": "65a13b77-d942-422c-9fdf-78019225d039",
      "name": "InitDate1"
    },
    {
      "parameters": {
        "operation": "formatDate",
        "date": "={{ Date.now() }}",
        "format": "x",
        "outputFieldName": "date",
        "options": {}
      },
      "type": "n8n-nodes-base.dateTime",
      "typeVersion": 2,
      "position": [
        784,
        -2336
      ],
      "id": "098308da-108e-4bd2-a352-0daaf707fc55",
      "name": "EndDate2"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "8804c58c-beb5-4a68-99f7-8a88ad7dae5f",
              "name": "input",
              "value": "={{ $('whatsapp').item.json.messages[0].text.body }}",
              "type": "string"
            },
            {
              "id": "b6fb45cd-c192-4497-a224-83576706bbb5",
              "name": "=output",
              "value": "={{ $('AI Agent1').item.json.output }}",
              "type": "string"
            },
            {
              "id": "9ba62e3d-161d-4865-a072-4f1d32621123",
              "name": "id",
              "value": "={{$execution.id }}",
              "type": "string"
            },
            {
              "id": "acbe54f6-d4a7-438b-96ba-c37988f55ef8",
              "name": "init_date",
              "value": "={{ $('InitDate1').item.json.date * 1_000_000 }}",
              "type": "number"
            },
            {
              "id": "3ee62ea4-3c05-4553-b0db-ac912d4467c7",
              "name": "end_date",
              "value": "={{ $('EndDate2').item.json.date  * 1_000_000}}",
              "type": "number"
            },
            {
              "id": "d251c363-103c-40e9-9d35-9990f144a79d",
              "name": "quality",
              "value": "good",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        992,
        -2400
      ],
      "id": "ad56f897-666e-42c8-8b9c-1d92d247e6b0",
      "name": "Edit Fields2"
    },
    {
      "parameters": {
        "operation": "formatDate",
        "date": "={{ Date.now() }}",
        "format": "x",
        "outputFieldName": "date",
        "options": {}
      },
      "type": "n8n-nodes-base.dateTime",
      "typeVersion": 2,
      "position": [
        768,
        -2512
      ],
      "id": "fece38e4-9edc-4569-ba1a-03aaf3093e3f",
      "name": "EndDate3"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "8804c58c-beb5-4a68-99f7-8a88ad7dae5f",
              "name": "input",
              "value": "={{ $('whatsapp').item.json.messages[0].text.body }}",
              "type": "string"
            },
            {
              "id": "b6fb45cd-c192-4497-a224-83576706bbb5",
              "name": "output",
              "value": "=Gracias por tu consulta, un especialista te contactará",
              "type": "string"
            },
            {
              "id": "9ba62e3d-161d-4865-a072-4f1d32621123",
              "name": "id",
              "value": "={{$execution.id }}",
              "type": "string"
            },
            {
              "id": "acbe54f6-d4a7-438b-96ba-c37988f55ef8",
              "name": "init_date",
              "value": "={{ $('InitDate1').item.json.date * 1_000_000 }}",
              "type": "number"
            },
            {
              "id": "3ee62ea4-3c05-4553-b0db-ac912d4467c7",
              "name": "end_date",
              "value": "={{ $('EndDate3').item.json.date  * 1_000_000}}",
              "type": "number"
            },
            {
              "id": "2ad0f0eb-6852-4dcf-b21d-92a39376ed4a",
              "name": "quality",
              "value": "bad",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        976,
        -2576
      ],
      "id": "ac833ca4-b1dd-415d-8f88-a103e2e51a9e",
      "name": "Edit Fields3"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.datadoghq.eu/api/intake/llm-obs/v1/trace/spans",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Accept",
              "value": "application/json"
            },
            {
              "name": "DD-API-KEY",
              "value": "SET_YOUR_APIKEY_HERE"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"data\": {\n    \"type\": \"span\",\n    \"attributes\": {\n      \"ml_app\": \"whats-bot\",\n      \"session_id\": \"1\",\n      \"tags\": [\n        \"service:whats-bot-service\",\n        \"env:staging\",\n        \"user_handle:example-user@example.com\",\n        \"user_id:1234\"\n      ],\n      \"spans\": [\n        {\n          \"parent_id\": \"undefined\",\n          \"trace_id\": \"{{ $execution.id }}\",\n          \"span_id\": \"{{ $execution.id }}\",\n          \"name\": \"whats-bot-span\",\n          \"meta\": {\n            \"kind\": \"agent\",\n            \"quality\":\"{{$json.quality}}\",\n            \"input\": {\n              \"value\": \"{{$json.input.replace(/\\n/g, \"\\\\n\")}}\"\n            },\n            \"output\": {\n              \"value\": \"{{$json.output.replace(/\\n/g, \"\\\\n\")}}\"\n            }\n          },\n          \"start_ns\": {{ $('InitDate1').item.json.date }}000000,\n          \"duration\": {{$json.end_date- $json.init_date}}\n        }\n      ]\n    }\n  }\n}",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1280,
        -2512
      ],
      "id": "ad8f4f89-fe4e-4328-9390-23a7d0e82122",
      "name": "Datadog HTTP Request3",
      "extendsCredential": "datadogApi",
      "onError": "continueErrorOutput"
    }
  ],
  "pinData": {},
  "connections": {
    "HTTP Request": {
      "main": [
        [
          {
            "node": "Respond to Webhook",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "WhatsApp Business Cloud": {
      "main": [
        []
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Simple Memory": {
      "ai_memory": [
        [
          {
            "node": "AI Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Edit Fields": {
      "main": [
        [
          {
            "node": "Datadog HTTP Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent": {
      "main": [
        [
          {
            "node": "WhatsApp Business Cloud",
            "type": "main",
            "index": 0
          },
          {
            "node": "EndDate",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "InitDate": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "EndDate": {
      "main": [
        [
          {
            "node": "Edit Fields",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If": {
      "main": [
        [
          {
            "node": "InitDate",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get availability in a calendar in Google Calendar": {
      "ai_tool": [
        [
          {
            "node": "AI Agent1",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Create an event in Google Calendar": {
      "ai_tool": [
        [
          {
            "node": "AI Agent1",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Upload your file here": {
      "main": [
        [
          {
            "node": "Postgres PGVector Store",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Default Data Loader": {
      "ai_document": [
        [
          {
            "node": "Postgres PGVector Store",
            "type": "ai_document",
            "index": 0
          }
        ]
      ]
    },
    "Embeddings Google Gemini": {
      "ai_embedding": [
        [
          {
            "node": "Postgres PGVector Store",
            "type": "ai_embedding",
            "index": 0
          },
          {
            "node": "Postgres PGVector Store1",
            "type": "ai_embedding",
            "index": 0
          }
        ]
      ]
    },
    "whatsapp": {
      "main": [
        [
          {
            "node": "InitDate1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent1": {
      "main": [
        [
          {
            "node": "WhatsApp Business Cloud1",
            "type": "main",
            "index": 0
          },
          {
            "node": "EndDate2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If1": {
      "main": [
        [
          {
            "node": "Sentiment Analysis",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model1": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent1",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Postgres Chat Memory": {
      "ai_memory": [
        [
          {
            "node": "AI Agent1",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Sentiment Analysis": {
      "main": [
        [
          {
            "node": "AI Agent1",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "AI Agent1",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "WhatsApp Business Cloud2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model2": {
      "ai_languageModel": [
        [
          {
            "node": "Sentiment Analysis",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "guardar_contacto": {
      "ai_tool": [
        [
          {
            "node": "AI Agent1",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "get_products": {
      "ai_tool": [
        [
          {
            "node": "AI Agent1",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Postgres PGVector Store1": {
      "ai_tool": [
        [
          {
            "node": "AI Agent1",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "InitDate1": {
      "main": [
        [
          {
            "node": "If1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "EndDate2": {
      "main": [
        [
          {
            "node": "Edit Fields2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Edit Fields2": {
      "main": [
        [
          {
            "node": "Datadog HTTP Request3",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "WhatsApp Business Cloud2": {
      "main": [
        [
          {
            "node": "EndDate3",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "EndDate3": {
      "main": [
        [
          {
            "node": "Edit Fields3",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Edit Fields3": {
      "main": [
        [
          {
            "node": "Datadog HTTP Request3",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": true,
  "settings": {
    "executionOrder": "v1",
    "timezone": "Europe/Madrid",
    "callerPolicy": "workflowsFromSameOwner"
  },
  "versionId": "1aedf5a2-8426-4343-a99b-c3d37b68d6f3",
  "meta": {
    "templateCredsSetupCompleted": true,
    "instanceId": "edf65107f4e74e1fc40836f00996d676566a5287b4feb81d57380eb9da83ec7e"
  },
  "id": "yTxWrWKvzAR4GAeN",
  "tags": [
    {
      "createdAt": "2025-10-17T20:29:05.379Z",
      "updatedAt": "2025-10-17T20:29:05.379Z",
      "id": "R02q32gn6O27XAZN",
      "name": "InnoIT"
    }
  ]
}