How to deploy a python-telegram-bot (PTB) bot — hosting on Botxona
python-telegram-bot (PTB) is one of the oldest and most stable Telegram bot libraries for Python. To run on Botxona, you don't need to change the API URL — Telegram requests are automatically routed through the platform proxy.
Steps
1. Build the Application
import os
from telegram.ext import Application, CommandHandler
from telegram import Update
from telegram.ext import ContextTypes
BOT_TOKEN = os.getenv("BOT_TOKEN")
app = Application.builder().token(BOT_TOKEN).build()
async def start(update: Update, context: ContextTypes.DEFAULT_TYPE):
await update.message.reply_text("Hi! I'm up and running.")
app.add_handler(CommandHandler("start", start))
if __name__ == "__main__":
app.run_polling()
There is no need to set base_url/base_file_url — both regular API calls and file downloads go through the proxy automatically.
2. Use DATA_DIR
DATA_DIR = os.getenv("DATA_DIR", "./data")
os.makedirs(DATA_DIR, exist_ok=True)
If you use PTB's persistence (e.g. PicklePersistence), point the file path at this folder:
from telegram.ext import PicklePersistence
persistence = PicklePersistence(filepath=os.path.join(DATA_DIR, "bot_data.pickle"))
3. requirements.txt
python-telegram-bot==21.6
If the base package isn't enough (e.g. python-telegram-bot[job-queue]), include the extras in brackets along with the version.
4. .env.example and ZIP
Document your bot's own settings (e.g. ADMIN_IDS) in .env.example, then archive the folder (Preparing a ZIP) and upload it to the dashboard.
5. Check and trial
After uploading, read the results here, then test the bot in Telegram during the 15-minute free trial.
Working with JobQueue
If you use PTB's JobQueue (e.g. run_daily, run_repeating), Botxona detects it automatically and switches the bot to always on — otherwise a scheduled task won't run while the bot is asleep. More: Sleep and wake-up.
Common errors
telegram.error.InvalidToken— the token was copied incorrectly or revoked in BotFather (Getting a token).- The bot won't start, "Conflict" error — something is connecting to the same token from two places; stop the bot elsewhere (e.g. on your computer).
Faster with AI
Instead of editing your existing code by hand, you can ask an AI to adapt it automatically using the Prompt library.
Next steps
The Dashboard tour and Reading logs.