Run a Telegram Bot 24/7 Without Interruptions
Stop hosting your Telegram bot on your laptop or a free tier that sleeps. Run it as a small always-on container that stays up around the clock, restarts itself on a crash, and keeps your token safe. Prepaid pricing, and a free $5 trial to start.
A Telegram bot is only useful when it is awake. Running it on your laptop means it dies when you close the lid, and many free tiers put your process to sleep after a few idle minutes, so the first person to message your bot after a quiet hour gets silence. The fix is to run the bot as a small always-on container that stays up 24/7 and restarts itself if it ever crashes. This guide does exactly that.
Why a container app is the right home for a bot
A bot is a long-running process, not a website that answers one request and moves on. It needs to stay alive, hold its connection to Telegram, and come straight back after any hiccup. An always-on container app on alawadi.cloud gives you all three: it runs continuously, the platform restarts it automatically if the process exits, and it keeps running as long as your balance is positive.
How a bot talks to Telegram
There are two ways, and it helps to know which you are using:
- Long polling (
getUpdates): your bot repeatedly asks Telegram for new messages. All traffic is outbound, so the bot needs no public URL. This is the simplest setup and the one this guide uses. - Webhooks: Telegram pushes updates to a public HTTPS URL you expose. If you prefer this, expose port
8080and point the webhook at your*.alawadi.cloudsubdomain, which already has TLS.
For most bots, long polling is the easiest way to get to 24/7, so start there.
What you'll need
- A bot token from Telegram's BotFather
- Your bot's code (this guide uses Python; Node with Telegraf works the same way)
- Docker installed locally to build and test the image
- An alawadi.cloud account: Google sign-in, no card, free trial credit inside the portal
Step 1: A minimal bot
Here is a complete long-polling bot with python-telegram-bot. It reads its token from an environment variable, never from a hard-coded string:
import os
from telegram import Update
from telegram.ext import Application, CommandHandler, ContextTypes
async def start(update: Update, _: ContextTypes.DEFAULT_TYPE) -> None:
await update.message.reply_text("Hello! I run 24/7 on alawadi.cloud.")
def main() -> None:
token = os.environ["BOT_TOKEN"] # injected from the portal, never hard-coded
app = Application.builder().token(token).build()
app.add_handler(CommandHandler("start", start))
app.run_polling() # long polling: outbound calls only
if __name__ == "__main__":
main()Put python-telegram-bot==21.6 in a requirements.txt beside it.
Step 2: A Dockerfile
The image installs the dependencies and runs the bot as a non-root user, since the platform rejects root containers. A long-polling bot serves no HTTP, so it needs no exposed port:
FROM python:3.12-slim
WORKDIR /app
COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
# Run as a non-root user; the platform rejects root containers
RUN useradd --create-home bot
USER bot
CMD ["python", "bot.py"]Build and run it locally with your token to confirm the bot answers /start:
docker build -t my-telegram-bot .
docker run --rm -e BOT_TOKEN=your-token-here my-telegram-botStep 3: Keep the token a secret
Never bake your bot token into the image or commit it to Git. In the portal, set BOT_TOKEN as an environment variable (or a secret) on the service, and the platform injects it at runtime. If a token ever leaks, revoke it in BotFather and set a new value, no rebuild required.
Step 4: Deploy it and let it stay up
Open Cloud Studio, create an Application, give it a name, and point it at your image through a private registry and GitHub OIDC, the same push-to-deploy flow described in the 5-minute deploy guide. Once it is running:
- It stays up 24/7, holding its long-polling loop to Telegram without you touching anything.
- If the process crashes, the platform restarts it automatically.
- Live logs in the dashboard show every update your bot handles, which makes debugging painless.
Run exactly one instance
A long-polling bot must run as a single instance. If two copies poll Telegram with the same token, they fight over updates and you get a "Conflict: terminated by other getUpdates request" error. Keep the bot at one replica in the portal: autoscaling is meant for web apps that handle many parallel requests, not for a single polling loop. If you ever need more throughput, move to webhooks rather than adding replicas.
Step 5: Give your bot a memory (optional)
If your bot needs to remember users, scores, or state, add a managed PostgreSQL or Redis database from the Databases tab. Linking it injects the connection details into your bot automatically, and the platform handles its storage and backups. The pattern is the same one shown in the launch checklist.
What it costs, and how to start
A small always-on bot is inexpensive, and usage is deducted from a USD-credit ledger with optional USD, SYP, AED, or JOD display. Estimate it with the pricing calculator, then claim the $5 trial credit in the portal with no card. Prepaid vouchers priced in SYP are the only live top-up rail; card and cryptocurrency top-ups are not currently available. If your balance runs out, the bot stops gracefully and your data is kept for 7 days while you top up, so nothing is deleted out from under you.
FAQ
Do I need a public URL for my bot?
Not with long polling. The bot only makes outbound calls to Telegram, so it needs no inbound address. Choose webhooks (and expose port 8080) only if you specifically want Telegram to push updates to you.
Will my bot really never sleep?
Correct. An always-on container is not a sleep-on-idle free tier. It runs continuously as long as your balance is positive, and the platform restarts it if it crashes.
Can I run a Node bot instead?
Yes. The same steps apply with Telegraf or grammY: read the token from an environment variable, run the bot as a non-root container, and deploy it. Another question? Open a support ticket in the portal or email [email protected].
The company behind alawadi.cloud
The company building an Arabic-first cloud platform, from the physical servers up to the developer experience.