This guide will help you deploy lex-tg to Railway.app using Docker and a PostgreSQL database.
- Go to Railway Dashboard.
- Click New Project -> Deploy from GitHub Repo.
- Select your
lex-tgrepository.
- In your Railway project canvas, click New -> Database -> Add PostgreSQL.
- Railway will automatically create a
DATABASE_URLvariable for the project.
- Click on your bot service.
- Go to the Variables tab and add the following:
API_ID: Your Telegram API ID.API_HASH: Your Telegram API Hash.BOT_TOKEN: Your Telegram Bot Token.OWNER_ID: Your Telegram User ID.DATABASE_URL: Set this to${{Postgres.DATABASE_URL}}(Railway automatically links it).LOG_LEVEL:INFOENABLE_VIDEO_WATERMARK:TrueorFalse.VIDEO_WATERMARK_MAX_SIZE_MB: E.g.,20.
Railway's filesystem is ephemeral. To prevent data loss and repeated log-ins:
- Go to your bot service -> Settings.
- Scroll to Volumes -> Add Volume.
- Create volumes for the following paths:
- Mount Path:
/app/sessions(For Telegram sessions) - Mount Path:
/app/data(For local cache snapshots) - Mount Path:
/app/logs(Optional, for persistent logs)
- Mount Path:
- Every time you push to GitHub, Railway will build the Docker container and deploy it.
- Check the Logs tab to verify the
lex-tg is running!message appears.
- Database Connection: Ensure
DATABASE_URLuses the${{Postgres.DATABASE_URL}}reference. - Session Reset: If the bot asks to log in again after a restart, ensure the volume is correctly mounted to
/app/sessions. - Migrations: The bot automatically runs
alembic upgrade headon startup. check the logs if you see migration errors.