diff --git a/internal/services/callback.go b/internal/services/callback.go index 13d3d54..415f7cb 100644 --- a/internal/services/callback.go +++ b/internal/services/callback.go @@ -48,8 +48,9 @@ type Envelope struct { // bug_optimization_submit 工单回调 const ( - ActionBugOptimizationSubmitDone = "bug_optimization_submit_done" // 工单完成回调 - ActionBugOptimizationSubmitUpdate = "bug_optimization_submit_update" // 工单更新回调 + ActionBugOptimizationSubmitProcess = "bug_optimization_submit_process" // 工单过程回调 + ActionBugOptimizationSubmitDone = "bug_optimization_submit_done" // 工单完成回调 + ActionBugOptimizationSubmitUpdate = "bug_optimization_submit_update" // 工单更新回调 ) // BugOptimizationSubmitDoneData 工单完成回调数据 @@ -167,6 +168,18 @@ func (s *CallbackService) handleDingTalkCallback(c *fiber.Ctx, env Envelope) err // 删除映射 s.botTool.DelTaskMapping(env.TaskID) + return c.JSON(fiber.Map{"code": 0, "message": "ok"}) + case ActionBugOptimizationSubmitProcess: + type processData struct { + Process string `json:"process"` + } + var data processData + if err := json.Unmarshal(env.Data, &data); err != nil { + return errorcode.ParamErr("invalid json: %v", err) + } + + s.sendStreamLoading(sessionID, data.Process) + return c.JSON(fiber.Map{"code": 0, "message": "ok"}) default: return errorcode.ParamErr("unknown action: %s", env.Action) @@ -194,6 +207,10 @@ func (s *CallbackService) getDingtalkReceivers(ctx context.Context, receiverIds // sendStreamLog 发送流式日志 func (s *CallbackService) sendStreamLog(sessionID string, content string) { + if content == "" { + return + } + streamLog := entitys.Response{ Index: constants.BotToolsBugOptimizationSubmit, Content: content, @@ -205,6 +222,10 @@ func (s *CallbackService) sendStreamLog(sessionID string, content string) { // sendStreamTxt 发送流式文本 func (s *CallbackService) sendStreamTxt(sessionID string, content string) { + if content == "" { + return + } + streamLog := entitys.Response{ Index: constants.BotToolsBugOptimizationSubmit, Content: content, @@ -214,6 +235,21 @@ func (s *CallbackService) sendStreamTxt(sessionID string, content string) { s.gateway.SendToUid(sessionID, streamLogBytes) } +// sendStreamLoading 发送流式加载过程 +func (s *CallbackService) sendStreamLoading(sessionID string, content string) { + if content == "" { + return + } + + streamLog := entitys.Response{ + Index: constants.BotToolsBugOptimizationSubmit, + Content: content, + Type: entitys.ResponseLoading, + } + streamLogBytes := pkg.JsonByteIgonErr(streamLog) + s.gateway.SendToUid(sessionID, streamLogBytes) +} + // handleBugOptimizationSubmitUpdate 处理 bug 优化提交更新回调 func (s *CallbackService) handleBugOptimizationSubmitUpdate(ctx context.Context, taskData json.RawMessage) (string, *errorcode.BusinessErr) { var data BugOptimizationSubmitUpdateData