Files
WhatsAppCentralizado/services/integrations/app/routers/sync.py
Claude AI 95cd70af1f feat(integrations): add contact sync service
Add bidirectional contact synchronization between WhatsApp Central and Odoo,
including sync endpoints and ContactSyncService.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-29 22:26:18 +00:00

49 lines
1.4 KiB
Python

from fastapi import APIRouter, HTTPException
from pydantic import BaseModel
from typing import Optional
from app.services.sync import ContactSyncService
router = APIRouter(prefix="/api/sync", tags=["sync"])
class SyncContactRequest(BaseModel):
contact_id: str
phone: str
name: Optional[str] = None
email: Optional[str] = None
@router.post("/contact-to-odoo")
async def sync_contact_to_odoo(request: SyncContactRequest):
"""Sync WhatsApp contact to Odoo partner"""
try:
service = ContactSyncService()
partner_id = await service.sync_contact_to_odoo(
contact_id=request.contact_id,
phone=request.phone,
name=request.name,
email=request.email,
)
if partner_id:
return {"success": True, "odoo_partner_id": partner_id}
raise HTTPException(500, "Failed to sync contact")
except Exception as e:
raise HTTPException(500, str(e))
@router.post("/partner-to-contact/{partner_id}")
async def sync_partner_to_contact(partner_id: int):
"""Sync Odoo partner to WhatsApp contact"""
try:
service = ContactSyncService()
contact_id = await service.sync_partner_to_contact(partner_id)
return {
"success": True,
"contact_id": contact_id,
"message": "Contact found" if contact_id else "No matching contact",
}
except Exception as e:
raise HTTPException(500, str(e))