diff --git a/backend/platform-bridge/cmd/main.go b/backend/platform-bridge/cmd/main.go index b788a0e..015947a 100644 --- a/backend/platform-bridge/cmd/main.go +++ b/backend/platform-bridge/cmd/main.go @@ -281,6 +281,19 @@ func main() { // Setup HTTP server. mux := http.NewServeMux() bh := handler.NewBridgeHandler(router) + bh.SetLogFunc(func(platform, channelID, senderID, content string, success bool) { + msgLogger.Log(logging.LogEntry{ + Timestamp: time.Now(), + Direction: "outgoing", + Platform: platform, + ChannelID: channelID, + SenderID: senderID, + SenderName: "Cyrene", + Content: content, + ContentType: "text", + Success: success, + }) + }) bh.RegisterRoutes(mux) bh.StartChannelRefresh(10 * time.Minute) diff --git a/backend/platform-bridge/internal/handler/bridge_handler.go b/backend/platform-bridge/internal/handler/bridge_handler.go index 3d26837..1db4e9e 100644 --- a/backend/platform-bridge/internal/handler/bridge_handler.go +++ b/backend/platform-bridge/internal/handler/bridge_handler.go @@ -18,6 +18,7 @@ type BridgeHandler struct { internalToken string channelsMu sync.RWMutex cachedChannels []bridge.ChannelInfo + logFn func(platform, channelID, senderID, content string, success bool) // outgoing message logger } func NewBridgeHandler(router *bridge.PlatformRouter) *BridgeHandler { @@ -27,6 +28,11 @@ func NewBridgeHandler(router *bridge.PlatformRouter) *BridgeHandler { } } +// SetLogFunc sets the outgoing message logger callback. +func (h *BridgeHandler) SetLogFunc(fn func(platform, channelID, senderID, content string, success bool)) { + h.logFn = fn +} + func (h *BridgeHandler) RegisterRoutes(mux *http.ServeMux) { mux.HandleFunc("/health", h.health) mux.HandleFunc("/api/v1/platforms", h.listPlatforms) @@ -220,6 +226,13 @@ func (h *BridgeHandler) sendProactive(w http.ResponseWriter, r *http.Request) { log.Printf("[send-proactive] 已发送: adapter=%s chat=%s user=%d group=%d at=%s len=%d", adapterName, msgType, userID, groupID, req.AtUserID, len(content)) + if h.logFn != nil { + chID := req.GroupID + if msgType == "private" { + chID = req.UserID + } + h.logFn(req.Platform, chID, "Cyrene", content, true) + } writeJSON(w, http.StatusOK, map[string]interface{}{ "success": true, "message": "消息已发送",