Build a Telegram Payment Bot with Stars — No IP or ID Needed
Developers can accept donations and sell digital goods in Telegram without registering an individual entrepreneur (IP) or providing passport details. By using Telegram Stars as currency, the bot generates invoices and processes payments automatically. The system uses Python with aiogram 3, SQLite for data storage, and aiohttp for the Mini App API. This lets any Telegram user create products and generate payment links instantly.
System Architecture
The aiogram 3 bot interacts with an SQLite database storing products, sellers, and payment links. A separate aiohttp API serves the Mini App via endpoints:
/api/products— product catalog/api/donate— donation button data/api/create_invoice— invoice generation
Payment logic is handled entirely within the bot: the Mini App fetches data via API, the bot creates invoices, and confirms successful payments through the successful_payment event.
Generating Unique Payment Links
For security, links are generated with unique codes like prod_fgU7d, stored in the payment_links table. Full URL: https://t.me/System_Paybot?start=prod_fgU7d. This prevents ID brute-forcing and enables traffic source tracking.
When delivering content, the bot detects the file type from file_id and uses a universal send mechanism:
try:
await message.answer_document(document=content, caption=thanks)
except:
try:
await message.answer_photo(photo=content, caption=thanks)
except:
# further attempts for video, audio, etc.
The sendDocument method works reliably across most Telegram file types.
Processing Stars Payments
Invoices are created using the create_invoice_link method with parameters:
invoice_link = await bot.create_invoice_link(
title=title,
description=f"Purchase: {title}",
payload=f"pay_{product_id}_{user_id}",
provider_token="",
currency="XTR",
prices=[{"label": title, "amount": amount}]
)
Telegram handles the payment and sends a successful_payment update with the payload to identify the product and deliver it to the user.
Admin Features & Analytics
Owners have access to commands:
/admin_stats— overall stats/admin_users— recent users/admin_broadcast— mass messaging/admin_ban//admin_unban— access control
Sellers use /stats for personal analytics.
Deployment Troubleshooting
Stars Limitations
Stars are credited directly to the bot owner and cannot be transferred to others. Solution: open-source code allows anyone to deploy their own bots.
HTTPS for Mini App
Mini App requires HTTPS. When port 443 is occupied (e.g., by Xray VPN), use a subdomain with Nginx on port 8443:
- Subdomain:
shop.system-dev.ru - Certbot for SSL certificates
- Open port 8443 in iptables
- BotFather URL:
https://shop.system-dev.ru:8443
Set permissions on /var/www/systempay to chmod 755 for www-data.
CORS in API
Add middleware in aiohttp:
@web.middleware
async def cors_middleware(request, handler):
response = await handler(request)
response.headers['Access-Control-Allow-Origin'] = '*'
response.headers['Access-Control-Allow-Methods'] = 'GET, POST, OPTIONS'
response.headers['Access-Control-Allow-Headers'] = 'Content-Type'
return response
Final Capabilities
The bot supports:
- Uploading files of any type or sharing links
- Donations of any amount
- Mini App with product catalog and responsive UI
- Personal analytics dashboard
- Admin panel
Ready for immediate use to automate sales in Telegram.
Key Takeaways
- Unique link codes ensure security and traffic analytics without ID guessing.
- Universal file delivery via
sendDocumentwith fallbacks works across all Telegram formats. - Stars integration is simple but funds go to the bot owner — open source enables self-hosting.
- HTTPS on non-standard ports is solved using Nginx + Certbot without conflicts with VPNs.
- CORS middleware in aiohttp resolves cross-origin issues for Mini App.
— Editorial Team
No comments yet.