A practical Telegram bot powered by OpenAI: chat naturally, understand photos, generate or edit images, and transcribe voice notes, all in one conversation.
- Family assistant chat with data safety.
- Quick image generation or edits directly from Telegram prompts.
- Voice notes to text, then continue the conversation from transcription.
- Conversational chat with per-chat memory.
- Photo understanding and follow-up questions.
- Image generation and image editing flows.
- Voice message transcription.
- Document context support for common text-like formats.
- Access control via Telegram user allowlist.
- Telegram bot token (create a bot via
@BotFather). - OpenAI API key.
- Docker + Docker Compose (recommended), or Go
1.27+for local runs.
- Copy the template:
cp .env.example .env-
Fill required values in
.env. -
Start:
docker compose up -dUse --build when you want compose to rebuild the image from local source:
docker compose up -d --build- Logs:
docker compose logs -fdocker run --rm \
-e TELEGRAM_TOKEN=... \
-e OPENAI_API_KEY=... \
-e ALLOWED_TG_IDS=123456789 \
-e SYSTEM_PROMPT="You are a helpful assistant" \
ghcr.io/dasmfm/openai-telegram-bot:latestgo run ./cmd/bot- Restrict access with
ALLOWED_TG_IDS; do not run with an empty allowlist. - Keep
OPENAI_API_KEYandTELEGRAM_TOKENonly in.envor your secret manager. - Rotate tokens immediately if logs or shell history may have exposed them.
| Variable | Required | Default | Description | Example |
|---|---|---|---|---|
TELEGRAM_TOKEN |
Yes | - | Telegram Bot API token from BotFather. | 123456:ABC... |
OPENAI_API_KEY |
Yes | - | OpenAI API key used for all model calls. | sk-proj-... |
ALLOWED_TG_IDS |
Yes | - | Comma-separated Telegram user IDs allowed to use the bot. | 123456789,987654321 |
OPENAI_MODEL |
No | gpt-6.1-sol |
Main text model for chat responses. | gpt-6.1-sol |
IMAGE_MODEL |
No | gpt-image-2.6-flare |
Model used for image generation/editing. | gpt-image-2.6-flare |
ROUTER_MODEL |
No | gpt-6-luna |
Model used to route text vs image actions. | gpt-6-luna |
SYSTEM_PROMPT |
No | empty | Custom behavior prompt appended to base Telegram HTML prompt. | You are a helpful assistant. |
MAX_HISTORY_MSGS |
No | 20 |
Max number of messages kept in memory per chat. | 20 |
MAX_FILE_MB |
No | 20 |
Max downloaded file size from Telegram. | 20 |
REQUEST_TIMEOUT_SEC |
No | 120 |
Timeout for OpenAI/Telegram request handling. | 120 |
TRANSCRIBE_MODEL |
No | gpt-transcribe |
Model used for voice transcription. | gpt-transcribe |
/help— shows a short help message with supported input types./reset— clears conversation memory for the current chat.
go test -count=1 ./...