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>
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
from app.routers.odoo import router as odoo_router
|
||||
from app.routers.sync import router as sync_router
|
||||
|
||||
__all__ = ["odoo_router"]
|
||||
__all__ = ["odoo_router", "sync_router"]
|
||||
|
||||
48
services/integrations/app/routers/sync.py
Normal file
48
services/integrations/app/routers/sync.py
Normal file
@@ -0,0 +1,48 @@
|
||||
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))
|
||||
Reference in New Issue
Block a user