feat(routes): close first chatwoot parity gaps
This commit is contained in:
@@ -18,7 +18,7 @@ import (
|
||||
// Reference: Chatwoot app/controllers/api/v1/conversations_controller.rb
|
||||
type ConversationHandler struct {
|
||||
conversationSvc *service.ConversationService
|
||||
messageSvc *service.MessageService
|
||||
messageSvc *service.MessageService
|
||||
}
|
||||
|
||||
// NewConversationHandler creates a new ConversationHandler.
|
||||
@@ -459,7 +459,7 @@ func (h *ConversationHandler) UpdatePriority(c *gin.Context) {
|
||||
}
|
||||
|
||||
var req struct {
|
||||
Priority string `json:"priority" binding:"required,oneof=urgent high medium low"`
|
||||
Priority string `json:"priority" binding:"required,oneof=urgent high medium low none"`
|
||||
}
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
response.AbortWithStatusError(c, http.StatusBadRequest, response.ErrValidation, err.Error())
|
||||
@@ -474,6 +474,40 @@ func (h *ConversationHandler) UpdatePriority(c *gin.Context) {
|
||||
response.OK(c, conversation)
|
||||
}
|
||||
|
||||
// TogglePriority updates a conversation priority using Chatwoot's member action path.
|
||||
// POST /api/v1/accounts/:account_id/conversations/:conversation_id/toggle_priority
|
||||
// Reference: Chatwoot conversations#toggle_priority returns head :ok.
|
||||
func (h *ConversationHandler) TogglePriority(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
|
||||
}
|
||||
|
||||
var req struct {
|
||||
Priority *string `json:"priority"`
|
||||
}
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
response.AbortWithStatusError(c, http.StatusBadRequest, response.ErrValidation, err.Error())
|
||||
return
|
||||
}
|
||||
priority := ""
|
||||
if req.Priority != nil {
|
||||
priority = *req.Priority
|
||||
}
|
||||
|
||||
if _, svcErr := h.conversationSvc.UpdatePriority(c.Request.Context(), accountID, conversationID, priority); svcErr != nil {
|
||||
handleServiceError(c, svcErr)
|
||||
return
|
||||
}
|
||||
c.Status(http.StatusOK)
|
||||
}
|
||||
|
||||
// ListMessages lists messages in a conversation.
|
||||
// GET /api/v1/accounts/:account_id/conversations/:conversation_id/messages
|
||||
func (h *ConversationHandler) ListMessages(c *gin.Context) {
|
||||
@@ -781,4 +815,4 @@ func (h *ConversationHandler) UnreadCounts(c *gin.Context) {
|
||||
}
|
||||
|
||||
response.OK(c, payload)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user