Align GoChat with Chatwoot frontend contracts

This commit is contained in:
2026-06-13 22:13:32 +08:00
parent 71abf58636
commit d884fdda0a
162 changed files with 9825 additions and 528 deletions
@@ -450,7 +450,28 @@ func (h *ConversationHandler) UpdateLabels(c *gin.Context) {
handleServiceError(c, svcErr)
return
}
c.JSON(http.StatusOK, serializeConversation(h.requestContext(c), h.conversationSvc.DB(), conversation))
c.JSON(http.StatusOK, gin.H{"payload": gin.H{"conversationId": strconv.FormatUint(uint64(conversation.ID), 10), "labels": labelList(conversation.Labels)}})
}
// GetLabels returns the labels assigned to a conversation.
// GET /api/v1/accounts/:account_id/conversations/:conversation_id/labels
// Reference: Chatwoot dashboard conversationLabels store expects { payload: [] }.
func (h *ConversationHandler) GetLabels(c *gin.Context) {
accountID, err := parseUintParam(c, "account_id")
if err != nil {
response.AbortWithStatusError(c, http.StatusBadRequest, response.ErrBadRequest, "invalid account_id")
return
}
conversationID, err := parseUintParam(c, "conversation_id")
if err != nil {
response.AbortWithStatusError(c, http.StatusBadRequest, response.ErrBadRequest, "invalid conversation id")
return
}
conversation, ok := h.resolveConversationRoute(c, accountID, conversationID)
if !ok {
return
}
c.JSON(http.StatusOK, gin.H{"payload": labelList(conversation.Labels)})
}
// @Summary Search conversations
@@ -993,26 +1014,31 @@ func (h *ConversationHandler) AssignTeam(c *gin.Context) {
}
var req struct {
AgentID *uint `json:"agent_id"`
TeamID *uint `json:"team_id"`
AgentID *uint `json:"agent_id"`
AssigneeID *uint `json:"assignee_id"`
TeamID *uint `json:"team_id"`
}
if err := c.ShouldBindJSON(&req); err != nil {
response.AbortWithStatusError(c, http.StatusBadRequest, response.ErrValidation, err.Error())
return
}
agentID := req.AgentID
if agentID == nil {
agentID = req.AssigneeID
}
conversation, ok := h.resolveConversationRoute(c, accountID, conversationID)
if !ok {
return
}
conversation, svcErr := h.conversationSvc.AssignTeam(c.Request.Context(), accountID, conversation.ID, req.AgentID, req.TeamID)
conversation, svcErr := h.conversationSvc.AssignTeam(c.Request.Context(), accountID, conversation.ID, agentID, req.TeamID)
if svcErr != nil {
handleServiceError(c, svcErr)
return
}
if req.AgentID != nil {
c.JSON(http.StatusOK, serializeUserFromDB(c.Request.Context(), h.conversationSvc.DB(), *req.AgentID, accountID))
if agentID != nil {
c.JSON(http.StatusOK, serializeUserFromDB(c.Request.Context(), h.conversationSvc.DB(), *agentID, accountID))
return
}
if req.TeamID != nil {
@@ -1034,7 +1060,7 @@ func handleServiceError(c *gin.Context, err error) {
response.AbortWithStatusError(c, http.StatusNotFound, response.ErrNotFound, errMsg)
return
}
if strings.Contains(lower, "invalid") || strings.Contains(lower, "validation") || strings.Contains(lower, "required") {
if strings.Contains(lower, "invalid") || strings.Contains(lower, "validation") || strings.Contains(lower, "required") || strings.Contains(lower, "unsupported file type") || strings.Contains(lower, "mime type") || strings.Contains(lower, "file size") {
response.AbortWithStatusError(c, http.StatusBadRequest, response.ErrValidation, errMsg)
return
}