{
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "be20ceb6-bfab-48c0-9e76-ece594aa90a1",
      "name": "Gmail Trigger",
      "type": "n8n-nodes-base.gmailTrigger",
      "position": [
        -960,
        64
      ],
      "parameters": {
        "filters": {},
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        }
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "d2aa66f3-60d4-4f3f-a216-06edf20fe429",
      "name": "Microsoft Outlook Trigger",
      "type": "n8n-nodes-base.microsoftOutlookTrigger",
      "position": [
        -960,
        240
      ],
      "parameters": {
        "filters": {},
        "options": {},
        "pollTimes": {
          "item": [
            {
              "mode": "everyHour"
            }
          ]
        }
      },
      "credentials": {
        "microsoftOutlookOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "abe1118d-948b-4225-a606-1c422ba5930d",
      "name": "Email Trigger (IMAP)",
      "type": "n8n-nodes-base.emailReadImap",
      "position": [
        -960,
        432
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 2.1
    },
    {
      "id": "8a4600c0-3d7b-4c2e-bff0-43a742f38578",
      "name": "from Idealista?",
      "type": "n8n-nodes-base.filter",
      "position": [
        -736,
        224
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "3853f10a-19b5-4830-b416-901aa268e54e",
              "operator": {
                "type": "string",
                "operation": "contains"
              },
              "leftValue": "={{ $json.from || $json.From || $json.Subject }}",
              "rightValue": "idealista.com"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "f7a019b1-3b82-4af8-9793-a9f538de7508",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -976,
        -800
      ],
      "parameters": {
        "color": 3,
        "width": 1056,
        "height": 448,
        "content": "## How to Automatically Qualify Idealista Leads via WhatsApp Using an AI Agent\n\nThis workflow automates the process of capturing incoming **property leads from Idealista** one of the leading real estate platforms in **Spain, Italy, and Portugal** and qualifying them instantly via **WhatsApp** with Superchat.\n\nThe workflow monitors your inbox for new emails and applies a filter to identify messages coming from **Idealista**. Once a matching email is detected, it is forwarded to an **AI agent** that parses the unstructured email content and extracts key lead information, including:\n\n* **Name** \u2013 the lead's full name\n* **Phone number** \u2013 the lead's contact number\n* **Email** \u2013 the lead's email address\n* **Property of interest** \u2013 the listing the lead is inquiring about\n\nOnce the lead data is structured, the workflow automatically sends a **WhatsApp template message** to the lead to initiate the qualification process ensuring the fastest response times and a professional first touchpoint.\n\nBy automating this flow, you eliminate manual email screening, reduce response times from hours to seconds, and ensure no Idealista lead slips through the cracks."
      },
      "typeVersion": 1
    },
    {
      "id": "be408c95-3690-4fed-8283-4337ff4e5109",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -976,
        -304
      ],
      "parameters": {
        "width": 272,
        "height": 192,
        "content": "## STEP 1\nConnect your email inbox\n- Gmail OR\n- Outlook OR\n- IMAP (All email providers)\n\nDelete/Remove the others"
      },
      "typeVersion": 1
    },
    {
      "id": "2dc47cf7-d703-4696-b0b6-9873049f738b",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        -576,
        528
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o",
          "cachedResultName": "gpt-4o"
        },
        "options": {},
        "builtInTools": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "e346e541-605c-4b83-95fc-954d230cb87b",
      "name": "Structured Output Parser",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        -400,
        432
      ],
      "parameters": {
        "jsonSchemaExample": "{\n    \"firstName\": \"\",\n    \"lastName\": \"\",\n    \"phone\": \"\",\n    \"email\": \"\",\n    \"propertyRef\": \"\",\n    \"propertyTitle\": \"\",\n  \"propertyAddress\": \"\",\n    \"propertyLink\": \"\",\n    \"message\": \"\",\n    \"timestamp\": \"\",\n    \"source\": \"Idealista\"\n  }"
      },
      "typeVersion": 1.3
    },
    {
      "id": "fe74439c-d630-42d6-b4b2-b808252c5d99",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -576,
        -304
      ],
      "parameters": {
        "width": 272,
        "height": 96,
        "content": "## STEP 2\nConnect your OpenAI API Key or connect a different LLM"
      },
      "typeVersion": 1
    },
    {
      "id": "cccf993d-4461-4276-b4e5-306af19b21f1",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -224,
        -304
      ],
      "parameters": {
        "width": 272,
        "height": 96,
        "content": "## STEP 3\nConnect your Superchat Workspace [through an API Key.](https://help.superchat.com/en/articles/213219-introduction-to-integrations#h_56604e4ec3)"
      },
      "typeVersion": 1
    },
    {
      "id": "a713d62f-abe6-4709-aee8-a97355e5a9d1",
      "name": "Sticky Note7",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -224,
        -192
      ],
      "parameters": {
        "width": 272,
        "height": 256,
        "content": "## STEP 4\n[Create a WhatsApp Template](https://help.superchat.com/en/articles/25035-get-started-whatsapp-templates) to reach out to your Idealista Leads.\n\n1. Select your WhatsApp Channel in the Superchat Node\n2. Select your WhatsApp template (when it's approved)\n3. Fill out your variables in chronological order"
      },
      "typeVersion": 1
    },
    {
      "id": "61175179-b8b0-4cbd-8b84-07ab90ff249a",
      "name": "Send WhatsApp Template",
      "type": "n8n-nodes-superchat.superchat",
      "position": [
        -144,
        224
      ],
      "parameters": {
        "resource": "message",
        "channelId": {
          "__rl": true,
          "mode": "list",
          "value": "mc_MB7FsZpu70EWyZIv03Kc8",
          "cachedResultName": "WhatsApp: +1234567890"
        },
        "operation": "sendWhatsAppTemplate",
        "variables": {
          "values": []
        },
        "identifier": "={{ $json.phone}}",
        "templateId": {
          "__rl": true,
          "mode": "list",
          "value": "tn_J5mvc0rOLTGNigcUeC87X",
          "cachedResultName": "2_Kreditanfrage"
        },
        "otherOptions": {}
      },
      "credentials": {
        "superchatApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "8e5da037-2e73-413d-ac6f-5a13de755d34",
      "name": "AI Agent extracts Lead Information",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        -544,
        224
      ],
      "parameters": {
        "text": "=Here is the email:\n{{JSON.stringify($json)}}",
        "options": {
          "systemMessage": "You are an expert data extractor that converts real-estate lead emails from Idealista into structured JSON.\n\nYour task is to read the raw email text and extract only the relevant lead information.\n\nRules:\n- Always output valid JSON (UTF-8, no code blocks, no extra text).\n- Include these keys:\n  {\n  \"firstName\": \"\",\n    \"lastName\": \"\",\n    \"phone\": \"\",\n    \"email\": \"\",\n    \"propertyRef\": \"\",\n    \"propertyTitle\": \"\",\n  \"propertyAddress\": \"\",\n    \"propertyLink\": \"\",\n    \"message\": \"\",\n    \"timestamp\": \"\",\n    \"source\": \"Idealista\"\n  }\n- If some data is missing, leave the field empty (do not write \u201cnull\u201d or \u201cunknown\u201d).\n- Normalize phone numbers to include country code +34 if missing.\n- Extract the name from expressions like \u201cHola, soy \u2026\u201d, \u201cMe llamo \u2026\u201d, or \u201cMi nombre es \u2026\u201d.\n- Extract the property reference (e.g. \u201cRef: 1165\u201d) or detect it from text patterns like \u201creferencia 1165\u201d.\n- Extract the link (if present) from \u201cidealista.com/inmueble/...\u201d.\n- Extract the timestamp if mentioned.\n- The \u201cmessage\u201d field should include the free-text part the user wrote.\n- Do not include explanations, notes, or comments \u2014 only clean JSON.\n\nIf the input is not an Idealista lead, return an empty JSON object: {}."
        },
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 3.1
    },
    {
      "id": "3fc1957b-5f02-4eed-ba5f-7c3de56f8e95",
      "name": "Sticky Note8",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -672,
        480
      ],
      "parameters": {
        "color": 5,
        "width": 224,
        "content": "## STEP 2"
      },
      "typeVersion": 1
    },
    {
      "id": "e4b6365f-a13c-4c76-8ea7-63049f88d670",
      "name": "Sticky Note9",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1088,
        48
      ],
      "parameters": {
        "color": 5,
        "width": 272,
        "height": 528,
        "content": "## STEP 1"
      },
      "typeVersion": 1
    },
    {
      "id": "621b6311-1091-43c5-ab5f-bcc1ca152917",
      "name": "Sticky Note10",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -224,
        144
      ],
      "parameters": {
        "color": 5,
        "width": 224,
        "height": 288,
        "content": "## STEP 3 & 4"
      },
      "typeVersion": 1
    },
    {
      "id": "662fa97a-96e4-4b51-bf3a-a51bd64388c8",
      "name": "Sticky Note11",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        128,
        128
      ],
      "parameters": {
        "width": 272,
        "height": 368,
        "content": "## Example Template\n\nHola {{firstName}}, gracias por tu inter\u00e9s en la referencia {{propertyTitle}} en la direccion {{propertyAddress}}.\n\nAqu\u00ed tienes el enlace del anuncio: {{propertyLink}}.\n\nPara poder ayudarte mejor por favor elige una opcion:\n\nButton: Saber los requisitos\nButton: Agendar una visita\nButton: Conocer mas pisos"
      },
      "typeVersion": 1
    }
  ],
  "connections": {
    "Gmail Trigger": {
      "main": [
        [
          {
            "node": "from Idealista?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "from Idealista?": {
      "main": [
        [
          {
            "node": "AI Agent extracts Lead Information",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent extracts Lead Information",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Email Trigger (IMAP)": {
      "main": [
        [
          {
            "node": "from Idealista?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Structured Output Parser": {
      "ai_outputParser": [
        [
          {
            "node": "AI Agent extracts Lead Information",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Microsoft Outlook Trigger": {
      "main": [
        [
          {
            "node": "from Idealista?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent extracts Lead Information": {
      "main": [
        [
          {
            "node": "Send WhatsApp Template",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}