Running a Telegram bot on your laptop works fine — until you close the lid. The moment your machine goes to sleep, your bot goes offline. The fix is simple: put it on a server that never sleeps. And no, you don't need to spend $10 a month on a big VPS to do it.
A NAT VPS for $0.99 a month is more than enough to run a Python Telegram bot around the clock. This guide walks you through the whole thing: from getting your server, installing Python, setting up your bot, and making sure it restarts automatically if anything goes wrong.
What you'll need
- A NATBox Nano VPS ($0.99/mo) — or any Linux server with SSH access
- A Telegram bot token from @BotFather
- Basic comfort with a Linux terminal
That's it. You don't need a dedicated IP address, a domain, or Docker. Just a shell.
Step 1 — Get your VPS and connect
Once you order and receive your SSH credentials by email, open a terminal and connect:
ssh root@147.135.215.238 -p YOUR_PORT
You'll land in a clean Debian shell. The first thing to do is update the package list and install a few essentials:
apt update && apt install -y python3 python3-pip python3-venv git
On a 256MB RAM container this takes about 30 seconds. Nothing dramatic.
Step 2 — Create your bot on Telegram
If you haven't already, open Telegram and search for @BotFather. Send it /newbot, follow the prompts, and copy the token it gives you. It looks like this:
1234567890:AAExxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Keep that safe. You'll need it in a moment.
Step 3 — Set up your Python environment
Back on your VPS, create a folder for the bot and set up a virtual environment. This keeps your bot's dependencies isolated, which matters if you ever run multiple projects on the same server.
mkdir ~/mybot && cd ~/mybot
python3 -m venv venv
source venv/bin/activate
pip install python-telegram-bot
The python-telegram-bot library handles all the API communication for you. It's well-documented and actively maintained.
Step 4 — Write the bot
Create a file called bot.py:
nano bot.py
Paste in this starter bot. It responds to /start and echoes back any text you send it:
from telegram import Update
from telegram.ext import ApplicationBuilder, CommandHandler, MessageHandler, filters, ContextTypes
TOKEN = "YOUR_BOT_TOKEN_HERE"
async def start(update: Update, context: ContextTypes.DEFAULT_TYPE):
await update.message.reply_text("Bot is alive and running on a $0.99 VPS!")
async def echo(update: Update, context: ContextTypes.DEFAULT_TYPE):
await update.message.reply_text(update.message.text)
app = ApplicationBuilder().token(TOKEN).build()
app.add_handler(CommandHandler("start", start))
app.add_handler(MessageHandler(filters.TEXT & ~filters.COMMAND, echo))
app.run_polling()
Replace YOUR_BOT_TOKEN_HERE with the token from BotFather. Save and exit (Ctrl+X, then Y).
Test it manually first:
python3 bot.py
Open Telegram, find your bot, and send /start. If it replies, you're good. Press Ctrl+C to stop it.
Step 5 — Keep it running with systemd
This is the part most tutorials skip, and it's the most important. Running python3 bot.py in a terminal means your bot dies the moment you disconnect. You need systemd to manage it as a proper background service.
Create the service file:
nano /etc/systemd/system/mybot.service
Paste this in — adjusting the path to match your username and folder if needed:
[Unit]
Description=Telegram Bot
After=network.target
[Service]
Type=simple
WorkingDirectory=/root/mybot
ExecStart=/root/mybot/venv/bin/python3 /root/mybot/bot.py
Restart=on-failure
RestartSec=5s
[Install]
WantedBy=multi-user.target
Now enable and start it:
systemctl daemon-reload
systemctl enable mybot
systemctl start mybot
Check that it's running:
systemctl status mybot
You should see active (running) in green. Your bot is now a proper system service. It starts automatically on reboot and restarts itself if it crashes — no babysitting required.
Step 6 — Check the logs
If something goes wrong, the first place to look is the service log:
journalctl -u mybot -f
The -f flag tails the log in real time, like tail -f. Most issues at this stage are typos in the token or a missing library — both obvious from the log output.
Does a NAT VPS actually work for Telegram bots?
Yes — and it's actually a great fit. Telegram bots use long polling by default, which means your bot initiates outbound connections to Telegram's servers. It doesn't need to receive incoming connections on a public port, so a shared NAT IP doesn't matter at all.
The only time you'd need a dedicated IP is if you switch to webhooks — and for most bots, polling is simpler and works perfectly.
How much RAM does a Telegram bot actually use?
A basic Python bot with python-telegram-bot uses around 25–40MB of RAM when idle. A NATBox Nano gives you 256MB, which comfortably runs one or two bots alongside the OS. If you're running something heavier — a bot with database lookups, image processing, or a web framework — step up to the Micro plan at $1.99 for 512MB.
What else can you run on the same VPS?
Since your bot barely touches the CPU and uses under 50MB of RAM, you've got headroom left. Common additions on the same Nano container:
- A second lightweight bot
- A small SQLite or Redis instance for bot state
- A cron job for scheduled tasks
- A static site or simple Flask/FastAPI app on one of your 19 spare ports
That's one of the advantages of having 20 dedicated ports — you're not stuck hosting just one thing.
Keeping your bot secure
A few basics worth doing once you're up and running:
- Don't hardcode your token in the source file — use an environment variable or a
.envfile loaded withpython-dotenv - Add your SSH key to
~/.ssh/authorized_keysand disable password authentication - Run
apt upgraderegularly — on a Debian system this is usually painless and keeps your container patched
None of this is mandatory for a personal project, but it's good habit.
Final thoughts
Hosting a Telegram bot doesn't need to be complicated or expensive. A $0.99/mo NAT VPS gives you a persistent Linux environment, systemd process management, and enough RAM and CPU for several bots running side by side. The whole setup in this guide takes under 15 minutes once you have your credentials.
If you want to try it risk-free before committing to a monthly plan, grab a Burner VPS for $0.25 — 24 hours of a full Linux container to test the whole setup. If it works, a Nano plan is one click away.