Get Started

Build a Telegram bot powered by AI

Message your own AI from your phone, wherever you are. You'll build a Telegram bot in Python that answers with a model on your PC (free and private) or an API model, talks only to you, remembers each conversation, respects rate limits and keeps running on its own.

90 minIntermediateTools: Free with a local Ollama model. With an API model, about a tenth of a penny per message (gpt-5-mini). Running it 24/7 on a small VPS is optional, from $4 to $6 a month.Step 1 free
A working Telegram bot in Python (python-telegram-bot 22.8) that answers with Ollama on your PC or an API model, switched with one line in .env
A bot that only answers youit's locked to your Telegram user ID and gives strangers silence
Per-chat memory that survives restarts, with a /reset command to wipe it
  • Protection on both sides: Telegram's flood limits handled for you, plus your own cooldown and daily cap to protect your API bill
  • Two ways to keep it running: Task Scheduler on your Windows PC, or a small Linux VPS with systemd
  • A starter kit with an offline test that checks the whole bot with no token, no internet and no model
Before you start
  • Telegram on your phone (free). Creating a bot is free and needs no extra phone number.
  • uv, the Python tool from Put AI in your terminal. It fetches Python and the bot's libraries for you.
  • A brain, one of these. Local: Ollama 0.20.7 or newer with gemma4:e2b, from Run a ChatGPT-style AI on your own laptop. Free, and your PC has to be on. Or an API model: an account and prepaid credit with a provider. The example uses OpenAI's gpt-5-mini at $0.25 per million input tokens and $2 per million output tokens (OpenAI pricing ↗).
  • Optional, for 24/7 without your PC: a small Linux VPS. DigitalOcean's Basic Droplets start at $4 a month (512MiB RAM) or $6 a month (1GiB), billed per second and capped at the monthly price (DigitalOcean pricing ↗). Prices are in US dollars and change from time to time, so check the links. Oracle Cloud's Always Free tier is a no-cost alternative (step 7). Webhooks (also optional) need a domain too.
  • Comfort with the terminal: cd, running a command, reading an error. If that's new, do the Terminal survival kit first.
01/07Create your bot with BotFather0 done
STEP 01 of 07~10 min

Create your bot with BotFather

BotFather is Telegram's own bot for making bots. It gives you a token, and that token is the key to your bot.

  1. A Telegram bot is a special account that your program controls through the Bot API ↗. You don't log in as the bot. Instead, your code sends every request with a secret token, and Telegram treats whoever holds it as the bot.

  2. In Telegram, search for @BotFather (it has a blue verified tick, so ignore look-alikes) and send:

    Message to @BotFather
    /newbot
    • Name: what people see in the chat header, like Sam's AI. You can change it later.
    • Username: 5 to 32 characters, Latin letters, numbers and underscores only, and it must end in bot, like sams_pocket_ai_bot. You can't change it later.
  3. BotFather replies with a link to your bot and the token. A token is a number, a colon, then a long code. This is the example token from Telegram's own docs ↗:

    What a token looks like
    110201543:AAHdqTcvCH1vGWJxfSeofSAs0K5PALDsaw
  4. Keep the chat with BotFather open; you'll paste the token into a file in the next step. Now two settings that shrink what a stranger could do with your bot. First, stop anyone adding it to a group:

    Message to @BotFather
    /setjoingroups
  5. Pick your bot, then Disable. Second, give it a command menu, so / in the chat shows what it can do:

    Message to @BotFather
    /setcommands
  6. Pick your bot and send this as one message:

    Command list
    start - Say hello
    reset - Forget this conversation
    CarefulTreat the token like a password. Anyone who has it can read every message sent to your bot and reply as it. Never put it in code, a screenshot, a GitHub repo, a Discord message or a chat with an AI assistant. If it ever leaks, send /mybots to BotFather, pick your bot, tap API Token, then Revoke current token. The old token dies at once and BotFather gives you a new one to put in .env.
✓
CheckpointBotFather has given you a token, and the t.me/... link it sent opens a chat with your new bot.
If it breaksBotFather won't accept the username + 1 more
BotFather won't accept the username
It's taken, too short, or doesn't end in bot. Usernames are first come, first served, so add a word or an underscore: sams_pocket_ai_bot rather than ai_bot.
I closed the chat and lost the token
Send /mybots, pick your bot and tap API Token. It shows the current token again. Nothing needs revoking unless someone else might have seen it.
Still stuck? Ask the community
Next mission · Own your AIFine-tune a small AI on your own writing and run it in Ollama
→