A small Telegram bot written in Python that sells a single digital book in PDF format. The idea is simple: a user opens the bot, sees a short description, goes to an external payment page, and then receives the book file.
The bot is aimed at authors or small projects that want a minimal, no-frills way to sell a single digital product through Telegram. Payment itself happens on an external page; the bot only handles the flow around it and keeps track of buyers
/start- greeting, short book description and an inline "Buy book 💳" button with an external payment link./i_paid- the user tells the bot they completed the payment; the user is then marked as "paid" in the database./get_book- if the user is marked as paid, the bot send the PDF book./buyers- show a list of all buyers (available only for admins)./broadcast- send a simple broadcast message to all users (admins only).
- Python 3.x
- aiogram
- python-dotenv
- SQLite - lightweight built-in database for users and purchases
- Standard library:
asyncio,logging,pathlib,database, etc.
A simplified view of the project layout:
app/
main.py # bot entrypoint (used with: python -m app.main)
handlers.py # command/message handlers
keyboards.py # inline keyboards
config.py # configuration, paths, .env loading
services/
payments.py # payment / purchase storage logic
crm.py # simple CRM: user tracking, first
data/
book.pdf # the book file
images/ # optional images for intro / cover
requirements.txt
README.md
- Clone the repository and go to the project directory:
git clone https://github.com/kandera37/book-bot-telegram.git cd book-bot-telegram - (Optional) Create and activate virtual environment:
python -m venv .venv source .venv/bin/activate # Windows: .venv\Scripts\activate
- Install dependencies:
pip install -r requirements.txt
Copy .env.example to .env and fill in your values:
cp .env.example .envThen edit .env and set:
BOT_TOKEN=...
PAY_URL=...If you want to show an intro image on /start, you can also add files like:
data/images/01_intro.jpg
data/images/02_author.jpg
Images are loaded from the data/images folder and sorted by file name.
python -m app.mainThe bot will start in polling mode.
Open Telegram, find your bot and send /start to begin.
In this version, there is no real payment provider integration. The flow is intentionally simple:
- The user taps the "Buy book 💳" button and goes to an external payment page (PAY_URL).
- After payment, the user returns to the bot and sends
/i_paid. - The bot marked as paid in the SQLite database.
- The next
/get_bookcall sends the PDF book.
This setup is enough for a prototype or for internal use, and it keeps the bot logic independent of any specific payment service.
I treat this project as a small but complete example of Telegram bot:
- Structure - code is split into modules (
handlers,keyboards,services,config) instead of one big script. - Configuration - the bot token and payment URL are loaded from
.env; secrets are not hard-coded and should not be committed to the repository. - Database layer - SQLite is used for storing users and purchases; there is a separate CRM module that keeps track of
first_seen/last_seentimestamps. - Logging - key actions (commands, book delivery, broadcast failures) are logged using the standard logging module.
In a real production setup this bot could be extended with a proper payment provider integration, more detailed CRM, and additional admin tooling. For now, it shows how I structure and ship a small, self-contained Python project.