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
aiogram>=3.13import 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+
python-telegram-bot>=21import 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
- Create the deployment with the Python polling bot profile. Upload both files to the root and set
MAIN_FILEtomain.py. - Save
TELEGRAM_BOT_TOKENin Variables and start the deployment. - Stop any copy on your laptop, then send
/startfrom 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.