{
  "name": "Create a session-based Telegram chatbot with GPT-4o-mini and Google Sheets",
  "nodes": [
    {
      "id": "d3104851-90ec-4f0c-ab4d-aee5a6faf81b",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        640,
        1180
      ]
    },
    {
      "id": "e25050a1-e49b-4b46-8452-ce7b3388c7f3",
      "name": "Simple Memory",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        780,
        1180
      ]
    },
    {
      "id": "d50951ae-e9a2-492c-8ff5-a039ca6975e4",
      "name": "Get message",
      "type": "n8n-nodes-base.telegramTrigger",
      "position": [
        -520,
        -60
      ]
    },
    {
      "id": "1bc9aa0f-8af8-47b8-b7d7-6bfd9280b65f",
      "name": "Command or text?",
      "type": "n8n-nodes-base.switch",
      "position": [
        -20,
        -60
      ]
    },
    {
      "id": "4a405332-99a8-4ec9-84d5-89f9f5f1610f",
      "name": "Get session",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        -260,
        -60
      ]
    },
    {
      "id": "860fa8d5-6c9b-476b-857b-9c47a023d72f",
      "name": "Disable previous session",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        640,
        -760
      ]
    },
    {
      "id": "6ff1cf54-5406-4c86-a77e-8424208d4728",
      "name": "Set new session",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        960,
        -760
      ]
    },
    {
      "id": "be9c755a-0c52-453c-b448-98975d4c6e87",
      "name": "Session activated",
      "type": "n8n-nodes-base.telegram",
      "position": [
        1240,
        -760
      ]
    },
    {
      "id": "31478ec5-c1de-43db-ac9d-9b34f68e951c",
      "name": "Send response",
      "type": "n8n-nodes-base.telegram",
      "position": [
        1100,
        980
      ]
    },
    {
      "id": "be35b9a6-2914-409f-bc9c-6199ccb9e4ed",
      "name": "Update database",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1420,
        980
      ]
    },
    {
      "id": "dacc79e0-56ff-47d6-b09f-16ebfb31cbfa",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -540,
        -540
      ],
      "parameters": {
        "width": 620,
        "height": 360,
        "content": "# Telegram ChatBot with multiple sessions\n\nThis workflow creates an **AI-powered Telegram chatbot** with **session management**, allowing users to:  \n- **Start new conversations** (`/new`).  \n- **Chec"
      }
    },
    {
      "id": "55751f99-ee2e-429b-99cd-fef30eb56fb8",
      "name": "Summarization Chain",
      "type": "@n8n/n8n-nodes-langchain.chainSummarization",
      "position": [
        1040,
        200
      ]
    },
    {
      "id": "c7f0d136-4a77-4bc8-b2ef-b03fa41ad1ff",
      "name": "OpenAI Chat Model1",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        1020,
        380
      ]
    },
    {
      "id": "a455cf00-2f72-4377-ac2a-d65ab8c30e31",
      "name": "OpenAI Chat Model2",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        1660,
        800
      ]
    },
    {
      "id": "e55082e4-4e65-4fbb-8850-d3b64093eab6",
      "name": "Basic LLM Chain",
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "position": [
        1680,
        600
      ]
    },
    {
      "id": "1e670eaa-fd9f-4e79-b2a8-bd43240455db",
      "name": "Get message1",
      "type": "n8n-nodes-base.set",
      "position": [
        600,
        -100
      ]
    },
    {
      "id": "65771b1e-47fc-439d-a1ea-9901bac047d8",
      "name": "Set to expire",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1040,
        -100
      ]
    },
    {
      "id": "d18268f6-8792-4a66-aa32-35b596e7fcad",
      "name": "Exist?",
      "type": "n8n-nodes-base.if",
      "position": [
        1540,
        -100
      ]
    },
    {
      "id": "6eeb7e4d-8af0-4d71-981d-66a39f4870a3",
      "name": "OK",
      "type": "n8n-nodes-base.telegram",
      "position": [
        1880,
        -40
      ]
    },
    {
      "id": "1a6b9065-154f-4c43-9406-110636884f3d",
      "name": "KO",
      "type": "n8n-nodes-base.telegram",
      "position": [
        1880,
        -200
      ]
    },
    {
      "id": "a2463ecc-fc82-401d-bf1b-6104f4b379e6",
      "name": "Trim resume",
      "type": "n8n-nodes-base.code",
      "position": [
        820,
        -100
      ]
    },
    {
      "id": "c24a0c1d-290f-4e0c-8da9-98de14a65e2b",
      "name": "Get session1",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        600,
        200
      ]
    },
    {
      "id": "84cc4b12-ab2b-4509-a2e3-1c4d952904c5",
      "name": "Prompt + Resume",
      "type": "n8n-nodes-base.code",
      "position": [
        820,
        200
      ]
    },
    {
      "id": "3ae34388-95a0-41d7-8f20-7fa74817dab8",
      "name": "Send summary",
      "type": "n8n-nodes-base.telegram",
      "position": [
        1420,
        200
      ]
    },
    {
      "id": "d38eb058-29a3-4500-b6de-f700b8f501e9",
      "name": "Get message2",
      "type": "n8n-nodes-base.set",
      "position": [
        620,
        600
      ]
    },
    {
      "id": "ee6713b5-6264-43e8-86a4-f9584049f05b",
      "name": "Trim question",
      "type": "n8n-nodes-base.code",
      "position": [
        860,
        600
      ]
    },
    {
      "id": "65482069-1c41-4977-8f18-75f192866fdd",
      "name": "Set new current session",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1280,
        -100
      ]
    },
    {
      "id": "91ef2595-acca-4efd-8331-3450fa466d33",
      "name": "Response + Text",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1140,
        600
      ]
    },
    {
      "id": "2fbaf240-c01e-48dc-90bf-cc655eb7cd4d",
      "name": "fullText",
      "type": "n8n-nodes-base.code",
      "position": [
        1440,
        600
      ]
    },
    {
      "id": "30e29b4f-da86-4cee-b875-7985b5d82b7e",
      "name": "Send answer",
      "type": "n8n-nodes-base.telegram",
      "position": [
        2080,
        600
      ]
    },
    {
      "id": "41e2b5b3-25a2-411c-929a-ad4c22f45cd1",
      "name": "Send current session",
      "type": "n8n-nodes-base.telegram",
      "position": [
        620,
        -440
      ]
    },
    {
      "id": "e30bb12b-8e46-4fe4-81b7-72ce036d431f",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        640,
        -880
      ],
      "parameters": {
        "width": 580,
        "height": 80,
        "content": "## NEW SESSION\n"
      }
    },
    {
      "id": "7e23ee2d-b4ee-4be8-969b-c713039dacdf",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        620,
        -560
      ],
      "parameters": {
        "width": 580,
        "height": 80,
        "content": "## GET CURRENT SESSION\n"
      }
    },
    {
      "id": "5b10cf55-3730-4e0c-8db7-49c82e9b1350",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        600,
        -220
      ],
      "parameters": {
        "width": 580,
        "height": 80,
        "content": "## RESUME SESSION\n"
      }
    },
    {
      "id": "f0932a2c-ebf2-4179-972a-073e5edfa50d",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        600,
        100
      ],
      "parameters": {
        "width": 580,
        "height": 80,
        "content": "## GET SUMMARY\n"
      }
    },
    {
      "id": "9d9fdca4-870b-4ef4-9415-2fb750eb6466",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        620,
        500
      ],
      "parameters": {
        "width": 580,
        "height": 80,
        "content": "## SEND QUESTION\n"
      }
    },
    {
      "id": "aa55d92a-ec31-42c3-8b17-fa9d81d99c31",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        640,
        860
      ],
      "parameters": {
        "width": 580,
        "height": 80,
        "content": "## CHATBOT\n"
      }
    },
    {
      "id": "fa4dd49c-881b-41d2-84b4-82cbd3e62d0e",
      "name": "Telegram Chatbot",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        640,
        980
      ]
    }
  ],
  "connections": {
    "Exist?": {
      "main": [
        [
          {
            "node": "KO",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "OK",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "fullText": {
      "main": [
        [
          {
            "node": "Basic LLM Chain",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get message": {
      "main": [
        [
          {
            "node": "Get session",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get session": {
      "main": [
        [
          {
            "node": "Command or text?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Trim resume": {
      "main": [
        [
          {
            "node": "Set to expire",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get message1": {
      "main": [
        [
          {
            "node": "Trim resume",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get message2": {
      "main": [
        [
          {
            "node": "Trim question",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get session1": {
      "main": [
        [
          {
            "node": "Prompt + Resume",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send response": {
      "main": [
        [
          {
            "node": "Update database",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set to expire": {
      "main": [
        [
          {
            "node": "Set new current session",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Simple Memory": {
      "ai_memory": [
        [
          {
            "node": "Telegram Chatbot",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Trim question": {
      "main": [
        [
          {
            "node": "Response + Text",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Basic LLM Chain": {
      "main": [
        [
          {
            "node": "Send answer",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prompt + Resume": {
      "main": [
        [
          {
            "node": "Summarization Chain",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Response + Text": {
      "main": [
        [
          {
            "node": "fullText",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set new session": {
      "main": [
        [
          {
            "node": "Session activated",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Command or text?": {
      "main": [
        [
          {
            "node": "Disable previous session",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Send current session",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Get message1",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Get session1",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Get message2",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Telegram Chatbot",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Telegram Chatbot": {
      "main": [
        [
          {
            "node": "Send response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Telegram Chatbot",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model1": {
      "ai_languageModel": [
        [
          {
            "node": "Summarization Chain",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model2": {
      "ai_languageModel": [
        [
          {
            "node": "Basic LLM Chain",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Summarization Chain": {
      "main": [
        [
          {
            "node": "Send summary",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set new current session": {
      "main": [
        [
          {
            "node": "Exist?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Disable previous session": {
      "main": [
        [
          {
            "node": "Set new session",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}