{
  "name": "Build a Telegram AI chatbot with human takeover using Trilox and GPT-4o-mini",
  "nodes": [
    {
      "id": "bd8c533c-7405-47a0-a6d9-47671fea6e7f",
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        2016,
        400
      ]
    },
    {
      "id": "719418b0-451a-4537-b9cd-b3afc2471108",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        1968,
        592
      ]
    },
    {
      "id": "c63dc94b-c610-4f1c-b673-a38baf8bd2de",
      "name": "Conversation Memory",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        2064,
        704
      ]
    },
    {
      "id": "9d8884d3-4af5-4318-b232-803bc0607cf0",
      "name": "Structured Output Parser",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        2208,
        592
      ]
    },
    {
      "id": "cd70daab-da7d-4b77-aca6-8f986553177c",
      "name": "Handler Status Router",
      "type": "n8n-nodes-base.switch",
      "position": [
        1632,
        1072
      ]
    },
    {
      "id": "aca159b5-cb45-4012-aa19-5660470e9638",
      "name": "Telegram Trigger",
      "type": "n8n-nodes-base.telegramTrigger",
      "position": [
        -16,
        1120
      ]
    },
    {
      "id": "61779a6a-67dd-46b1-a7ec-560d79f9dd43",
      "name": "Message Type Router",
      "type": "n8n-nodes-base.switch",
      "position": [
        224,
        1104
      ]
    },
    {
      "id": "1b49da3d-f949-453f-bf19-51b5fd0232b8",
      "name": "Download Voice File",
      "type": "n8n-nodes-base.telegram",
      "position": [
        512,
        1168
      ]
    },
    {
      "id": "3c3df40a-9fa6-4fda-8f35-b48ecb77d8f9",
      "name": "Transcribe Voice Message",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "position": [
        672,
        1168
      ]
    },
    {
      "id": "54e91bc6-6af2-4e2d-811e-3e9f7e57612e",
      "name": "Merge Text Input",
      "type": "n8n-nodes-base.merge",
      "position": [
        928,
        1088
      ]
    },
    {
      "id": "f8fcc53a-65e2-4ae1-9cb3-3d93545a169f",
      "name": "Extract Text",
      "type": "n8n-nodes-base.set",
      "position": [
        512,
        1008
      ]
    },
    {
      "id": "f50a4fba-a745-4164-a068-e338e42f1326",
      "name": "Needs Human?",
      "type": "n8n-nodes-base.if",
      "position": [
        3216,
        256
      ]
    },
    {
      "id": "0c8688c3-be15-46c8-bfb3-ffb8bbdc6725",
      "name": "Send Bot Reply",
      "type": "n8n-nodes-base.telegram",
      "position": [
        2800,
        256
      ]
    },
    {
      "id": "7621466b-526e-4edc-b53f-552f0f2b0b5e",
      "name": "Handler Status Router 2",
      "type": "n8n-nodes-base.switch",
      "position": [
        2592,
        384
      ]
    },
    {
      "id": "7a6f54af-15de-457e-a56e-8deadae21809",
      "name": "Done (No Escalation)",
      "type": "n8n-nodes-base.noOp",
      "position": [
        3456,
        352
      ]
    },
    {
      "id": "37c6b17d-06e3-48c7-afb8-591e80aeffdc",
      "name": "Suppress Bot Reply",
      "type": "n8n-nodes-base.noOp",
      "position": [
        2800,
        448
      ]
    },
    {
      "id": "38667d28-efad-4464-9c41-75bcafce7d47",
      "name": "Send Awaiting Message",
      "type": "n8n-nodes-base.telegram",
      "position": [
        1984,
        1088
      ]
    },
    {
      "id": "2295314f-28be-40dd-9f57-638f88f714f4",
      "name": "Bot Stays Silent",
      "type": "n8n-nodes-base.noOp",
      "position": [
        2016,
        1536
      ]
    },
    {
      "id": "aecb50a8-8e05-4351-ac2e-77c63fa43e5d",
      "name": "Forward to Telegram",
      "type": "n8n-nodes-base.telegram",
      "position": [
        2480,
        1536
      ]
    },
    {
      "id": "712871d0-0f10-4b82-8acd-167052b103f4",
      "name": "Record Visitor Message",
      "type": "n8n-nodes-trilox.trilox",
      "position": [
        1168,
        1088
      ]
    },
    {
      "id": "3cfa9b44-671a-48cd-9a3f-09adfaa750fc",
      "name": "Record Bot Response",
      "type": "n8n-nodes-trilox.trilox",
      "position": [
        3008,
        256
      ]
    },
    {
      "id": "fb5b7df5-14e2-46ed-b005-9afb46442c4a",
      "name": "Record Awaiting Message",
      "type": "n8n-nodes-trilox.trilox",
      "position": [
        2192,
        1088
      ]
    },
    {
      "id": "5fc27776-9ea9-4dbd-869f-7cee23b8eb48",
      "name": "Check Handler (Pre-Bot)",
      "type": "n8n-nodes-trilox.trilox",
      "position": [
        1392,
        1088
      ]
    },
    {
      "id": "05aed161-d1d9-426d-a891-bb9c3c04e833",
      "name": "Check Handler (Post-Bot)",
      "type": "n8n-nodes-trilox.trilox",
      "position": [
        2304,
        400
      ]
    },
    {
      "id": "7302b50e-557c-4e4c-90a9-a489360751e0",
      "name": "Trilox Trigger (Agent Reply)",
      "type": "n8n-nodes-trilox.triloxTrigger",
      "position": [
        2000,
        1712
      ]
    },
    {
      "id": "4e7cf467-50ac-4066-a8fd-d78be8950db9",
      "name": "Escalate to Human",
      "type": "n8n-nodes-trilox.trilox",
      "position": [
        3456,
        208
      ]
    },
    {
      "id": "28d84020-78d1-48a4-9870-749eb4a7c9d1",
      "name": "Channel Router",
      "type": "n8n-nodes-base.switch",
      "position": [
        2176,
        1648
      ]
    },
    {
      "id": "aead1ed1-f034-41c7-b4fb-c1c6097d7402",
      "name": "Other Channels (Placeholder)",
      "type": "n8n-nodes-base.noOp",
      "position": [
        2496,
        1728
      ]
    },
    {
      "id": "2af0e5fa-e8f1-4eae-876c-1f19a13a644f",
      "name": "Ignore Unsupported",
      "type": "n8n-nodes-base.noOp",
      "position": [
        512,
        1328
      ]
    },
    {
      "id": "186d4e64-2163-477c-8d5f-36e0d8eed4a7",
      "name": "Sticky Note - Setup Guide",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -784,
        464
      ],
      "parameters": {
        "width": 680,
        "height": 1200,
        "content": "## 🤖 Telegram AI Chatbot with Human Takeover\n\nA complete Telegram chatbot with AI responses, real-time monitoring, and human takeover — powered by **Trilox**.\n\nWhen the bot can't help (or says somethi"
      }
    },
    {
      "id": "c6be7413-cb54-4dc8-bb3c-f7e34a3b9770",
      "name": "Sticky Note - Message Intake",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -80,
        880
      ],
      "parameters": {
        "width": 520,
        "height": 360,
        "content": "## 1️⃣ Message Intake\nReceive Telegram messages and normalize them into a single text field.\n\n**Text messages** → extracted directly\n**Voice messages** → downloaded and transcribed via OpenAI Whisper "
      }
    },
    {
      "id": "84e8e26f-d970-4a09-a60a-22f6decd2d3c",
      "name": "Sticky Note - Record & Check",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1088,
        880
      ],
      "parameters": {
        "width": 488,
        "height": 368,
        "content": "## 2️⃣ Record & Check Handler\nLog the visitor message to **Trilox**, then check who's handling this conversation.\n\n**Check Handler** returns `handlerType`:\n- `bot` → AI Agent responds\n- `awaiting_huma"
      }
    },
    {
      "id": "d89259ca-7365-4f8d-9f83-d5cbcc995c8a",
      "name": "Sticky Note - Bot Handler",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1920,
        32
      ],
      "parameters": {
        "width": 596,
        "height": 876,
        "content": "## 3️⃣ Bot Handler\nAI Agent generates a response with structured output:\n```json\n{\n \"message\": \"reply text\",\n \"is_human_required\": true/false\n}\n```\n\n**Critical:** After AI responds, we check the handl"
      }
    },
    {
      "id": "68ea2ee3-8184-4b78-8964-abb16adf6ff3",
      "name": "Sticky Note - Awaiting Human",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1920,
        944
      ],
      "parameters": {
        "width": 600,
        "height": 328,
        "content": "## 4️⃣ Awaiting Human\nConversation has been escalated but no human has picked it up yet.\n\nSend the customer a courtesy message and log it to Trilox."
      }
    },
    {
      "id": "7a404979-7bd6-4006-b514-0ff97247c5d1",
      "name": "Sticky Note - Human Agent Reply",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1904,
        1312
      ],
      "parameters": {
        "width": 624,
        "height": 748,
        "content": "## 5️⃣ Human Agent Reply\n**Trilox Trigger** fires when a human replies from the Trilox inbox.\n\nThe **Channel Router** checks which platform the conversation is on and forwards the human's reply to the"
      }
    },
    {
      "id": "1e74811d-db50-4f79-af01-61cc7596dc44",
      "name": "Sticky Note - Quick Test",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -80,
        1280
      ],
      "parameters": {
        "width": 440,
        "height": 380,
        "content": "## 🧪 Quick Test\n\n1. Activate this workflow\n2. Message your Telegram bot: **\"Hi, what are your hours?\"**\n3. Open Trilox inbox → you should see the conversation\n4. Message: **\"I need a refund\"** → bot e"
      }
    },
    {
      "id": "04a89a53-f512-411c-b7a3-41e073097a54",
      "name": "Sticky Note - Channel Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2352,
        1888
      ],
      "parameters": {
        "width": 400,
        "height": 140,
        "content": "💡 **Other channels** are not connected in this template. The placeholder outputs are here so you can quickly add WhatsApp, Messenger, Instagram, or Widget support by connecting the appropriate send no"
      }
    }
  ],
  "connections": {
    "AI Agent": {
      "main": [
        [
          {
            "node": "Check Handler (Post-Bot)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Text": {
      "main": [
        [
          {
            "node": "Merge Text Input",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Needs Human?": {
      "main": [
        [
          {
            "node": "Escalate to Human",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Done (No Escalation)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Channel Router": {
      "main": [
        [
          {
            "node": "Forward to Telegram",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Other Channels (Placeholder)",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Other Channels (Placeholder)",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Other Channels (Placeholder)",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Other Channels (Placeholder)",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Other Channels (Placeholder)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send Bot Reply": {
      "main": [
        [
          {
            "node": "Record Bot Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge Text Input": {
      "main": [
        [
          {
            "node": "Record Visitor Message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Telegram Trigger": {
      "main": [
        [
          {
            "node": "Message Type Router",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Conversation Memory": {
      "ai_memory": [
        [
          {
            "node": "AI Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Download Voice File": {
      "main": [
        [
          {
            "node": "Transcribe Voice Message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Message Type Router": {
      "main": [
        [
          {
            "node": "Extract Text",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Download Voice File",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Ignore Unsupported",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Record Bot Response": {
      "main": [
        [
          {
            "node": "Needs Human?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Handler Status Router": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Send Awaiting Message",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Bot Stays Silent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send Awaiting Message": {
      "main": [
        [
          {
            "node": "Record Awaiting Message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Record Visitor Message": {
      "main": [
        [
          {
            "node": "Check Handler (Pre-Bot)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Handler (Pre-Bot)": {
      "main": [
        [
          {
            "node": "Handler Status Router",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Handler Status Router 2": {
      "main": [
        [
          {
            "node": "Send Bot Reply",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Suppress Bot Reply",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Suppress Bot Reply",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Handler (Post-Bot)": {
      "main": [
        [
          {
            "node": "Handler Status Router 2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Structured Output Parser": {
      "ai_outputParser": [
        [
          {
            "node": "AI Agent",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Transcribe Voice Message": {
      "main": [
        [
          {
            "node": "Merge Text Input",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Trilox Trigger (Agent Reply)": {
      "main": [
        [
          {
            "node": "Channel Router",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}