n8n recipe · ai

Telegram → AI Agent → Telegram

An AI Agent answers each Telegram message, looking things up in Google Sheets when it needs to, and replies on Telegram.

텔레그램에 메시지가 오면 AI 에이전트가 필요할 때 구글 시트를 찾아보고 답을 텔레그램으로 보내요.

Steps

  1. When when a telegram message comes in — Telegram node
  2. Then answer it using google sheets as a tool — AI Agent node · may use: Google Sheets
  3. Then reply on telegram — Telegram node

Fields to fill (5)

The file has every node wired up. These are the blanks only you can fill (your form, your sheet, your words).

NodeWhat to do
Telegramfill chatId (Unique identifier for the target chat or username, To fin...)
Telegramfill text (Text of the message to be sent) — the AI step's output: run that node once in n8n and pick its output field
OpenAI Chat Modelcheck model: OpenAI Chat Model chosen by default (most used) — swap for Gemini, Anthropic, Ollama … if you like
OpenAI Chat Modelfill model (The model)
Google Sheets toolpick workflowId: a small workflow that does the Google Sheets part (Execute Workflow Trigger → the Google Sheets action(s) the agent may take); the node list we read (n8n 2.43.2) has no Google Sheets tool node to plug in directly

Accounts to connect (4)

In n8n, pick or add a credential on each node — one of the types below.

Get the n8n file

Download telegram-agent-answers-from-sheets.json

  1. Open a new, empty workflow in n8n.
  2. Open the workflow menu (⋯) and choose Import from File — or copy the JSON below and paste it onto the canvas (Ctrl/Cmd+V).
  3. Connect the accounts, fill the fields above, run one test, then turn the workflow on.
Or copy the JSON
{
  "name": "An AI Agent answers each Telegram message",
  "nodes": [
    {
      "id": "n1",
      "name": "Telegram Trigger",
      "type": "n8n-nodes-base.telegramTrigger",
      "typeVersion": 1.5,
      "parameters": {
        "updates": [
          "message"
        ]
      },
      "position": [
        240,
        300
      ],
      "notes": "step: when a telegram message comes in"
    },
    {
      "id": "n2",
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 3.1,
      "parameters": {
        "promptType": "define",
        "text": "=Answer it:\n\n{{ JSON.stringify($json) }}"
      },
      "position": [
        460,
        300
      ],
      "notes": "step: answer it using google sheets as a tool"
    },
    {
      "id": "n3",
      "name": "Telegram",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "parameters": {
        "resource": "message",
        "operation": "sendMessage",
        "chatId": "",
        "text": ""
      },
      "position": [
        680,
        300
      ],
      "notes": "step: reply on telegram"
    },
    {
      "id": "n4",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.3,
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": ""
        }
      },
      "position": [
        460,
        500
      ]
    },
    {
      "id": "n5",
      "name": "Google Sheets tool",
      "type": "@n8n/n8n-nodes-langchain.toolWorkflow",
      "typeVersion": 2.2,
      "parameters": {
        "description": "Call this to use Google Sheets.",
        "workflowId": {
          "__rl": true,
          "mode": "list",
          "value": ""
        }
      },
      "position": [
        640,
        500
      ]
    }
  ],
  "connections": {
    "Telegram Trigger": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent": {
      "main": [
        [
          {
            "node": "Telegram",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Google Sheets tool": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "active": false
}