real-time streaming message relay from telegram to chatgpt
Receives incoming Telegram messages via polling or webhook, forwards them to OpenAI's ChatGPT API, and streams responses back using Server-Sent Events (SSE). The bot maintains a message processing loop that captures user input, sends it to ChatGPT's streaming endpoint, and progressively updates the Telegram message as tokens arrive, reducing perceived latency compared to waiting for full response completion.
Unique: Implements SSE-based streaming with in-place Telegram message editing rather than sending multiple separate messages, reducing chat clutter and providing a native streaming UX within Telegram's constraints. Uses Go's lightweight concurrency model to handle multiple user conversations simultaneously without blocking.
vs alternatives: Faster perceived response time than polling-based bots because streaming tokens update the same message in real-time; more efficient than webhook-based approaches because it maintains persistent connections to OpenAI's SSE stream.
browser-based openai session authentication with automatic token capture
Launches a headless browser window when no stored session token exists, guides the user through OpenAI's login flow, automatically extracts the session token from browser cookies, and persists it to the local config file for future use. This eliminates manual token extraction and handles session refresh transparently, supporting both interactive setup and programmatic authentication.
Unique: Uses browser automation to capture session tokens directly from cookies rather than requiring users to manually extract them, reducing setup friction. Stores tokens in platform-specific config directories (XDG_CONFIG_HOME on Linux, AppData on Windows) following OS conventions.
vs alternatives: More user-friendly than manual token extraction (which requires browser DevTools knowledge); more reliable than API key-based auth because it uses the same session mechanism as the web interface, avoiding API-specific limitations.
two-tier configuration system with environment and persistent storage
Manages bot configuration through a hybrid approach: environment variables (.env file) for runtime settings like TELEGRAM_TOKEN and EDIT_WAIT_SECONDS, combined with persistent JSON storage for stateful data like OpenAI session tokens. Configuration is loaded on startup, with environment variables taking precedence, and persistent state is written back to platform-specific config directories after authentication or updates.
Unique: Separates transient configuration (Telegram token, edit wait time) from stateful data (OpenAI session token) across two storage layers, allowing environment-based deployment while maintaining session persistence. Uses platform-specific config directories (XDG_CONFIG_HOME, AppData, Library) rather than hardcoded paths.
vs alternatives: More flexible than single-file config because it supports both containerized (env vars) and local (persistent JSON) deployments; more secure than embedding secrets in code, though less secure than encrypted vaults.
telegram message update batching with configurable edit delay
Buffers streaming ChatGPT tokens and updates the Telegram message at configurable intervals (default ~1 second via EDIT_WAIT_SECONDS) rather than on every token, respecting Telegram's rate limits (~1 edit per second per message). This prevents API throttling errors and reduces network overhead while maintaining perceived real-time streaming by batching multiple tokens into single edit operations.
Unique: Implements configurable token batching with a timer-based approach rather than fixed batch sizes, allowing operators to tune streaming feel without code changes. Respects Telegram's documented 1-edit-per-second limit by design rather than retrying on throttle errors.
vs alternatives: More predictable than naive streaming (which hits rate limits immediately); more responsive than sending complete responses as separate messages because updates happen in-place.
multi-user isolation with optional telegram id allowlisting
Optionally restricts bot access to a single Telegram user by checking the incoming message sender's ID against a configured TELEGRAM_ID value. When set, only messages from that user ID are processed; all others are silently ignored. This provides a simple access control mechanism without requiring a full authentication system, suitable for personal bot deployments.
Unique: Provides optional single-user allowlisting via environment variable rather than requiring a full user database or authentication system. Fails open (accepts all users) if TELEGRAM_ID is not set, making it opt-in rather than forcing configuration.
vs alternatives: Simpler than OAuth-based access control for personal deployments; more secure than no access control, though less flexible than role-based systems.
cross-platform binary distribution with docker containerization
Provides pre-compiled binaries for macOS (Intel/ARM), Linux (x86/ARM), and Windows, eliminating the need for users to compile from source. Additionally offers a Docker image (ghcr.io/m1guelpf/chatgpt-telegram) that bundles the binary with runtime dependencies, allowing deployment via container orchestration with volume mounts for persistent config and environment variable injection for secrets.
Unique: Distributes pre-compiled binaries for 5 platform variants (macOS Intel/ARM, Linux x86/ARM, Windows) alongside a Docker image, eliminating compilation friction for both local and containerized deployments. Uses GitHub Releases for binary hosting and ghcr.io for container registry.
vs alternatives: Faster to deploy than source-based installation because no compilation is required; more portable than Docker-only distribution because it supports bare-metal and local development.
stateless message processing with per-conversation context isolation
Processes each incoming Telegram message independently without maintaining conversation history or context between messages. Each message is sent to ChatGPT as a standalone request, and responses are isolated to that single message. This stateless design simplifies deployment and avoids memory leaks from unbounded conversation history, but requires users to provide full context in each message if they want multi-turn conversations.
Unique: Deliberately avoids conversation state management, treating each message as independent. This simplifies deployment and prevents memory leaks, but trades off multi-turn conversation capability. Contrasts with stateful bots that maintain conversation history.
vs alternatives: More memory-efficient and simpler to deploy than stateful bots because no history storage is needed; less capable for multi-turn conversations, making it suitable only for single-query use cases.
openai api integration with session token authentication
Communicates with OpenAI's ChatGPT API using session-based authentication (session tokens extracted from browser cookies) rather than API keys. Sends user messages to OpenAI's streaming endpoint, receives Server-Sent Events (SSE) with token-by-token responses, and handles streaming response parsing. This approach mirrors the web interface's authentication mechanism, avoiding API key management and supporting the same session lifecycle as the browser.
Unique: Uses session token authentication (reverse-engineered from browser behavior) instead of official OpenAI API keys, allowing users to leverage existing web accounts. Implements SSE parsing to handle streaming responses token-by-token rather than waiting for complete responses.
vs alternatives: Avoids API key management and works with free OpenAI accounts; less reliable than official API because it's not officially supported and may break if OpenAI changes their web interface.