How to Host a Free Python Telegram Payment Bot on PythonAnywhere
Building an automated Telegram bot that sells digital files, premium channel subscriptions, API keys, or coaching services is one of the most profitable projects a developer can build. However, for indie developers, college students, and bootstrap builders in India, two major obstacles traditionally block deployment: costly monthly VPS hosting (₹500 to ₹1,500/month) and stringent payment gateway gatekeeping (mandatory GST certificates, current accounts, and 2% gateway transaction fees).
In this step-by-step developer tutorial, we demonstrate how to build and host an automated UPI payment collection Telegram bot completely free of charge. By combining PythonAnywhere's Free Cloud Hosting with FamGateway's 100% Free Forever UPI Engine, you can deploy a full-featured payment bot with ₹0 hosting costs and ₹0 gateway fees.
- Cloud Compute: PythonAnywhere Free Tier (512MB disk, Bash terminal, Python 3.10+ runtime) → ₹0/month
- UPI Payment Rails: FamGateway (0.0% gateway commission, instant P2P bank credit) → 100% Free Forever
- Official Whitelist:
famgateway.inis officially approved on PythonAnywhere's Global Whitelist - Settlement Speed: 0.0 seconds (funds credit directly to your personal bank account or FamPay handle)
1. The PythonAnywhere Free Tier Proxy Challenge Explained
PythonAnywhere (owned by Anaconda) is one of the most respected cloud hosting environments for Python developers worldwide. It enables users to deploy Python web applications and run background scripts directly from a browser-based console.
However, to prevent malicious actors from abusing free resources to launch botnets or send spam, PythonAnywhere enforces a strict security policy on Free Tier accounts:
"Free accounts have restricted internet access: they can only make outbound HTTP and HTTPS requests to sites that are on our whitelist."
If a free-tier script attempts to connect to an unauthorized domain, PythonAnywhere's internal HTTP proxy immediately rejects the connection with a 403 Forbidden or ProxyError: Cannot connect to destination. Consequently, developers attempting to integrate standard third-party APIs or micro-gateways find their bots crash immediately upon deployment.
The Breakthrough: FamGateway is Officially Whitelisted
Following rigorous architectural and security review, famgateway.in is officially approved and listed on PythonAnywhere's Global Outbound Allowlist:
Target URL: https://www.pythonanywhere.com/whitelist/
Entry: famgateway.in [Approved API Endpoint]
Because famgateway.in is whitelisted, any Python script, Flask application, or Telegram worker hosted on a free PythonAnywhere account can initiate payment orders, retrieve QR codes, and poll payment statuses natively without needing custom proxies or paid upgrades.
2. Prerequisites & Account Setup (Under 3 Minutes)
Before authoring the bot code, verify you have the following free credentials:
- PythonAnywhere Account: Create a free account at pythonanywhere.com.
-
FamGateway API Key: Sign up for free at FamGateway Registration. Navigate to your dashboard and copy your private
api_key. You can link any verified personal bank UPI ID or FamPay account. -
Telegram Bot Token: Open Telegram, search for
@BotFather, send the command/newbot, and follow the prompts to obtain your bot's HTTP API token (e.g.,123456789:ABCdefGhIJKlmNoPQRstuVWXyz).
3. Setting Up Your Python Environment on PythonAnywhere
Log in to your PythonAnywhere dashboard and follow these terminal commands to initialize your environment:
Step 1: Open a Bash Console
From the PythonAnywhere Dashboard, click on Consoles → Bash. This opens an interactive Linux shell in your browser.
Step 2: Install Required Libraries via Pip
Install FamGateway's official Python SDK on PyPI alongside python-telegram-bot:
Note: The --user flag ensures packages are installed into your local home directory without requiring administrative root permissions.
4. Complete Production Bot Code (`bot.py`)
Create a new Python file named bot.py in your home directory (/home/yourusername/bot.py) using PythonAnywhere's built-in file editor or via nano bot.py:
import logging
from telegram import Update, InlineKeyboardButton, InlineKeyboardMarkup
from telegram.ext import Application, CommandHandler, CallbackQueryHandler, ContextTypes
from famgateway import FamGateway
# Configure logging
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO)
# Configuration Credentials
TELEGRAM_BOT_TOKEN = "YOUR_TELEGRAM_BOT_TOKEN"
FAMGATEWAY_API_KEY = "YOUR_FAMGATEWAY_API_KEY"
# Initialize the official FamGateway client
fg = FamGateway(api_key=FAMGATEWAY_API_KEY)
async def start(update: Update, context: ContextTypes.DEFAULT_TYPE):
keyboard = [
[InlineKeyboardButton("Buy Premium License (₹99)", callback_data="buy_99")],
[InlineKeyboardButton("Buy Lifetime Access (₹299)", callback_data="buy_299")]
]
reply_markup = InlineKeyboardMarkup(keyboard)
await update.message.reply_text(
"Welcome to the Premium Store!\nSelect an option below to pay instantly via UPI:",
reply_markup=reply_markup
)
async def handle_purchase(update: Update, context: ContextTypes.DEFAULT_TYPE):
query = update.callback_query
await query.answer()
amount = 99.0 if query.data == "buy_99" else 299.0
# 1. Create payment session via FamGateway API
order = fg.create_order(amount=amount)
# 2. Build interactive keyboard with 1-Tap UPI Intent
keyboard = [
[InlineKeyboardButton("Pay via UPI App", url=order.upi_intent_url)],
[InlineKeyboardButton("Check Payment Status", callback_data=f"check_{order.order_id}")]
]
reply_markup = InlineKeyboardMarkup(keyboard)
# 3. Send dynamic QR code image directly to the chat
await query.message.reply_photo(
photo=order.qr_code_url,
caption=(
f"Order #{order.order_id} Created!\n"
f"Amount: ₹{amount}\n\n"
"Scan the QR code with PhonePe, Google Pay, or Paytm, or tap the button below."
),
reply_markup=reply_markup
)
async def check_status(update: Update, context: ContextTypes.DEFAULT_TYPE):
query = update.callback_query
order_id = query.data.replace("check_", "")
# Query FamGateway status engine
status = fg.get_status(order_id)
if status.is_paid:
await query.answer("Payment Confirmed!", show_alert=True)
await query.message.reply_text(
f"SUCCESS! Your payment has been verified.\n"
f"Bank UTR: {status.utr}\n"
f"Your license key: FG-PREMIUM-XYZ-12345"
)
elif status.is_expired:
await query.answer("This order has expired.", show_alert=True)
else:
await query.answer("Payment still pending. Please authorize in your UPI app.", show_alert=True)
def main():
app = Application.builder().token(TELEGRAM_BOT_TOKEN).build()
app.add_handler(CommandHandler("start", start))
app.add_handler(CallbackQueryHandler(handle_purchase, pattern="^buy_"))
app.add_handler(CallbackQueryHandler(check_status, pattern="^check_"))
print("Bot started successfully on PythonAnywhere!")
app.run_polling()
if __name__ == "__main__":
main()
5. Running the Bot on PythonAnywhere Free Tier
To start the bot, execute the following command in your PythonAnywhere Bash console:
Open your bot in Telegram and send /start. You will receive an immediate interactive menu. Tapping either purchase button triggers a dynamic UPI QR code and deep intent link generated directly via FamGateway's backend.
Automating 24/7 Execution on Free Accounts
Free PythonAnywhere consoles remain active while your browser session is open, but can terminate after prolonged inactivity. To ensure uninterrupted uptime on a free account:
- Scheduled Tasks: Navigate to the Tasks tab in your PythonAnywhere dashboard. Create a daily task configured to run
python3 /home/yourusername/bot.py. If the process ever restarts, the scheduled task revives it automatically. - Telegram Webhooks (Zero-CPU Mode): For high-volume storefronts, transition from polling to Telegram Webhooks using PythonAnywhere's free Flask web routing. In this architecture, Telegram delivers incoming messages directly to your Flask HTTPS endpoint, which processes payments without requiring a background polling daemon.
6. Why This Solution Outperforms Paid Aggregators
When comparing this free Python cloud pipeline against traditional corporate payment solutions, the structural advantages for Indian solo developers are overwhelming:
| Architecture Dimension | FamGateway + PythonAnywhere | Traditional Gateways + Paid VPS |
|---|---|---|
| Monthly Hosting Cost | ₹0 (100% Free Forever) | ₹500 to ₹1,500 / month |
| Payment Gateway Cut | 0.0% Commission | 2.0% + 18% GST |
| Settlement Window | 0.0 Seconds (Direct Bank P2P) | T+2 Business Days (Escrow Hold) |
| GSTIN Requirement | None (Section 22 CGST Exempt) | Mandatory Corporate Registration |
| Outbound Proxy Support | Native (Whitelisted Domain) | Blocked by PythonAnywhere Proxy |
For a deep dive into our bank verification engine, UTR resolution mechanisms, and IMAP security standards, explore our IMAP Security and Gmail App Password Guide and our UPI UTR Number Verification Manual.
7. Frequently Asked Questions
Can I accept UPI payments on PythonAnywhere Free Tier?
Yes. While PythonAnywhere Free Tier accounts enforce an outbound HTTP proxy that blocks connections to arbitrary external domains, famgateway.in is officially listed on PythonAnywhere's global whitelist (pythonanywhere.com/whitelist/). This allows Python scripts and Telegram bots hosted on free accounts to make outbound API calls to FamGateway without encountering 403 Forbidden proxy errors.
What are the total hosting and payment processing costs for this setup?
The total cost is exactly 0 Rupees. PythonAnywhere provides free beginner hosting accounts (512MB storage, Bash console, and scheduled tasks), and FamGateway operates on a 100% Free Forever model with zero setup fees, zero monthly charges, and 0.0% transaction commission. You achieve an automated, production-ready payment pipeline at zero financial expense.
How does the bot verify that the user completed the UPI payment?
FamGateway generates dynamic UPI intent links and QR codes containing distinct tracking order IDs. The Python script polls fg.get_status(order_id) every 3 to 5 seconds. As soon as the customer authorizes payment in any UPI application, FamGateway's stateless socket engine parses bank credit emails in real time and updates the order status to COMPLETED, returning the official 12-digit bank UTR reference.
Do I need a GST number or business bank account to run a payment bot?
No. Under Section 22 of the Central Goods and Services Tax (CGST) Act, individual service providers with an annual turnover under 20 Lakh Rupees are legally exempt from mandatory GST registration. FamGateway allows developers to connect their personal bank account or verified FamPay handle to receive payments directly via peer-to-peer NPCI rails.
How do I keep my Telegram bot running 24/7 on PythonAnywhere Free Tier?
On PythonAnywhere Free Tier, you can configure a daily Scheduled Task that executes a long-running polling loop, or integrate PythonAnywhere's free Flask/WSGI web app hosting with Telegram Webhooks. When using Telegram Webhooks, incoming user messages trigger your Flask route directly without continuous background CPU consumption.
Related Developer Guides & Resources
Is ZapUPI Safe or Fake? 2026 Technical Audit, Code Decompilation & Security Review
An independent technical security audit and developer review of ZapUPI. We decompile public integration pac...
Best ZapUPI Alternative in India: FamGateway vs ZapUPI (Zero-Fee, Non-Custodial UPI Gateway Comparison 2026)
In-depth technical and architectural comparison between FamGateway and ZapUPI. Discover why non-custodial, ...
What is the Minimum Age Limit for FamPay? Age Requirements, 18+ Adult Usage & KYC Limits (2026)
What is the minimum age limit for FamPay? The official minimum age is 11 years old. Learn how minors (11-17...