Puedes usar una VM en Oracle Cloud Free Tier para correr tu bot de Telegram 24/7. Sin costo, sólo necesitas:

  1. Un Script de configuración automática para instalar Python, Git, y tu bot de Telegram en tu VM gratuita de Oracle.
  2. Un systemd service para que tu bot inicie automáticamente.
  3. Configurar un dominio gratuito con SSL (ej. usando Cloudflare) para webhooks de tu bot.

1️⃣ Crear y configurar la VM en Oracle Cloud Free Tier**

  1. Inicia sesión en Oracle Cloud.

  2. Ve a Compute > Instances > Create Instance.

  3. Elige:

    • Shape: VM.Standard.A1.Flex (ARM) (elige 1 OCPU, 1 GB RAM para Always Free).
    • Imagen: Ubuntu 22.04 LTS (recomendado).
  4. Configura SSH:

De forma predeterminada, al crear una instancia de OCI Compute Linux se genera un par de claves OpenSSH.

  • Descarga la clave privada para poder conectarte a la instancia mediante SSH. No se mostrará de nuevo.
  1. Da clic en Create y espera a que la VM se provision.

2️⃣ Conéctate a tu VM vía SSH

Desde tu máquina local:

ssh -i /ruta/a/tu/llave.pem ubuntu@<Public_IP_de_tu_VM>

(O opc@ si usas Oracle Linux, ajusta según tu usuario.)


3️⃣ Configurar el entorno de Python en la VM

Instala Python y pip:

sudo apt update
sudo apt install python3 python3-pip -y

Instala python-telegram-bot u otras dependencias de tu bot:

pip3 install python-telegram-bot requests

O usa tu requirements.txt si tienes:

pip3 install -r requirements.txt

4️⃣ Sube tu bot a la VM

Opciones:

  • Usar scp:

    scp -i /ruta/a/llave.pem bot.py ubuntu@<Public_IP>:/home/ubuntu
  • Clonar desde GitHub si lo tienes en un repo privado/público:

    sudo apt install git -y
    git clone <URL_de_tu_repo>

5️⃣ Probar tu bot en la VM

Ejecuta:

python3 bot.py

Verifica que responde correctamente en Telegram.


6️⃣ Configurar tu bot para correr 24/7

Para mantenerlo siempre corriendo incluso tras reinicios:

Opción rápida: screen o tmux

  1. Instala:

    sudo apt install screen -y
  2. Abre una sesión:

    screen -S bot
  3. Corre tu bot:

    python3 bot.py
  4. Detach con Ctrl+A, D (el bot sigue corriendo).
  5. Para volver:

    screen -r bot

Opción recomendada: systemd service

  1. Crea el archivo de servicio:

    sudo nano /etc/systemd/system/telegrambot.service

    Contenido:

    [Unit]
    Description=Telegram Bot
    After=network.target
    
    [Service]
    User=ubuntu
    WorkingDirectory=/home/ubuntu
    ExecStart=/usr/bin/python3 /home/ubuntu/bot.py
    Restart=always
    
    [Install]
    WantedBy=multi-user.target

    Ajusta la ruta si tu archivo está en otra carpeta.

  2. Recarga systemd:

    sudo systemctl daemon-reload
  3. Inicia el servicio:

    sudo systemctl start telegrambot
  4. Habilita inicio automático al reiniciar:

    sudo systemctl enable telegrambot
  5. Verifica el estado:

    sudo systemctl status telegrambot

Con esto, tu bot de Telegram correrá 24/7 en Oracle Cloud Free Tier.


7️⃣ (Opcional) Configurar Webhook

Si tu bot usa webhook, necesitarás: ✅ Configurar Nginx o Caddy con SSL (Let's Encrypt). ✅ Abrir el puerto 443 en el firewall de Oracle Cloud:

  • Ve a Networking > VCN > Security Lists > Ingress Rules y permite el puerto 443.

✅ Configurar tu bot con:

bot.setWebhook("https://tu_dominio_o_ip/webhook")

Si no quieres complicarte, puedes mantener long-polling, que funciona igual de bien para la mayoría de bots de trading o alertas.


🚀 Resumen rápido

✅ Oracle Cloud Free Tier te permite correr tu bot 24/7 sin costo. ✅ Funciona igual que PythonAnywhere, pero con control total. ✅ Usa systemd para estabilidad en producción. ✅ Puedes migrar en 30 min con esta guía.


Si deseas: ✅ Te preparo el archivo telegrambot.service listo para tu estructura. ✅ Te genero un setup.sh que instale dependencias y configure el bot automáticamente en tu VM. ✅ Te ayudo a configurar tu webhook con dominio y SSL gratuito si deseas.

Avísame y avanzamos en dejar tu bot de Telegram corriendo 24/7 de forma sólida y gratuita en Oracle Cloud Free Tier.