Home / Guides / Telegram Bot

Deploy a Telegram bot on VPS in 10 minutes

Works on any Ubuntu 22.04/24.04 VPS. Total cost: from โ‚ฌ3/mo โ€” a bot doesn't need more than a NAT plan.

1. Get a server

Order any plan on our plans page โ€” for a bot, Buran NAT (โ‚ฌ3) is enough. You'll get IP, login and password by email in ~2 minutes.

2. Connect & prepare

ssh root@YOUR_SERVER_IP
apt update && apt upgrade -y
apt install -y python3-pip python3-venv

3. Bot code

mkdir -p /opt/mybot && cd /opt/mybot
python3 -m venv venv
source venv/bin/activate
pip install "python-telegram-bot==21.*"
cat > bot.py <<'EOF'
from telegram.ext import ApplicationBuilder, CommandHandler
async def start(update, context):
    await update.message.reply_text("Hello from Buran!")
app = ApplicationBuilder().token("YOUR_BOT_TOKEN").build()
app.add_handler(CommandHandler("start", start))
app.run_polling()
EOF

4. Systemd: bot survives reboots

cat > /etc/systemd/system/mybot.service <<'EOF'
[Unit]
Description=My Telegram Bot
After=network-online.target
[Service]
WorkingDirectory=/opt/mybot
ExecStart=/opt/mybot/venv/bin/python bot.py
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable --now mybot
systemctl status mybot

Done. The bot restarts on crash and on server reboot. Need an upgrade path later? See all plans.

Related