A bot in an hour: ChatGPT writes the code
The course's core move: you don't write code — you commission it. We take the ChatGPT master prompt apart, learn to accept the work with three client questions, and look at the bot code's anatomy — what a handler is and where the bot «listens» to Telegram.
Here's the prompt that does 80% of this course's work. All you need for it is any access to ChatGPT — the free tier is enough. First the whole thing, then why every line earns its place — and how to accept the work without reading the code.
The master prompt for bot code
Write a Telegram bot in Python (python-telegram-bot library). What it does: replies to the /start command with a greeting, and echoes any text message back politely. Requirements: read the token from the BOT_TOKEN environment variable, keep everything in one file bot.py, comment every code block in plain words explaining what it does. Add exactly one feature at a time: just this for now, we'll extend later. I'm not a programmer: finish with step-by-step launch instructions.
Why the prompt is built this way
- «in Python (python-telegram-bot)» — the most popular language and library for bots: ChatGPT has seen thousands of such projects, so generation errors are fewest. Stack popularity = the quality of the code you'll get.
- «token from an environment variable» — an environment variable is a named setting the program receives from the system at launch rather than from its own text. That way the token (remember the ignition key from the previous lesson?) never lands in the code text. A day-one habit: in the 24/7 module you'll see what disaster it prevents.
- «comment in plain words» — the code becomes readable: you see what happens where without knowing Python.
- «one feature at a time» — simple code checks simply. Want ten features? Order them one by one, each in its own follow-up message.
- «I'm not a programmer: launch instructions» — flips ChatGPT into patient-mentor mode, no jargon dumps.
Why python-telegram-bot specifically
A library is a kit of ready-made parts programs are built from: instead of «spell out to Telegram letter by letter what I want» you get ready commands like «reply» and «show buttons». python-telegram-bot has been developed for over ten years and catches up with every fresh Bot API version: 10.0 is fully supported, Rich Messages support from 10.1 is on the way. For you this means the library is alive, and the code ChatGPT generates won't crumble from old age in a month.
What comes back — and one catch
ChatGPT will answer the master prompt in three parts: the code itself (one block, the bot.py file), a short explanation of what's inside, and step-by-step launch instructions. Save the code into a bot.py file on your computer — we'll run it in the next lesson.
One catch worth knowing in advance: ChatGPT sometimes confidently produces code in an outdated style — bot libraries have changed over the years, and the internet is full of old examples. The warning sign: the code mentions the telebot library or something you didn't order. One reply cures it: «Use python-telegram-bot specifically, a fresh version, syntax of version 21 or newer». It's exactly these stale examples that make video courses about bots rot within a year — a text and a prompt are easy to update, re-recording a hundred videos is not.
Acceptance: three client questions
The code has arrived. You don't have to read it — but you do have to accept the work. A professional client doesn't pore over blueprints; they ask «what breaks if…». Ask ChatGPT right in the same conversation:
- «What will the bot do if a user sends a photo or a voice note instead of text?» — a boundary check: good code doesn't crash on the unexpected.
- «What happens if the internet drops for a minute?» — a resilience check: the program should survive a hiccup, not die forever.
- «Does this code send data anywhere other than Telegram?» — an honesty check: there must be no extra recipients in the code.
If any answer doesn't satisfy you, ask right away: «fix the code so that…». That is your role: you are the client and the inspector. You spell out, run, check, request fixes. This is vibe coding (the approach where AI writes the code and the human sets tasks and accepts the work) — except the product here is a bot.
Try it in the sandbox: code anatomy
See how bot code is built before you even install Python. The prompt is self-contained:
You are ChatGPT and I'm commissioning a bot. My order: «Write a Telegram bot in Python (python-telegram-bot library). It replies to /start with a greeting and politely echoes any text. Token from the BOT_TOKEN environment variable, one file bot.py, every block commented in plain words. I'm not a programmer: finish with launch instructions». Generate the code, then dissect it as a teacher: show which line reads the token; what a handler is and which handlers are here; where the bot starts «listening» to Telegram; and what breaks if each block is removed in turn.
After that walkthrough, the word handler (a piece of code responsible for one type of message: the /start command, plain text, a button press) stops being magic — and any bot is built precisely out of handlers.
What's next
You have the prompt and the acceptance ritual. In the next lesson we run the generated code on your computer — and the bot answers you in Telegram for the first time.
Short questions on the lesson — with an explanation for every answer.