feat(channels): align whatsapp authorization

This commit is contained in:
2026-06-06 19:37:51 +08:00
parent a5a28ce73e
commit 0277898979
8 changed files with 582 additions and 8 deletions
+38
View File
@@ -153,6 +153,44 @@ func (h *InboxHandler) Create(c *gin.Context) {
c.JSON(http.StatusOK, serializeInbox(inbox))
}
// WhatsAppAuthorization handles Chatwoot's embedded signup callback for
// WhatsApp Cloud channel creation and reauthorization.
// POST /api/v1/accounts/:account_id/whatsapp/authorization
func (h *InboxHandler) WhatsAppAuthorization(c *gin.Context) {
accountID, err := parseUintParam(c, "account_id")
if err != nil {
response.AbortWithStatusError(c, http.StatusBadRequest, response.ErrBadRequest, "invalid account_id")
return
}
var req service.WhatsAppAuthorizationRequest
if err := c.ShouldBind(&req); err != nil {
c.JSON(http.StatusUnprocessableEntity, gin.H{"success": false, "error": err.Error()})
return
}
result, svcErr := h.svc.AuthorizeWhatsAppEmbeddedSignup(c.Request.Context(), accountID, req)
if svcErr != nil {
status := http.StatusUnprocessableEntity
if req.InboxID != nil && strings.Contains(strings.ToLower(svcErr.Error()), "record not found") {
status = http.StatusNotFound
}
c.JSON(status, gin.H{"success": false, "error": svcErr.Error()})
return
}
payload := gin.H{
"success": true,
"id": result.Inbox.ID,
"name": result.Inbox.Name,
"channel_type": "whatsapp",
}
if result.Message != "" {
payload["message"] = result.Message
}
c.JSON(http.StatusOK, payload)
}
// @Summary Update an inbox
// @Description Updates an existing inbox's configuration
// @Tags Inboxes