Lesson 9 / 12Module 3. Practical Projects
Academy/Vibe Coding/Lesson 9. Practical project: Creating a Telegram bot with AI
Intermediate20 minutes

Lesson 9. Practical project: Creating a Telegram bot with AI

Telegram is a primary messenger in many regions worldwide, boasting over 900 million users. A Telegram bot is your 24/7 assistant: it takes orders, answers questions, and provides information. In this lesson, you will build a fully functional bot using AI.

Topic breakdown

A Telegram bot is an automated program inside Telegram. Users communicate with the bot via messages, and the bot replies in a programmed way. Bots are used for: taking orders, booking appointments, giving info, and even accepting payments.

Bot creation process: 1) Getting a token via BotFather (inside Telegram), 2) Writing a Node.js program (with AI), 3) Adding bot logic (commands, buttons), 4) Running it on a server. All this takes 30-60 minutes with AI.

In this lesson we create a simple but useful bot: greeting on /start command, a menu with inline buttons, providing information, and replying to user messages. This is the foundation — you can adapt it to your needs later.

Technology: Node.js + telegraf library (the most popular Telegram bot framework). The AI knows this library excellently and writes clean code. You simply describe the bot's logic in natural language.

What you'll learn

  • Creating a new bot via BotFather and getting a token
  • Setting up a Node.js project and installing telegraf
  • Programming bot commands (/start, /help, /info)
  • Creating a menu using inline keyboard buttons
  • Logic for replying to user messages
  • Running the bot locally and on a server

Deep dive

The Telegram bot market: practically every business has or needs a Telegram bot. Delivery services, banks, state services — all operate via bots. You too can create a bot for your business or a client — it's real work with real income.

Bot architecture is simple: user sends a message -> Telegram server sends it to your server (webhook) or your program requests it from Telegram (polling) -> your program generates a response -> Telegram shows it to the user. This cycle takes 100ms-1s.

Inline keyboard vs Reply keyboard: Inline keyboards are buttons attached to the message (compact, stylish, trigger callbacks). Reply keyboards replace the typing area with large buttons (for quick access). Most bots use both: reply keyboard for main menu, inline keyboard for selections.

Deployment options: 1) Railway.app — free plan, Node.js support, automatic deployment from GitHub. 2) Render.com — free, but 'sleeps' after 15 mins of inactivity. 3) VPS (DigitalOcean, Kamatera) — $4-5/mo, full control. For beginners, Railway is easiest.

Ready prompt template

Copy and adapt
Create a Telegram bot. Node.js + telegraf@4. Bot functions: 1) /start — greeting message and main menu (inline keyboard), 2) Menu buttons: 'Services', 'Pricing', 'Contact', 3) When each button is clicked — output corresponding info, 4) /help — help message. Token is stored in a .env file. Use TypeScript.

Why it works

Technology: 'Node.js + telegraf@4' — specific library and version

Functionality: '/start, menu, buttons, /help' — bot actions clearly defined

Logic: 'when button clicked — info' — AI will create callback handlers

Security: 'Token in .env file' — secret key won't be exposed in code

Language: 'TypeScript' — for type safety

Practice

  • Go to @BotFather in Telegram, send the /newbot command and create a new bot
  • Copy the token provided by BotFather
  • Open a new folder in Cursor
  • In Agent mode (Cmd+I) enter the prompt above — Agent will create the files
  • In the .env file, add BOT_TOKEN=your_token_here
  • In the terminal: npm install -> npm run dev (or npx ts-node src/bot.ts)
  • Go to your bot in Telegram and send the /start command
  • In Chat, ask: 'Add one more button: Order — when clicked, ask for a phone number'

Common mistakes

  • Hardcoding the token directly in the code — always store it in .env, and add .env to .gitignore
  • Choosing the wrong bot name — the username must end in _bot (e.g., my_service_bot)
  • Not knowing the difference between webhook and polling — polling for local dev, webhook for servers
  • Failing to add error handling — without try/catch, the bot will crash on errors
  • Forgetting to keep the bot running — on free servers (Railway, Render) it needs to run continuously

Lesson FAQ

Can I create a Telegram bot completely for free?

Yes, completely free. BotFather is free, Node.js is free, and Railway has a free hosting tier. You get a working bot at no cost.

How many users can the bot serve concurrently?

A simple bot (polling) can easily handle 100-500 simultaneously. With webhooks — 10,000+. Massive bots require special architecture, but for standard business needs, this is perfectly sufficient.

Can the bot accept payments?

Yes, the Telegram Bot API supports payments. Integration with payment systems is possible. However, it's slightly more complex — master the basics first, then move to payments.

Next step

Creating a Telegram bot with AI: Practical Lesson | Prompter