Telegram bots1 minute to read

How do I host an aiogram or python-telegram-bot bot 24/7?

Run a Python Telegram bot built with aiogram or python-telegram-bot on an always-on worker: files, requirements, token variable and a first reply.

Run it as a polling worker

Use a host that keeps a Python process running and installs your requirements. On Bothosting, choose the Python polling bot profile, upload main.py and requirements.txt, save the BotFather token as TELEGRAM_BOT_TOKEN and start it. No domain or open port is needed. Spark runs it free with 256 MB RAM, renewed every 7 days.

aiogram 3

requirements.txt
aiogram>=3.13
main.py
import asyncio, os
from aiogram import Bot, Dispatcher
from aiogram.filters import CommandStart
from aiogram.types import Message

dp = Dispatcher()

@dp.message(CommandStart())
async def start(message: Message):
    await message.answer('Hosted and running.')

async def main():
    bot = Bot(os.environ['TELEGRAM_BOT_TOKEN'])
    await dp.start_polling(bot)

asyncio.run(main())

python-telegram-bot 21+

requirements.txt
python-telegram-bot>=21
main.py
import os
from telegram import Update
from telegram.ext import Application, CommandHandler, ContextTypes

async def start(update: Update, context: ContextTypes.DEFAULT_TYPE):
    await update.message.reply_text('Hosted and running.')

app = Application.builder().token(os.environ['TELEGRAM_BOT_TOKEN']).build()
app.add_handler(CommandHandler('start', start))
app.run_polling()

Start it and check the reply

  1. Create the deployment with the Python polling bot profile. Upload both files to the root and set MAIN_FILE to main.py.
  2. Save TELEGRAM_BOT_TOKEN in Variables and start the deployment.
  3. Stop any copy on your laptop, then send /start from your phone.

If nothing arrives and the log shows a conflict error, another process or a webhook is using the token. See switching from webhook to polling. To keep state across restarts, see remembering conversations.