feat: send-proactive 消息记入平台日志 — ethend可见

This commit is contained in:
2026-06-23 21:42:23 +08:00
parent 3a5591833f
commit cdfe440044
2 changed files with 26 additions and 0 deletions
+13
View File
@@ -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)
@@ -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": "消息已发送",