mirror of
https://github.com/NoFxAiOS/nofx.git
synced 2026-07-18 01:44:38 +08:00
feat: Add Telegram AI Assistant (moltbot-nofx integration)
- 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
This commit is contained in:
60
telegram/config.go
Normal file
60
telegram/config.go
Normal file
@@ -0,0 +1,60 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user