wappa 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of wappa might be problematic. Click here for more details.
- wappa/__init__.py +85 -0
- wappa/api/__init__.py +1 -0
- wappa/api/controllers/__init__.py +10 -0
- wappa/api/controllers/webhook_controller.py +441 -0
- wappa/api/dependencies/__init__.py +15 -0
- wappa/api/dependencies/whatsapp_dependencies.py +220 -0
- wappa/api/dependencies/whatsapp_media_dependencies.py +26 -0
- wappa/api/middleware/__init__.py +7 -0
- wappa/api/middleware/error_handler.py +158 -0
- wappa/api/middleware/owner.py +99 -0
- wappa/api/middleware/request_logging.py +184 -0
- wappa/api/routes/__init__.py +6 -0
- wappa/api/routes/health.py +102 -0
- wappa/api/routes/webhooks.py +211 -0
- wappa/api/routes/whatsapp/__init__.py +15 -0
- wappa/api/routes/whatsapp/whatsapp_interactive.py +429 -0
- wappa/api/routes/whatsapp/whatsapp_media.py +440 -0
- wappa/api/routes/whatsapp/whatsapp_messages.py +195 -0
- wappa/api/routes/whatsapp/whatsapp_specialized.py +516 -0
- wappa/api/routes/whatsapp/whatsapp_templates.py +431 -0
- wappa/api/routes/whatsapp_combined.py +35 -0
- wappa/cli/__init__.py +9 -0
- wappa/cli/main.py +199 -0
- wappa/core/__init__.py +6 -0
- wappa/core/config/__init__.py +5 -0
- wappa/core/config/settings.py +161 -0
- wappa/core/events/__init__.py +41 -0
- wappa/core/events/default_handlers.py +642 -0
- wappa/core/events/event_dispatcher.py +244 -0
- wappa/core/events/event_handler.py +247 -0
- wappa/core/events/webhook_factory.py +219 -0
- wappa/core/factory/__init__.py +15 -0
- wappa/core/factory/plugin.py +68 -0
- wappa/core/factory/wappa_builder.py +326 -0
- wappa/core/logging/__init__.py +5 -0
- wappa/core/logging/context.py +100 -0
- wappa/core/logging/logger.py +343 -0
- wappa/core/plugins/__init__.py +34 -0
- wappa/core/plugins/auth_plugin.py +169 -0
- wappa/core/plugins/cors_plugin.py +128 -0
- wappa/core/plugins/custom_middleware_plugin.py +182 -0
- wappa/core/plugins/database_plugin.py +235 -0
- wappa/core/plugins/rate_limit_plugin.py +183 -0
- wappa/core/plugins/redis_plugin.py +224 -0
- wappa/core/plugins/wappa_core_plugin.py +261 -0
- wappa/core/plugins/webhook_plugin.py +253 -0
- wappa/core/types.py +108 -0
- wappa/core/wappa_app.py +546 -0
- wappa/database/__init__.py +18 -0
- wappa/database/adapter.py +107 -0
- wappa/database/adapters/__init__.py +17 -0
- wappa/database/adapters/mysql_adapter.py +187 -0
- wappa/database/adapters/postgresql_adapter.py +169 -0
- wappa/database/adapters/sqlite_adapter.py +174 -0
- wappa/domain/__init__.py +28 -0
- wappa/domain/builders/__init__.py +5 -0
- wappa/domain/builders/message_builder.py +189 -0
- wappa/domain/entities/__init__.py +5 -0
- wappa/domain/enums/messenger_platform.py +123 -0
- wappa/domain/factories/__init__.py +6 -0
- wappa/domain/factories/media_factory.py +450 -0
- wappa/domain/factories/message_factory.py +497 -0
- wappa/domain/factories/messenger_factory.py +244 -0
- wappa/domain/interfaces/__init__.py +32 -0
- wappa/domain/interfaces/base_repository.py +94 -0
- wappa/domain/interfaces/cache_factory.py +85 -0
- wappa/domain/interfaces/cache_interface.py +199 -0
- wappa/domain/interfaces/expiry_repository.py +68 -0
- wappa/domain/interfaces/media_interface.py +311 -0
- wappa/domain/interfaces/messaging_interface.py +523 -0
- wappa/domain/interfaces/pubsub_repository.py +151 -0
- wappa/domain/interfaces/repository_factory.py +108 -0
- wappa/domain/interfaces/shared_state_repository.py +122 -0
- wappa/domain/interfaces/state_repository.py +123 -0
- wappa/domain/interfaces/tables_repository.py +215 -0
- wappa/domain/interfaces/user_repository.py +114 -0
- wappa/domain/interfaces/webhooks/__init__.py +1 -0
- wappa/domain/models/media_result.py +110 -0
- wappa/domain/models/platforms/__init__.py +15 -0
- wappa/domain/models/platforms/platform_config.py +104 -0
- wappa/domain/services/__init__.py +11 -0
- wappa/domain/services/tenant_credentials_service.py +56 -0
- wappa/messaging/__init__.py +7 -0
- wappa/messaging/whatsapp/__init__.py +1 -0
- wappa/messaging/whatsapp/client/__init__.py +5 -0
- wappa/messaging/whatsapp/client/whatsapp_client.py +417 -0
- wappa/messaging/whatsapp/handlers/__init__.py +13 -0
- wappa/messaging/whatsapp/handlers/whatsapp_interactive_handler.py +653 -0
- wappa/messaging/whatsapp/handlers/whatsapp_media_handler.py +579 -0
- wappa/messaging/whatsapp/handlers/whatsapp_specialized_handler.py +434 -0
- wappa/messaging/whatsapp/handlers/whatsapp_template_handler.py +416 -0
- wappa/messaging/whatsapp/messenger/__init__.py +5 -0
- wappa/messaging/whatsapp/messenger/whatsapp_messenger.py +904 -0
- wappa/messaging/whatsapp/models/__init__.py +61 -0
- wappa/messaging/whatsapp/models/basic_models.py +65 -0
- wappa/messaging/whatsapp/models/interactive_models.py +287 -0
- wappa/messaging/whatsapp/models/media_models.py +215 -0
- wappa/messaging/whatsapp/models/specialized_models.py +304 -0
- wappa/messaging/whatsapp/models/template_models.py +261 -0
- wappa/persistence/cache_factory.py +93 -0
- wappa/persistence/json/__init__.py +14 -0
- wappa/persistence/json/cache_adapters.py +271 -0
- wappa/persistence/json/handlers/__init__.py +1 -0
- wappa/persistence/json/handlers/state_handler.py +250 -0
- wappa/persistence/json/handlers/table_handler.py +263 -0
- wappa/persistence/json/handlers/user_handler.py +213 -0
- wappa/persistence/json/handlers/utils/__init__.py +1 -0
- wappa/persistence/json/handlers/utils/file_manager.py +153 -0
- wappa/persistence/json/handlers/utils/key_factory.py +11 -0
- wappa/persistence/json/handlers/utils/serialization.py +121 -0
- wappa/persistence/json/json_cache_factory.py +76 -0
- wappa/persistence/json/storage_manager.py +285 -0
- wappa/persistence/memory/__init__.py +14 -0
- wappa/persistence/memory/cache_adapters.py +271 -0
- wappa/persistence/memory/handlers/__init__.py +1 -0
- wappa/persistence/memory/handlers/state_handler.py +250 -0
- wappa/persistence/memory/handlers/table_handler.py +280 -0
- wappa/persistence/memory/handlers/user_handler.py +213 -0
- wappa/persistence/memory/handlers/utils/__init__.py +1 -0
- wappa/persistence/memory/handlers/utils/key_factory.py +11 -0
- wappa/persistence/memory/handlers/utils/memory_store.py +317 -0
- wappa/persistence/memory/handlers/utils/ttl_manager.py +235 -0
- wappa/persistence/memory/memory_cache_factory.py +76 -0
- wappa/persistence/memory/storage_manager.py +235 -0
- wappa/persistence/redis/README.md +699 -0
- wappa/persistence/redis/__init__.py +11 -0
- wappa/persistence/redis/cache_adapters.py +285 -0
- wappa/persistence/redis/ops.py +880 -0
- wappa/persistence/redis/redis_cache_factory.py +71 -0
- wappa/persistence/redis/redis_client.py +231 -0
- wappa/persistence/redis/redis_handler/__init__.py +26 -0
- wappa/persistence/redis/redis_handler/state_handler.py +176 -0
- wappa/persistence/redis/redis_handler/table.py +158 -0
- wappa/persistence/redis/redis_handler/user.py +138 -0
- wappa/persistence/redis/redis_handler/utils/__init__.py +12 -0
- wappa/persistence/redis/redis_handler/utils/key_factory.py +32 -0
- wappa/persistence/redis/redis_handler/utils/serde.py +146 -0
- wappa/persistence/redis/redis_handler/utils/tenant_cache.py +268 -0
- wappa/persistence/redis/redis_manager.py +189 -0
- wappa/processors/__init__.py +6 -0
- wappa/processors/base_processor.py +262 -0
- wappa/processors/factory.py +550 -0
- wappa/processors/whatsapp_processor.py +810 -0
- wappa/schemas/__init__.py +6 -0
- wappa/schemas/core/__init__.py +71 -0
- wappa/schemas/core/base_message.py +499 -0
- wappa/schemas/core/base_status.py +322 -0
- wappa/schemas/core/base_webhook.py +312 -0
- wappa/schemas/core/types.py +253 -0
- wappa/schemas/core/webhook_interfaces/__init__.py +48 -0
- wappa/schemas/core/webhook_interfaces/base_components.py +293 -0
- wappa/schemas/core/webhook_interfaces/universal_webhooks.py +348 -0
- wappa/schemas/factory.py +754 -0
- wappa/schemas/webhooks/__init__.py +3 -0
- wappa/schemas/whatsapp/__init__.py +6 -0
- wappa/schemas/whatsapp/base_models.py +285 -0
- wappa/schemas/whatsapp/message_types/__init__.py +93 -0
- wappa/schemas/whatsapp/message_types/audio.py +350 -0
- wappa/schemas/whatsapp/message_types/button.py +267 -0
- wappa/schemas/whatsapp/message_types/contact.py +464 -0
- wappa/schemas/whatsapp/message_types/document.py +421 -0
- wappa/schemas/whatsapp/message_types/errors.py +195 -0
- wappa/schemas/whatsapp/message_types/image.py +424 -0
- wappa/schemas/whatsapp/message_types/interactive.py +430 -0
- wappa/schemas/whatsapp/message_types/location.py +416 -0
- wappa/schemas/whatsapp/message_types/order.py +372 -0
- wappa/schemas/whatsapp/message_types/reaction.py +271 -0
- wappa/schemas/whatsapp/message_types/sticker.py +328 -0
- wappa/schemas/whatsapp/message_types/system.py +317 -0
- wappa/schemas/whatsapp/message_types/text.py +411 -0
- wappa/schemas/whatsapp/message_types/unsupported.py +273 -0
- wappa/schemas/whatsapp/message_types/video.py +344 -0
- wappa/schemas/whatsapp/status_models.py +479 -0
- wappa/schemas/whatsapp/validators.py +454 -0
- wappa/schemas/whatsapp/webhook_container.py +438 -0
- wappa/webhooks/__init__.py +17 -0
- wappa/webhooks/core/__init__.py +71 -0
- wappa/webhooks/core/base_message.py +499 -0
- wappa/webhooks/core/base_status.py +322 -0
- wappa/webhooks/core/base_webhook.py +312 -0
- wappa/webhooks/core/types.py +253 -0
- wappa/webhooks/core/webhook_interfaces/__init__.py +48 -0
- wappa/webhooks/core/webhook_interfaces/base_components.py +293 -0
- wappa/webhooks/core/webhook_interfaces/universal_webhooks.py +441 -0
- wappa/webhooks/factory.py +754 -0
- wappa/webhooks/whatsapp/__init__.py +6 -0
- wappa/webhooks/whatsapp/base_models.py +285 -0
- wappa/webhooks/whatsapp/message_types/__init__.py +93 -0
- wappa/webhooks/whatsapp/message_types/audio.py +350 -0
- wappa/webhooks/whatsapp/message_types/button.py +267 -0
- wappa/webhooks/whatsapp/message_types/contact.py +464 -0
- wappa/webhooks/whatsapp/message_types/document.py +421 -0
- wappa/webhooks/whatsapp/message_types/errors.py +195 -0
- wappa/webhooks/whatsapp/message_types/image.py +424 -0
- wappa/webhooks/whatsapp/message_types/interactive.py +430 -0
- wappa/webhooks/whatsapp/message_types/location.py +416 -0
- wappa/webhooks/whatsapp/message_types/order.py +372 -0
- wappa/webhooks/whatsapp/message_types/reaction.py +271 -0
- wappa/webhooks/whatsapp/message_types/sticker.py +328 -0
- wappa/webhooks/whatsapp/message_types/system.py +317 -0
- wappa/webhooks/whatsapp/message_types/text.py +411 -0
- wappa/webhooks/whatsapp/message_types/unsupported.py +273 -0
- wappa/webhooks/whatsapp/message_types/video.py +344 -0
- wappa/webhooks/whatsapp/status_models.py +479 -0
- wappa/webhooks/whatsapp/validators.py +454 -0
- wappa/webhooks/whatsapp/webhook_container.py +438 -0
- wappa-0.1.0.dist-info/METADATA +269 -0
- wappa-0.1.0.dist-info/RECORD +211 -0
- wappa-0.1.0.dist-info/WHEEL +4 -0
- wappa-0.1.0.dist-info/entry_points.txt +2 -0
- wappa-0.1.0.dist-info/licenses/LICENSE +201 -0
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Health check endpoints for the Wappa framework.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
import time
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
from fastapi import APIRouter
|
|
9
|
+
|
|
10
|
+
from wappa.core.config.settings import settings
|
|
11
|
+
from wappa.core.logging.logger import get_api_logger
|
|
12
|
+
|
|
13
|
+
logger = get_api_logger()
|
|
14
|
+
router = APIRouter(tags=["Health"])
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@router.get("/health")
|
|
18
|
+
async def health_check() -> dict[str, Any]:
|
|
19
|
+
"""
|
|
20
|
+
Basic health check endpoint.
|
|
21
|
+
|
|
22
|
+
Returns application status, environment information, and response time.
|
|
23
|
+
"""
|
|
24
|
+
start_time = time.time()
|
|
25
|
+
|
|
26
|
+
# Basic health indicators
|
|
27
|
+
is_healthy = True
|
|
28
|
+
|
|
29
|
+
# Calculate response time
|
|
30
|
+
response_time = time.time() - start_time
|
|
31
|
+
|
|
32
|
+
health_data = {
|
|
33
|
+
"status": "healthy" if is_healthy else "unhealthy",
|
|
34
|
+
"timestamp": time.time(),
|
|
35
|
+
"response_time_ms": round(response_time * 1000, 2),
|
|
36
|
+
"environment": {
|
|
37
|
+
"environment": settings.environment,
|
|
38
|
+
"version": "2.0.0",
|
|
39
|
+
"log_level": settings.log_level,
|
|
40
|
+
"owner_id": settings.owner_id,
|
|
41
|
+
},
|
|
42
|
+
"services": {"logging": "operational", "configuration": "loaded"},
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
logger.info(
|
|
46
|
+
f"Health check completed - Status: {health_data['status']}, "
|
|
47
|
+
f"Response Time: {health_data['response_time_ms']}ms"
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
return health_data
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
@router.get("/health/detailed")
|
|
54
|
+
async def detailed_health_check() -> dict[str, Any]:
|
|
55
|
+
"""
|
|
56
|
+
Detailed health check with configuration information.
|
|
57
|
+
|
|
58
|
+
Useful for debugging and monitoring.
|
|
59
|
+
"""
|
|
60
|
+
start_time = time.time()
|
|
61
|
+
|
|
62
|
+
# Calculate response time
|
|
63
|
+
response_time = time.time() - start_time
|
|
64
|
+
|
|
65
|
+
detailed_data = {
|
|
66
|
+
"status": "healthy",
|
|
67
|
+
"timestamp": time.time(),
|
|
68
|
+
"response_time_ms": round(response_time * 1000, 2),
|
|
69
|
+
"application": {
|
|
70
|
+
"name": "Wappa Framework",
|
|
71
|
+
"version": "2.0.0",
|
|
72
|
+
"environment": settings.environment,
|
|
73
|
+
"is_development": settings.is_development,
|
|
74
|
+
},
|
|
75
|
+
"configuration": {
|
|
76
|
+
"log_level": settings.log_level,
|
|
77
|
+
"log_dir": settings.log_dir,
|
|
78
|
+
"owner_id": settings.owner_id,
|
|
79
|
+
"api_version": settings.api_version,
|
|
80
|
+
"time_zone": settings.time_zone,
|
|
81
|
+
"port": settings.port,
|
|
82
|
+
},
|
|
83
|
+
"platform_configs": {
|
|
84
|
+
"whatsapp": {
|
|
85
|
+
"configured": bool(settings.wp_access_token and settings.wp_phone_id),
|
|
86
|
+
"webhook_token_configured": bool(
|
|
87
|
+
settings.whatsapp_webhook_verify_token
|
|
88
|
+
),
|
|
89
|
+
"phone_id": settings.wp_phone_id,
|
|
90
|
+
"business_id": settings.wp_bid,
|
|
91
|
+
},
|
|
92
|
+
"redis": {
|
|
93
|
+
"configured": settings.has_redis,
|
|
94
|
+
"url": settings.redis_url if settings.has_redis else None,
|
|
95
|
+
},
|
|
96
|
+
"openai": {"configured": bool(settings.openai_api_key)},
|
|
97
|
+
},
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
logger.info("Detailed health check completed")
|
|
101
|
+
|
|
102
|
+
return detailed_data
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Universal webhook routes for the Wappa framework.
|
|
3
|
+
|
|
4
|
+
Provides webhook endpoints that delegate to WebhookController for business logic.
|
|
5
|
+
Routes handle only HTTP concerns (validation, responses) while controller
|
|
6
|
+
handles dependency injection and webhook processing.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from fastapi import APIRouter, HTTPException, Query, Request
|
|
10
|
+
|
|
11
|
+
from wappa.api.controllers import WebhookController
|
|
12
|
+
from wappa.core.events import (
|
|
13
|
+
WappaEventDispatcher,
|
|
14
|
+
WebhookEndpointType,
|
|
15
|
+
webhook_url_factory,
|
|
16
|
+
)
|
|
17
|
+
from wappa.core.logging.logger import get_logger
|
|
18
|
+
from wappa.schemas.core.types import PlatformType
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def create_webhook_router(event_dispatcher: WappaEventDispatcher) -> APIRouter:
|
|
22
|
+
"""
|
|
23
|
+
Create webhook router with controller delegation.
|
|
24
|
+
|
|
25
|
+
This factory function creates the webhook routes that delegate all business logic
|
|
26
|
+
to the WebhookController, maintaining clean separation of concerns.
|
|
27
|
+
|
|
28
|
+
Args:
|
|
29
|
+
event_dispatcher: WappaEventDispatcher instance with user's event handler
|
|
30
|
+
|
|
31
|
+
Returns:
|
|
32
|
+
APIRouter configured with webhook endpoints
|
|
33
|
+
"""
|
|
34
|
+
# Create controller instance for this router
|
|
35
|
+
webhook_controller = WebhookController(event_dispatcher)
|
|
36
|
+
|
|
37
|
+
router = APIRouter(
|
|
38
|
+
prefix="/webhook",
|
|
39
|
+
tags=["Webhooks"],
|
|
40
|
+
responses={
|
|
41
|
+
400: {"description": "Bad Request - Invalid webhook payload"},
|
|
42
|
+
401: {"description": "Unauthorized - Invalid tenant credentials"},
|
|
43
|
+
403: {"description": "Forbidden - Webhook verification failed"},
|
|
44
|
+
500: {"description": "Internal Server Error"},
|
|
45
|
+
},
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
@router.get("/messenger/{platform}/verify")
|
|
49
|
+
async def verify_webhook(
|
|
50
|
+
request: Request,
|
|
51
|
+
platform: str,
|
|
52
|
+
hub_mode: str = Query(None, alias="hub.mode"),
|
|
53
|
+
hub_verify_token: str = Query(None, alias="hub.verify_token"),
|
|
54
|
+
hub_challenge: str = Query(None, alias="hub.challenge"),
|
|
55
|
+
):
|
|
56
|
+
"""
|
|
57
|
+
Handle webhook verification (challenge-response) for messaging platforms.
|
|
58
|
+
|
|
59
|
+
Delegates all business logic to WebhookController while handling HTTP concerns.
|
|
60
|
+
|
|
61
|
+
Args:
|
|
62
|
+
request: FastAPI request object
|
|
63
|
+
platform: The messaging platform (whatsapp, telegram, teams, instagram)
|
|
64
|
+
hub_mode: Verification mode (usually "subscribe")
|
|
65
|
+
hub_verify_token: Token provided by platform for verification
|
|
66
|
+
hub_challenge: Challenge string to return if verification succeeds
|
|
67
|
+
|
|
68
|
+
Returns:
|
|
69
|
+
PlainTextResponse with challenge string if verification succeeds
|
|
70
|
+
"""
|
|
71
|
+
# Delegate to controller (handles business logic and tenant extraction)
|
|
72
|
+
return await webhook_controller.verify_webhook(
|
|
73
|
+
request=request,
|
|
74
|
+
platform=platform,
|
|
75
|
+
hub_mode=hub_mode,
|
|
76
|
+
hub_verify_token=hub_verify_token,
|
|
77
|
+
hub_challenge=hub_challenge,
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
@router.get("/messenger/{tenant_id}/{platform}")
|
|
81
|
+
async def verify_webhook_at_tenant_url(
|
|
82
|
+
request: Request,
|
|
83
|
+
tenant_id: str,
|
|
84
|
+
platform: str,
|
|
85
|
+
hub_mode: str = Query(None, alias="hub.mode"),
|
|
86
|
+
hub_verify_token: str = Query(None, alias="hub.verify_token"),
|
|
87
|
+
hub_challenge: str = Query(None, alias="hub.challenge"),
|
|
88
|
+
):
|
|
89
|
+
"""
|
|
90
|
+
Handle webhook verification at the same URL used for processing.
|
|
91
|
+
|
|
92
|
+
WhatsApp and other platforms send verification requests to the same URL
|
|
93
|
+
they use for webhook processing. This handles GET requests with verification.
|
|
94
|
+
"""
|
|
95
|
+
# Delegate to controller (tenant_id will be extracted from URL by middleware)
|
|
96
|
+
return await webhook_controller.verify_webhook(
|
|
97
|
+
request=request,
|
|
98
|
+
platform=platform,
|
|
99
|
+
hub_mode=hub_mode,
|
|
100
|
+
hub_verify_token=hub_verify_token,
|
|
101
|
+
hub_challenge=hub_challenge,
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
@router.post("/messenger/{tenant_id}/{platform}")
|
|
105
|
+
async def process_webhook(
|
|
106
|
+
request: Request,
|
|
107
|
+
tenant_id: str,
|
|
108
|
+
platform: str,
|
|
109
|
+
):
|
|
110
|
+
"""
|
|
111
|
+
Process incoming webhook payload from a messaging platform.
|
|
112
|
+
|
|
113
|
+
Delegates business logic to WebhookController while handling HTTP concerns.
|
|
114
|
+
The controller creates per-request dependencies with correct tenant isolation.
|
|
115
|
+
|
|
116
|
+
Args:
|
|
117
|
+
request: FastAPI request object
|
|
118
|
+
tenant_id: Tenant identifier for multi-tenant support (extracted by middleware)
|
|
119
|
+
platform: The messaging platform (whatsapp, telegram, teams, instagram)
|
|
120
|
+
|
|
121
|
+
Returns:
|
|
122
|
+
Dict with status confirmation
|
|
123
|
+
"""
|
|
124
|
+
# Parse JSON payload (HTTP concern - handled in route)
|
|
125
|
+
try:
|
|
126
|
+
payload = await request.json()
|
|
127
|
+
except Exception as e:
|
|
128
|
+
logger = get_logger(__name__)
|
|
129
|
+
logger.error(f"Failed to parse webhook payload: {e}")
|
|
130
|
+
raise HTTPException(status_code=400, detail="Invalid JSON payload") from e
|
|
131
|
+
|
|
132
|
+
# Delegate to controller (handles all business logic and dependency injection)
|
|
133
|
+
return await webhook_controller.process_webhook(
|
|
134
|
+
request=request,
|
|
135
|
+
platform=platform,
|
|
136
|
+
payload=payload,
|
|
137
|
+
)
|
|
138
|
+
|
|
139
|
+
@router.get("/messenger/{tenant_id}/{platform}/status")
|
|
140
|
+
async def webhook_status(
|
|
141
|
+
request: Request,
|
|
142
|
+
tenant_id: str,
|
|
143
|
+
platform: str,
|
|
144
|
+
):
|
|
145
|
+
"""
|
|
146
|
+
Get webhook status and configuration for a specific platform.
|
|
147
|
+
|
|
148
|
+
Useful for debugging and monitoring webhook health.
|
|
149
|
+
|
|
150
|
+
Args:
|
|
151
|
+
request: FastAPI request object
|
|
152
|
+
tenant_id: Tenant identifier
|
|
153
|
+
platform: The messaging platform
|
|
154
|
+
|
|
155
|
+
Returns:
|
|
156
|
+
Dict with webhook status information
|
|
157
|
+
"""
|
|
158
|
+
logger = get_logger(__name__)
|
|
159
|
+
logger.info(f"Status check for {platform} webhook - tenant: {tenant_id}")
|
|
160
|
+
|
|
161
|
+
# Generate webhook URLs for this platform and tenant
|
|
162
|
+
try:
|
|
163
|
+
platform_type = PlatformType(platform.lower())
|
|
164
|
+
except ValueError:
|
|
165
|
+
raise HTTPException(
|
|
166
|
+
status_code=400, detail=f"Unsupported platform: {platform}"
|
|
167
|
+
)
|
|
168
|
+
|
|
169
|
+
webhook_url = webhook_url_factory.generate_webhook_url(platform_type, tenant_id)
|
|
170
|
+
verify_url = webhook_url_factory.generate_webhook_url(
|
|
171
|
+
platform_type, "", WebhookEndpointType.VERIFY
|
|
172
|
+
)
|
|
173
|
+
|
|
174
|
+
# Get controller health status
|
|
175
|
+
controller_status = webhook_controller.get_health_status()
|
|
176
|
+
|
|
177
|
+
return {
|
|
178
|
+
"status": "active",
|
|
179
|
+
"platform": platform,
|
|
180
|
+
"tenant_id": tenant_id,
|
|
181
|
+
"webhook_url": webhook_url,
|
|
182
|
+
"verify_url": verify_url,
|
|
183
|
+
"controller_status": controller_status,
|
|
184
|
+
"supported_platforms": [p.value.lower() for p in PlatformType],
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
@router.get("/platforms")
|
|
188
|
+
async def list_supported_platforms():
|
|
189
|
+
"""
|
|
190
|
+
List all supported platforms and their webhook patterns.
|
|
191
|
+
|
|
192
|
+
Returns:
|
|
193
|
+
Dict with all supported platforms and URL patterns
|
|
194
|
+
"""
|
|
195
|
+
patterns = webhook_url_factory.get_supported_platforms()
|
|
196
|
+
|
|
197
|
+
return {
|
|
198
|
+
"supported_platforms": list(patterns.keys()),
|
|
199
|
+
"platform_details": patterns,
|
|
200
|
+
"webhook_pattern": "/webhook/messenger/{tenant_id}/{platform}",
|
|
201
|
+
"verify_pattern": "/webhook/messenger/{platform}/verify",
|
|
202
|
+
"features": [
|
|
203
|
+
"Challenge-response verification",
|
|
204
|
+
"Multi-platform support",
|
|
205
|
+
"Multi-tenant support",
|
|
206
|
+
"Event dispatcher routing",
|
|
207
|
+
"Default status/error handling",
|
|
208
|
+
],
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
return router
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"""WhatsApp API routes package."""
|
|
2
|
+
|
|
3
|
+
from .whatsapp_interactive import router as whatsapp_interactive_router
|
|
4
|
+
from .whatsapp_media import router as whatsapp_media_router
|
|
5
|
+
from .whatsapp_messages import router as whatsapp_messages_router
|
|
6
|
+
from .whatsapp_specialized import router as whatsapp_specialized_router
|
|
7
|
+
from .whatsapp_templates import router as whatsapp_templates_router
|
|
8
|
+
|
|
9
|
+
__all__ = [
|
|
10
|
+
"whatsapp_messages_router",
|
|
11
|
+
"whatsapp_media_router",
|
|
12
|
+
"whatsapp_interactive_router",
|
|
13
|
+
"whatsapp_templates_router",
|
|
14
|
+
"whatsapp_specialized_router",
|
|
15
|
+
]
|