Bots de Telegram2 minutos de lectura

¿Cómo alojo 24/7 un bot hecho con aiogram o python-telegram-bot?

Ejecuta un bot de Telegram en Python hecho con aiogram o python-telegram-bot en un worker siempre activo: archivos, dependencias, variable del token y una primera respuesta.

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

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())

Implementar aiogram y verificar el registro del router.

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()

Despliegue python-telegram-bot con persistencia.

Inícialo y comprueba la respuesta

  1. Crea el despliegue con el perfil de bot de polling en Python. Sube ambos archivos a la raíz y pon MAIN_FILE en main.py.
  2. Guarda TELEGRAM_BOT_TOKEN en Variables y arranca el despliegue.
  3. Detén cualquier copia en tu portátil y luego envía /start desde 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.