{
  "name": "Telegram AI Agent",
  "nodes": [
    {
      "parameters": {
        "updates": [
          "message"
        ]
      },
      "id": "1",
      "name": "Telegram Trigger",
      "type": "n8n-nodes-base.telegramTrigger",
      "typeVersion": 1,
      "position": [
        200,
        300
      ],
      "credentials": {
        "telegramApi": {
          "id": "1",
          "name": "Telegram"
        }
      }
    },
    {
      "parameters": {
        "mode": "rules",
        "rules": {
          "values": [
            {
              "outputKey": "voice",
              "conditions": {
                "combinator": "and",
                "conditions": [
                  {
                    "operator": {
                      "type": "exists"
                    },
                    "leftValue": "={{ $json.message.voice }}"
                  }
                ]
              }
            },
            {
              "outputKey": "text",
              "conditions": {
                "combinator": "and",
                "conditions": [
                  {
                    "operator": {
                      "type": "exists"
                    },
                    "leftValue": "={{ $json.message.text }}"
                  }
                ]
              }
            }
          ]
        }
      },
      "id": "2",
      "name": "Switch",
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3,
      "position": [
        450,
        300
      ]
    },
    {
      "parameters": {
        "resource": "file",
        "fileId": "={{ $json.message.voice.file_id }}"
      },
      "id": "3",
      "name": "Download Voice",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1,
      "position": [
        700,
        180
      ],
      "credentials": {
        "telegramApi": {
          "id": "1",
          "name": "Telegram"
        }
      }
    },
    {
      "parameters": {
        "resource": "audio",
        "operation": "transcribe",
        "binaryPropertyName": "data"
      },
      "id": "4",
      "name": "Transcribe Audio",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "typeVersion": 1,
      "position": [
        950,
        180
      ],
      "credentials": {
        "openAiApi": {
          "id": "1",
          "name": "OpenAI"
        }
      }
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "name": "prompt",
              "value": "={{ $json.message.text }}",
              "type": "string"
            }
          ]
        }
      },
      "id": "5",
      "name": "Set Text",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3,
      "position": [
        700,
        420
      ]
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "={{ $json.prompt || $json.text }}"
      },
      "id": "6",
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 1.7,
      "position": [
        1250,
        300
      ]
    },
    {
      "parameters": {
        "model": "gpt-4o"
      },
      "id": "7",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1,
      "position": [
        1250,
        500
      ],
      "credentials": {
        "openAiApi": {
          "id": "1",
          "name": "OpenAI"
        }
      }
    },
    {
      "parameters": {
        "chatId": "={{ $json.message.chat.id }}",
        "text": "={{ $json.output }}"
      },
      "id": "8",
      "name": "Send Message",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1,
      "position": [
        1500,
        300
      ],
      "credentials": {
        "telegramApi": {
          "id": "1",
          "name": "Telegram"
        }
      }
    }
  ],
  "connections": {
    "Telegram Trigger": {
      "main": [
        [
          {
            "node": "Switch",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Switch": {
      "main": [
        [
          {
            "node": "Download Voice",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Set Text",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download Voice": {
      "main": [
        [
          {
            "node": "Transcribe Audio",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Transcribe Audio": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Text": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent": {
      "main": [
        [
          {
            "node": "Send Message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {},
  "versionId": "1"
}