Add whatsapp feature

This commit is contained in:
Urtzi Alfaro
2025-11-13 16:01:08 +01:00
parent d7df2b0853
commit 9bc048d360
74 changed files with 9765 additions and 533 deletions

View File

@@ -14,6 +14,7 @@ from app.api.notifications import router as notification_router
from app.api.notification_operations import router as notification_operations_router
from app.api.analytics import router as analytics_router
from app.api.audit import router as audit_router
from app.api.whatsapp_webhooks import router as whatsapp_webhooks_router
from app.services.messaging import setup_messaging, cleanup_messaging
from app.services.sse_service import SSEService
from app.services.notification_orchestrator import NotificationOrchestrator
@@ -21,13 +22,14 @@ from app.services.email_service import EmailService
from app.services.whatsapp_service import WhatsAppService
from app.consumers.po_event_consumer import POEventConsumer
from shared.service_base import StandardFastAPIService
from shared.clients.tenant_client import TenantServiceClient
import asyncio
class NotificationService(StandardFastAPIService):
"""Notification Service with standardized setup"""
expected_migration_version = "359991e24ea2"
expected_migration_version = "whatsapp001"
async def verify_migrations(self):
"""Verify database schema matches the latest migrations."""
@@ -47,13 +49,14 @@ class NotificationService(StandardFastAPIService):
# Define expected database tables for health checks
notification_expected_tables = [
'notifications', 'notification_templates', 'notification_preferences',
'notification_logs', 'email_templates', 'whatsapp_templates'
'notification_logs', 'email_templates', 'whatsapp_messages', 'whatsapp_templates'
]
self.sse_service = None
self.orchestrator = None
self.email_service = None
self.whatsapp_service = None
self.tenant_client = None
self.po_consumer = None
self.po_consumer_task = None
@@ -172,9 +175,13 @@ class NotificationService(StandardFastAPIService):
# Call parent startup (includes database, messaging, etc.)
await super().on_startup(app)
# Initialize tenant client for fetching tenant-specific settings
self.tenant_client = TenantServiceClient(settings)
self.logger.info("Tenant service client initialized")
# Initialize services
self.email_service = EmailService()
self.whatsapp_service = WhatsAppService()
self.whatsapp_service = WhatsAppService(tenant_client=self.tenant_client)
# Initialize SSE service
self.sse_service = SSEService()
@@ -195,7 +202,10 @@ class NotificationService(StandardFastAPIService):
app.state.whatsapp_service = self.whatsapp_service
# Initialize and start PO event consumer
self.po_consumer = POEventConsumer(self.email_service)
self.po_consumer = POEventConsumer(
email_service=self.email_service,
whatsapp_service=self.whatsapp_service
)
# Start consuming PO approved events in background
# Use the global notification_publisher from messaging module
@@ -284,6 +294,7 @@ service.setup_custom_endpoints()
# IMPORTANT: Register audit router FIRST to avoid route matching conflicts
# where {notification_id} would match literal paths like "audit-logs"
service.add_router(audit_router, tags=["audit-logs"])
service.add_router(whatsapp_webhooks_router, tags=["whatsapp-webhooks"])
service.add_router(notification_operations_router, tags=["notification-operations"])
service.add_router(analytics_router, tags=["notifications-analytics"])
service.add_router(notification_router, tags=["notifications"])