mirror of
https://github.com/NoFxAiOS/nofx.git
synced 2026-07-10 22:36:58 +08:00
- Add assistant package with AI Agent runtime - agent.go: Core agent loop with tool calling - session.go: Conversation memory management - tool.go: Tool interface and base implementation - trading_tools.go: Trading-specific tools (13 tools) - prompts.go: Trading expert system prompts (EN/ZH) - Add telegram package for Telegram bot integration - bot.go: Telegram bot with rate limiting & access control - config.go: Environment-based configuration - Update main.go to initialize Telegram bot on startup - Update .env.example with new configuration options - Add gopkg.in/telebot.v3 dependency Trading tools available: - Query: get_balance, get_positions, list_traders, get_trader_status - Control: start_trader, stop_trader - Trading: get_market_price, open_long, open_short, close_position - Config: list_strategies, list_exchanges, list_ai_models
61 lines
1.5 KiB
Go
61 lines
1.5 KiB
Go
package telegram
|
|
|
|
import (
|
|
"os"
|
|
"strconv"
|
|
"strings"
|
|
)
|
|
|
|
// LoadConfigFromEnv loads Telegram bot configuration from environment variables
|
|
func LoadConfigFromEnv() BotConfig {
|
|
config := DefaultBotConfig()
|
|
|
|
// Bot token (required)
|
|
config.Token = os.Getenv("TELEGRAM_BOT_TOKEN")
|
|
|
|
// Webhook settings
|
|
if webhook := os.Getenv("TELEGRAM_WEBHOOK_URL"); webhook != "" {
|
|
config.UseWebhook = true
|
|
config.WebhookURL = webhook
|
|
}
|
|
if port := os.Getenv("TELEGRAM_WEBHOOK_PORT"); port != "" {
|
|
if p, err := strconv.Atoi(port); err == nil {
|
|
config.WebhookPort = p
|
|
}
|
|
}
|
|
|
|
// Allowed users (comma-separated list of user IDs)
|
|
if allowedStr := os.Getenv("TELEGRAM_ALLOWED_USERS"); allowedStr != "" {
|
|
for _, idStr := range strings.Split(allowedStr, ",") {
|
|
idStr = strings.TrimSpace(idStr)
|
|
if id, err := strconv.ParseInt(idStr, 10, 64); err == nil {
|
|
config.AllowedUserIDs = append(config.AllowedUserIDs, id)
|
|
}
|
|
}
|
|
}
|
|
|
|
// Admin users
|
|
if adminStr := os.Getenv("TELEGRAM_ADMIN_USERS"); adminStr != "" {
|
|
for _, idStr := range strings.Split(adminStr, ",") {
|
|
idStr = strings.TrimSpace(idStr)
|
|
if id, err := strconv.ParseInt(idStr, 10, 64); err == nil {
|
|
config.AdminUserIDs = append(config.AdminUserIDs, id)
|
|
}
|
|
}
|
|
}
|
|
|
|
// Rate limiting
|
|
if rateStr := os.Getenv("TELEGRAM_RATE_LIMIT"); rateStr != "" {
|
|
if rate, err := strconv.Atoi(rateStr); err == nil {
|
|
config.MaxMessagesPerMinute = rate
|
|
}
|
|
}
|
|
|
|
// Language
|
|
if lang := os.Getenv("TELEGRAM_LANGUAGE"); lang != "" {
|
|
config.DefaultLanguage = lang
|
|
}
|
|
|
|
return config
|
|
}
|