Overview
TheClientConfig struct provides extensive configuration options to customize your Gogram client behavior, from basic authentication to advanced networking settings.
Basic Configuration
While
AppHash is optional in the config, it’s required for authentication and certain API methods. You can omit it only if you’re importing an existing session.Configuration Fields
Required Fields
The App ID from my.telegram.org. Required for all clients.
The App Hash from my.telegram.org. Optional in config, but required for:
- Authentication (Login/LoginBot)
- Certain API methods that need app credentials
- Initial client setup without existing session
Session Management
The session file path to use for storing authentication data.
Use a string session instead of a file. Useful for cloud deployments.
Custom name for the session. Alternative to
Session field.AES encryption key for the session file (32 characters).
Optional, not needed unless you need extra protection from string session being leaked.
Don’t save the session to a file. Session is lost when the program exits.
Device Configuration
Device information sent to Telegram servers.
Network Configuration
The data center to connect to (1-5). Default is DC 4.
Manually specify the IP address of the DC to connect to.
Local address binding for multi-interface support (IP:port).
Force the client to use IPv6 connections.
Proxy configuration for routing traffic. See Proxy Configuration.
Use WebSocket transport instead of TCP.
This must be enabled to use the library inside browsers, since they don’t allow TCP connections from JavaScript.
Use wss:// (WebSocket over TLS) instead of ws://.
Transport & Protocol
The transport mode to use. Options:
Abridged, Intermediate, PaddedIntermediate, Full.Custom public keys to verify the server with.
Use the test data centers instead of production.
Behavior & Features
Default parse mode for messages. Options:
HTML, Markdown.Don’t handle updates. Useful for stateless bots.
Disable caching peer and chat information.
Cache the exported file operation senders.
Custom cache implementation for storing peer information.
See Client Cache.
Don’t preconnect to the DC until
Connect() is called. Otherwise it preconnects if string session is provided.Commands & Messages
Command prefixes to recognize. Can be multiple characters.
Time to wait for album messages in milliseconds.
Rate Limiting & Timeouts
Threshold in milliseconds to sleep before flood wait.
TCP connection timeout in seconds.
RPC request timeout in seconds.
Custom handler for flood wait errors. Return
true to retry, false to drop the requestLogging
The library log level. Options:
DebugLevel, InfoLevel, WarnLevel, ErrorLevel.Custom error handler for global error handling.
Using ClientConfigBuilder
For more convenient configuration, use theClientConfigBuilder:
Builder Methods
Complete Example
Best Practices
Use Builder Pattern
Use ClientConfigBuilder for cleaner, more maintainable configuration.
Encrypt Sessions
Always use SessionAESKey to encrypt session files in production.
Set Timeouts
Configure appropriate timeouts based on your network conditions.
Handle Floods
Implement custom FloodHandler to manage rate limiting gracefully.
Use String Sessions
For cloud deployments, prefer StringSession over file-based sessions.
Enable Logging
Use appropriate LogLevel for debugging and production monitoring.