Spaces:
Running

axeronis commited on
Commit
2eb43c8
·
1 Parent(s): b944d36

feat: add DELETE /meta/whatsapp/disconnect endpoint

Browse files
Files changed (1) hide show
  1. backend/app/api/channels.py +29 -1
backend/app/api/channels.py CHANGED
@@ -329,7 +329,6 @@ async def disconnect_linkedin(
329
 
330
  # ==================== WHATSAPP CLOUD API ENDPOINTS ====================
331
 
332
- # Alias for /meta/whatsapp/status (frontend compatibility)
333
  @router.get("/meta/whatsapp/status")
334
  async def get_meta_whatsapp_status(
335
  current_user: User = Depends(get_current_user),
@@ -339,6 +338,35 @@ async def get_meta_whatsapp_status(
339
  return await get_whatsapp_status(current_user, session)
340
 
341
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
342
  class WhatsAppConnectRequest(BaseModel):
343
  """WhatsApp Cloud API connection request."""
344
  access_token: str
 
329
 
330
  # ==================== WHATSAPP CLOUD API ENDPOINTS ====================
331
 
 
332
  @router.get("/meta/whatsapp/status")
333
  async def get_meta_whatsapp_status(
334
  current_user: User = Depends(get_current_user),
 
338
  return await get_whatsapp_status(current_user, session)
339
 
340
 
341
+ @router.delete("/meta/whatsapp/disconnect")
342
+ async def disconnect_meta_whatsapp(
343
+ current_user: User = Depends(get_current_user),
344
+ session = Depends(get_session)
345
+ ):
346
+ """Disconnect Meta WhatsApp Cloud API."""
347
+ try:
348
+ tenant_id = current_user.tenant_id
349
+
350
+ tenant = await session.get(Tenant, tenant_id)
351
+ if not tenant:
352
+ raise HTTPException(status_code=404, detail="Tenant not found")
353
+
354
+ # Clear WhatsApp config
355
+ tenant.meta_wa_config = None
356
+ tenant.whatsapp_connected = False
357
+
358
+ session.add(tenant)
359
+ await session.commit()
360
+
361
+ logger.info(f"WhatsApp disconnected for tenant {tenant_id}")
362
+
363
+ return {"ok": True, "status": "disconnected", "message": "WhatsApp успешно отключен"}
364
+
365
+ except Exception as e:
366
+ logger.error(f"Failed to disconnect WhatsApp: {e}")
367
+ raise HTTPException(status_code=500, detail=str(e))
368
+
369
+
370
  class WhatsAppConnectRequest(BaseModel):
371
  """WhatsApp Cloud API connection request."""
372
  access_token: str