mirror of
https://github.com/NoFxAiOS/nofx.git
synced 2026-07-14 08:16:56 +08:00
feat(telegram): add AI agent bot with streaming and account context
- Add Telegram bot with long-polling and AI agent loop (api_call tool)
- SSE streaming with real-time message editing and ⏳ placeholder
- Account state injection at conversation start (models, exchanges,
strategies, traders, per-trader PnL and statistics)
- Lane semaphore per chat serializes concurrent messages (60s timeout)
- Idle timeout watchdog (60s) prevents hung streaming connections
- Look-ahead buffer prevents partial <api_call> tag leaking to user
- Fix PUT /strategies/:id to merge config (read-then-merge pattern)
- Add route registry with full API schema for LLM documentation
- Add TelegramConfig store and Web UI config modal
- Add GetAnyEnabled to AIModel store for bot LLM client selection
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"nofx/experience"
|
||||
"nofx/mcp"
|
||||
"os"
|
||||
@@ -44,6 +45,10 @@ type Config struct {
|
||||
AlpacaAPIKey string // Alpaca API key for US stocks
|
||||
AlpacaSecretKey string // Alpaca secret key
|
||||
TwelveDataKey string // TwelveData API key for forex & metals
|
||||
|
||||
// Telegram Bot configuration
|
||||
TelegramBotToken string // TELEGRAM_BOT_TOKEN (required to enable bot)
|
||||
TelegramAdminChatID int64 // TELEGRAM_ADMIN_CHAT_ID (optional, 0 = auto-bind on first /start)
|
||||
}
|
||||
|
||||
// Init initializes global configuration (from .env)
|
||||
@@ -104,6 +109,17 @@ func Init() {
|
||||
cfg.AlpacaSecretKey = os.Getenv("ALPACA_SECRET_KEY")
|
||||
cfg.TwelveDataKey = os.Getenv("TWELVEDATA_API_KEY")
|
||||
|
||||
// Telegram Bot configuration
|
||||
cfg.TelegramBotToken = os.Getenv("TELEGRAM_BOT_TOKEN")
|
||||
if chatIDStr := os.Getenv("TELEGRAM_ADMIN_CHAT_ID"); chatIDStr != "" {
|
||||
if id, err := strconv.ParseInt(chatIDStr, 10, 64); err == nil {
|
||||
cfg.TelegramAdminChatID = id
|
||||
} else {
|
||||
// logger may not be init yet, use fmt
|
||||
fmt.Printf("WARNING: TELEGRAM_ADMIN_CHAT_ID invalid value %q, ignoring: %v\n", chatIDStr, err)
|
||||
}
|
||||
}
|
||||
|
||||
// Database configuration
|
||||
if v := os.Getenv("DB_TYPE"); v != "" {
|
||||
cfg.DBType = strings.ToLower(v)
|
||||
|
||||
Reference in New Issue
Block a user