{
  "id": "J2D0BssoDmn4BC6D",
  "meta": {
    "instanceId": "143d2ab55c8bffb06f8b9c7ad30335764fdc48bbbacecbe2218dadb998a32213",
    "templateCredsSetupCompleted": true
  },
  "name": "AI Customer-Support Assistant u00b7 WhatsApp Ready u00b7 Works for Any Business",
  "tags": [],
  "nodes": [
    {
      "id": "fe395033-e36e-42d4-a0ce-8362b172be31",
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "maxTries": 5,
      "position": [
        120,
        140
      ],
      "parameters": {
        "text": "={{ $json.messages[0].text.body }}",
        "options": {
          "maxIterations": 10,
          "systemMessage": "=You are [Company Name]u2019s real-time website assistant for https://www.your-company-url.com.nnAVAILABLE TOOLSnu2022 list_links(url) u2192 { urls:[ u2026 ] }  u2014 returns up to 100 internal links from that page  nu2022 get_page(url)   u2192 { text:"u2026" }    u2014 returns the visible, tag-free text of the page (JavaScript rendered if needed)nnSEARCH STRATEGYn1. Start with list_links on the root page.  n2. Pick u2264 5 links whose URL or anchor text best match the useru2019s question (producto, pago, envu00edo, servicio, polu00edtica, etc.).  n3. For each chosen link call get_page once.  n4. Read the returned text and look for the answer.  n5. If the answer is still unknown, you may repeat steps 1-4 one level deeper.  n6. Stop after two list_links rounds **or** eight get_page calls (whichever comes first).nnANSWER RULESnu2022 Reply in clear and friendly toon **as part of [Company Name]** (use u201cweu201d, u201couru201d).  nu2022 Keep answers concise but complete.  nu2022 **No Markdown ni su00edmbolos de formato. Nunca uses \*, **, \_, \~, ni [texto](url).**  n  Write urls like: Descriptive Text u2423URL   Ej.: Combos https://u2026  nu2022 Quote the exact wording for facts such as stock status, prices, envu00edos, mu00e9todos de pago, garantu00edas o polu00edticas.  nu2022 If the information is not on the site, reply exactly:  n  u201cI can't find that information on our site right now. Do you want me to put you through to a human agent?u201d  nu2022 Stay on-domain; ignore mailto:, tel:, javascript:, or off-site links.nu2022 Finally, if any of the tools returns a status code 404, then reply:n"Non-subscribed user."",
          "returnIntermediateSteps": true
        },
        "promptType": "define",
        "hasOutputParser": true
      },
      "retryOnFail": false,
      "typeVersion": 1.7,
      "alwaysOutputData": true,
      "waitBetweenTries": null
    },
    {
      "id": "3953a213-6140-4603-a069-93718e4d8982",
      "name": "list_links",
      "type": "@n8n/n8n-nodes-langchain.toolHttpRequest",
      "position": [
        260,
        420
      ],
      "parameters": {
        "url": "https://lemolex.app.n8n.cloud/webhook/list-links",
        "method": "POST",
        "sendBody": true,
        "parametersBody": {
          "values": [
            {
              "name": "url",
              "value": "https://www.your-company-url.com",
              "valueProvider": "fieldValue"
            },
            {
              "name": "auth-token",
              "value": "your-auth-token (read setup guide)",
              "valueProvider": "fieldValue"
            }
          ]
        },
        "toolDescription": "Returns up to 100 unique, fully-qualified INTERNAL links for a given page.nnInput  (JSON body the model must supply)n  {n    "url": ""n  }nnBehaviourn  u2022 Crawls only the domain of the input URL.n  u2022 Converts relative <a href> values to absolute URLs.n  u2022 Drops empty roots ("/"), mailto:, tel:, javascript:, and off-site links.n  u2022 De-duplicates the list.n  u2022 Responds with a JSON object:nn      {n        "urls": [ "", "", u2026 ]n      }nnUse this tool when you need a navigation map of the current page.nPass one of the returned URLs back into other tools (e.g. get_text) to read its content.n"
      },
      "typeVersion": 1.1
    },
    {
      "id": "21ceaf5e-d2d4-47c3-98cb-ee7c0ab0fcab",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        40,
        340
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini"
        },
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "id": "jh4eAOIykIxQWUI9",
          "name": "OpenAi account"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "7e0e84c8-ad96-44d1-9de9-c639230418fd",
      "name": "WhatsApp Trigger",
      "type": "n8n-nodes-base.whatsAppTrigger",
      "position": [
        -260,
        140
      ],
      "webhookId": "857366e8-7b6f-45a7-bbd1-f876002620d7",
      "parameters": {
        "updates": [
          "messages"
        ]
      },
      "credentials": {
        "whatsAppTriggerApi": {
          "id": "EB6eAVg9ZBZGYsyX",
          "name": "WhatsApp OAuth account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "c2a0ba34-4a23-4918-9be8-7b9d50279cde",
      "name": "cleanAnswer",
      "type": "n8n-nodes-base.code",
      "position": [
        1040,
        120
      ],
      "parameters": {
        "jsCode": "// cleanAnswer u2013 run once per itemnlet txt = $('AI Agent').first().json.output || '';nn// 1. Remove bold / italic / strike markersntxt = txt.replace(/[*_~]+/g, '');nn// 2. Convert [Texto](https://url) u2192 Texto https://urlntxt = txt.replace(/\[([^\]]+)\]\((https?:\/\/[^\s)]+)\)/g, '$1 $2');nn// 3. Collapse 3+ blank linesntxt = txt.replace(/\n{3,}/g, '\n\n').trim();nnreturn [{ json: { answer: txt } }];n"
      },
      "typeVersion": 2
    },
    {
      "id": "ef403af2-4543-4edb-80ae-afda1e98a2a9",
      "name": "get_page",
      "type": "@n8n/n8n-nodes-langchain.toolHttpRequest",
      "position": [
        420,
        420
      ],
      "parameters": {
        "url": "https://lemolex.app.n8n.cloud/webhook/get_text",
        "method": "POST",
        "sendBody": true,
        "parametersBody": {
          "values": [
            {
              "name": "url"
            },
            {
              "name": "auth-token",
              "value": "your-auth-token (read setup guide)",
              "valueProvider": "fieldValue"
            }
          ]
        },
        "toolDescription": "Fetches the fully-rendered **plain text** of a single web.  nu2022 Input  : { "url": "" }  nu2022 Auth   : token is sent as HTTP basic-auth.  nu2022 Query  : url=  nu2022 Output : { "text": "", "url": "" }  nu2022 The "text" field already has **all HTML tags removed** .  nu2022 Use this tool whenever you need the actual words that appear on the pageu2014product details, prices, stock lines, shipping terms, payment options, company policies, etc.  nu2022 Do **not** call it on off-site links or mailto:/tel:/javascript: pseudo-links.  n"
      },
      "typeVersion": 1.1
    },
    {
      "id": "46c1fd08-9b61-4ea9-bee3-9ad8b7e7ce4d",
      "name": "24-hour window check",
      "type": "n8n-nodes-base.code",
      "position": [
        520,
        140
      ],
      "parameters": {
        "jsCode": "// within24h?  u2013 run once per itemn// Meta (WhatsApp) timestamp arrives as seconds since epochnconst lastTs = Number($('WhatsApp Trigger').first().json.messages[0].timestamp) * 1000;   // u2192 msnconst withinWindow = Date.now() - lastTs  Facebook)n[https://www.your-company-url.com] with your company Root URL that you copied before.nCheck for these 2 values along the entire text.n- Go back to the tools list_links and get_page and paste the Root URL inside the body parameters, specifically:n*Name: url*n*Value: https://www.your-company-url.com **(e.g https://www.facebook.com)**nn3. Connect your credentials:n- Go to the OpenAI Chat Model node and connect your OpenAI credentials.n- Go to the Postgres Users Memory node and connect your Supabase credentials. A tutorial for this: https://youtu.be/6w5f_jsPYSQ?si=MPdXYUjxv3fghQPj&amp;t=105 (Minute 1:45 to 5:00)n- Go to the WhatsApp nodes "WhatsApp Trigger", "Send Pre-approved Template Message to Reopen the Conversation" and "Send AI Agent's Answer" to connect your credentials. A tutorial for this: https://youtu.be/ZrhTQle55LQ?si=MO_leooogO9KchCVn- Go to the "Send Pre-approved Template Message to Reopen the Conversation" and select the template message under the "Template" parameter.n***If you don't want to use this feature (not recommended) delete the nodes "24-hour window check", "If" and "Send Pre-approved Template Message to Reopen the Conversation". Then connect the AI Agent node to the "cleanAnswer" node.***nnn### **You are ready**"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "245c3695-7177-4a1d-a33d-7aedd0eccc44",
  "connections": {
    "If": {
      "main": [
        [
          {
            "node": "cleanAnswer",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Send Pre-approved Template Message to Reopen the Conversation",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent": {
      "main": [
        [
          {
            "node": "24-hour window check",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "get_page": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "list_links": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "cleanAnswer": {
      "main": [
        [
          {
            "node": "Send AI Agent's Answer",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "WhatsApp Trigger": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "24-hour window check": {
      "main": [
        [
          {
            "node": "If",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Postgres Users Memory": {
      "ai_memory": [
        [
          {
            "node": "AI Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    }
  }
}