NodeOps
UK

Guide

How to Deploy a Telegram Bot That Runs 24/7

Deploy your bot to a cloud platform using a CLI. Set your bot token as an environment variable, deploy with one command, and your bot stays online permanently. For webhook-based bots, the deployment gives you an HTTPS URL that Telegram can send updates to.

The problem

Your Telegram bot works on your local machine but dies when you close the terminal. Telegram bots need a persistent server to receive updates, either via long polling or webhooks. Running it on your laptop is not production-ready.

Long polling vs webhooks

Telegram bots can receive updates two ways. Long polling: your bot repeatedly asks Telegram for new messages. Simple but your process must stay running. Webhooks: Telegram sends updates to your HTTPS URL. More efficient but requires a public URL with SSL. Cloud deployment gives you both options: a persistent process for long polling, and an HTTPS URL for webhooks.

What you need for production

A persistent process (for long polling) or an HTTPS endpoint (for webhooks), environment variables for the bot token, automatic restart on crash, and log access. Memory: 128MB-256MB for most bots. If your bot uses AI (calling OpenAI, running local models), you may need 512MB-1024MB.

Approaches compared

Platform CLI (CreateOS, Railway, Fly)

Pros

  • One-command deploy with HTTPS URL
  • Supports both polling and webhooks
  • Environment variables for bot token
  • Auto-restart

Cons

  • Monthly cost for persistent process

Best for: Most Telegram bots, especially webhook-based

Serverless (Vercel, Cloudflare Workers)

Pros

  • Free for low traffic
  • Auto-scales

Cons

  • Webhook only (no long polling)
  • Cold start delays
  • Timeout limits

Best for: Simple command-response bots with low traffic

VPS with systemd or pm2

Pros

  • Cheap
  • Full control

Cons

  • Manual SSL for webhooks
  • Manual process management

Best for: Developers comfortable with Linux server administration

Deploy a Telegram bot with CreateOS CLI

Here is how to do it step by step using CreateOS CLI.

1

Install the CLI

$ brew install createos

Single binary for macOS and Linux.

2

Deploy your bot

$ createos login && createos init && createos deploy

Deploys your bot and gives you an HTTPS URL for webhooks.

3

Set the bot token

$ createos env set TELEGRAM_BOT_TOKEN=your-token-here

Get your token from @BotFather. Store it as an environment variable.

4

Set up the webhook (optional)

$ curl https://api.telegram.org/bot$TOKEN/setWebhook?url=https://your-bot.nodeops.app/webhook

Point Telegram to your deployed URL. All updates are now sent to your server automatically.

Frequently asked questions

Should I use long polling or webhooks?
Webhooks are more efficient for production. Telegram pushes updates to your server instead of your bot polling. But webhooks require an HTTPS URL. If you deploy to a platform, you get HTTPS automatically, so webhooks are the better choice.
How much does it cost to host a Telegram bot?
Small bots cost $3-7 per month on cloud platforms. Serverless options (Vercel, Cloudflare Workers) can be free for very low traffic bots using webhooks. VPS hosting starts at $4-6 per month.
Can I deploy a bot that uses AI?
Yes. Deploy your bot the same way, just add your LLM API key as an environment variable: createos env set OPENAI_API_KEY=sk-... The bot calls the AI API on each message and responds with the generated text.

Try it yourself

$ brew install createos

100,000+ Builders. One Workspace.

Get product updates, builder stories, and early access to features that help you ship faster.

CreateOS is a unified intelligent workspace where ideas move seamlessly from concept to live deployment, eliminating context-switching across tools, infrastructure, and workflows with the opportunity to monetize ideas immediately on the CreateOS Marketplace.