Ejecútalo como un worker de polling
Usa un host que mantenga un proceso de Python en ejecución e instale tus requirements. En Bothosting, elige el perfil de bot de polling en Python, sube main.py y requirements.txt, guarda el token de BotFather como TELEGRAM_BOT_TOKEN e inícialo. No hace falta dominio ni puerto abierto. Spark lo ejecuta gratis con 256 MB RAM y se renueva cada 7 días.
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()Inícialo y comprueba la respuesta
- Crea el despliegue con el perfil de bot de polling en Python. Sube ambos archivos a la raíz y pon
MAIN_FILEenmain.py. - Guarda
TELEGRAM_BOT_TOKENen Variables y arranca el despliegue. - Detén cualquier copia en tu portátil y luego envía
/startdesde el teléfono.
Si no llega nada y el registro muestra un error de conflicto, otro proceso o un webhook está usando el token. Consulta el cambio de webhook a polling. Para conservar el estado entre reinicios, consulta recordar conversaciones.