Telegram bot for running a private helpdesk
- Python 97%
- Mako 2.5%
- Dockerfile 0.5%
| bot | ||
| docs | ||
| migrations | ||
| .env.example | ||
| .gitignore | ||
| alembic.ini | ||
| docker-compose.yml | ||
| Dockerfile | ||
| mkdocs.yml | ||
| README.md | ||
| requirements.txt | ||
Helpdesk Bot
A Telegram bot that provides private, one-on-one support sessions between users and agents — all through a single shared support channel.
How it works
- A user joins the support channel
- The bot greets them privately via DM and asks for their question
- Their question is relayed to a staff-only agent group as a support ticket
- An agent claims the ticket and the conversation continues — user in DMs, agent in the group
- When resolved, the user is automatically removed from the support channel and can rejoin anytime
No user ever sees another user's conversation. The support channel itself is locked — members cannot send messages in it.
Features
- Private by design — all support conversation happens in DMs and a staff-only group
- Session-based — users are added on join, removed on resolution, and can return as needed
- Ticket tracking — every conversation is logged to PostgreSQL with full message history
- Role-based access — users, agents, and admins each have distinct capabilities
- No setup needed for users — just join the channel and the bot handles the rest
Requirements
- Python 3.11+ (or Docker)
- PostgreSQL 14+
- A Telegram bot token from @BotFather
- Two Telegram supergroups (support channel + agent group)
Quick start (Docker)
cp .env.example .env
# Edit .env with your values
docker compose run --rm migrate
docker compose up -d bot db
Quick start (local)
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
cp .env.example .env
# Edit .env with your values
alembic upgrade head
python -m bot.main
Configuration
Copy .env.example to .env and fill in:
| Variable | Description |
|---|---|
TELEGRAM_TOKEN |
Bot token from @BotFather |
DATABASE_URL |
PostgreSQL connection string (postgresql+asyncpg://...) |
SUPPORT_GROUP_ID |
Chat ID of the supergroup users join |
AGENT_GROUP_ID |
Chat ID of the staff-only agent group |
ADMIN_IDS |
Comma-separated Telegram user IDs with admin access |
See docs/configuration.md for full details.
Telegram setup
Support channel
- Create a supergroup and add the bot as admin with Delete messages and Ban users permissions
- In Group Settings → Permissions, disable Send Messages for members
- Set
SUPPORT_GROUP_IDto the group's chat ID
Agent group
- Create a second supergroup with only your support staff
- Add the bot as admin with Send messages and Delete messages permissions
- Set
AGENT_GROUP_IDto the group's chat ID
Tip: Forward any message from a group to @userinfobot to get its chat ID.
Documentation
Tech stack
| Concern | Choice |
|---|---|
| Bot framework | python-telegram-bot v20+ |
| ORM | SQLAlchemy 2.0 async |
| DB driver | asyncpg |
| Migrations | Alembic |
| Settings | pydantic-settings |