{
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "368c3442-b61b-4e35-9de0-f7ef3f52aa0f",
      "name": "\ud83d\udce9 Receive Telegram Message",
      "type": "n8n-nodes-base.telegramTrigger",
      "position": [
        1072,
        1968
      ],
      "parameters": {
        "updates": [
          "message"
        ],
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "fe8f2304-f2f6-45d5-8f26-3e07f59f2122",
      "name": "Sticky Note \u2014 Overview",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1168,
        304
      ],
      "parameters": {
        "color": 5,
        "width": 560,
        "height": 496,
        "content": "# \ud83d\udcac AI Chat Bot \u2014 Telegram + AIMLAPI (via n8n)\n\nThis workflow lets users chat with **GPT-5** directly in Telegram. Messages are processed and answered in real-time via **AIMLAPI**.\n\n---\n\n## \ud83d\ude80 Features\n\n* Chat with GPT-5 using natural language\n* Context-aware conversation\n* Telegram delivery of responses\n* Easy to extend with logging or moderation"
      },
      "typeVersion": 1
    },
    {
      "id": "1d3c2472-92fe-4d4e-b157-81de61882d0b",
      "name": "Sticky Note \u2014 Customization",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1168,
        816
      ],
      "parameters": {
        "color": 5,
        "width": 560,
        "height": 560,
        "content": "## \u2699\ufe0f Customization\n\n* Change the `model` parameter to use other AI models (Claude, Gemini, etc.)\n* Add:\n  * Message logging to Google Sheets or DB\n  * NSFW filtering\n  * Command handling (`/help`, `/reset`)\n\n---\n\n## \ud83d\udca1 Example User Flow\n\n1. User sends:\n   ```\n   What's the capital of Japan?\n   ```\n2. Bot replies:\n   > The capital of Japan is Tokyo.\n\n3. Chat continues naturally with context preserved"
      },
      "typeVersion": 1
    },
    {
      "id": "fc3443dd-7c1d-478f-846b-e20b2d480898",
      "name": "Sticky Note \u2014 Setup Guide",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1744,
        448
      ],
      "parameters": {
        "color": 5,
        "width": 560,
        "height": 544,
        "content": "# \ud83d\udee0 Setup Guide\n\n### 1. \ud83d\udcf2 Create a Telegram Bot\n* Go to [@BotFather](https://t.me/BotFather)\n* Use `/newbot`, set a name and username\n* Save the **API token**\n\n---\n### 2. \ud83d\udd10 Connect Telegram API in n8n\n* Go to `Credentials > Telegram API`\n* Create new credentials using the token from BotFather\n\n---\n### 3. \ud83d\udd0c Set Up AIMLAPI Credentials in n8n\n* Go to `Credentials > AI/ML API`\n* Enter your **API key**\n* Base URL: `https://api.aimlapi.com/v1`\n* Docs: [docs.aimlapi.com](https://docs.aimlapi.com)"
      },
      "typeVersion": 1
    },
    {
      "id": "cdd88b85-4766-4e2c-9e5f-7b409963c443",
      "name": "Sticky Note \u2014 Logging & Testing",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1744,
        1008
      ],
      "parameters": {
        "color": 5,
        "width": 560,
        "height": 432,
        "content": "## \ud83d\udcc1 Optional Data Logging\n\nYou can log every chat message to Google Sheets or a database for analytics:\n\n` | user_id | date | message | response | `\n` | ------- | ---- | ------- | -------- | `\n\n---\n## \ud83e\uddea Testing Tips\n\n* Use a test Telegram chat before production\n* Add `Console` or `Set` nodes to inspect payloads\n* For realistic tests, run via `/execute` from Telegram, **not** \"Execute Node\""
      },
      "typeVersion": 1
    },
    {
      "id": "f6b40a2d-c83a-47aa-9046-23cdc601ef73",
      "name": "\ud83d\udcdd Log Successful Generation",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        2784,
        1968
      ],
      "parameters": {
        "columns": {
          "value": {
            "date": "={{ new Date().toISOString().split('T')[0] }}",
            "query": "={{ $('\ud83d\udce9 Receive Telegram Message').item.json.message.text }}",
            "result": "={{ $('\ud83e\udde0 Process with GPT\u20115').item.json.content }}",
            "user_id": "={{ $json.result.from.id }}"
          },
          "schema": [
            {
              "id": "user_id",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "user_id",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "date",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "date",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "query",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "query",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "result",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "result",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "append",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 2060422727,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/19rsFwln4KMpGjOzxOdz7OC_-kRH8_qD4Agx5lXlDD9k/edit#gid=2060422727",
          "cachedResultName": "Sheet1"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "19rsFwln4KMpGjOzxOdz7OC_-kRH8_qD4Agx5lXlDD9k",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/19rsFwln4KMpGjOzxOdz7OC_-kRH8_qD4Agx5lXlDD9k/edit?usp=drivesdk",
          "cachedResultName": "AI bot usage statistic"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.6
    },
    {
      "id": "a00ee4eb-0c89-48a2-87c1-000197b71a55",
      "name": "Sticky Note \u2014 Receive Message",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        944,
        1552
      ],
      "parameters": {
        "color": 3,
        "width": 384,
        "height": 608,
        "content": "# \ud83d\udce5 Step 1 \u2014 Receive Telegram Message\nListens for new messages sent to your Telegram bot.\n\nCaptures:\n* **chat.id** \u2014 used for sending responses back\n* **message.text** \u2014 the text provided by the user\n\n\ud83d\udca1 You can restrict to specific commands/keywords if needed."
      },
      "typeVersion": 1
    },
    {
      "id": "375019d6-a2c0-438c-950c-376603599dc5",
      "name": "Sticky Note \u2014 GPT\u20115 Processing",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1744,
        1552
      ],
      "parameters": {
        "width": 384,
        "height": 608,
        "content": "# \ud83e\udde0 Step 2 \u2014 Process with GPT\u20115\nSends the raw Telegram message text to **AI/ML API** using `openai/gpt-5-chat-latest`.\n\nPurpose:\n* Improve or expand the input text\n* Make it more descriptive/structured as needed\n\n\u2699\ufe0f Configurable:\n* Change the model ID\n* Add system instructions to control style, tone, or length"
      },
      "typeVersion": 1
    },
    {
      "id": "e58d2186-f12e-43a4-9b7c-a644d27e64fa",
      "name": "Sticky Note \u2014 Send Response",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2144,
        1552
      ],
      "parameters": {
        "color": 4,
        "width": 384,
        "height": 608,
        "content": "# \ud83d\udce4 Step 3 \u2014 Send Response to Telegram\nSends the model\u2019s response back to the same user.\n\nIncludes:\n* **chat_id** \u2014 from the original message\n* **text/caption** \u2014 the result returned by GPT\u20115\n\n\ud83d\udca1 You can format text, add emojis, or customize the reply style here."
      },
      "typeVersion": 1
    },
    {
      "id": "06a31bfb-15af-40fe-b468-057cf985180f",
      "name": "Sticky Note \u2014 Logging",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2640,
        1552
      ],
      "parameters": {
        "color": 5,
        "width": 384,
        "height": 608,
        "content": "# \ud83d\udcdd Step 4 \u2014 Log Interaction (Optional)\nAppends a row to your sheet/database with:\n* **date** \u2014 ISO date\n* **user_id** \u2014 from Telegram\n* **query** \u2014 original message text\n* **result** \u2014 model output (text or link, depending on your setup)\n\nUse this for:\n* Usage tracking & quotas\n* Analytics and QA"
      },
      "typeVersion": 1
    },
    {
      "id": "333a49e9-e553-4f95-87b9-d89548db6114",
      "name": "\ud83e\udde0 Process with GPT\u20115",
      "type": "n8n-nodes-aimlapi.aimlApi",
      "position": [
        1888,
        1968
      ],
      "parameters": {
        "model": "openai/gpt-5-chat-latest",
        "prompt": "={{ $('\ud83d\udce9 Receive Telegram Message').item.json.message.text }}",
        "options": {},
        "requestOptions": {}
      },
      "credentials": {
        "aimlApi": {
          "name": "<your credential>"
        }
      },
      "retryOnFail": false,
      "typeVersion": 1,
      "alwaysOutputData": false
    },
    {
      "id": "960ea33b-3c1a-4ad1-a330-18aab8bc030a",
      "name": "\ud83d\udce4 Send Response to Telegram",
      "type": "n8n-nodes-base.telegram",
      "position": [
        2288,
        1968
      ],
      "parameters": {
        "text": "={{ $json.content }}",
        "chatId": "={{ $('\ud83d\udce9 Receive Telegram Message').item.json.message.chat.id }}",
        "additionalFields": {
          "appendAttribution": false,
          "reply_to_message_id": "={{ $('\ud83d\udce9 Receive Telegram Message').item.json.message.message_id }}"
        }
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "7cc29371-2e04-440c-baea-4f7a716a5acf",
      "name": "Sticky Note \u2014 Receive Message1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1344,
        1552
      ],
      "parameters": {
        "color": 3,
        "width": 384,
        "height": 608,
        "content": "# \ud83d\udcac Step 1.5 \u2014 Simulate Typing in Telegram\n\n\nSends a \"typing\u2026\" chat action to the user in Telegram before delivering the actual \nresponse. \n\nThis creates a more natural conversational experience by letting the user know the bot is processing their message. \n\nUseful for longer AI processing times or when generating detailed responses."
      },
      "typeVersion": 1
    },
    {
      "id": "3e50eeda-e420-48fe-b136-1191d679f422",
      "name": "\ud83d\udcac Simulate Typing in Telegram",
      "type": "n8n-nodes-base.telegram",
      "position": [
        1488,
        1968
      ],
      "parameters": {
        "chatId": "={{ $json.message.chat.id }}",
        "operation": "sendChatAction"
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    }
  ],
  "connections": {
    "\ud83e\udde0 Process with GPT\u20115": {
      "main": [
        [
          {
            "node": "\ud83d\udce4 Send Response to Telegram",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "\ud83d\udce9 Receive Telegram Message": {
      "main": [
        [
          {
            "node": "\ud83d\udcac Simulate Typing in Telegram",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "\ud83d\udce4 Send Response to Telegram": {
      "main": [
        [
          {
            "node": "\ud83d\udcdd Log Successful Generation",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "\ud83d\udcac Simulate Typing in Telegram": {
      "main": [
        [
          {
            "node": "\ud83e\udde0 Process with GPT\u20115",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}