chore: stabilize chatwoot parity baseline
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/gochat/gochat/internal/service"
|
||||
"github.com/gochat/gochat/pkg/response"
|
||||
)
|
||||
|
||||
// InboxHandler handles inbox-related API endpoints.
|
||||
@@ -224,8 +225,8 @@ func (h *InboxHandler) Delete(c *gin.Context) {
|
||||
// POST /api/v1/accounts/:id/inboxes/:inbox_id/set_agent_bot
|
||||
// Reference: Chatwoot InboxesController#set_agent_bot
|
||||
func (h *InboxHandler) SetAgentBot(c *gin.Context) {
|
||||
accountID, err := parseUintParam(c, "id")
|
||||
if err != nil {
|
||||
accountID := parseAccountIDParam(c)
|
||||
if accountID == 0 {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid account id"})
|
||||
return
|
||||
}
|
||||
@@ -241,6 +242,10 @@ func (h *InboxHandler) SetAgentBot(c *gin.Context) {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid request body: " + err.Error()})
|
||||
return
|
||||
}
|
||||
if !h.svc.Ready() {
|
||||
response.AbortWithStatusError(c, http.StatusUnprocessableEntity, response.ErrInternal, "failed to set agent bot")
|
||||
return
|
||||
}
|
||||
|
||||
binding, svcErr := h.svc.SetAgentBot(c.Request.Context(), accountID, inboxID, req)
|
||||
if svcErr != nil {
|
||||
@@ -261,8 +266,8 @@ func (h *InboxHandler) SetAgentBot(c *gin.Context) {
|
||||
// GET /api/v1/accounts/:id/inboxes/:inbox_id/health
|
||||
// Reference: Chatwoot InboxesController#health
|
||||
func (h *InboxHandler) Health(c *gin.Context) {
|
||||
accountID, err := parseUintParam(c, "id")
|
||||
if err != nil {
|
||||
accountID := parseAccountIDParam(c)
|
||||
if accountID == 0 {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid account id"})
|
||||
return
|
||||
}
|
||||
@@ -273,6 +278,11 @@ func (h *InboxHandler) Health(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
if !h.svc.Ready() {
|
||||
response.AbortWithStatusError(c, http.StatusUnprocessableEntity, response.ErrInternal, "failed to check inbox health")
|
||||
return
|
||||
}
|
||||
|
||||
result, svcErr := h.svc.Health(c.Request.Context(), accountID, inboxID)
|
||||
if svcErr != nil {
|
||||
handleServiceError(c, svcErr)
|
||||
@@ -286,8 +296,8 @@ func (h *InboxHandler) Health(c *gin.Context) {
|
||||
// POST /api/v1/accounts/:id/inboxes/:inbox_id/sync_templates
|
||||
// Reference: Chatwoot InboxesController#sync_templates
|
||||
func (h *InboxHandler) SyncTemplates(c *gin.Context) {
|
||||
accountID, err := parseUintParam(c, "id")
|
||||
if err != nil {
|
||||
accountID := parseAccountIDParam(c)
|
||||
if accountID == 0 {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid account id"})
|
||||
return
|
||||
}
|
||||
@@ -298,6 +308,11 @@ func (h *InboxHandler) SyncTemplates(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
if !h.svc.Ready() {
|
||||
response.AbortWithStatusError(c, http.StatusUnprocessableEntity, response.ErrInternal, "failed to sync templates")
|
||||
return
|
||||
}
|
||||
|
||||
templates, svcErr := h.svc.SyncTemplates(c.Request.Context(), accountID, inboxID)
|
||||
if svcErr != nil {
|
||||
handleServiceError(c, svcErr)
|
||||
@@ -311,8 +326,8 @@ func (h *InboxHandler) SyncTemplates(c *gin.Context) {
|
||||
// POST /api/v1/accounts/:id/inboxes/:inbox_id/register_webhook
|
||||
// Reference: Chatwoot InboxesController#register_webhook
|
||||
func (h *InboxHandler) RegisterWebhook(c *gin.Context) {
|
||||
accountID, err := parseUintParam(c, "id")
|
||||
if err != nil {
|
||||
accountID := parseAccountIDParam(c)
|
||||
if accountID == 0 {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid account id"})
|
||||
return
|
||||
}
|
||||
@@ -328,6 +343,10 @@ func (h *InboxHandler) RegisterWebhook(c *gin.Context) {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid request body: " + err.Error()})
|
||||
return
|
||||
}
|
||||
if !h.svc.Ready() {
|
||||
response.AbortWithStatusError(c, http.StatusUnprocessableEntity, response.ErrInternal, "failed to register webhook")
|
||||
return
|
||||
}
|
||||
|
||||
svcErr := h.svc.RegisterWebhook(c.Request.Context(), accountID, inboxID, req)
|
||||
if svcErr != nil {
|
||||
@@ -342,8 +361,8 @@ func (h *InboxHandler) RegisterWebhook(c *gin.Context) {
|
||||
// GET /api/v1/accounts/:id/inboxes/:inbox_id/agent_bot
|
||||
// Reference: Chatwoot InboxesController#agent_bot
|
||||
func (h *InboxHandler) GetAgentBot(c *gin.Context) {
|
||||
accountID, err := parseUintParam(c, "id")
|
||||
if err != nil {
|
||||
accountID := parseAccountIDParam(c)
|
||||
if accountID == 0 {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid account id"})
|
||||
return
|
||||
}
|
||||
@@ -354,6 +373,11 @@ func (h *InboxHandler) GetAgentBot(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
if !h.svc.Ready() {
|
||||
response.AbortWithStatusError(c, http.StatusUnprocessableEntity, response.ErrInternal, "failed to get agent bot")
|
||||
return
|
||||
}
|
||||
|
||||
agentBot, svcErr := h.svc.GetAgentBot(c.Request.Context(), accountID, inboxID)
|
||||
if svcErr != nil {
|
||||
handleServiceError(c, svcErr)
|
||||
@@ -372,8 +396,8 @@ func (h *InboxHandler) GetAgentBot(c *gin.Context) {
|
||||
// DELETE /api/v1/accounts/:id/inboxes/:inbox_id/avatar
|
||||
// Reference: Chatwoot InboxesController#destroy_avatar
|
||||
func (h *InboxHandler) DeleteAvatar(c *gin.Context) {
|
||||
accountID, err := parseUintParam(c, "id")
|
||||
if err != nil {
|
||||
accountID := parseAccountIDParam(c)
|
||||
if accountID == 0 {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid account id"})
|
||||
return
|
||||
}
|
||||
@@ -384,6 +408,11 @@ func (h *InboxHandler) DeleteAvatar(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
if !h.svc.Ready() {
|
||||
response.AbortWithStatusError(c, http.StatusUnprocessableEntity, response.ErrInternal, "failed to delete inbox avatar")
|
||||
return
|
||||
}
|
||||
|
||||
inbox, svcErr := h.svc.DeleteAvatar(c.Request.Context(), accountID, inboxID)
|
||||
if svcErr != nil {
|
||||
handleServiceError(c, svcErr)
|
||||
@@ -397,8 +426,8 @@ func (h *InboxHandler) DeleteAvatar(c *gin.Context) {
|
||||
// GET /api/v1/accounts/:id/inboxes/:inbox_id/campaigns
|
||||
// Reference: Chatwoot InboxesController#campaigns
|
||||
func (h *InboxHandler) ListCampaigns(c *gin.Context) {
|
||||
accountID, err := parseUintParam(c, "id")
|
||||
if err != nil {
|
||||
accountID := parseAccountIDParam(c)
|
||||
if accountID == 0 {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid account id"})
|
||||
return
|
||||
}
|
||||
@@ -409,6 +438,11 @@ func (h *InboxHandler) ListCampaigns(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
if !h.svc.Ready() {
|
||||
response.AbortWithStatusError(c, http.StatusUnprocessableEntity, response.ErrInternal, "failed to list campaigns")
|
||||
return
|
||||
}
|
||||
|
||||
campaigns, svcErr := h.svc.ListCampaigns(c.Request.Context(), accountID, inboxID)
|
||||
if svcErr != nil {
|
||||
handleServiceError(c, svcErr)
|
||||
@@ -441,4 +475,4 @@ func (h *InboxHandler) ResetSecret(c *gin.Context) {
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, inbox)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user