feat(inboxes): align whatsapp health endpoints
This commit is contained in:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user