A lightweight, efficient Telegram bot for customer support that enables seamless two-way communication between users and support administrators. This bot allows support staff to respond to user inquiries directly through Telegram, with proper message threading and media support.
- Two-way Communication: Users message the bot and administrators reply from a designated admin chat
- Proper Message Threading: Maintains conversation context with threaded replies in both directions
- Media Support: Handles all types of attachments (photos, videos, documents, voice messages, etc.)
- Start/Restart Button: Convenient button for users to restart conversations
- No Database Required: Lightweight implementation that doesn't require a database
- Easy to Deploy: Simple setup as a systemd service for 24/7 operation
- Python 3.7+
- python-telegram-bot (v20+)
- python-dotenv
-
Clone the repository:
git clone https://github.com/yourusername/telegram-support-bot.git cd telegram-support-bot
-
Create a virtual environment:
python -m venv .venv source .venv/bin/activate # On Windows: .venv\Scripts\activate
-
Install dependencies:
pip install -r requirements.txt
-
Create a
.env
file with your configuration:TELEGRAM_BOT_TOKEN=your_bot_token_from_botfather ADMIN_CHAT_ID=your_admin_group_chat_id
-
Run the bot:
python main.py
-
Create a systemd service file:
sudo nano /etc/systemd/system/support-tg-bot.service
-
Add the following content (adjust paths as needed):
[Unit] Description=Telegram Support Bot After=network.target [Service] User=root WorkingDirectory=/opt/support-tg-bot ExecStart=/opt/support-tg-bot/.venv/bin/python /opt/support-tg-bot/main.py Restart=always [Install] WantedBy=multi-user.target
-
Enable and start the service:
sudo systemctl daemon-reload sudo systemctl enable support-tg-bot.service sudo systemctl start support-tg-bot.service
-
Check the status:
sudo systemctl status support-tg-bot.service
- Create a new bot using @BotFather on Telegram
- Copy the bot token provided by BotFather
- Add the token to your
.env
file
- Create a group chat in Telegram
- Add your bot to the group
- Send any message to the group
- Visit
https://api.telegram.org/bot<YOUR_BOT_TOKEN>/getUpdates
in your browser - Find the
chat
object with"type":"group"
and copy theid
value - Add this ID to your
.env
file asADMIN_CHAT_ID
-
User Interaction:
- Users send messages to the bot
- The bot forwards these messages to the admin group
- Each message includes user info and unique IDs for tracking
-
Admin Responses:
- Admins reply to forwarded messages in the group
- The bot sends these replies back to the corresponding user
- Replies maintain proper threading and context
-
Message Threading:
- Each message contains hidden tags to maintain the conversation context
- This allows for proper reply chains without requiring a database
You can customize the bot's messages by editing these variables in the main.py
file:
WELCOME_MESSAGE
: Sent when a user first starts the botCONFIRMATION_MESSAGE
: Sent after a user submits a message
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.