What we're building
Our bot isn't just a script with buttons. It's an AI agent that understands natural language, has access to your store's knowledge base, and can perform concrete actions: check order status, recommend a product, answer a FAQ.
Here's the architecture of what we're about to build:
Trigger
Commands
Tools
Sheets FAQ
Buffer
Reply
Components:
- Telegram Trigger — listens for every incoming message
- Switch — routes commands (/help, /status, /order) and regular messages
- AI Agent (Tools Agent) — the bot's brain, wired to OpenAI or Claude
- Google Sheets Tool — knowledge base: FAQ, product catalog, order status
- Memory Buffer — conversation memory (the bot remembers context)
- Telegram Send Message — sends the reply back to the customer
n8n (self-hosted or cloud), a Telegram account, an OpenAI API key (or Claude API key), and a Google account for Sheets. If you don't have n8n yet — head over to our VPS install guide.
Create the bot via BotFather
BotFather is Telegram's official bot for creating other bots. Open Telegram, find @BotFather, and walk through these steps:
- Send
/newbot - Enter the bot's name (what customers see), e.g. My Store Support
- Enter the bot's username (must end in "bot"), e.g. mystore_support_bot
- BotFather will give you an API Token — a long string like
7123456789:AAHdqTcv.... Save it — you'll need it in n8n
Optional but recommended — configure the bot via more BotFather commands:
# Add a bot description
/setdescription
→ Store AI assistant. Answering your questions 24/7 🤖
# Add an avatar
/setuserpic
→ [upload your store logo]
# Set the command list
/setcommands
→ help - What I can do
status - Check order status
order - Place an order
catalog - Browse the catalog
Connect the Telegram Trigger in n8n
Open n8n and create a new workflow (call it something like "Telegram AI Bot"). Then:
- Add the first node: search for "Telegram Trigger" and pick the trigger "On Message". This means the workflow fires on every incoming message
- In the "Credential to connect with" field, click "Create New" → paste your API Token from BotFather → save
- Under "Updates", select "message" — the bot will react to text messages
Once you save the Telegram Trigger, n8n automatically registers a webhook with the Telegram API. If you see a green check — the connection is live. If you get an error — verify that your n8n is reachable over HTTPS (Telegram requires SSL for webhooks).
Now every message sent to your bot will hand n8n a payload. Here's an example of the JSON output from Telegram Trigger:
{
"message": {
"text": "Hi, where's my order #4821?",
"chat": {
"id": 123456789,
"first_name": "Olena"
},
"from": {
"id": 123456789,
"username": "olena_ua"
}
}
}
AI Agent — the bot's brain
The AI Agent is your bot's "brain". In n8n it's a dedicated node that connects to an LLM (GPT-4o, Claude, Gemini) and has access to "tools" — Google Sheets, HTTP Request, Calculator, and so on.
Add an "AI Agent" node after the Telegram Trigger. In the "Agent Type" field, pick "Tools Agent" — this type is purpose-built for agents that call external tools.
Next, wire up a language model — click the "Model" input and add one of these nodes:
| Model | n8n node | Price | When to pick it |
|---|---|---|---|
| GPT-4o-mini | OpenAI Chat Model | $0.15/1M input | Best price/quality ratio |
| GPT-4o | OpenAI Chat Model | $2.50/1M input | Complex tasks, heavier reasoning |
| Claude 3.5 Sonnet | Anthropic Chat Model | $3/1M input | Long context, follows instructions well |
| Gemini Flash | Google Gemini Chat Model | Free (with limits) | Testing, minimal budget |
Now configure the System Prompt — this is the instruction set that shapes how the bot behaves:
You are an AI assistant for [STORE NAME] online store.
RULES:
- Reply in English
- Be polite, concise, and helpful
- Use the Google Sheets Tool to find answers to FAQ questions
- If you don't know an answer — say so honestly and offer
to connect the customer with a manager
- Never invent information about products or prices
- To check order status, ask for the order number
TONE:
Friendly but professional. Use emoji sparingly.
Write in short sentences. Max 3-4 sentences per reply.
ESCALATION:
If the customer is unhappy, wants a return, or asks something
complex — reply: "Connecting you with a manager 🙏"
and append the tag [ESCALATE] at the end of your reply.
Next, wire up the Memory Buffer — click the "Memory" input and add a "Window Buffer Memory" node. In the Session Key field, paste {{ $json.message.chat.id }} — this gives the bot separate memory per user.
Without the correct Session Key, the bot will mix conversations between different users. Using the Telegram Chat ID guarantees each customer gets their own isolated conversation history.
Knowledge base via Google Sheets
Google Sheets is the simplest way to build a knowledge base for your bot. Create a spreadsheet with two sheets.
Sheet 1: FAQ
| Question | Answer | Category |
|---|---|---|
| How do I place an order? | Add the item to your cart on the website and check out. Or send us the product number. | Orders |
| What are the shipping options? | Nova Poshta (1-2 days), Ukrposhta (3-5 days), pickup from Kyiv. | Shipping |
| How do I return an item? | Within 14 days of receipt. Contact a manager. | Returns |
| What payment methods do you accept? | Card online (Visa/MC), LiqPay, cash on delivery. | Payment |
Sheet 2: Orders
| order_id | customer_name | status | tracking | total |
|---|---|---|---|---|
| #4821 | Olena K. | Shipped | 20450012345678 | 1,250 ₴ |
| #4822 | Andriy M. | Processing | — | 890 ₴ |
Now connect Google Sheets as a Tool for the AI Agent. Click the "Tools" input on the AI Agent node → add "Google Sheets Tool" → authenticate with your Google account via OAuth2.
In the Tool description, write the following (this matters — the AI Agent uses this description to decide when to invoke the tool):
Name: FAQ_and_Orders
Description: Use this tool for:
1) Looking up answers to customer questions (FAQ)
2) Checking order status by order_id
The spreadsheet has two sheets: "FAQ" and "Orders".
Now when a customer asks "Where's my order #4821?", the AI Agent automatically calls the Google Sheets Tool, finds the row where order_id = #4821, and replies: "Your order #4821 has shipped! Nova Poshta tracking number: 20450012345678 📦".
Commands /help, /status, /order
Commands give customers quick access to common actions without having to type out a full message. We'll implement this with a Switch node placed between Telegram Trigger and AI Agent.
Add a "Switch" node between Telegram Trigger and AI Agent. Then configure the rules:
Rule 1: {{ $json.message.text }} starts with "/help"
→ Output 1 (Help response)
Rule 2: {{ $json.message.text }} starts with "/status"
→ Output 2 (Status check)
Rule 3: {{ $json.message.text }} starts with "/order"
→ Output 3 (New order flow)
Rule 4: {{ $json.message.text }} starts with "/start"
→ Output 4 (Welcome message)
Default:
→ AI Agent (handles everything else)
For each output, add a Telegram Send Message node with the matching copy. Here's an example — the /start welcome message:
Hi, {{ $json.message.from.first_name }}! 👋
I'm the AI assistant for [STORE NAME]. Here's what I can do:
📋 /help — What I can do
📦 /status — Check your order
🛒 /order — Place an order
Or just ask me anything — I'll answer! 🤖
And here's the /status prompt asking for the order number:
📦 To check your status, send me your order number.
For example: #4821
I'll find it and show you the current status and tracking number.
Escalating to a human
No bot should pretend to know everything. Let's add escalation to a live manager:
- After the AI Agent, add an "IF" node that checks whether the reply contains the
[ESCALATE]tag - If TRUE — in parallel, send the customer a message ("Connecting you with a manager. Please expect a reply within 5 minutes 🙏"), send the manager a notification in a separate chat with the full conversation context, the customer's name, and username, and log the escalation to Google Sheets (date, customer, reason)
- If FALSE — send the AI Agent's reply straight to the customer via Telegram Send Message
Create a dedicated Telegram group called "Bot Escalations" and add your managers to it. When the bot can't answer — the message with full context lands in that group. A manager sees the entire conversation history and can reply to the customer directly.
Test and ship to production
Before launch, test every scenario:
- /start — bot greets and shows the command menu
- /help — bot explains what it can do
- /status — bot asks for the order number, then finds it in Google Sheets
- "What are the shipping options?" — bot finds the answer in the FAQ
- "I want a refund" — bot escalates to a manager
- An unknown question — bot honestly says it doesn't know and offers to connect with a manager
- Conversation context — ask a follow-up question to verify the bot remembers the previous exchange
If everything works — click "Active" in the top-right corner of the workflow. The bot is now running 24/7.
The most frequent problems: the webhook won't register (n8n isn't reachable over HTTPS), the AI Agent returns an error (check your API key), Google Sheets can't find data (check the column names). Every error is visible in the "Executions" tab in n8n.
What to add next
Voice messages
Add voice message handling: Telegram Trigger (voice) → download the audio → OpenAI Whisper (transcription) → AI Agent. Customer sends a voice note — the bot understands it and replies in text.
Photo processing
Customer sends a product photo → GPT-4o Vision analyzes the image → AI Agent responds. Useful for support: "My item arrived damaged" + photo.
Accepting payments
Telegram supports built-in payments. Add a Telegram Send Invoice node to accept payment right in the chat. For international payments, Stripe integrates natively; for Ukrainian stores, use LiqPay as the payment provider.
Multilingual support
Add this to your System Prompt: "Detect the customer's language and reply in the same language." The AI Agent will automatically switch between English, Ukrainian, Spanish, or whatever the customer writes in.
Other channels
The same AI Agent workflow runs on WhatsApp (via Twilio or the Meta API), Viber, Facebook Messenger, and even a website widget (via n8n Chat Trigger). All you swap is the Telegram Trigger for the corresponding trigger of another channel — the entire AI logic stays identical.
| Channel | n8n trigger | Difficulty |
|---|---|---|
| Telegram | Telegram Trigger | Easy |
| Twilio Trigger / Meta Webhook | Medium | |
| Viber | Webhook (Viber API) | Medium |
| Website | n8n Chat Trigger | Easy |
| Facebook Messenger Trigger | Medium |
Frequently asked questions
How much does a Telegram bot on n8n cost?
Self-hosted n8n is free. OpenAI API (GPT-4o-mini) — from $0.15/1M tokens, which averages $2–10/mo for a small store. Google Sheets is free. VPS runs about $5/mo. Total: from $7/mo for a full-featured AI bot running 24/7.
How many messages can the bot handle?
On a VPS with 2 vCPU / 4 GB RAM — 1000+ messages per day with no trouble. n8n processes each message as a separate execution. The real bottleneck is the LLM provider's API rate limits, but for a small business this is more than enough.
Can I use a real database instead of Google Sheets?
Yes. n8n supports PostgreSQL, MySQL, MongoDB, Airtable, Supabase, and more. For a small store, Google Sheets is an ideal start (simple, free, transparent). For scaling — migrate to PostgreSQL or Airtable.
How does the bot handle spam or nonsense messages?
An AI Agent with the right System Prompt politely handles nonsense: "Sorry, I didn't quite catch that. Try /help for a list of commands." For spam protection, add rate limiting via an IF node (max 10 messages per minute from one user).
How do I update the knowledge base?
Just edit Google Sheets — changes are picked up automatically on the next request. Added a new product — the bot already knows about it. Changed shipping terms — the bot answers with the new info. No restart, no deploy.