
Telegram bot
ChatGPT Telegram Bot
A pet project for integrating ChatGPT into Telegram with two launch modes: via Bot API as a bot or via MTProto as a user. The bot supports live response updates, dialog history, system prompts and RU/EN localization.
Inside
- Two modes: as a Telegram bot or as a user through MTProto.
- `/system`, `/history` and `/clear_history` commands for behavior and context control.
- The answer is updated in real time by editing the message, with configurable update interval.
Key points
2 modes
bot and user client
RU/EN
localization
Docker
quick launch
Product view
ChatGPT Telegram Bot
The interface works directly inside Telegram: the user sends a prompt, the bot progressively updates the answer message, and in history mode it includes previous dialog context. This makes the project feel less like a one-off command bot and more like a full chat assistant inside a familiar messenger.

Functionality
Features
Bot API and user mode
The project can run as a regular Telegram bot through a BotFather token or as a user client through API_ID/API_HASH and MTProto authorization.
System behavior
The `/system` command changes assistant behavior: for example, translator, editor or domain assistant modes.
Dialog history
`/history` enables chat mode with previous messages included; `/clear_history` forces stored context cleanup.
Token limits
`MAX_MSG_TOKENS` controls the maximum tokens sent to the model: message history plus the new request.
Workflow
User flow
- 01
Choose launch mode
Bot mode requires a BotFather token, while user mode requires API_ID, API_HASH and a Telegram phone number.
- 02
Add OpenAI API key
The key and Telegram settings are added to the `docker-compose.yaml` environment.
- 03
Run with Docker
Basic launch uses `docker-compose up -d`; user mode additionally requires `node tglogin.js` and pm2 restart.
- 04
Configure in Telegram
After launch, behavior and history are controlled by commands directly in the chat.
Under the hood
Technical side
Telegram integration
`node-telegram-bot-api` is used for bot mode, `@mtproto/core` for user mode.
OpenAI streaming parser
`eventsource-parser` helps process response streams and update the message while text is generated.
Localization and config
RU/EN localization is controlled by `APP_LOCALE`; model version is switched through `MODEL_VERSION`.