Files
customer-server/controller/ragflow_controller.go
2026-03-14 10:02:49 +08:00

65 lines
1.6 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Package controller - RAGFlow控制器
// 功能接收来自外部的RAGFlow请求测试/调试用)
package controller
import (
"customer-server/consumer"
"gitea.com/red-future/common/redis"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/net/ghttp"
)
type ragflow struct{}
var RAGFlow = new(ragflow)
// Process 处理RAGFlow请求
// 参数: r - HTTP请求对象
// 功能: 接收外部RAGFlow消息请求直接调用consumer处理逻辑用于测试
// 注意: 正常流程不经过此接口而是直接消费Redis Stream
func (c *ragflow) Process(r *ghttp.Request) {
ctx := r.Context()
// 调试:打印原始请求体
bodyBytes := r.GetBody()
g.Log().Infof(ctx, "收到原始请求体: %s", string(bodyBytes))
var req redis.SendStreamMessage
if err := r.Parse(&req); err != nil {
r.Response.WriteJsonExit(g.Map{
"code": 400,
"msg": "参数错误: " + err.Error(),
})
return
}
g.Log().Infof(ctx, "收到RAGFlow请求 - 用户: %s, 内容: %s", req.UserId, req.Content)
// 直接调用consumer的处理逻辑
message := map[string]interface{}{
"UserId": req.UserId,
"Content": req.Content,
"MessageId": req.MessageId,
"Platform": req.Platform,
"TenantId": req.TenantId,
"AccountName": req.AccountName,
"ChatId": req.ChatId,
"ReplyQueue": req.ReplyQueue,
"History": req.History,
}
if err := consumer.HandleMessageHTTP(ctx, message); err != nil {
r.Response.WriteJsonExit(g.Map{
"code": 500,
"msg": "处理失败: " + err.Error(),
})
return
}
r.Response.WriteJsonExit(g.Map{
"code": 0,
"msg": "success",
})
}