{
  "name": "Allow users to send a sequence of messages to an AI agent in Telegram",
  "nodes": [
    {
      "id": "a3cc74e9-c696-48de-a04e-d48555641897",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1640,
        -800
      ],
      "parameters": {
        "width": 220,
        "height": 280,
        "content": "## 1. Receive Message\n\n"
      }
    },
    {
      "id": "ff18667d-0a31-4768-acf8-ed0d53b2f382",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        160,
        -840
      ],
      "parameters": {
        "width": 600,
        "height": 520,
        "content": "## 3. AI Assistant\n"
      }
    },
    {
      "id": "ce90f954-19b6-4224-ae88-b20c4da639e6",
      "name": "Reply",
      "type": "n8n-nodes-base.telegram",
      "position": [
        920,
        -700
      ]
    },
    {
      "id": "6f46d89b-034c-47ea-a217-8d007bec1531",
      "name": "Receive Message",
      "type": "n8n-nodes-base.telegramTrigger",
      "position": [
        -1580,
        -680
      ]
    },
    {
      "id": "0f391daa-0e74-4058-8923-52f3c050c9ad",
      "name": "Wait 10 Seconds",
      "type": "n8n-nodes-base.wait",
      "position": [
        -1000,
        -580
      ]
    },
    {
      "id": "8e6495d8-db6e-4692-ade5-45239049de34",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1320,
        -760
      ],
      "parameters": {
        "width": 1400,
        "height": 440,
        "content": "## 2. Buffer Incoming Messages"
      }
    },
    {
      "id": "d4876fd2-2e0b-4f82-9dc3-553f926310bd",
      "name": "Add to Queued Messages",
      "type": "n8n-nodes-base.supabase",
      "position": [
        -1240,
        -680
      ]
    },
    {
      "id": "a2eeb77f-2d74-44ac-9812-c3659d2e2803",
      "name": "No Operation, do nothing",
      "type": "n8n-nodes-base.noOp",
      "position": [
        -340,
        -460
      ]
    },
    {
      "id": "638fc82e-aba1-4deb-b506-33dcf4746896",
      "name": "Aggregate",
      "type": "n8n-nodes-base.aggregate",
      "position": [
        220,
        -700
      ]
    },
    {
      "id": "772f60e5-e52f-4779-aa03-e4d532ee4b5c",
      "name": "Delete Queued Messages",
      "type": "n8n-nodes-base.supabase",
      "position": [
        -100,
        -700
      ]
    },
    {
      "id": "16b46a70-85a0-4c8c-94ba-172ebe9aafa4",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        860,
        -780
      ],
      "parameters": {
        "width": 280,
        "height": 260,
        "content": "## 4. Send Reply\n\n\n"
      }
    },
    {
      "id": "9162f110-465f-4cd6-9f03-17751d7e43a4",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        380,
        -460
      ]
    },
    {
      "id": "b47ef0c9-725b-4837-b9e9-96a4ff2b3636",
      "name": "Sort by Message ID",
      "type": "n8n-nodes-base.sort",
      "position": [
        -580,
        -680
      ]
    },
    {
      "id": "1aa80c99-eec8-4174-bcf3-c6873354ed0f",
      "name": "Get Queued Messages",
      "type": "n8n-nodes-base.supabase",
      "position": [
        -780,
        -680
      ]
    },
    {
      "id": "85050328-b5aa-47fe-802c-7d9f31f225cb",
      "name": "Check Most Recent Message",
      "type": "n8n-nodes-base.if",
      "position": [
        -360,
        -680
      ]
    },
    {
      "id": "bed86d81-bb57-42ce-aaa7-4bdc21e1651c",
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        420,
        -700
      ]
    },
    {
      "id": "4f468a14-fbea-44ec-a2b8-e4b3785c0362",
      "name": "Postgres Chat Memory",
      "type": "@n8n/n8n-nodes-langchain.memoryPostgresChat",
      "position": [
        560,
        -460
      ]
    },
    {
      "id": "610516e8-d4ad-448e-ac97-17aad1a31862",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2420,
        -820
      ],
      "parameters": {
        "width": 700,
        "height": 420,
        "content": "## Allow Users to Send a Sequence of Messages to an AI Agent in Telegram with Supabase\n### Use Case\nWhen creating chatbots that interface through applications such as **Telegram** and **WhatsApp**, us"
      }
    },
    {
      "id": "c8bd8777-fb0f-4941-8674-f5bb7c264506",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1640,
        -1060
      ],
      "parameters": {
        "width": 520,
        "height": 220,
        "content": "### Setup\n1. Create a table in Supabase called **message_queue**. It needs to have the following columns: **user_id** (`uint8`), **message** (`text`), and **message_id** (`uint8`)\n2. Add your **Telegr"
      }
    },
    {
      "id": "24604fc7-7957-4e20-8303-b31f2ce1e257",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1060,
        -700
      ],
      "parameters": {
        "width": 220,
        "height": 280,
        "content": "### Modification\nChange the value of *Wait Amount* to vary the buffering window"
      }
    },
    {
      "id": "24f388f3-5655-4bd4-9c30-978efb2dc400",
      "name": "Sticky Note8",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        180,
        -480
      ],
      "parameters": {
        "width": 340,
        "height": 140,
        "content": "### Modification\nReplace this sub-node \nto use a different language\n model"
      }
    },
    {
      "id": "3db12526-6b97-4e3a-b53d-987f5d20c46e",
      "name": "Sticky Note9",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        380,
        -800
      ],
      "parameters": {
        "width": 340,
        "height": 240,
        "content": "### Modification\nAdd a **System Message** to tailor the chatbot to your use case"
      }
    }
  ],
  "connections": {
    "AI Agent": {
      "main": [
        [
          {
            "node": "Reply",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Aggregate": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Receive Message": {
      "main": [
        [
          {
            "node": "Add to Queued Messages",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait 10 Seconds": {
      "main": [
        [
          {
            "node": "Get Queued Messages",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Sort by Message ID": {
      "main": [
        [
          {
            "node": "Check Most Recent Message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Queued Messages": {
      "main": [
        [
          {
            "node": "Sort by Message ID",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Postgres Chat Memory": {
      "ai_memory": [
        [
          {
            "node": "AI Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Add to Queued Messages": {
      "main": [
        [
          {
            "node": "Wait 10 Seconds",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Delete Queued Messages": {
      "main": [
        [
          {
            "node": "Aggregate",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Most Recent Message": {
      "main": [
        [
          {
            "node": "Delete Queued Messages",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "No Operation, do nothing",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}