Railway

Deploy Telegram Bot

Launch your Telegram bot with an admin UI, then make the code your own.

Deploy Telegram Bot

/var/lib/postgresql/data

Just deployed

Deploy and Host Telegram Bot Studio on Railway

Telegram Bot Studio is a ready-to-use Telegram bot with a built-in web dashboard for managing commands, replies, media responses, and reply keyboards without editing code.

This template deploys the bot together with PostgreSQL, so user data and dynamic commands are stored persistently. Developers can also customize the source code later by ejecting the upstream repository and modifying the bot, FastAPI dashboard, handlers, integrations, or business logic.

About Hosting Telegram Bot Studio

This template deploys two connected services:

  • Telegram Bot Studio — runs the Telegram bot and password-protected administration dashboard
  • PostgreSQL — stores bot users and dynamic command configuration

The bot uses Telegram long polling, while the administration panel runs in the same application process and is exposed through Railway's public HTTPS domain.

PostgreSQL is connected automatically through Railway private networking. Database migrations run automatically when the application starts, so there is no manual database initialization step required.

Included Architecture

ServicePurpose
Telegram Bot StudioTelegram bot, FastAPI dashboard, command runtime
PostgreSQLPersistent users and dynamic command storage
Railway Private NetworkingInternal application-to-database connectivity
Railway Public NetworkingHTTPS access to the administration dashboard
Alembic MigrationsAutomatically prepares and updates the database schema
                    Telegram Users
                           │
                           ▼
                    Telegram API
                           │
                           ▼
                 ┌─────────────────────┐
                 │ Telegram Bot Studio │
                 │                     │
                 │ Bot Poller          │
                 │ FastAPI Admin UI    │
                 │ Dynamic Commands    │
                 └──────────┬──────────┘
                            │
                     Private Network
                            │
                            ▼
                   ┌─────────────────┐
                   │   PostgreSQL    │
                   │                 │
                   │ Users           │
                   │ Commands        │
                   └─────────────────┘

Common Use Cases

  • Launch a Telegram bot without building the entire project from scratch
  • Manage bot commands from a web dashboard
  • Add or update replies without redeploying
  • Create text, photo, and document responses
  • Add Telegram reply keyboards
  • Track Telegram users persistently
  • Build an internal support or information bot
  • Create a community or utility bot
  • Use the included project as a starting point for a custom Telegram application
  • Extend the bot with external APIs, automation platforms, databases, or business logic

Built-In Bot Features

Telegram Bot Studio includes several commands out of the box:

CommandPurpose
/startDisplays the welcome response and persistent menu
/helpShows available commands
/aboutDisplays bot information
/pingChecks whether the bot is responding

Normal text messages can also be handled by the default echo functionality.

Unknown commands fall through to the dynamic command registry, allowing commands created from the Studio dashboard to work without modifying the source code.

Telegram Bot Studio Dashboard

The administration dashboard runs in the same service as the Telegram bot.

From the dashboard you can:

  • Add commands
  • Edit existing commands
  • Enable or disable commands
  • Delete commands
  • Create text replies
  • Send photos
  • Send documents
  • Use media URLs or Telegram file_id values
  • Configure reply keyboards
  • Apply command changes without redeploying

Changes are loaded into the running bot and the Telegram command menu is refreshed when configurations are saved.

Getting Started

Before deployment, you only need to provide:

BOT_TOKEN

To obtain it:

  1. Open Telegram.
  2. Start a conversation with @BotFather.
  3. Create a new bot.
  4. Copy the generated bot token.
  5. Paste the token into the BOT_TOKEN variable.
  6. Deploy the template.

After deployment:

  1. Wait until Telegram Bot Studio and PostgreSQL are online.
  2. Open the public Railway URL assigned to Telegram Bot Studio.
  3. Open the service Variables page.
  4. Copy:
PANEL_USERNAME
PANEL_PASSWORD
  1. Sign in to the dashboard.
  2. Add or customize bot commands.
  3. Open Telegram and start your bot.

PostgreSQL Persistence

PostgreSQL is included by default in this template.

