Blog

Keep your Telegram bot running 24/7

You built the bot. It answers you, it does the thing you wanted, and it works. Then you close your laptop and it goes quiet.

That is the moment most bots need a real home. Dockhold gives your bot one: it runs your code all day, restarts it if it stops, and updates it when you push to GitHub. Your bot keeps listening whether your computer is on or not.

A bot is not a website

A website waits for someone to visit. A bot has to sit and listen, even when nobody has typed anything for hours.

That difference matters more than it sounds. Many hosts put your app to sleep when no web traffic arrives, and a sleeping bot misses messages. Dockhold does not do that. Your app stays running, so the bot is there when someone finally sends /start at 3 in the morning.

The same is true for anything else that has to keep working quietly in the background:

Push your code, and the bot updates

Connect your bot’s GitHub repository once. After that, every push to your main branch builds a new version and puts it live.

No logging into a server. No copying files by hand. No trying to remember, six months later, which command you used to start the thing.

If your bot only lives on your computer for now, you do not even need GitHub. Run this in your project folder:

npx dockhold deploy

Your code goes up and comes back as a running app. Run the same command again whenever you want to ship a change.

Keep your bot token out of your code

Your bot token is a password. Anyone who has it can take over your bot, so it should never sit in your source code or in a file you push to GitHub.

Store it as an encrypted secret instead. Dockhold passes it to your bot as an environment variable when the app starts, so your code reads it the same way it does on your machine:

import os

token = os.environ["BOT_TOKEN"]

Your code stays code. Your secrets stay somewhere safer. You can read more in environment variables and secrets.

A long-polling bot should run as a single copy. If two copies poll Telegram at the same time, they fight over the same messages and your users see duplicate replies.

When your bot needs to remember things

Sooner or later a bot needs memory: who its users are, what they asked for last time, what is still in the queue.

Turn on the managed Postgres database and your app receives a DATABASE_URL automatically. There is nothing to install and no second provider to sign up for. Use it for users, chat history, settings, jobs, or whatever your bot needs to keep.

If you want your bot to do something at a fixed time, like send a morning summary, you can also set up a scheduled task instead of writing your own timer loop.

Start small, grow later

A small bot fits in the free capacity every account gets: 256 MB of always-on app power, a managed database, 10 GB of storage, and automatic HTTPS. No card needed.

If the bot grows, you add more capacity for $5 a month per 512 MB. You are buying a pool of resources, not a separate plan for every little app, so your bot and your next project can share it.

Give your bot somewhere to live

Connect the repository, or deploy the folder you already have on your computer. Either way it takes a few minutes, and then the bot is simply online.

Want working code to start from? The templates page has bots you can deploy as they are, then edit.

← All posts