feat(captain): align task payload persistence
This commit is contained in:
@@ -30,6 +30,22 @@ func (h *CaptainTaskExtendedHandler) LabelSuggestion(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
if c.Request.Method == http.MethodPost {
|
||||
var req service.ChatwootLabelSuggestionRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
response.AbortWithStatusError(c, http.StatusBadRequest, response.ErrBadRequest, "invalid request body: "+err.Error())
|
||||
return
|
||||
}
|
||||
result, err := h.svc.LabelSuggestion(c.Request.Context(), uint(accountID), &req)
|
||||
if err != nil {
|
||||
applogger.L().Errorf("Label suggestion: %v", err)
|
||||
renderCaptainTaskError(c, err)
|
||||
return
|
||||
}
|
||||
renderCaptainExtendedTaskResult(c, result)
|
||||
return
|
||||
}
|
||||
|
||||
// Parse conversation_ids from query param (comma-separated)
|
||||
convIDsStr := c.Query("conversation_ids")
|
||||
if convIDsStr == "" {
|
||||
@@ -69,6 +85,22 @@ func (h *CaptainTaskExtendedHandler) FollowUp(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
if c.Request.Method == http.MethodPost {
|
||||
var req service.ChatwootFollowUpRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
response.AbortWithStatusError(c, http.StatusBadRequest, response.ErrBadRequest, "invalid request body: "+err.Error())
|
||||
return
|
||||
}
|
||||
result, err := h.svc.FollowUp(c.Request.Context(), uint(accountID), &req)
|
||||
if err != nil {
|
||||
applogger.L().Errorf("Follow-up: %v", err)
|
||||
renderCaptainTaskError(c, err)
|
||||
return
|
||||
}
|
||||
renderCaptainExtendedTaskResult(c, result)
|
||||
return
|
||||
}
|
||||
|
||||
convIDsStr := c.Query("conversation_ids")
|
||||
if convIDsStr == "" {
|
||||
response.AbortWithStatusError(c, http.StatusBadRequest, response.ErrValidation, "conversation_ids required")
|
||||
@@ -98,6 +130,18 @@ func (h *CaptainTaskExtendedHandler) FollowUp(c *gin.Context) {
|
||||
response.OK(c, result)
|
||||
}
|
||||
|
||||
func renderCaptainExtendedTaskResult(c *gin.Context, result *service.ChatwootTaskResult) {
|
||||
if result == nil || result.Message == nil {
|
||||
c.JSON(http.StatusOK, gin.H{"message": nil})
|
||||
return
|
||||
}
|
||||
payload := gin.H{"message": *result.Message}
|
||||
if result.FollowUpContext != nil {
|
||||
payload["follow_up_context"] = result.FollowUpContext
|
||||
}
|
||||
c.JSON(http.StatusOK, payload)
|
||||
}
|
||||
|
||||
// parseUintSlice parses a comma-separated string of uint values.
|
||||
func parseUintSlice(s string) ([]uint, error) {
|
||||
parts := strings.Split(s, ",")
|
||||
@@ -114,4 +158,4 @@ func parseUintSlice(s string) ([]uint, error) {
|
||||
result = append(result, uint(v))
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user