{
  "name": "Telegram GPT Assistant",
  "nodes": [
    {
      "parameters": {
        "updates": ["message"],
        "additionalFields": {}
      },
      "id": "tga00001-0001-4000-8000-000000000001",
      "name": "Telegram Message Trigger",
      "type": "n8n-nodes-base.telegramTrigger",
      "typeVersion": 1,
      "position": [240, 300]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "field1",
              "name": "userMessage",
              "value": "={{ $json.message.text }}",
              "type": "string"
            },
            {
              "id": "field2",
              "name": "chatId",
              "value": "={{ $json.message.chat.id }}",
              "type": "string"
            },
            {
              "id": "field3",
              "name": "userName",
              "value": "={{ $json.message.from.first_name }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "tga00001-0002-4000-8000-000000000002",
      "name": "Extract Message",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3,
      "position": [460, 300]
    },
    {
      "parameters": {
        "model": "gpt-4o-mini",
        "messages": {
          "values": [
            {
              "role": "system",
              "content": "You are a friendly and knowledgeable AI assistant in a Telegram chat. Provide helpful, concise answers. If unsure, say so honestly."
            },
            {
              "role": "user",
              "content": "={{ $json.userMessage }}"
            }
          ]
        },
        "options": {
          "temperature": 0.8,
          "maxTokens": 300
        }
      },
      "id": "tga00001-0003-4000-8000-000000000003",
      "name": "Generate GPT Reply",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "typeVersion": 1,
      "position": [680, 300]
    },
    {
      "parameters": {
        "chatId": "={{ $('Extract Message').item.json.chatId }}",
        "text": "={{ $json.message.content }}",
        "additionalFields": {
          "parse_mode": "Markdown"
        }
      },
      "id": "tga00001-0004-4000-8000-000000000004",
      "name": "Send Reply to Telegram",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1,
      "position": [900, 300]
    }
  ],
  "connections": {
    "Telegram Message Trigger": {
      "main": [[{ "node": "Extract Message", "type": "main", "index": 0 }]]
    },
    "Extract Message": {
      "main": [[{ "node": "Generate GPT Reply", "type": "main", "index": 0 }]]
    },
    "Generate GPT Reply": {
      "main": [[{ "node": "Send Reply to Telegram", "type": "main", "index": 0 }]]
    }
  },
  "active": false,
  "settings": { "executionOrder": "v1" },
  "meta": {},
  "pinData": {}
}
