• Crear un bot de Telegram en Debian y dejarlo en ejecución

    Podemos utilizar Python en Debian para crear un bot de Telegram que esté siempre en ejecución, de forma que podamos interactuar con él en cualquier momento. Para ello primero:

    CREAMOS EL USUARIO QUE EJECUTARÁ EL BOT

    adduser telegrambot

    CREAMOS LOS ARCHIVOS Y LA CARPETA PARA EL BOT

    mkdir -p /home/telegrambot/bot/
    touch /home/telegrambot/bot/principal.py
    touch /home/telegrambot/bot/funciones.py
    touch /home/telegrambot/bot/TokenDelBot.txt
    chown telegrambot:telegrambot /home/telegrambot -R

    INSTALAMOS PYTHON Y LA LIBRERÍA PARA EL BOT

    apt-get update && apt-get install python3
    pip3 install python-telegram-bot

    CREAMOS EL SERVICIO DE SYSTEMD

    echo '[Unit]'                                                    > /etc/systemd/system/TelegramBot.service
    echo 'Description=Telegram Bot'                                 >> /etc/systemd/system/TelegramBot.service
    echo 'After=network.target'                                     >> /etc/systemd/system/TelegramBot.service
    echo ''                                                         >> /etc/systemd/system/TelegramBot.service
    echo '[Service]'                                                >> /etc/systemd/system/TelegramBot.service
    echo 'ExecStart=/usr/bin/python3 /home/telegrambot/bot/main.py' >> /etc/systemd/system/TelegramBot.service
    echo 'WorkingDirectory=/home/telegrambot/bot'                   >> /etc/systemd/system/TelegramBot.service
    echo 'Restart=always'                                           >> /etc/systemd/system/TelegramBot.service
    echo 'User=telegrambot'                                         >> /etc/systemd/system/TelegramBot.service
    echo ''                                                         >> /etc/systemd/system/TelegramBot.service
    echo '[Install]'                                                >> /etc/systemd/system/TelegramBot.service
    echo 'WantedBy=multi-user.target'                               >> /etc/systemd/system/TelegramBot.service

    INICIAMOS Y ACTIVAMOS EL BOT

    systemctl enable TelegramBot --now

     


    Deja una respuesta