Telegram Auto Reply Bot is a self‑hosted agent that uses a regular Telegram user account to automatically reply to private messages, mimicking a human operator. By leveraging Telethon and OpenTele, it bypasses Bot API limitations and provides a seamless conversation experience powered by GPT‑4.1 mini.
TGAutoReplyBot uses your existing Telegram Desktop session (tdata) to log in as a regular user (not a bot). This makes it indistinguishable from a human in chat, allowing for natural interactions.
The bot:
- Responds to private messages using OpenAI GPT‑4.1 mini.
- Sends delayed greetings to mimic human behavior.
- Handles multi-turn conversations via OpenAI Assistant Threads.
- Maintains context per chat by caching thread IDs.
- Forwards messages to a manager group (optional).
- Runs using
Telethon,OpenTele, andasynciofor full concurrency. - Requires no Bot API token — just your
tdatafolder from Telegram Desktop.
-
Clone the repository:
git clone https://github.com/stufently/TGAutoReplyBot.git cd TGAutoReplyBot -
Prepare your .env file:
Run the following command to create a working .env file based on the provided sample:
cp .env.SAMPLE .env
✏️ Open .env in any text editor and fill in your values:
-
"OPENAI_API_KEY"
-
"ASSISTANT_ID"
-
"FORWARD_ENABLED, GROUP_CHAT_ID, PROXIES (optional)"
-
-
Place Telegram Desktop session:
-
Locate your tdata folder from Telegram Desktop.
-
Copy it into the project folder as: tdatas/tdata/
📁 Final structure should be: TGAutoReplyBot/tdatas/tdata/
-
Create required directories:
mkdir -p tdatas sessions
These will store Telegram data and session files (needed for persistent login).
-
Build and run the bot locally:
docker-compose up --build -d
This will build and run the bot in detached mode. It will pull the Docker image ghcr.io/stufently/tgautoreplybot:latest and start the bot with the necessary dependencies.
-
Check status or logs:
- Status:
docker-compose ps
- Logs:
docker-compose logs -f
📦 Example docker-compose.yml
version: "3.8"
services:
tgautoreplybot:
image: ghcr.io/stufently/tgautoreplybot:latest # Build from local Dockerfile
container_name: tgautoreplybot
env_file: .env # Load environment variables
volumes:
- ./tdatas:/app/tdatas # Telegram Desktop sessions
- ./sessions:/app/sessions # Persist Telethon sessions
restart: unless-stopped # Auto-restart on failure or reboot