feat(channels): align whatsapp calling toggles

This commit is contained in:
2026-06-06 20:10:06 +08:00
parent 0277898979
commit e2fdb8a171
12 changed files with 436 additions and 10 deletions
+54
View File
@@ -749,6 +749,60 @@ func (h *InboxHandler) RegisterWebhook(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{"message": "Webhook registered successfully"})
}
// EnableWhatsAppCalling enables WhatsApp Calling for a Cloud API inbox.
// POST /api/v1/accounts/:id/inboxes/:inbox_id/enable_whatsapp_calling
// Reference: Enterprise::Api::V1::Accounts::InboxesController#enable_whatsapp_calling
func (h *InboxHandler) EnableWhatsAppCalling(c *gin.Context) {
h.handleWhatsAppCallingToggle(c, true)
}
// DisableWhatsAppCalling disables WhatsApp Calling for a Cloud API inbox.
// POST /api/v1/accounts/:id/inboxes/:inbox_id/disable_whatsapp_calling
// Reference: Enterprise::Api::V1::Accounts::InboxesController#disable_whatsapp_calling
func (h *InboxHandler) DisableWhatsAppCalling(c *gin.Context) {
h.handleWhatsAppCallingToggle(c, false)
}
func (h *InboxHandler) handleWhatsAppCallingToggle(c *gin.Context, enable bool) {
accountID := parseAccountIDParam(c)
if accountID == 0 {
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid account id"})
return
}
inboxID, err := parseUintParam(c, "inbox_id")
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid inbox id"})
return
}
if !h.svc.Ready() {
response.AbortWithStatusError(c, http.StatusUnprocessableEntity, response.ErrInternal, "failed to update WhatsApp calling")
return
}
var svcErr error
if enable {
svcErr = h.svc.EnableWhatsAppCalling(c.Request.Context(), accountID, inboxID)
} else {
svcErr = h.svc.DisableWhatsAppCalling(c.Request.Context(), accountID, inboxID)
}
if svcErr != nil {
if errors.Is(svcErr, service.ErrInboxWhatsAppCallingUnsupported) || errors.Is(svcErr, service.ErrInboxWhatsAppCallingFeatureRequired) {
c.JSON(http.StatusUnprocessableEntity, gin.H{"error": svcErr.Error()})
return
}
if strings.Contains(strings.ToLower(svcErr.Error()), "not found") {
handleServiceError(c, svcErr)
return
}
c.JSON(http.StatusUnprocessableEntity, gin.H{"error": svcErr.Error()})
return
}
c.Status(http.StatusOK)
}
// GetAgentBot retrieves the currently active agent bot for an inbox.
// GET /api/v1/accounts/:id/inboxes/:inbox_id/agent_bot
// Reference: Chatwoot InboxesController#agent_bot