TELEGRAM · PRACTICAL GUIDE

Telegram bot works only on your computer? How to run it around the clock

You built a Telegram bot, said hello, and got a reply. Then you closed your laptop and the bot went silent. Telegram delivers messages, but your code still runs on your computer. Here is how to move it to hosting and verify it works independently of your PC.

Mia watches Telegram messages reach a cloud server while her laptop is closed
Illustration: the bot receives messages on a server independently of the laptop.

Why the bot stops with your laptop

A local bot may receive messages through long polling: it repeatedly asks Telegram for new events. When your process sleeps or the computer turns off, nothing asks anymore. To reply without your laptop, run the code on a server or an app platform.

Another option is a webhook: Telegram sends events to your public HTTPS URL. That fits app hosting: your code handles web requests when messages arrive. A bot cannot receive getUpdates while a webhook is active. Stop the old local process before switching.

If you do not have a bot yet, start with our creation guide. This article covers the next step: deployment and operation.

Build a ChatGPT bot first →

Step 1. Save the code and remove secrets

  • Test /start, a normal message, and an AI service failure locally. Save the working code in your own GitHub repository.
  • Keep the @BotFather token, OpenAI or other model key, and webhook secret out of GitHub. If a token was committed to a public repository, rotate it with BotFather.
  • Check that the project has a start command and dependency list. For a webhook, the server must accept POST requests on the path you will register with Telegram.
  • If the old code calls getUpdates or starts polling on boot, ask your agent to switch event delivery to a webhook. Do not run both modes for one token.

Step 2. Give the code a place to run

We will use CMO Studio as an example. It lists Node.js and Python hosting, GitHub integration, a public URL, logs, and environment settings. Create a separate test project and connect only this bot's repository. Check the current plan's runtime, resource, network, and background-job limits; do not buy a plan based on a blanket ‘24/7’ claim.

After the first deploy, open the app's assigned URL. Telegram needs a public HTTPS endpoint; a custom domain is optional for the first test. If the app does not start, inspect build/start logs and the platform-provided port.

Create a test bot project in CMO Studio →

Step 3. Configure the webhook without exposing your token

Let the app accept POST requests at a path such as /telegram/webhook. Check the X-Telegram-Bot-Api-Secret-Token header, parse the JSON update, and send a successful HTTP response when the event is accepted. Telegram's setWebhook supports secret_token: it is separate from the BotFather token. For slow AI calls, plan queueing and repeat delivery so updates are neither lost nor processed twice.

Set TELEGRAM_BOT_TOKEN, TELEGRAM_WEBHOOK_SECRET and, if needed, OPENAI_API_KEY in hosting secrets. Match the variable names to your code. Then call Telegram's official setWebhook method with the app's HTTPS URL and secret_token. Do this from server-side code or your own local script that reads secrets; never paste a real token into an article, chat, GitHub, or public link.

You can give this request to a coding agent alongside your bot's source. It should change the real project, not merely describe a solution:

My Telegram bot currently uses polling locally. Convert it to a webhook for Node.js/Python hosting: add POST /telegram/webhook, check X-Telegram-Bot-Api-Secret-Token, handle Telegram updates, send an HTTP response, and listen on the environment's port. Read the bot token, webhook secret, and model key only from environment variables. Provide a safe one-off setWebhook procedure that does not print the token. Do not remove local mode before showing a diff and tests; do not merge a pull request without my review. Show how to check getWebhookInfo and one bot reply after deployment.

Step 4. Verify it without your computer

  • Message the test bot with /start from another device. Check hosting logs for the incoming POST and any 401, 404, or 500 response.
  • Call getWebhookInfo through a secure local or server-side tool. Inspect url, pending_update_count, and last_error_message to see where Telegram sends events and whether delivery is failing.
  • Stop the old local process, turn off or disconnect the laptop, and send a new message from your phone. If the bot replies, it no longer depends on that local process.
  • Make a small GitHub update and repeat the test. Record how to roll back to the last working deployment; if there is a database, verify that it survives a new release.

If the bot stays silent: four quick checks

  • An empty url in getWebhookInfo means the webhook is not set. Configure it again and check setWebhook's response.
  • If last_error_message appears or pending_update_count rises, check HTTPS, the /telegram/webhook path, and HTTP status in logs. A wrong secret causes rejection; a wrong path causes 404.
  • If the webhook accepts POST but nobody gets a reply, check the AI API key, spending limit, exception handling, and logs. HTTP 200 alone does not prove sendMessage succeeded.
  • If the bot replies twice, check whether your handler processes a retried event again. Use update_id to protect against duplicates.

What will it cost?

Creating a bot through BotFather does not pay for hosting. Server resources, a database, email, and AI model calls may have separate costs. CMO Studio lists a free tier and paid plans; check current limits before launch, and remember that OpenAI or another model provider bills separately.

A VPS with your own setup is another option if you want full control over the process, but updates, HTTPS, restarts, and monitoring become your responsibility. For a typical webhook bot, test the host with a small project and choose a paid plan based on observed load.

General app deployment guide →

For developers: GitHub, Postgres, MCP, and rollback →

Sources and verification

  1. Telegram Bot API: setWebhook and getWebhookInfo
  2. Telegram: webhook guide
  3. CMO Studio: features and pricing
  4. CMO Studio: official deployment guide

Found this useful? Share it

Send this to someone working on a similar problem.

Share on Telegram ↗

Read via RSS · Weekly newsletter in Ukrainian

Discussion

Share a thought or ask about the article. Your nickname and comment will be public.

Loading comments…

Telegram chat ↗