The database stores:

  • Telegram users
  • Telegram usernames
  • First names
  • Last activity information
  • Dynamic commands
  • Command settings
  • Reply configuration
  • Media responses
  • Keyboard configuration

When a user runs /start, their information can be inserted or refreshed in PostgreSQL.

Database connections use asyncpg connection pooling and are closed cleanly during application shutdown.

Automatic Database Migrations

No manual database migration command is required.

On startup, the application checks whether a database connection exists and automatically runs:

alembic upgrade head

before starting the bot process.

This allows schema updates to follow application updates without requiring the user to enter the Railway Console manually.

Ready to Use, Ready to Customize

Telegram Bot Studio is designed to work immediately after deployment, but the source code is also available if you want to build something more advanced.

The Railway template uses the GitHub repository:

https://github.com/codestorm-official/telegram-bot-studio

The project is open source under the MIT License.

If you want to customize the application after deployment, you can eject the upstream repository from Railway and create your own copy.

You can then modify:

  • Telegram handlers
  • Built-in commands
  • FastAPI routes
  • Dashboard pages
  • Authentication
  • Database models
  • Business logic
  • External API integrations
  • AI integrations
  • Webhooks
  • Automation workflows

This gives you two ways to use the template:

ModeBest For
Dashboard ModeManaging commands without coding
Developer ModeBuilding a fully customized Telegram application

Project Stack

Telegram Bot Studio is built using:

  • Python
  • python-telegram-bot
  • FastAPI
  • PostgreSQL
  • asyncpg
  • Alembic
  • Docker
  • Railway

The web dashboard and Telegram bot run in the same application service, so no additional frontend or backend container is required.

Deployment Behavior

The project already includes Railway configuration using its Dockerfile.

The configured start process is:

sh start.sh

The startup script:

  1. Runs database migrations when PostgreSQL is configured.
  2. Starts the Telegram bot application.

This means no custom Railway start command needs to be configured separately.

Replica and Scaling Considerations

This template should run with:

1 replica

The bot currently uses Telegram long polling.

Telegram's getUpdates model only allows one active polling consumer for a bot token, so running multiple replicas would cause conflicts.

Horizontal scaling would require moving to a webhook-based architecture or implementing coordination between instances.

Security Considerations

The administration panel can change bot behavior and should be treated as an administrative interface.

For production deployments:

  • Keep BOT_TOKEN private.
  • Use a strong dashboard password.
  • Keep PostgreSQL on Railway private networking.
  • Do not expose PostgreSQL publicly unless necessary.
  • Keep the panel secret key persistent.
  • Keep secure cookies enabled.
  • Rotate credentials if they are exposed.
  • Review custom commands before enabling them publicly.

The dashboard includes signed sessions and CSRF protection for state-changing forms.

Dependencies for Telegram Bot Studio Hosting

  • Telegram Bot Studio — Telegram bot runtime and administration dashboard
  • PostgreSQL — persistent users and dynamic command storage
  • Railway Private Networking — internal database communication
  • Railway Public Networking — HTTPS access to the Studio dashboard
  • Telegram Bot Token — provided by the user from @BotFather
  • Alembic — automatic database schema migrations

No Redis or persistent application volume is required.

Deployment Dependencies

Why Deploy Telegram Bot Studio on Railway?

Railway is a singular platform to deploy your infrastructure stack. Railway will host your infrastructure so you don't have to deal with configuration, while allowing you to vertically and horizontally scale it.

By deploying Telegram Bot Studio on Railway, you get a ready-to-use Telegram bot, PostgreSQL persistence, a password-protected administration dashboard, automatic database migrations, and full access to the source code when you want to customize the project further.


Template Content

More templates in this category

View Template
Telegram JavaScript Bot
A template for Telegram bot in JavaScript using grammY

Agampreet Singh
294
View Template
Cobalt Tools [Updated Aug ’26]
Cobalt Tools [Aug ’26] (Media Downloader, Converter & Automation) Self Host

shinyduo
268
View Template
Telegram Gateway
Multi-bot Telegram webhook gateway with real-time WebSocket event streaming

INAPP
5