feat(inboxes): align whatsapp health endpoints

This commit is contained in:
2026-06-05 22:25:04 +08:00
parent 3fc275b639
commit af9e1eb711
6 changed files with 276 additions and 272 deletions
+15 -4
View File
@@ -2,6 +2,7 @@ package v1
import (
"encoding/json"
"errors"
"io"
"net/http"
"strconv"
@@ -623,6 +624,10 @@ func (h *InboxHandler) Health(c *gin.Context) {
result, svcErr := h.svc.Health(c.Request.Context(), accountID, inboxID)
if svcErr != nil {
if errors.Is(svcErr, service.ErrInboxHealthWhatsAppCloudOnly) {
c.JSON(http.StatusBadRequest, gin.H{"error": service.InboxHealthWhatsAppCloudOnlyMessage})
return
}
handleServiceError(c, svcErr)
return
}
@@ -677,9 +682,11 @@ func (h *InboxHandler) RegisterWebhook(c *gin.Context) {
}
var req service.RegisterWebhookRequest
if err := c.ShouldBindJSON(&req); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid request body: " + err.Error()})
return
if c.Request.Body != nil && c.Request.ContentLength != 0 {
if err := c.ShouldBindJSON(&req); err != nil {
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")
@@ -688,11 +695,15 @@ func (h *InboxHandler) RegisterWebhook(c *gin.Context) {
svcErr := h.svc.RegisterWebhook(c.Request.Context(), accountID, inboxID, req)
if svcErr != nil {
if errors.Is(svcErr, service.ErrInboxHealthWhatsAppCloudOnly) {
c.JSON(http.StatusBadRequest, gin.H{"error": service.InboxHealthWhatsAppCloudOnlyMessage})
return
}
handleServiceError(c, svcErr)
return
}
c.JSON(http.StatusOK, gin.H{"message": "webhook registered successfully"})
c.JSON(http.StatusOK, gin.H{"message": "Webhook registered successfully"})
}
// GetAgentBot retrieves the currently active agent bot for an inbox.