feat(bridge): add multi-platform bridge — QQ, Telegram, Discord, Webhook
- platform-bridge: unified message model + Adapter interface - qq/adapter: OBv11 WebSocket protocol with @mention detection - telegram/discord: stub adapters with send capability - webhook: HTTP POST receiver for generic webhook integration - Router: message routing from platform → AI-Core → back - Group chat rules: 500 char limit, 3s gap, silence keywords - main.go: conditional adapter loading via env vars
This commit is contained in:
1 parent
7e3ec8da93
commit
17ef73bcbe
7 files changed
+460
No files matched your search
@@ -10,6 +10,7 @@ import (
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"git.yeij.top/AskaEth/Cyrene_v2/internal/config"
|
||||
"git.yeij.top/AskaEth/Cyrene_v2/internal/db"
|
||||
@@ -38,6 +39,11 @@ import (
|
||||
"git.yeij.top/AskaEth/Cyrene_v2/services/gateway/api"
|
||||
"git.yeij.top/AskaEth/Cyrene_v2/services/gateway/ws"
|
||||
"git.yeij.top/AskaEth/Cyrene_v2/services/memory"
|
||||
bridge "git.yeij.top/AskaEth/Cyrene_v2/services/platform-bridge"
|
||||
bridgeqq "git.yeij.top/AskaEth/Cyrene_v2/services/platform-bridge/qq"
|
||||
bridgetg "git.yeij.top/AskaEth/Cyrene_v2/services/platform-bridge/telegram"
|
||||
bridgedc "git.yeij.top/AskaEth/Cyrene_v2/services/platform-bridge/discord"
|
||||
bridgewh "git.yeij.top/AskaEth/Cyrene_v2/services/platform-bridge/webhook"
|
||||
voicesvc "git.yeij.top/AskaEth/Cyrene_v2/services/voice"
|
||||
)
|
||||
|
||||
@@ -175,6 +181,51 @@ func main() {
|
||||
orch := orchestrator.NewPipeline(llmSelector, semanticCache, ctxStore, subMgr, personaInjector)
|
||||
log.Printf("[orchestrator] pipeline ready")
|
||||
|
||||
// === 11.5 Platform Bridge ===
|
||||
bridgeRouter := bridge.NewRouter()
|
||||
// QQ adapter — enabled when OBv11 WebSocket URL is configured
|
||||
if qqURL := os.Getenv("QQ_OBV11_WS_URL"); qqURL != "" {
|
||||
qqAdapter := bridgeqq.New(bridgeqq.Config{
|
||||
Name: "qq-main", WSURL: qqURL,
|
||||
AccessToken: os.Getenv("QQ_ACCESS_TOKEN"),
|
||||
BotQQ: os.Getenv("QQ_BOT_QQ"),
|
||||
})
|
||||
bridgeRouter.Register(qqAdapter)
|
||||
}
|
||||
// Telegram
|
||||
if tgToken := os.Getenv("TG_BOT_TOKEN"); tgToken != "" {
|
||||
bridgeRouter.Register(bridgetg.New(bridgetg.Config{Name: "tg-main", Token: tgToken}))
|
||||
}
|
||||
// Discord
|
||||
if dcToken := os.Getenv("DC_BOT_TOKEN"); dcToken != "" {
|
||||
bridgeRouter.Register(bridgedc.New(bridgedc.Config{Name: "dc-main", Token: dcToken}))
|
||||
}
|
||||
// Webhook
|
||||
if whAddr := os.Getenv("WEBHOOK_LISTEN_ADDR"); whAddr != "" {
|
||||
bridgeRouter.Register(bridgewh.New(bridgewh.Config{Name: "webhook-main", ListenAddr: whAddr}))
|
||||
}
|
||||
|
||||
// Route incoming messages to orchestrator
|
||||
bridgeRouter.SetMessageHandler(func(msg *bridge.UnifiedMessage) {
|
||||
log.Printf("[bridge] incoming %s from %s: %s", msg.Platform, msg.SenderName, msg.Content)
|
||||
tokenCh, _, err := orch.ProcessInput(context.Background(), "bridge-"+msg.Source, msg.Content)
|
||||
if err != nil {
|
||||
log.Printf("[bridge] orchestrator error: %v", err)
|
||||
return
|
||||
}
|
||||
var fullContent string
|
||||
for token := range tokenCh {
|
||||
fullContent += token.Content
|
||||
}
|
||||
if fullContent != "" {
|
||||
bridgeRouter.SendTo(msg.Platform, msg.Source, fullContent, bridge.SendOptions{
|
||||
MaxLength: 500, MinGap: 3 * time.Second,
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
bridgeRouter.StartAll(); log.Printf("[bridge] platform bridge ready")
|
||||
|
||||
// === 12. Gateway ===
|
||||
userStore := api.NewMemUserStore(cfg.AdminPassword)
|
||||
authMgr := api.NewRealAuthManager(cfg.JWTSecret, cfg.JWTExpiryHours, userStore)
|
||||
|
||||
Reference in new issue
Block a user