- Telegram integration for customer statistics - MCP server implementation with rate limiting - Cache system for performance optimization - Multi-language support - RESTful API endpoints 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
61 lines
1.0 KiB
Go
61 lines
1.0 KiB
Go
package telegram
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
)
|
|
|
|
type ProxyConfig struct {
|
|
Type string
|
|
Host string
|
|
Port int
|
|
Username string
|
|
Password string
|
|
}
|
|
|
|
type Config struct {
|
|
APIID int
|
|
APIHash string
|
|
BotUsername string
|
|
SessionString string
|
|
SessionStorage string
|
|
RateLimit int
|
|
RateLimitWindow time.Duration
|
|
CacheTTL time.Duration
|
|
Proxy *ProxyConfig
|
|
}
|
|
|
|
func (c Config) Validate() error {
|
|
if c.APIID == 0 {
|
|
return fmt.Errorf("APIID must be provided")
|
|
}
|
|
if c.APIHash == "" {
|
|
return fmt.Errorf("APIHash must be provided")
|
|
}
|
|
if c.BotUsername == "" {
|
|
return fmt.Errorf("BotUsername must be provided")
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (c Config) RateLimitPerSecond() int {
|
|
if c.RateLimit <= 0 {
|
|
return 18
|
|
}
|
|
return c.RateLimit
|
|
}
|
|
|
|
func (c Config) RateLimitDuration() time.Duration {
|
|
if c.RateLimitWindow <= 0 {
|
|
return time.Second
|
|
}
|
|
return c.RateLimitWindow
|
|
}
|
|
|
|
func (c Config) CacheDuration() time.Duration {
|
|
if c.CacheTTL <= 0 {
|
|
return time.Hour
|
|
}
|
|
return c.CacheTTL
|
|
}
|